electrum

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

commit 4e4d4d33c3bf6dc9fe8ebeabe3ecf6566f0bfbcd
parent e0c03d6207c39b78a1e07e78133b1c1e3324442b
Author: ThomasV <thomasv@gitorious>
Date:   Sun,  4 Nov 2012 17:17:40 +0100

fix race condition with prevout_values

Diffstat:
Mlib/wallet.py | 36+++++++++++++++++-------------------
1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/lib/wallet.py b/lib/wallet.py @@ -372,24 +372,22 @@ class Wallet: def get_tx_value(self, tx_hash, addresses = None): # return the balance for that tx if addresses is None: addresses = self.all_addresses() - v = 0 - d = self.transactions.get(tx_hash) - if not d: return 0 - - for item in d.get('inputs'): - addr = item.get('address') - if addr in addresses: - key = item['prevout_hash'] + ':%d'%item['prevout_n'] - value = self.prevout_values[ key ] - v -= value - - for item in d.get('outputs'): - addr = item.get('address') - if addr in addresses: - value = item.get('value') - v += value - - return v + with self.lock: + v = 0 + d = self.transactions.get(tx_hash) + if not d: return 0 + for item in d.get('inputs'): + addr = item.get('address') + if addr in addresses: + key = item['prevout_hash'] + ':%d'%item['prevout_n'] + value = self.prevout_values[ key ] + v -= value + for item in d.get('outputs'): + addr = item.get('address') + if addr in addresses: + value = item.get('value') + v += value + return v @@ -541,9 +539,9 @@ class Wallet: #print "updating history for", addr with self.lock: self.transactions[tx_hash] = d + self.update_tx_outputs(tx_hash) if self.verifier: self.verifier.add(tx_hash) - self.update_tx_outputs(tx_hash) self.save()