mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
refactor: use address_to_scriptpubkey to retrieve addresses scriptpubkey
This commit updates the code by replacing the RPC call used to decode an address and retrieve its corresponding scriptpubkey with the address_to_scriptpubkey function. address_to_scriptpubkey function can now decode all addresses formats, which makes it more efficient to use.
This commit is contained in:
@@ -9,6 +9,7 @@ import time
|
||||
import unittest
|
||||
|
||||
from .address import (
|
||||
address_to_scriptpubkey,
|
||||
key_to_p2sh_p2wpkh,
|
||||
key_to_p2wpkh,
|
||||
script_to_p2sh_p2wsh,
|
||||
@@ -205,7 +206,7 @@ def create_witness_tx(node, use_p2wsh, utxo, pubkey, encode_p2sh, amount):
|
||||
else:
|
||||
addr = key_to_p2sh_p2wpkh(pubkey) if encode_p2sh else key_to_p2wpkh(pubkey)
|
||||
if not encode_p2sh:
|
||||
assert_equal(node.getaddressinfo(addr)['scriptPubKey'], witness_script(use_p2wsh, pubkey))
|
||||
assert_equal(address_to_scriptpubkey(addr).hex(), witness_script(use_p2wsh, pubkey))
|
||||
return node.createrawtransaction([utxo], {addr: amount})
|
||||
|
||||
def send_to_witness(use_p2wsh, node, utxo, pubkey, encode_p2sh, amount, sign=True, insert_redeem_script=""):
|
||||
|
||||
@@ -13,6 +13,7 @@ from typing import (
|
||||
Optional,
|
||||
)
|
||||
from test_framework.address import (
|
||||
address_to_scriptpubkey,
|
||||
create_deterministic_address_bcrt1_p2tr_op_true,
|
||||
key_to_p2pkh,
|
||||
key_to_p2sh_p2wpkh,
|
||||
@@ -96,7 +97,7 @@ class MiniWallet:
|
||||
self._scriptPubKey = key_to_p2pk_script(pub_key.get_bytes())
|
||||
elif mode == MiniWalletMode.ADDRESS_OP_TRUE:
|
||||
self._address, self._internal_key = create_deterministic_address_bcrt1_p2tr_op_true()
|
||||
self._scriptPubKey = bytes.fromhex(self._test_node.validateaddress(self._address)['scriptPubKey'])
|
||||
self._scriptPubKey = address_to_scriptpubkey(self._address)
|
||||
|
||||
# When the pre-mined test framework chain is used, it contains coinbase
|
||||
# outputs to the MiniWallet's default address in blocks 76-100
|
||||
|
||||
Reference in New Issue
Block a user