electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 75ddc066bb84c5b2d05753884b9871c39f582548
parent df73b8017a3a367f85ad8a8f7012fa80ab77415d
Author: ThomasV <thomasv@gitorious>
Date:   Sat,  2 May 2015 11:05:38 +0200

fix #1181

Diffstat:
Mlib/wallet.py | 49++++++++++++++++++++++---------------------------
1 file changed, 22 insertions(+), 27 deletions(-)

diff --git a/lib/wallet.py b/lib/wallet.py @@ -462,39 +462,45 @@ class Abstract_Wallet(object): fee = v_out - v_in return is_relevant, is_send, v, fee - def get_addr_utxo(self, address): + def get_addr_io(self, address): h = self.history.get(address, []) - coins = {} + received = {} + sent = {} for tx_hash, height in h: l = self.txo.get(tx_hash, {}).get(address, []) for n, v, is_cb in l: - coins[tx_hash + ':%d'%n] = (height, v, is_cb) + received[tx_hash + ':%d'%n] = (height, v, is_cb) for tx_hash, height in h: l = self.txi.get(tx_hash, {}).get(address, []) for txi, v in l: - coins.pop(txi) + sent[txi] = height + return received, sent + + def get_addr_utxo(self, address): + coins, spent = self.get_addr_io(address) + for txi in spent: + coins.pop(txi) return coins.items() - #return the total amount ever received by an address + # return the total amount ever received by an address def get_addr_received(self, address): - h = self.history.get(address, []) - received = 0 - for tx_hash, height in h: - l = self.txo.get(tx_hash, {}).get(address, []) - for n, v, is_cb in l: - received += v - return received + received, sent = self.get_addr_io(address) + return sum([v for height, v, is_cb in received.values()]) + # return the confirmed balance and pending (unconfirmed) balance change of a bitcoin address def get_addr_balance(self, address): - "returns the confirmed balance and pending (unconfirmed) balance change of a bitcoin address" - coins = self.get_addr_utxo(address) + received, sent = self.get_addr_io(address) c = u = 0 - for txo, v in coins: - tx_height, v, is_cb = v + for txo, (tx_height, v, is_cb) in received.items(): if tx_height > 0: c += v else: u += v + if txo in sent: + if sent[txo] > 0: + c -= v + else: + u -= v return c, u @@ -525,17 +531,6 @@ class Abstract_Wallet(object): coins = coins[1:] + [ coins[0] ] return [value for height, value in coins] - def get_addr_balance2(self, address): - "returns the confirmed balance and pending (unconfirmed) balance change of a bitcoin address" - coins = self.get_addr_utxo(address) - c = u = 0 - for txo, v, height in coins: - if height > 0: - c += v - else: - u += v - return c, u - def get_account_name(self, k): return self.labels.get(k, self.accounts[k].get_name(k))