3232 CTxIn ,
3333 CTxInWitness ,
3434 CTxOut ,
35+ hash256 ,
3536)
3637from test_framework .script import (
3738 CScript ,
@@ -65,7 +66,10 @@ class MiniWalletMode(Enum):
6566 However, if the transactions need to be modified by the user (e.g. prepending
6667 scriptSig for testing opcodes that are activated by a soft-fork), or the txs
6768 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:
6973
7074 | output | | tx is | can modify | needs
7175 mode | description | address | standard | scriptSig | signing
@@ -80,22 +84,25 @@ class MiniWalletMode(Enum):
8084
8185
8286class 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 ):
8488 self ._test_node = test_node
8589 self ._utxos = []
8690 self ._mode = mode
8791
8892 assert isinstance (mode , MiniWalletMode )
8993 if mode == MiniWalletMode .RAW_OP_TRUE :
94+ assert tag_name is None
9095 self ._scriptPubKey = bytes (CScript ([OP_TRUE ]))
9196 elif mode == MiniWalletMode .RAW_P2PK :
9297 # use simple deterministic private key (k=1)
98+ assert tag_name is None
9399 self ._priv_key = ECKey ()
94100 self ._priv_key .set ((1 ).to_bytes (32 , 'big' ), True )
95101 pub_key = self ._priv_key .get_pubkey ()
96102 self ._scriptPubKey = key_to_p2pk_script (pub_key .get_bytes ())
97103 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 )
99106 self ._scriptPubKey = address_to_scriptpubkey (self ._address )
100107
101108 # When the pre-mined test framework chain is used, it contains coinbase
0 commit comments