bitcoin.py: parameterise a few address-related methods with network
This commit is contained in:
@@ -402,7 +402,8 @@ def parse_redeemScript(s):
|
||||
redeemScript = multisig_script(pubkeys, m)
|
||||
return m, n, x_pubkeys, pubkeys, redeemScript
|
||||
|
||||
def get_address_from_output_script(_bytes):
|
||||
|
||||
def get_address_from_output_script(_bytes, *, net=None):
|
||||
decoded = [x for x in script_GetOp(_bytes)]
|
||||
|
||||
# The Genesis Block, self-payments, and pay-by-IP-address payments look like:
|
||||
@@ -415,19 +416,19 @@ def get_address_from_output_script(_bytes):
|
||||
# DUP HASH160 20 BYTES:... EQUALVERIFY CHECKSIG
|
||||
match = [ opcodes.OP_DUP, opcodes.OP_HASH160, opcodes.OP_PUSHDATA4, opcodes.OP_EQUALVERIFY, opcodes.OP_CHECKSIG ]
|
||||
if match_decoded(decoded, match):
|
||||
return TYPE_ADDRESS, hash160_to_p2pkh(decoded[2][1])
|
||||
return TYPE_ADDRESS, hash160_to_p2pkh(decoded[2][1], net=net)
|
||||
|
||||
# p2sh
|
||||
match = [ opcodes.OP_HASH160, opcodes.OP_PUSHDATA4, opcodes.OP_EQUAL ]
|
||||
if match_decoded(decoded, match):
|
||||
return TYPE_ADDRESS, hash160_to_p2sh(decoded[1][1])
|
||||
return TYPE_ADDRESS, hash160_to_p2sh(decoded[1][1], net=net)
|
||||
|
||||
# segwit address
|
||||
possible_witness_versions = [opcodes.OP_0] + list(range(opcodes.OP_1, opcodes.OP_16 + 1))
|
||||
for witver, opcode in enumerate(possible_witness_versions):
|
||||
match = [ opcode, opcodes.OP_PUSHDATA4 ]
|
||||
if match_decoded(decoded, match):
|
||||
return TYPE_ADDRESS, hash_to_segwit_addr(decoded[1][1], witver=witver)
|
||||
return TYPE_ADDRESS, hash_to_segwit_addr(decoded[1][1], witver=witver, net=net)
|
||||
|
||||
return TYPE_SCRIPT, bh2u(_bytes)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user