@@ -361,10 +361,12 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
361
361
}
362
362
363
363
/// Converts a descriptor using one kind of keys to another kind of key.
364
- pub fn translate_pk < T , Q , E > ( & self , t : & mut T ) -> Result < Descriptor < Q > , TranslateErr < E > >
364
+ pub fn translate_pk < T > (
365
+ & self ,
366
+ t : & mut T ,
367
+ ) -> Result < Descriptor < T :: TargetPk > , TranslateErr < T :: Error > >
365
368
where
366
- T : Translator < Pk , Q , E > ,
367
- Q : MiniscriptKey ,
369
+ T : Translator < Pk > ,
368
370
{
369
371
let desc = match * self {
370
372
Descriptor :: Bare ( ref bare) => Descriptor :: Bare ( bare. translate_pk ( t) ?) ,
@@ -600,7 +602,10 @@ impl Descriptor<DescriptorPublicKey> {
600
602
) -> Result < Descriptor < DefiniteDescriptorKey > , ConversionError > {
601
603
struct Derivator ( u32 ) ;
602
604
603
- impl Translator < DescriptorPublicKey , DefiniteDescriptorKey , ConversionError > for Derivator {
605
+ impl Translator < DescriptorPublicKey > for Derivator {
606
+ type TargetPk = DefiniteDescriptorKey ;
607
+ type Error = ConversionError ;
608
+
604
609
fn pk (
605
610
& mut self ,
606
611
pk : & DescriptorPublicKey ,
@@ -691,9 +696,10 @@ impl Descriptor<DescriptorPublicKey> {
691
696
692
697
struct KeyMapWrapper < ' a , C : secp256k1:: Signing > ( KeyMap , & ' a secp256k1:: Secp256k1 < C > ) ;
693
698
694
- impl < ' a , C : secp256k1:: Signing > Translator < String , DescriptorPublicKey , Error >
695
- for KeyMapWrapper < ' a , C >
696
- {
699
+ impl < ' a , C : secp256k1:: Signing > Translator < String > for KeyMapWrapper < ' a , C > {
700
+ type TargetPk = DescriptorPublicKey ;
701
+ type Error = Error ;
702
+
697
703
fn pk ( & mut self , pk : & String ) -> Result < DescriptorPublicKey , Error > {
698
704
parse_key ( pk, & mut self . 0 , self . 1 )
699
705
}
@@ -738,29 +744,35 @@ impl Descriptor<DescriptorPublicKey> {
738
744
pub fn to_string_with_secret ( & self , key_map : & KeyMap ) -> String {
739
745
struct KeyMapLookUp < ' a > ( & ' a KeyMap ) ;
740
746
741
- impl < ' a > Translator < DescriptorPublicKey , String , ( ) > for KeyMapLookUp < ' a > {
742
- fn pk ( & mut self , pk : & DescriptorPublicKey ) -> Result < String , ( ) > {
747
+ impl < ' a > Translator < DescriptorPublicKey > for KeyMapLookUp < ' a > {
748
+ type TargetPk = String ;
749
+ type Error = core:: convert:: Infallible ;
750
+
751
+ fn pk ( & mut self , pk : & DescriptorPublicKey ) -> Result < String , Self :: Error > {
743
752
key_to_string ( pk, self . 0 )
744
753
}
745
754
746
- fn sha256 ( & mut self , sha256 : & sha256:: Hash ) -> Result < String , ( ) > {
755
+ fn sha256 ( & mut self , sha256 : & sha256:: Hash ) -> Result < String , Self :: Error > {
747
756
Ok ( sha256. to_string ( ) )
748
757
}
749
758
750
- fn hash256 ( & mut self , hash256 : & hash256:: Hash ) -> Result < String , ( ) > {
759
+ fn hash256 ( & mut self , hash256 : & hash256:: Hash ) -> Result < String , Self :: Error > {
751
760
Ok ( hash256. to_string ( ) )
752
761
}
753
762
754
- fn ripemd160 ( & mut self , ripemd160 : & ripemd160:: Hash ) -> Result < String , ( ) > {
763
+ fn ripemd160 ( & mut self , ripemd160 : & ripemd160:: Hash ) -> Result < String , Self :: Error > {
755
764
Ok ( ripemd160. to_string ( ) )
756
765
}
757
766
758
- fn hash160 ( & mut self , hash160 : & hash160:: Hash ) -> Result < String , ( ) > {
767
+ fn hash160 ( & mut self , hash160 : & hash160:: Hash ) -> Result < String , Self :: Error > {
759
768
Ok ( hash160. to_string ( ) )
760
769
}
761
770
}
762
771
763
- fn key_to_string ( pk : & DescriptorPublicKey , key_map : & KeyMap ) -> Result < String , ( ) > {
772
+ fn key_to_string (
773
+ pk : & DescriptorPublicKey ,
774
+ key_map : & KeyMap ,
775
+ ) -> Result < String , core:: convert:: Infallible > {
764
776
Ok ( match key_map. get ( pk) {
765
777
Some ( secret) => secret. to_string ( ) ,
766
778
None => pk. to_string ( ) ,
@@ -835,7 +847,10 @@ impl Descriptor<DescriptorPublicKey> {
835
847
836
848
// Now, transform the multipath key of each descriptor into a single-key using each index.
837
849
struct IndexChoser ( usize ) ;
838
- impl Translator < DescriptorPublicKey , DescriptorPublicKey , Error > for IndexChoser {
850
+ impl Translator < DescriptorPublicKey > for IndexChoser {
851
+ type TargetPk = DescriptorPublicKey ;
852
+ type Error = Error ;
853
+
839
854
fn pk ( & mut self , pk : & DescriptorPublicKey ) -> Result < DescriptorPublicKey , Error > {
840
855
match pk {
841
856
DescriptorPublicKey :: Single ( ..) | DescriptorPublicKey :: XPub ( ..) => {
@@ -892,10 +907,10 @@ impl Descriptor<DefiniteDescriptorKey> {
892
907
) -> Result < Descriptor < bitcoin:: PublicKey > , ConversionError > {
893
908
struct Derivator < ' a , C : secp256k1:: Verification > ( & ' a secp256k1:: Secp256k1 < C > ) ;
894
909
895
- impl < ' a , C : secp256k1:: Verification >
896
- Translator < DefiniteDescriptorKey , bitcoin:: PublicKey , ConversionError >
897
- for Derivator < ' a , C >
898
- {
910
+ impl < ' a , C : secp256k1:: Verification > Translator < DefiniteDescriptorKey > for Derivator < ' a , C > {
911
+ type TargetPk = bitcoin:: PublicKey ;
912
+ type Error = ConversionError ;
913
+
899
914
fn pk (
900
915
& mut self ,
901
916
pk : & DefiniteDescriptorKey ,
0 commit comments