@@ -1004,7 +1004,7 @@ mod tests {
1004
1004
use bitcoin:: hashes:: Hash ;
1005
1005
use bitcoin:: script:: PushBytes ;
1006
1006
use bitcoin:: sighash:: EcdsaSighashType ;
1007
- use bitcoin:: { bip32, PublicKey , Sequence } ;
1007
+ use bitcoin:: { bip32, PublicKey , Sequence , XOnlyPublicKey } ;
1008
1008
1009
1009
use super :: checksum:: desc_checksum;
1010
1010
use super :: * ;
@@ -2064,4 +2064,58 @@ pk(03f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8))";
2064
2064
)
2065
2065
. unwrap_err ( ) ;
2066
2066
}
2067
+
2068
+ #[ test]
2069
+ fn convert_public_key_descriptor_to_definite_key ( ) {
2070
+ let descriptor_str = "wsh(or_d(pk(021d4ea7132d4e1a362ee5efd8d0b59dd4d1fe8906eefa7dd812b05a46b73d829b),pk(0302c8bbbb393f32c843149ce36d56405595aaabab2d0e1f4ca5f9de67dd7419f6)))" ;
2071
+ let full_pk_descriptor: Descriptor < PublicKey > =
2072
+ Descriptor :: from_str ( descriptor_str) . unwrap ( ) ;
2073
+
2074
+ struct TranslateFullPk ;
2075
+
2076
+ impl Translator < bitcoin:: PublicKey > for TranslateFullPk {
2077
+ type TargetPk = DefiniteDescriptorKey ;
2078
+ type Error = core:: convert:: Infallible ;
2079
+
2080
+ fn pk (
2081
+ & mut self ,
2082
+ pk : & bitcoin:: PublicKey ,
2083
+ ) -> Result < DefiniteDescriptorKey , Self :: Error > {
2084
+ Ok ( DefiniteDescriptorKey :: new ( DescriptorPublicKey :: from ( * pk) )
2085
+ . expect ( "DescriptorPublicKey from PublicKey has no wildcards" ) )
2086
+ }
2087
+
2088
+ translate_hash_clone ! ( bitcoin:: PublicKey , DefiniteDescriptorKey , Self :: Error ) ;
2089
+ }
2090
+
2091
+ let converted_descriptor = full_pk_descriptor
2092
+ . translate_pk ( & mut TranslateFullPk )
2093
+ . expect ( "infallible" ) ;
2094
+
2095
+ assert_eq ! ( full_pk_descriptor. to_string( ) , converted_descriptor. to_string( ) ) ;
2096
+
2097
+ let xonly_descriptor_str = "tr(1d4ea7132d4e1a362ee5efd8d0b59dd4d1fe8906eefa7dd812b05a46b73d829b,pk(02c8bbbb393f32c843149ce36d56405595aaabab2d0e1f4ca5f9de67dd7419f6))" ;
2098
+ let xonly_pk_descriptor: Descriptor < XOnlyPublicKey > =
2099
+ Descriptor :: from_str ( xonly_descriptor_str) . unwrap ( ) ;
2100
+
2101
+ struct TranslateXOnlyPk ;
2102
+
2103
+ impl Translator < XOnlyPublicKey > for TranslateXOnlyPk {
2104
+ type TargetPk = DefiniteDescriptorKey ;
2105
+ type Error = core:: convert:: Infallible ;
2106
+
2107
+ fn pk ( & mut self , pk : & XOnlyPublicKey ) -> Result < DefiniteDescriptorKey , Self :: Error > {
2108
+ Ok ( DefiniteDescriptorKey :: new ( DescriptorPublicKey :: from ( * pk) )
2109
+ . expect ( "DescriptorPublicKey from XOnlyPublicKey has no wildcards" ) )
2110
+ }
2111
+
2112
+ translate_hash_clone ! ( XOnlyPublicKey , DefiniteDescriptorKey , Self :: Error ) ;
2113
+ }
2114
+
2115
+ let xonly_converted_descriptor = xonly_pk_descriptor
2116
+ . translate_pk ( & mut TranslateXOnlyPk )
2117
+ . expect ( "infallible" ) ;
2118
+
2119
+ assert_eq ! ( xonly_pk_descriptor. to_string( ) , xonly_converted_descriptor. to_string( ) ) ;
2120
+ }
2067
2121
}
0 commit comments