tSimply verifier now network is in-process - electrum - Electrum Bitcoin wallet (HTM) git clone https://git.parazyd.org/electrum (DIR) Log (DIR) Files (DIR) Refs (DIR) Submodules --- (DIR) commit be7cb011a3e17c83e110f827026fd6a9b6859a9e (DIR) parent be8a87c322cfdb82cd0f84816726cd78881536d4 (HTM) Author: Neil Booth <kyuupichan@gmail.com> Date: Mon, 31 Aug 2015 18:12:02 +0900 Simply verifier now network is in-process Diffstat: M lib/verifier.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) --- (DIR) diff --git a/lib/verifier.py b/lib/verifier.py t@@ -40,31 +40,25 @@ class SPV(ThreadJob): if tx_hash not in self.merkle_roots and tx_height <= lh: request = ('blockchain.transaction.get_merkle', [tx_hash, tx_height]) - self.network.send([request], self.merkle_response) + self.network.send([request], self.verify_merkle) self.print_error('requested merkle', tx_hash) self.merkle_roots[tx_hash] = None - def merkle_response(self, r): + def verify_merkle(self, r): if r.get('error'): self.print_error('received an error:', r) return params = r['params'] - result = r['result'] + merkle = r['result'] - # Get the header asynchronously - as a thread job we cannot block + # Verify the hash of the server-provided merkle branch to a + # transaction matches the merkle root of its block tx_hash = params[0] - request = ('network.get_header',[result.get('block_height')]) - self.network.send([request], partial(self.verify, tx_hash, result)) - - def verify(self, tx_hash, merkle, header): - '''Verify the hash of the server-provided merkle branch to a - transaction matches the merkle root of its block - ''' tx_height = merkle.get('block_height') pos = merkle.get('pos') merkle_root = self.hash_merkle_root(merkle['merkle'], tx_hash, pos) - header = header.get('result') + header = self.network.get_header(tx_height) if not header or header.get('merkle_root') != merkle_root: # FIXME: we should make a fresh connection to a server to # recover from this, as this TX will now never verify