MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / __init__

Method __init__

test/functional/test_framework/wallet.py:91–117  ·  view source on GitHub ↗
(self, test_node, *, mode=MiniWalletMode.ADDRESS_OP_TRUE, tag_name=None)

Source from the content-addressed store, hash-verified

89
90class MiniWallet:
91 def __init__(self, test_node, *, mode=MiniWalletMode.ADDRESS_OP_TRUE, tag_name=None):
92 self._test_node = test_node
93 self._utxos = []
94 self._mode = mode
95
96 assert isinstance(mode, MiniWalletMode)
97 if mode == MiniWalletMode.RAW_OP_TRUE:
98 assert tag_name is None
99 self._scriptPubKey = bytes(CScript([OP_TRUE]))
100 elif mode == MiniWalletMode.RAW_P2PK:
101 # use simple deterministic private key (k=1)
102 assert tag_name is None
103 self._priv_key = ECKey()
104 self._priv_key.set((1).to_bytes(32, 'big'), True)
105 pub_key = self._priv_key.get_pubkey()
106 self._scriptPubKey = key_to_p2pk_script(pub_key.get_bytes())
107 elif mode == MiniWalletMode.ADDRESS_OP_TRUE:
108 internal_key = None if tag_name is None else compute_xonly_pubkey(hash256(tag_name.encode()))[0]
109 self._address, self._taproot_info = create_deterministic_address_bcrt1_p2tr_op_true(internal_key)
110 self._scriptPubKey = address_to_scriptpubkey(self._address)
111
112 # When the pre-mined test framework chain is used, it contains coinbase
113 # outputs to the MiniWallet's default address in blocks 76-100
114 # (see method BitcoinTestFramework._initialize_chain())
115 # The MiniWallet needs to rescan_utxos() in order to account
116 # for those mature UTXOs, so that all txs spend confirmed coins
117 self.rescan_utxos()
118
119 def _create_utxo(self, *, txid, vout, value, height, coinbase, confirmations):
120 return {"txid": txid, "vout": vout, "value": value, "height": height, "coinbase": coinbase, "confirmations": confirmations}

Callers

nothing calls this directly

Calls 13

rescan_utxosMethod · 0.95
CScriptClass · 0.90
ECKeyClass · 0.90
key_to_p2pk_scriptFunction · 0.90
compute_xonly_pubkeyFunction · 0.90
hash256Function · 0.90
address_to_scriptpubkeyFunction · 0.90
to_bytesMethod · 0.80
get_pubkeyMethod · 0.80
setMethod · 0.45
get_bytesMethod · 0.45

Tested by

no test coverage detected