remove blockchain object from verifier

This commit is contained in:
ThomasV 2014-03-10 20:53:05 +01:00
parent 6e30894af6
commit b4bed1ccaa
2 changed files with 9 additions and 3 deletions

View File

@ -402,6 +402,13 @@ class Network(threading.Thread):
return self.interface.synchronous_get(requests) return self.interface.synchronous_get(requests)
def get_header(self, tx_height):
return self.blockchain.read_header(tx_height)
def get_local_height(self):
return self.blockchain.local_height
#def retrieve_transaction(self, tx_hash, tx_height=0): #def retrieve_transaction(self, tx_hash, tx_height=0):
# import transaction # import transaction

View File

@ -32,7 +32,6 @@ class TxVerifier(threading.Thread):
self.daemon = True self.daemon = True
self.storage = storage self.storage = storage
self.network = network self.network = network
self.blockchain = network.blockchain
self.transactions = {} # requested verifications (with height sent by the requestor) self.transactions = {} # requested verifications (with height sent by the requestor)
self.verified_tx = storage.get('verified_tx3',{}) # height, timestamp of verified transactions self.verified_tx = storage.get('verified_tx3',{}) # height, timestamp of verified transactions
self.merkle_roots = storage.get('merkle_roots',{}) # hashed by me self.merkle_roots = storage.get('merkle_roots',{}) # hashed by me
@ -46,7 +45,7 @@ class TxVerifier(threading.Thread):
with self.lock: with self.lock:
if tx in self.verified_tx: if tx in self.verified_tx:
height, timestamp, pos = self.verified_tx[tx] height, timestamp, pos = self.verified_tx[tx]
conf = (self.blockchain.local_height - height + 1) conf = (self.network.get_local_height() - height + 1)
if conf <= 0: timestamp = None if conf <= 0: timestamp = None
elif tx in self.transactions: elif tx in self.transactions:
@ -134,7 +133,7 @@ class TxVerifier(threading.Thread):
tx_height = result.get('block_height') tx_height = result.get('block_height')
pos = result.get('pos') pos = result.get('pos')
self.merkle_roots[tx_hash] = self.hash_merkle_root(result['merkle'], tx_hash, pos) self.merkle_roots[tx_hash] = self.hash_merkle_root(result['merkle'], tx_hash, pos)
header = self.blockchain.read_header(tx_height) header = self.network.get_header(tx_height)
if not header: return if not header: return
assert header.get('merkle_root') == self.merkle_roots[tx_hash] assert header.get('merkle_root') == self.merkle_roots[tx_hash]
# we passed all the tests # we passed all the tests