32
32
CTxIn ,
33
33
CTxInWitness ,
34
34
CTxOut ,
35
+ hash256 ,
35
36
)
36
37
from test_framework .script import (
37
38
CScript ,
@@ -65,7 +66,10 @@ class MiniWalletMode(Enum):
65
66
However, if the transactions need to be modified by the user (e.g. prepending
66
67
scriptSig for testing opcodes that are activated by a soft-fork), or the txs
67
68
should contain an actual signature, the raw modes RAW_OP_TRUE and RAW_P2PK
68
- can be useful. Summary of modes:
69
+ can be useful. In order to avoid mixing of UTXOs between different MiniWallet
70
+ instances, a tag name can be passed to the default mode, to create different
71
+ output scripts. Note that the UTXOs from the pre-generated test chain can
72
+ only be spent if no tag is passed. Summary of modes:
69
73
70
74
| output | | tx is | can modify | needs
71
75
mode | description | address | standard | scriptSig | signing
@@ -80,22 +84,25 @@ class MiniWalletMode(Enum):
80
84
81
85
82
86
class MiniWallet :
83
- def __init__ (self , test_node , * , mode = MiniWalletMode .ADDRESS_OP_TRUE ):
87
+ def __init__ (self , test_node , * , mode = MiniWalletMode .ADDRESS_OP_TRUE , tag_name = None ):
84
88
self ._test_node = test_node
85
89
self ._utxos = []
86
90
self ._mode = mode
87
91
88
92
assert isinstance (mode , MiniWalletMode )
89
93
if mode == MiniWalletMode .RAW_OP_TRUE :
94
+ assert tag_name is None
90
95
self ._scriptPubKey = bytes (CScript ([OP_TRUE ]))
91
96
elif mode == MiniWalletMode .RAW_P2PK :
92
97
# use simple deterministic private key (k=1)
98
+ assert tag_name is None
93
99
self ._priv_key = ECKey ()
94
100
self ._priv_key .set ((1 ).to_bytes (32 , 'big' ), True )
95
101
pub_key = self ._priv_key .get_pubkey ()
96
102
self ._scriptPubKey = key_to_p2pk_script (pub_key .get_bytes ())
97
103
elif mode == MiniWalletMode .ADDRESS_OP_TRUE :
98
- self ._address , self ._internal_key = create_deterministic_address_bcrt1_p2tr_op_true ()
104
+ internal_key = None if tag_name is None else hash256 (tag_name .encode ())
105
+ self ._address , self ._internal_key = create_deterministic_address_bcrt1_p2tr_op_true (internal_key )
99
106
self ._scriptPubKey = address_to_scriptpubkey (self ._address )
100
107
101
108
# When the pre-mined test framework chain is used, it contains coinbase
0 commit comments