1
0

rely only on the verifier to get the height of transactions

This commit is contained in:
thomasv
2013-03-14 12:22:06 +01:00
parent bdb515dabd
commit 3b80ef7c60
2 changed files with 21 additions and 38 deletions

View File

@@ -49,14 +49,10 @@ class WalletVerifier(threading.Thread):
def get_confirmations(self, tx):
""" return the number of confirmations of a monitored transaction. """
with self.lock:
if tx in self.transactions.keys():
if tx in self.verified_tx:
height, timestamp = self.verified_tx[tx]
conf = (self.local_height - height + 1)
else:
conf = -1
if tx in self.verified_tx:
height, timestamp = self.verified_tx[tx]
conf = (self.local_height - height + 1)
else:
#print "verifier: tx not in list", tx
conf = 0
if conf <= 0:
@@ -65,6 +61,13 @@ class WalletVerifier(threading.Thread):
return conf, timestamp
def get_height(self, tx_hash):
with self.lock:
v = self.verified_tx.get(tx_hash)
height = v[0] if v else None
return height
def add(self, tx_hash, tx_height):
""" add a transaction to the list of monitored transactions. """
assert tx_height > 0
@@ -187,7 +190,8 @@ class WalletVerifier(threading.Thread):
# we passed all the tests
header = self.read_header(tx_height)
timestamp = header.get('timestamp')
self.verified_tx[tx_hash] = (tx_height, timestamp)
with self.lock:
self.verified_tx[tx_hash] = (tx_height, timestamp)
print_error("verified %s"%tx_hash)
self.config.set_key('verified_tx2', self.verified_tx, True)
self.interface.trigger_callback('updated')
@@ -245,12 +249,16 @@ class WalletVerifier(threading.Thread):
# this can be caused by a reorg.
print_error("verify header failed"+ repr(header))
# undo verifications
for tx_hash, item in self.verified_tx.items():
with self.lock:
items = self.verified_tx.items()[:]
for tx_hash, item in items:
tx_height, timestamp = item
if tx_height >= height:
print_error("redoing", tx_hash)
self.verified_tx.pop(tx_hash)
if tx_hash in self.merkle_roots: self.merkle_roots.pop(tx_hash)
with self.lock:
self.verified_tx.pop(tx_hash)
if tx_hash in self.merkle_roots:
self.merkle_roots.pop(tx_hash)
# return False to request previous header.
return False