17
17
use std:: collections:: { BTreeMap , HashMap , HashSet } ;
18
18
use std:: ops:: Deref ;
19
19
20
+ use bitcoin:: secp256k1;
20
21
use bitcoin:: util:: bip32:: { ChildNumber , DerivationPath , ExtendedPubKey , Fingerprint , KeySource } ;
21
22
use bitcoin:: util:: psbt;
22
- use bitcoin:: { Network , PublicKey , Script , TxOut } ;
23
+ use bitcoin:: { Network , Script , TxOut } ;
23
24
24
25
use miniscript:: descriptor:: { DescriptorType , InnerXKey } ;
25
26
pub use miniscript:: {
@@ -58,7 +59,7 @@ pub type DerivedDescriptor<'s> = Descriptor<DerivedDescriptorKey<'s>>;
58
59
///
59
60
/// [`psbt::Input`]: bitcoin::util::psbt::Input
60
61
/// [`psbt::Output`]: bitcoin::util::psbt::Output
61
- pub type HdKeyPaths = BTreeMap < PublicKey , KeySource > ;
62
+ pub type HdKeyPaths = BTreeMap < secp256k1 :: PublicKey , KeySource > ;
62
63
63
64
/// Trait for types which can be converted into an [`ExtendedDescriptor`] and a [`KeyMap`] usable by a wallet in a specific [`Network`]
64
65
pub trait IntoWalletDescriptor {
@@ -306,6 +307,7 @@ pub(crate) trait DerivedDescriptorMeta {
306
307
307
308
pub ( crate ) trait DescriptorMeta {
308
309
fn is_witness ( & self ) -> bool ;
310
+ fn is_taproot ( & self ) -> bool ;
309
311
fn get_extended_keys ( & self ) -> Result < Vec < DescriptorXKey < ExtendedPubKey > > , DescriptorError > ;
310
312
fn derive_from_hd_keypaths < ' s > (
311
313
& self ,
@@ -328,21 +330,21 @@ pub(crate) trait DescriptorScripts {
328
330
impl < ' s > DescriptorScripts for DerivedDescriptor < ' s > {
329
331
fn psbt_redeem_script ( & self ) -> Option < Script > {
330
332
match self . desc_type ( ) {
331
- DescriptorType :: ShWpkh => Some ( self . explicit_script ( ) ) ,
332
- DescriptorType :: ShWsh => Some ( self . explicit_script ( ) . to_v0_p2wsh ( ) ) ,
333
- DescriptorType :: Sh => Some ( self . explicit_script ( ) ) ,
334
- DescriptorType :: Bare => Some ( self . explicit_script ( ) ) ,
335
- DescriptorType :: ShSortedMulti => Some ( self . explicit_script ( ) ) ,
333
+ DescriptorType :: ShWpkh => Some ( self . explicit_script ( ) . unwrap ( ) ) ,
334
+ DescriptorType :: ShWsh => Some ( self . explicit_script ( ) . unwrap ( ) . to_v0_p2wsh ( ) ) ,
335
+ DescriptorType :: Sh => Some ( self . explicit_script ( ) . unwrap ( ) ) ,
336
+ DescriptorType :: Bare => Some ( self . explicit_script ( ) . unwrap ( ) ) ,
337
+ DescriptorType :: ShSortedMulti => Some ( self . explicit_script ( ) . unwrap ( ) ) ,
336
338
_ => None ,
337
339
}
338
340
}
339
341
340
342
fn psbt_witness_script ( & self ) -> Option < Script > {
341
343
match self . desc_type ( ) {
342
- DescriptorType :: Wsh => Some ( self . explicit_script ( ) ) ,
343
- DescriptorType :: ShWsh => Some ( self . explicit_script ( ) ) ,
344
+ DescriptorType :: Wsh => Some ( self . explicit_script ( ) . unwrap ( ) ) ,
345
+ DescriptorType :: ShWsh => Some ( self . explicit_script ( ) . unwrap ( ) ) ,
344
346
DescriptorType :: WshSortedMulti | DescriptorType :: ShWshSortedMulti => {
345
- Some ( self . explicit_script ( ) )
347
+ Some ( self . explicit_script ( ) . unwrap ( ) )
346
348
}
347
349
_ => None ,
348
350
}
@@ -362,6 +364,10 @@ impl DescriptorMeta for ExtendedDescriptor {
362
364
)
363
365
}
364
366
367
+ fn is_taproot ( & self ) -> bool {
368
+ self . desc_type ( ) == DescriptorType :: Tr
369
+ }
370
+
365
371
fn get_extended_keys ( & self ) -> Result < Vec < DescriptorXKey < ExtendedPubKey > > , DescriptorError > {
366
372
let mut answer = Vec :: new ( ) ;
367
373
@@ -448,15 +454,18 @@ impl DescriptorMeta for ExtendedDescriptor {
448
454
let descriptor = self . as_derived_fixed ( secp) ;
449
455
match descriptor. desc_type ( ) {
450
456
// TODO: add pk() here
451
- DescriptorType :: Pkh | DescriptorType :: Wpkh | DescriptorType :: ShWpkh
457
+ DescriptorType :: Pkh
458
+ | DescriptorType :: Wpkh
459
+ | DescriptorType :: ShWpkh
460
+ | DescriptorType :: Tr
452
461
if utxo. is_some ( )
453
462
&& descriptor. script_pubkey ( ) == utxo. as_ref ( ) . unwrap ( ) . script_pubkey =>
454
463
{
455
464
Some ( descriptor)
456
465
}
457
466
DescriptorType :: Bare | DescriptorType :: Sh | DescriptorType :: ShSortedMulti
458
467
if psbt_input. redeem_script . is_some ( )
459
- && & descriptor. explicit_script ( )
468
+ && & descriptor. explicit_script ( ) . unwrap ( )
460
469
== psbt_input. redeem_script . as_ref ( ) . unwrap ( ) =>
461
470
{
462
471
Some ( descriptor)
@@ -466,7 +475,7 @@ impl DescriptorMeta for ExtendedDescriptor {
466
475
| DescriptorType :: ShWshSortedMulti
467
476
| DescriptorType :: WshSortedMulti
468
477
if psbt_input. witness_script . is_some ( )
469
- && & descriptor. explicit_script ( )
478
+ && & descriptor. explicit_script ( ) . unwrap ( )
470
479
== psbt_input. witness_script . as_ref ( ) . unwrap ( ) =>
471
480
{
472
481
Some ( descriptor)
0 commit comments