1+ use crate :: bitcoin:: Address ;
12use crate :: bitcoin:: DescriptorId ;
23use crate :: bitcoin:: DescriptorType ;
34use crate :: error:: DescriptorError ;
@@ -12,6 +13,7 @@ use bdk_wallet::chain::DescriptorExt;
1213use bdk_wallet:: descriptor:: { ExtendedDescriptor , IntoWalletDescriptor } ;
1314use bdk_wallet:: keys:: DescriptorPublicKey as BdkDescriptorPublicKey ;
1415use bdk_wallet:: keys:: { DescriptorSecretKey as BdkDescriptorSecretKey , KeyMap } ;
16+ use bdk_wallet:: miniscript:: descriptor:: ConversionError ;
1517use bdk_wallet:: template:: {
1618 Bip44 , Bip44Public , Bip49 , Bip49Public , Bip84 , Bip84Public , Bip86 , Bip86Public ,
1719 DescriptorTemplate ,
@@ -355,6 +357,33 @@ impl Descriptor {
355357 pub fn desc_type ( & self ) -> DescriptorType {
356358 self . extended_descriptor . desc_type ( )
357359 }
360+
361+ pub fn derived_address (
362+ & self ,
363+ index : u32 ,
364+ network : Network ,
365+ ) -> Result < Arc < Address > , DescriptorError > {
366+ if self . extended_descriptor . is_multipath ( ) {
367+ return Err ( DescriptorError :: MultiPath ) ;
368+ }
369+
370+ let derived_descriptor = self
371+ . extended_descriptor
372+ . at_derivation_index ( index)
373+ . map_err ( |error| match error {
374+ ConversionError :: HardenedChild => DescriptorError :: HardenedDerivationXpub ,
375+ ConversionError :: MultiKey => DescriptorError :: MultiPath ,
376+ } ) ?;
377+
378+ let address = derived_descriptor
379+ . address ( network)
380+ . map_err ( |error| DescriptorError :: Miniscript {
381+ error_message : error. to_string ( ) ,
382+ } ) ?
383+ . into ( ) ;
384+
385+ Ok ( Arc :: new ( address) )
386+ }
358387}
359388
360389impl Display for Descriptor {
0 commit comments