@@ -29,6 +29,7 @@ use std::{
29
29
str:: { self , FromStr } ,
30
30
} ;
31
31
32
+ use bitcoin:: hashes:: hash160;
32
33
use bitcoin:: secp256k1;
33
34
use bitcoin:: util:: bip32;
34
35
use bitcoin:: { self , Script } ;
@@ -295,6 +296,46 @@ pub trait PkTranslate2<P: MiniscriptKey<Hash = P>, Q: MiniscriptKey>: PkTranslat
295
296
}
296
297
impl < P : MiniscriptKey < Hash = P > , Q : MiniscriptKey , T : PkTranslate < P , Q > > PkTranslate2 < P , Q > for T { }
297
298
299
+ /// Variant of `PkTranslate` where Q's hash is `hash160` so we can
300
+ /// derive hashes by calling `hash_to_hash160`
301
+ pub trait PkTranslate3 <
302
+ P : MiniscriptKey + ToPublicKey < PkCtx > ,
303
+ PkCtx : Copy ,
304
+ Q : MiniscriptKey < Hash = hash160:: Hash > ,
305
+ > : PkTranslate < P , Q >
306
+ {
307
+ /// Translate a struct from one generic to another where the
308
+ /// translation for Pk is provided by translatefpk
309
+ fn translate_pk3 < Fpk , E > (
310
+ & self ,
311
+ translatefpk : Fpk ,
312
+ pk_ctx : PkCtx ,
313
+ ) -> Result < <Self as PkTranslate < P , Q > >:: Output , E >
314
+ where
315
+ Fpk : FnMut ( & P ) -> Result < Q , E > ,
316
+ {
317
+ self . translate_pk ( translatefpk, |h| Ok ( P :: hash_to_hash160 ( h, pk_ctx) ) )
318
+ }
319
+
320
+ /// Translate a struct from one generic to another where the
321
+ /// translation for Pk is provided by translatefpk
322
+ fn translate_pk3_infallible < Fpk : FnMut ( & P ) -> Q > (
323
+ & self ,
324
+ translatefpk : Fpk ,
325
+ pk_ctx : PkCtx ,
326
+ ) -> <Self as PkTranslate < P , Q > >:: Output {
327
+ self . translate_pk_infallible ( translatefpk, |h| P :: hash_to_hash160 ( h, pk_ctx) )
328
+ }
329
+ }
330
+ impl <
331
+ P : MiniscriptKey + ToPublicKey < PkCtx > ,
332
+ PkCtx : Copy ,
333
+ Q : MiniscriptKey < Hash = hash160:: Hash > ,
334
+ T : PkTranslate < P , Q > ,
335
+ > PkTranslate3 < P , PkCtx , Q > for T
336
+ {
337
+ }
338
+
298
339
// There are some additional convenience functions we could add to `PkTranslate`
299
340
// for the common special cases where `P::Hash == Q::Hash`, or when `P == P::Hash`,
300
341
// but these are blocked on https://github.com/rust-lang/rust/issues/20041 which
0 commit comments