@@ -23,7 +23,7 @@ use crate::prelude::*;
2323use crate :: util:: { varint_len, witness_to_scriptsig} ;
2424use crate :: {
2525 BareCtx , Error , ForEachKey , FromStrKey , Miniscript , MiniscriptKey , Satisfier , ToPublicKey ,
26- TranslateErr , TranslatePk , Translator ,
26+ TranslateErr , Translator ,
2727} ;
2828
2929/// Create a Bare Descriptor. That is descriptor that is
@@ -92,6 +92,15 @@ impl<Pk: MiniscriptKey> Bare<Pk> {
9292 let scriptsig_len = self . ms . max_satisfaction_size ( ) ?;
9393 Ok ( 4 * ( varint_len ( scriptsig_len) + scriptsig_len) )
9494 }
95+
96+ /// Converts the keys in the script from one type to another.
97+ pub fn translate_pk < Q , T , E > ( & self , t : & mut T ) -> Result < Bare < Q > , TranslateErr < E > >
98+ where
99+ T : Translator < Pk , Q , E > ,
100+ Q : MiniscriptKey ,
101+ {
102+ Bare :: new ( self . ms . translate_pk ( t) ?) . map_err ( TranslateErr :: OuterError )
103+ }
95104}
96105
97106impl < Pk : MiniscriptKey + ToPublicKey > Bare < Pk > {
@@ -190,21 +199,6 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Bare<Pk> {
190199 }
191200}
192201
193- impl < P , Q > TranslatePk < P , Q > for Bare < P >
194- where
195- P : MiniscriptKey ,
196- Q : MiniscriptKey ,
197- {
198- type Output = Bare < Q > ;
199-
200- fn translate_pk < T , E > ( & self , t : & mut T ) -> Result < Bare < Q > , TranslateErr < E > >
201- where
202- T : Translator < P , Q , E > ,
203- {
204- Bare :: new ( self . ms . translate_pk ( t) ?) . map_err ( TranslateErr :: OuterError )
205- }
206- }
207-
208202/// A bare PkH descriptor at top level
209203#[ derive( Clone , Ord , PartialOrd , Eq , PartialEq , Hash ) ]
210204pub struct Pkh < Pk : MiniscriptKey > {
@@ -260,6 +254,19 @@ impl<Pk: MiniscriptKey> Pkh<Pk> {
260254 note = "Use max_weight_to_satisfy instead. The method to count bytes was redesigned and the results will differ from max_weight_to_satisfy. For more details check rust-bitcoin/rust-miniscript#476."
261255 ) ]
262256 pub fn max_satisfaction_weight ( & self ) -> usize { 4 * ( 1 + 73 + BareCtx :: pk_len ( & self . pk ) ) }
257+
258+ /// Converts the keys in a script from one type to another.
259+ pub fn translate_pk < Q , T , E > ( & self , t : & mut T ) -> Result < Pkh < Q > , TranslateErr < E > >
260+ where
261+ T : Translator < Pk , Q , E > ,
262+ Q : MiniscriptKey ,
263+ {
264+ let res = Pkh :: new ( t. pk ( & self . pk ) ?) ;
265+ match res {
266+ Ok ( pk) => Ok ( pk) ,
267+ Err ( e) => Err ( TranslateErr :: OuterError ( Error :: from ( e) ) ) ,
268+ }
269+ }
263270}
264271
265272impl < Pk : MiniscriptKey + ToPublicKey > Pkh < Pk > {
@@ -391,22 +398,3 @@ impl<Pk: FromStrKey> core::str::FromStr for Pkh<Pk> {
391398impl < Pk : MiniscriptKey > ForEachKey < Pk > for Pkh < Pk > {
392399 fn for_each_key < ' a , F : FnMut ( & ' a Pk ) -> bool > ( & ' a self , mut pred : F ) -> bool { pred ( & self . pk ) }
393400}
394-
395- impl < P , Q > TranslatePk < P , Q > for Pkh < P >
396- where
397- P : MiniscriptKey ,
398- Q : MiniscriptKey ,
399- {
400- type Output = Pkh < Q > ;
401-
402- fn translate_pk < T , E > ( & self , t : & mut T ) -> Result < Self :: Output , TranslateErr < E > >
403- where
404- T : Translator < P , Q , E > ,
405- {
406- let res = Pkh :: new ( t. pk ( & self . pk ) ?) ;
407- match res {
408- Ok ( pk) => Ok ( pk) ,
409- Err ( e) => Err ( TranslateErr :: OuterError ( Error :: from ( e) ) ) ,
410- }
411- }
412- }
0 commit comments