test: introduce address_to_scriptpubkey helper
Works only with legacy addresses (Base58Check) right now.
This commit is contained in:
1 parent
e704d4d26f
commit
983ca0456c
1 file changed
+15
@@ -10,6 +10,7 @@ from enum import Enum
|
|||||||
from random import choice
|
from random import choice
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from test_framework.address import (
|
from test_framework.address import (
|
||||||
|
base58_to_byte,
|
||||||
create_deterministic_address_bcrt1_p2tr_op_true,
|
create_deterministic_address_bcrt1_p2tr_op_true,
|
||||||
key_to_p2pkh,
|
key_to_p2pkh,
|
||||||
key_to_p2sh_p2wpkh,
|
key_to_p2sh_p2wpkh,
|
||||||
@@ -39,6 +40,8 @@ from test_framework.script_util import (
|
|||||||
key_to_p2pkh_script,
|
key_to_p2pkh_script,
|
||||||
key_to_p2sh_p2wpkh_script,
|
key_to_p2sh_p2wpkh_script,
|
||||||
key_to_p2wpkh_script,
|
key_to_p2wpkh_script,
|
||||||
|
keyhash_to_p2pkh_script,
|
||||||
|
scripthash_to_p2sh_script,
|
||||||
)
|
)
|
||||||
from test_framework.util import (
|
from test_framework.util import (
|
||||||
assert_equal,
|
assert_equal,
|
||||||
@@ -240,6 +243,18 @@ def getnewdestination(address_type='bech32'):
|
|||||||
return pubkey, scriptpubkey, address
|
return pubkey, scriptpubkey, address
|
||||||
|
|
||||||
|
|
||||||
|
def address_to_scriptpubkey(address):
|
||||||
|
"""Converts a given address to the corresponding output script (scriptPubKey)."""
|
||||||
|
payload, version = base58_to_byte(address)
|
||||||
|
if version == 111: # testnet pubkey hash
|
||||||
|
return keyhash_to_p2pkh_script(payload)
|
||||||
|
elif version == 196: # testnet script hash
|
||||||
|
return scripthash_to_p2sh_script(payload)
|
||||||
|
# TODO: also support other address formats
|
||||||
|
else:
|
||||||
|
assert False
|
||||||
|
|
||||||
|
|
||||||
def make_chain(node, address, privkeys, parent_txid, parent_value, n=0, parent_locking_script=None, fee=DEFAULT_FEE):
|
def make_chain(node, address, privkeys, parent_txid, parent_value, n=0, parent_locking_script=None, fee=DEFAULT_FEE):
|
||||||
"""Build a transaction that spends parent_txid.vout[n] and produces one output with
|
"""Build a transaction that spends parent_txid.vout[n] and produces one output with
|
||||||
amount = parent_value with a fee deducted.
|
amount = parent_value with a fee deducted.
|
||||||
|
|||||||
Reference in new issue
Block a user