9
9
from enum import Enum
10
10
from random import choice
11
11
from typing import Optional
12
- from test_framework .address import ADDRESS_BCRT1_P2WSH_OP_TRUE
12
+ from test_framework .address import create_deterministic_address_bcrt1_p2tr_op_true
13
13
from test_framework .descriptors import descsum_create
14
14
from test_framework .key import ECKey
15
15
from test_framework .messages import (
24
24
from test_framework .script import (
25
25
CScript ,
26
26
LegacySignatureHash ,
27
- OP_TRUE ,
27
+ LEAF_VERSION_TAPSCRIPT ,
28
28
OP_NOP ,
29
+ OP_TRUE ,
29
30
SIGHASH_ALL ,
30
31
)
31
32
from test_framework .script_util import (
@@ -43,7 +44,7 @@ class MiniWalletMode(Enum):
43
44
"""Determines the transaction type the MiniWallet is creating and spending.
44
45
45
46
For most purposes, the default mode ADDRESS_OP_TRUE should be sufficient;
46
- it simply uses a fixed bech32 P2WSH address whose coins are spent with a
47
+ it simply uses a fixed bech32m P2TR address whose coins are spent with a
47
48
witness stack of OP_TRUE, i.e. following an anyone-can-spend policy.
48
49
However, if the transactions need to be modified by the user (e.g. prepending
49
50
scriptSig for testing opcodes that are activated by a soft-fork), or the txs
@@ -53,7 +54,7 @@ class MiniWalletMode(Enum):
53
54
| output | | tx is | can modify | needs
54
55
mode | description | address | standard | scriptSig | signing
55
56
----------------+-------------------+-----------+----------+------------+----------
56
- ADDRESS_OP_TRUE | anyone-can-spend | bech32 | yes | no | no
57
+ ADDRESS_OP_TRUE | anyone-can-spend | bech32m | yes | no | no
57
58
RAW_OP_TRUE | anyone-can-spend | - (raw) | no | yes | no
58
59
RAW_P2PK | pay-to-public-key | - (raw) | yes | yes | yes
59
60
"""
@@ -79,7 +80,7 @@ def __init__(self, test_node, *, mode=MiniWalletMode.ADDRESS_OP_TRUE):
79
80
pub_key = self ._priv_key .get_pubkey ()
80
81
self ._scriptPubKey = key_to_p2pk_script (pub_key .get_bytes ())
81
82
elif mode == MiniWalletMode .ADDRESS_OP_TRUE :
82
- self ._address = ADDRESS_BCRT1_P2WSH_OP_TRUE
83
+ self ._address , self . _internal_key = create_deterministic_address_bcrt1_p2tr_op_true ()
83
84
self ._scriptPubKey = bytes .fromhex (self ._test_node .validateaddress (self ._address )['scriptPubKey' ])
84
85
85
86
def rescan_utxos (self ):
@@ -174,7 +175,7 @@ def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_
174
175
self ._utxos = sorted (self ._utxos , key = lambda k : (k ['value' ], - k ['height' ]))
175
176
utxo_to_spend = utxo_to_spend or self ._utxos .pop () # Pick the largest utxo (if none provided) and hope it covers the fee
176
177
if self ._priv_key is None :
177
- vsize = Decimal (96 ) # anyone-can-spend
178
+ vsize = Decimal (104 ) # anyone-can-spend
178
179
else :
179
180
vsize = Decimal (168 ) # P2PK (73 bytes scriptSig + 35 bytes scriptPubKey + 60 bytes other)
180
181
send_value = int (COIN * (utxo_to_spend ['value' ] - fee_rate * (vsize / 1000 )))
@@ -191,10 +192,10 @@ def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_
191
192
self .sign_tx (tx )
192
193
else :
193
194
# anyone-can-spend
194
- tx .vin [0 ].scriptSig = CScript ([OP_NOP ] * 35 ) # pad to identical size
195
+ tx .vin [0 ].scriptSig = CScript ([OP_NOP ] * 43 ) # pad to identical size
195
196
else :
196
197
tx .wit .vtxinwit = [CTxInWitness ()]
197
- tx .wit .vtxinwit [0 ].scriptWitness .stack = [CScript ([OP_TRUE ])]
198
+ tx .wit .vtxinwit [0 ].scriptWitness .stack = [CScript ([OP_TRUE ]), bytes ([ LEAF_VERSION_TAPSCRIPT ]) + self . _internal_key ]
198
199
tx_hex = tx .serialize ().hex ()
199
200
200
201
tx_info = from_node .testmempoolaccept ([tx_hex ])[0 ]
0 commit comments