@@ -76,14 +76,6 @@ pub type KeyMap = HashMap<DescriptorPublicKey, DescriptorSecretKey>;
7676// because of traits cannot know underlying generic of Self.
7777// Thus, we must implement additional trait for translate function
7878pub trait DescriptorTrait < Pk : MiniscriptKey > {
79- /// Computes the Bitcoin address of the descriptor, if one exists
80- /// Some descriptors like pk() don't have any address.
81- /// Errors:
82- /// - On raw/bare descriptors that don't have any address
83- fn address ( & self , network : Network ) -> Result < Address , Error >
84- where
85- Pk : ToPublicKey ;
86-
8779 /// Computes the scriptpubkey of the descriptor
8880 fn script_pubkey ( & self ) -> Script
8981 where
@@ -407,6 +399,25 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
407399 }
408400}
409401
402+ impl < Pk : MiniscriptKey + ToPublicKey > Descriptor < Pk > {
403+ /// Computes the Bitcoin address of the descriptor, if one exists
404+ ///
405+ /// Some descriptors like pk() don't have any address.
406+ ///
407+ /// # Errors
408+ /// For raw/bare descriptors that don't have any address.
409+ pub fn address ( & self , network : Network ) -> Result < Address , Error > {
410+ match * self {
411+ Descriptor :: Bare ( _) => Err ( Error :: BareDescriptorAddr ) ,
412+ Descriptor :: Pkh ( ref pkh) => Ok ( pkh. address ( network) ) ,
413+ Descriptor :: Wpkh ( ref wpkh) => Ok ( wpkh. address ( network) ) ,
414+ Descriptor :: Wsh ( ref wsh) => Ok ( wsh. address ( network) ) ,
415+ Descriptor :: Sh ( ref sh) => Ok ( sh. address ( network) ) ,
416+ Descriptor :: Tr ( ref tr) => Ok ( tr. address ( network) ) ,
417+ }
418+ }
419+ }
420+
410421impl < P , Q > TranslatePk < P , Q > for Descriptor < P >
411422where
412423 P : MiniscriptKey ,
@@ -438,21 +449,6 @@ where
438449}
439450
440451impl < Pk : MiniscriptKey > DescriptorTrait < Pk > for Descriptor < Pk > {
441- /// Computes the Bitcoin address of the descriptor, if one exists
442- fn address ( & self , network : Network ) -> Result < Address , Error >
443- where
444- Pk : ToPublicKey ,
445- {
446- match * self {
447- Descriptor :: Bare ( ref bare) => bare. address ( network) ,
448- Descriptor :: Pkh ( ref pkh) => pkh. address ( network) ,
449- Descriptor :: Wpkh ( ref wpkh) => wpkh. address ( network) ,
450- Descriptor :: Wsh ( ref wsh) => wsh. address ( network) ,
451- Descriptor :: Sh ( ref sh) => sh. address ( network) ,
452- Descriptor :: Tr ( ref tr) => tr. address ( network) ,
453- }
454- }
455-
456452 /// Computes the scriptpubkey of the descriptor
457453 fn script_pubkey ( & self ) -> Script
458454 where
0 commit comments