tprotocol v0.4: use position for branching - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 1e15dbab814b98bbd3d0abacb7a329f7a84c0103 DIR parent ee84e5c007d236f5087ea2dd1d2abe9eef3450b0 HTML Author: thomasv <thomasv@gitorious> Date: Fri, 26 Oct 2012 11:29:11 +0200 protocol v0.4: use position for branching Diffstat: M lib/verifier.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) --- DIR diff --git a/lib/verifier.py b/lib/verifier.py t@@ -144,7 +144,7 @@ class WalletVerifier(threading.Thread): def verify_merkle(self, tx_hash, result): tx_height = result.get('block_height') - self.merkle_roots[tx_hash] = self.hash_merkle_root(result['merkle'], tx_hash) + self.merkle_roots[tx_hash] = self.hash_merkle_root(result['merkle'], tx_hash, result.get('pos')) header = self.read_header(tx_height) if header: assert header.get('merkle_root') == self.merkle_roots[tx_hash] t@@ -239,16 +239,14 @@ class WalletVerifier(threading.Thread): h['nonce'] = hex_to_int(s[76:80]) return h - def hash_header(self, header): return rev_hex(Hash(self.header_to_string(header).decode('hex')).encode('hex')) - - def hash_merkle_root(self, merkle_s, target_hash): + def hash_merkle_root(self, merkle_s, target_hash, pos): h = hash_decode(target_hash) - for item in merkle_s: - is_left = item[0] == 'L' - h = Hash( h + hash_decode(item[1:]) ) if is_left else Hash( hash_decode(item[1:]) + h ) + for i in range(len(merkle_s)): + item = merkle_s[i] + h = Hash( hash_decode(item) + h ) if ((pos >> i) & 1) else Hash( h + hash_decode(item) ) return hash_encode(h) def path(self):