Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/address.py
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | def key_to_p2pkh(key, main=False): | ||||
return keyhash_to_p2pkh(hash160(key), main) | return keyhash_to_p2pkh(hash160(key), main) | ||||
def script_to_p2sh(script, main=False): | def script_to_p2sh(script, main=False): | ||||
script = check_script(script) | script = check_script(script) | ||||
return scripthash_to_p2sh(hash160(script), main) | return scripthash_to_p2sh(hash160(script), main) | ||||
def key_to_p2sh_p2wpkh(key, main=False): | |||||
key = check_key(key) | |||||
p2shscript = CScript([OP_0, hash160(key)]) | |||||
return script_to_p2sh(p2shscript, main) | |||||
def script_to_p2sh_p2wsh(script, main=False): | |||||
script = check_script(script) | |||||
p2shscript = CScript([OP_0, sha256(script)]) | |||||
return script_to_p2sh(p2shscript, main) | |||||
def check_key(key): | def check_key(key): | ||||
if (type(key) is str): | if (type(key) is str): | ||||
key = hex_str_to_bytes(key) # Assuming this is hex string | key = hex_str_to_bytes(key) # Assuming this is hex string | ||||
if (type(key) is bytes and (len(key) == 33 or len(key) == 65)): | if (type(key) is bytes and (len(key) == 33 or len(key) == 65)): | ||||
return key | return key | ||||
assert(False) | assert(False) | ||||
def check_script(script): | def check_script(script): | ||||
if (type(script) is str): | if (type(script) is str): | ||||
script = hex_str_to_bytes(script) # Assuming this is hex string | script = hex_str_to_bytes(script) # Assuming this is hex string | ||||
if (type(script) is bytes or type(script) is CScript): | if (type(script) is bytes or type(script) is CScript): | ||||
return script | return script | ||||
assert(False) | assert(False) |