X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=backends%2Fbitcoind%2Fdeserialize.py;h=75cbc3e7a9af473c62493db662d7f16a0adbd2d8;hb=2e20e3697bc7b7fddbd68500d3dfbf9878bae961;hp=a1e873c92feae5a38c183bef9db4f4d286c1d280;hpb=c9c337a89a3f04d7a985a521ca552d421fd94fda;p=electrum-server.git diff --git a/backends/bitcoind/deserialize.py b/backends/bitcoind/deserialize.py index a1e873c..75cbc3e 100644 --- a/backends/bitcoind/deserialize.py +++ b/backends/bitcoind/deserialize.py @@ -225,8 +225,7 @@ def parse_TxOut(vds, i): d = {} d['value'] = vds.read_int64() scriptPubKey = vds.read_bytes(vds.read_compact_size()) - d['address'] = extract_public_key(scriptPubKey) - #d['script'] = decode_script(scriptPubKey) + d['address'] = get_address_from_output_script(scriptPubKey) d['raw_output_script'] = scriptPubKey.encode('hex') d['index'] = i return d @@ -336,15 +335,10 @@ def match_decoded(decoded, to_match): return True -def extract_public_key(bytes): - decoded = list(script_GetOp(bytes)) - # non-generated TxIn transactions push a signature - # (seventy-something bytes) and then their public key - # (65 bytes) onto the stack: - match = [opcodes.OP_PUSHDATA4, opcodes.OP_PUSHDATA4] - if match_decoded(decoded, match): - return public_key_to_bc_address(decoded[1][1]) + +def get_address_from_output_script(bytes): + decoded = [ x for x in script_GetOp(bytes) ] # The Genesis Block, self-payments, and pay-by-IP-address payments look like: # 65 BYTES:... CHECKSIG @@ -369,5 +363,10 @@ def extract_public_key(bytes): if match_decoded(decoded, match): return hash_160_to_bc_address(decoded[2][1]) - #raise BaseException("address not found in script") see ce35795fb64c268a52324b884793b3165233b1e6d678ccaadf760628ec34d76b + # p2sh + match = [ opcodes.OP_HASH160, opcodes.OP_PUSHDATA4, opcodes.OP_EQUAL ] + if match_decoded(decoded, match): + addr = hash_160_to_bc_address(decoded[1][1],5) + return addr + return "None"