19
19
key_to_p2pkh ,
20
20
key_to_p2sh_p2wpkh ,
21
21
key_to_p2wpkh ,
22
+ output_key_to_p2tr ,
22
23
)
23
24
from test_framework .descriptors import descsum_create
24
- from test_framework .key import ECKey
25
+ from test_framework .key import (
26
+ ECKey ,
27
+ compute_xonly_pubkey ,
28
+ )
25
29
from test_framework .messages import (
26
30
COIN ,
27
31
COutPoint ,
38
42
OP_NOP ,
39
43
OP_TRUE ,
40
44
SIGHASH_ALL ,
45
+ taproot_construct ,
41
46
)
42
47
from test_framework .script_util import (
43
48
key_to_p2pk_script ,
@@ -286,10 +291,10 @@ def sendrawtransaction(self, *, from_node, tx_hex, maxfeerate=0, **kwargs):
286
291
return txid
287
292
288
293
289
- def getnewdestination (address_type = 'bech32 ' ):
294
+ def getnewdestination (address_type = 'bech32m ' ):
290
295
"""Generate a random destination of the specified type and return the
291
296
corresponding public key, scriptPubKey and address. Supported types are
292
- 'legacy', 'p2sh-segwit' and 'bech32 '. Can be used when a random
297
+ 'legacy', 'p2sh-segwit', 'bech32' and 'bech32m '. Can be used when a random
293
298
destination is needed, but no compiled wallet is available (e.g. as
294
299
replacement to the getnewaddress/getaddressinfo RPCs)."""
295
300
key = ECKey ()
@@ -304,7 +309,11 @@ def getnewdestination(address_type='bech32'):
304
309
elif address_type == 'bech32' :
305
310
scriptpubkey = key_to_p2wpkh_script (pubkey )
306
311
address = key_to_p2wpkh (pubkey )
307
- # TODO: also support bech32m (need to generate x-only-pubkey)
312
+ elif address_type == 'bech32m' :
313
+ tap = taproot_construct (compute_xonly_pubkey (key .get_bytes ())[0 ])
314
+ pubkey = tap .output_pubkey
315
+ scriptpubkey = tap .scriptPubKey
316
+ address = output_key_to_p2tr (pubkey )
308
317
else :
309
318
assert False
310
319
return pubkey , scriptpubkey , address
0 commit comments