fix race condition with prevout_values

This commit is contained in:
ThomasV 2012-11-04 17:17:40 +01:00
parent e0c03d6207
commit 4e4d4d33c3
1 changed files with 17 additions and 19 deletions

View File

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