@@ -1051,7 +1051,7 @@ mod tests {
1051
1051
use bitcoin:: hashes:: Hash ;
1052
1052
use bitcoin:: script:: PushBytes ;
1053
1053
use bitcoin:: sighash:: EcdsaSighashType ;
1054
- use bitcoin:: { bip32, PublicKey , Sequence } ;
1054
+ use bitcoin:: { bip32, PublicKey , Sequence , XOnlyPublicKey } ;
1055
1055
1056
1056
use super :: { checksum, * } ;
1057
1057
use crate :: hex_script;
@@ -2183,4 +2183,58 @@ pk(03f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8))";
2183
2183
)
2184
2184
. unwrap_err ( ) ;
2185
2185
}
2186
+
2187
+ #[ test]
2188
+ fn convert_public_key_descriptor_to_definite_key ( ) {
2189
+ let descriptor_str = "wsh(or_d(pk(021d4ea7132d4e1a362ee5efd8d0b59dd4d1fe8906eefa7dd812b05a46b73d829b),pk(0302c8bbbb393f32c843149ce36d56405595aaabab2d0e1f4ca5f9de67dd7419f6)))" ;
2190
+ let full_pk_descriptor: Descriptor < PublicKey > =
2191
+ Descriptor :: from_str ( descriptor_str) . unwrap ( ) ;
2192
+
2193
+ struct TranslateFullPk ;
2194
+
2195
+ impl Translator < bitcoin:: PublicKey > for TranslateFullPk {
2196
+ type TargetPk = DefiniteDescriptorKey ;
2197
+ type Error = core:: convert:: Infallible ;
2198
+
2199
+ fn pk (
2200
+ & mut self ,
2201
+ pk : & bitcoin:: PublicKey ,
2202
+ ) -> Result < DefiniteDescriptorKey , Self :: Error > {
2203
+ Ok ( DefiniteDescriptorKey :: new ( DescriptorPublicKey :: from ( * pk) )
2204
+ . expect ( "DescriptorPublicKey from PublicKey has no wildcards" ) )
2205
+ }
2206
+
2207
+ translate_hash_clone ! ( bitcoin:: PublicKey , DefiniteDescriptorKey , Self :: Error ) ;
2208
+ }
2209
+
2210
+ let converted_descriptor = full_pk_descriptor
2211
+ . translate_pk ( & mut TranslateFullPk )
2212
+ . expect ( "infallible" ) ;
2213
+
2214
+ assert_eq ! ( full_pk_descriptor. to_string( ) , converted_descriptor. to_string( ) ) ;
2215
+
2216
+ let xonly_descriptor_str = "tr(1d4ea7132d4e1a362ee5efd8d0b59dd4d1fe8906eefa7dd812b05a46b73d829b,pk(02c8bbbb393f32c843149ce36d56405595aaabab2d0e1f4ca5f9de67dd7419f6))" ;
2217
+ let xonly_pk_descriptor: Descriptor < XOnlyPublicKey > =
2218
+ Descriptor :: from_str ( xonly_descriptor_str) . unwrap ( ) ;
2219
+
2220
+ struct TranslateXOnlyPk ;
2221
+
2222
+ impl Translator < XOnlyPublicKey > for TranslateXOnlyPk {
2223
+ type TargetPk = DefiniteDescriptorKey ;
2224
+ type Error = core:: convert:: Infallible ;
2225
+
2226
+ fn pk ( & mut self , pk : & XOnlyPublicKey ) -> Result < DefiniteDescriptorKey , Self :: Error > {
2227
+ Ok ( DefiniteDescriptorKey :: new ( DescriptorPublicKey :: from ( * pk) )
2228
+ . expect ( "DescriptorPublicKey from XOnlyPublicKey has no wildcards" ) )
2229
+ }
2230
+
2231
+ translate_hash_clone ! ( XOnlyPublicKey , DefiniteDescriptorKey , Self :: Error ) ;
2232
+ }
2233
+
2234
+ let xonly_converted_descriptor = xonly_pk_descriptor
2235
+ . translate_pk ( & mut TranslateXOnlyPk )
2236
+ . expect ( "infallible" ) ;
2237
+
2238
+ assert_eq ! ( xonly_pk_descriptor. to_string( ) , xonly_converted_descriptor. to_string( ) ) ;
2239
+ }
2186
2240
}
0 commit comments