1717use std:: collections:: { BTreeMap , HashMap , HashSet } ;
1818use std:: ops:: Deref ;
1919
20+ use bitcoin:: secp256k1;
2021use bitcoin:: util:: bip32:: { ChildNumber , DerivationPath , ExtendedPubKey , Fingerprint , KeySource } ;
2122use bitcoin:: util:: psbt;
22- use bitcoin:: { Network , PublicKey , Script , TxOut } ;
23+ use bitcoin:: { Network , Script , TxOut } ;
2324
2425use miniscript:: descriptor:: { DescriptorType , InnerXKey } ;
2526pub use miniscript:: {
@@ -58,7 +59,7 @@ pub type DerivedDescriptor<'s> = Descriptor<DerivedDescriptorKey<'s>>;
5859///
5960/// [`psbt::Input`]: bitcoin::util::psbt::Input
6061/// [`psbt::Output`]: bitcoin::util::psbt::Output
61- pub type HdKeyPaths = BTreeMap < PublicKey , KeySource > ;
62+ pub type HdKeyPaths = BTreeMap < secp256k1 :: PublicKey , KeySource > ;
6263
6364/// Trait for types which can be converted into an [`ExtendedDescriptor`] and a [`KeyMap`] usable by a wallet in a specific [`Network`]
6465pub trait IntoWalletDescriptor {
@@ -306,6 +307,7 @@ pub(crate) trait DerivedDescriptorMeta {
306307
307308pub ( crate ) trait DescriptorMeta {
308309 fn is_witness ( & self ) -> bool ;
310+ fn is_taproot ( & self ) -> bool ;
309311 fn get_extended_keys ( & self ) -> Result < Vec < DescriptorXKey < ExtendedPubKey > > , DescriptorError > ;
310312 fn derive_from_hd_keypaths < ' s > (
311313 & self ,
@@ -328,21 +330,21 @@ pub(crate) trait DescriptorScripts {
328330impl < ' s > DescriptorScripts for DerivedDescriptor < ' s > {
329331 fn psbt_redeem_script ( & self ) -> Option < Script > {
330332 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 ( ) ) ,
336338 _ => None ,
337339 }
338340 }
339341
340342 fn psbt_witness_script ( & self ) -> Option < Script > {
341343 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 ( ) ) ,
344346 DescriptorType :: WshSortedMulti | DescriptorType :: ShWshSortedMulti => {
345- Some ( self . explicit_script ( ) )
347+ Some ( self . explicit_script ( ) . unwrap ( ) )
346348 }
347349 _ => None ,
348350 }
@@ -362,6 +364,10 @@ impl DescriptorMeta for ExtendedDescriptor {
362364 )
363365 }
364366
367+ fn is_taproot ( & self ) -> bool {
368+ self . desc_type ( ) == DescriptorType :: Tr
369+ }
370+
365371 fn get_extended_keys ( & self ) -> Result < Vec < DescriptorXKey < ExtendedPubKey > > , DescriptorError > {
366372 let mut answer = Vec :: new ( ) ;
367373
@@ -448,15 +454,18 @@ impl DescriptorMeta for ExtendedDescriptor {
448454 let descriptor = self . as_derived_fixed ( secp) ;
449455 match descriptor. desc_type ( ) {
450456 // TODO: add pk() here
451- DescriptorType :: Pkh | DescriptorType :: Wpkh | DescriptorType :: ShWpkh
457+ DescriptorType :: Pkh
458+ | DescriptorType :: Wpkh
459+ | DescriptorType :: ShWpkh
460+ | DescriptorType :: Tr
452461 if utxo. is_some ( )
453462 && descriptor. script_pubkey ( ) == utxo. as_ref ( ) . unwrap ( ) . script_pubkey =>
454463 {
455464 Some ( descriptor)
456465 }
457466 DescriptorType :: Bare | DescriptorType :: Sh | DescriptorType :: ShSortedMulti
458467 if psbt_input. redeem_script . is_some ( )
459- && & descriptor. explicit_script ( )
468+ && & descriptor. explicit_script ( ) . unwrap ( )
460469 == psbt_input. redeem_script . as_ref ( ) . unwrap ( ) =>
461470 {
462471 Some ( descriptor)
@@ -466,7 +475,7 @@ impl DescriptorMeta for ExtendedDescriptor {
466475 | DescriptorType :: ShWshSortedMulti
467476 | DescriptorType :: WshSortedMulti
468477 if psbt_input. witness_script . is_some ( )
469- && & descriptor. explicit_script ( )
478+ && & descriptor. explicit_script ( ) . unwrap ( )
470479 == psbt_input. witness_script . as_ref ( ) . unwrap ( ) =>
471480 {
472481 Some ( descriptor)
0 commit comments