7
7
from copy import deepcopy
8
8
from decimal import Decimal
9
9
from enum import Enum
10
- from random import choice
11
10
from typing import (
12
11
Any ,
13
12
List ,
14
13
Optional ,
15
14
)
16
15
from test_framework .address import (
17
16
base58_to_byte ,
18
- ADDRESS_BCRT1_P2WSH_OP_TRUE ,
17
+ create_deterministic_address_bcrt1_p2tr_op_true ,
19
18
key_to_p2pkh ,
20
19
key_to_p2sh_p2wpkh ,
21
20
key_to_p2wpkh ,
22
21
output_key_to_p2tr ,
23
22
)
24
-
23
+ from random import choice
24
+ from typing import Optional
25
25
from test_framework .descriptors import descsum_create
26
26
from test_framework .key import (
27
27
ECKey ,
39
39
from test_framework .script import (
40
40
CScript ,
41
41
LegacySignatureHash ,
42
- OP_TRUE ,
42
+ LEAF_VERSION_TAPSCRIPT ,
43
43
OP_NOP ,
44
+ OP_TRUE ,
44
45
SIGHASH_ALL ,
45
46
taproot_construct ,
46
47
)
56
57
assert_equal ,
57
58
assert_greater_than_or_equal ,
58
59
)
59
- from enum import Enum
60
60
61
61
DEFAULT_FEE = Decimal ("0.0001" )
62
62
63
63
class MiniWalletMode (Enum ):
64
64
"""Determines the transaction type the MiniWallet is creating and spending.
65
65
66
66
For most purposes, the default mode ADDRESS_OP_TRUE should be sufficient;
67
- it simply uses a fixed bech32 P2WSH address whose coins are spent with a
67
+ it simply uses a fixed bech32m P2TR address whose coins are spent with a
68
68
witness stack of OP_TRUE, i.e. following an anyone-can-spend policy.
69
69
However, if the transactions need to be modified by the user (e.g. prepending
70
70
scriptSig for testing opcodes that are activated by a soft-fork), or the txs
@@ -74,7 +74,7 @@ class MiniWalletMode(Enum):
74
74
| output | | tx is | can modify | needs
75
75
mode | description | address | standard | scriptSig | signing
76
76
----------------+-------------------+-----------+----------+------------+----------
77
- ADDRESS_OP_TRUE | anyone-can-spend | bech32 | yes | no | no
77
+ ADDRESS_OP_TRUE | anyone-can-spend | bech32m | yes | no | no
78
78
RAW_OP_TRUE | anyone-can-spend | - (raw) | no | yes | no
79
79
RAW_P2PK | pay-to-public-key | - (raw) | yes | yes | yes
80
80
"""
@@ -100,7 +100,7 @@ def __init__(self, test_node, *, mode=MiniWalletMode.ADDRESS_OP_TRUE):
100
100
pub_key = self ._priv_key .get_pubkey ()
101
101
self ._scriptPubKey = key_to_p2pk_script (pub_key .get_bytes ())
102
102
elif mode == MiniWalletMode .ADDRESS_OP_TRUE :
103
- self ._address = ADDRESS_BCRT1_P2WSH_OP_TRUE
103
+ self ._address , self . _internal_key = create_deterministic_address_bcrt1_p2tr_op_true ()
104
104
self ._scriptPubKey = bytes .fromhex (self ._test_node .validateaddress (self ._address )['scriptPubKey' ])
105
105
106
106
def _create_utxo (self , * , txid , vout , value , height ):
@@ -283,7 +283,7 @@ def create_self_transfer(self, *, fee_rate=Decimal("0.003"), fee=Decimal("0"), u
283
283
"""Create and return a tx with the specified fee. If fee is 0, use fee_rate, where the resulting fee may be exact or at most one satoshi higher than needed."""
284
284
utxo_to_spend = utxo_to_spend or self .get_utxo ()
285
285
if self ._priv_key is None :
286
- vsize = Decimal (96 ) # anyone-can-spend
286
+ vsize = Decimal (104 ) # anyone-can-spend
287
287
else :
288
288
vsize = Decimal (168 ) # P2PK (73 bytes scriptSig + 35 bytes scriptPubKey + 60 bytes other)
289
289
send_value = utxo_to_spend ["value" ] - (fee or (fee_rate * vsize / 1000 ))
@@ -300,10 +300,10 @@ def create_self_transfer(self, *, fee_rate=Decimal("0.003"), fee=Decimal("0"), u
300
300
self .sign_tx (tx )
301
301
else :
302
302
# anyone-can-spend
303
- tx .vin [0 ].scriptSig = CScript ([OP_NOP ] * 35 ) # pad to identical size
303
+ tx .vin [0 ].scriptSig = CScript ([OP_NOP ] * 43 ) # pad to identical size
304
304
else :
305
305
tx .wit .vtxinwit = [CTxInWitness ()]
306
- tx .wit .vtxinwit [0 ].scriptWitness .stack = [CScript ([OP_TRUE ])]
306
+ tx .wit .vtxinwit [0 ].scriptWitness .stack = [CScript ([OP_TRUE ]), bytes ([ LEAF_VERSION_TAPSCRIPT ]) + self . _internal_key ]
307
307
tx_hex = tx .serialize ().hex ()
308
308
309
309
assert_equal (tx .get_vsize (), vsize )
0 commit comments