diff options
author | Sebastian Falbesoner <sebastian.falbesoner@gmail.com> | 2021-12-26 02:31:11 +0100 |
---|---|---|
committer | Sebastian Falbesoner <sebastian.falbesoner@gmail.com> | 2021-12-26 12:10:56 +0100 |
commit | 983ca0456c0fd32dc6ce166cb1e9aeb925e81161 (patch) | |
tree | 6023a3a813967a243d9b8ffc0e70c3e6825e329d /test/functional/test_framework | |
parent | e704d4d26f62f83068dc7d4082ab9b57bc33d1fb (diff) |
test: introduce `address_to_scriptpubkey` helper
Works only with legacy addresses (Base58Check) right now.
Diffstat (limited to 'test/functional/test_framework')
-rw-r--r-- | test/functional/test_framework/wallet.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/test/functional/test_framework/wallet.py b/test/functional/test_framework/wallet.py index d7c78bdeb6..9158dd0942 100644 --- a/test/functional/test_framework/wallet.py +++ b/test/functional/test_framework/wallet.py @@ -10,6 +10,7 @@ from enum import Enum from random import choice from typing import Optional from test_framework.address import ( + base58_to_byte, create_deterministic_address_bcrt1_p2tr_op_true, key_to_p2pkh, key_to_p2sh_p2wpkh, @@ -39,6 +40,8 @@ from test_framework.script_util import ( key_to_p2pkh_script, key_to_p2sh_p2wpkh_script, key_to_p2wpkh_script, + keyhash_to_p2pkh_script, + scripthash_to_p2sh_script, ) from test_framework.util import ( assert_equal, @@ -240,6 +243,18 @@ def getnewdestination(address_type='bech32'): 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): """Build a transaction that spends parent_txid.vout[n] and produces one output with amount = parent_value with a fee deducted. |