transaction.get_address_from_output_script now handles witness version > 0
This commit is contained in:
@@ -44,7 +44,7 @@ from . import constants
|
||||
COINBASE_MATURITY = 100
|
||||
COIN = 100000000
|
||||
|
||||
# supported types of transction outputs
|
||||
# supported types of transaction outputs
|
||||
TYPE_ADDRESS = 0
|
||||
TYPE_PUBKEY = 1
|
||||
TYPE_SCRIPT = 2
|
||||
@@ -285,14 +285,14 @@ def hash160_to_p2sh(h160):
|
||||
def public_key_to_p2pkh(public_key):
|
||||
return hash160_to_p2pkh(hash_160(public_key))
|
||||
|
||||
def hash_to_segwit_addr(h):
|
||||
return segwit_addr.encode(constants.net.SEGWIT_HRP, 0, h)
|
||||
def hash_to_segwit_addr(h, witver):
|
||||
return segwit_addr.encode(constants.net.SEGWIT_HRP, witver, h)
|
||||
|
||||
def public_key_to_p2wpkh(public_key):
|
||||
return hash_to_segwit_addr(hash_160(public_key))
|
||||
return hash_to_segwit_addr(hash_160(public_key), witver=0)
|
||||
|
||||
def script_to_p2wsh(script):
|
||||
return hash_to_segwit_addr(sha256(bfh(script)))
|
||||
return hash_to_segwit_addr(sha256(bfh(script)), witver=0)
|
||||
|
||||
def p2wpkh_nested_script(pubkey):
|
||||
pkh = bh2u(hash_160(bfh(pubkey)))
|
||||
@@ -306,7 +306,7 @@ def pubkey_to_address(txin_type, pubkey):
|
||||
if txin_type == 'p2pkh':
|
||||
return public_key_to_p2pkh(bfh(pubkey))
|
||||
elif txin_type == 'p2wpkh':
|
||||
return hash_to_segwit_addr(hash_160(bfh(pubkey)))
|
||||
return public_key_to_p2wpkh(bfh(pubkey))
|
||||
elif txin_type == 'p2wpkh-p2sh':
|
||||
scriptSig = p2wpkh_nested_script(pubkey)
|
||||
return hash160_to_p2sh(hash_160(bfh(scriptSig)))
|
||||
|
||||
Reference in New Issue
Block a user