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:
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
# 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')
# 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