@@ -24,7 +24,7 @@ use crate::prelude::*;
2424use crate :: util:: { varint_len, witness_size} ;
2525use crate :: {
2626 errstr, Error , ForEachKey , FromStrKey , MiniscriptKey , Satisfier , ScriptContext , Tap , Threshold ,
27- ToPublicKey , TranslateErr , TranslatePk , Translator ,
27+ ToPublicKey , TranslateErr , Translator ,
2828} ;
2929
3030/// A Taproot Tree representation.
@@ -351,6 +351,21 @@ impl<Pk: MiniscriptKey> Tr<Pk> {
351351 . max ( )
352352 . ok_or ( Error :: ImpossibleSatisfaction )
353353 }
354+
355+ /// Converts keys from one type of public key to another.
356+ pub fn translate_pk < Q , T , E > ( & self , translate : & mut T ) -> Result < Tr < Q > , TranslateErr < E > >
357+ where
358+ T : Translator < Pk , Q , E > ,
359+ Q : MiniscriptKey ,
360+ {
361+ let tree = match & self . tree {
362+ Some ( tree) => Some ( tree. translate_helper ( translate) ?) ,
363+ None => None ,
364+ } ;
365+ let translate_desc = Tr :: new ( translate. pk ( & self . internal_key ) ?, tree)
366+ . map_err ( |e| TranslateErr :: OuterError ( e) ) ?;
367+ Ok ( translate_desc)
368+ }
354369}
355370
356371impl < Pk : MiniscriptKey + ToPublicKey > Tr < Pk > {
@@ -652,27 +667,6 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Tr<Pk> {
652667 }
653668}
654669
655- impl < P , Q > TranslatePk < P , Q > for Tr < P >
656- where
657- P : MiniscriptKey ,
658- Q : MiniscriptKey ,
659- {
660- type Output = Tr < Q > ;
661-
662- fn translate_pk < T , E > ( & self , translate : & mut T ) -> Result < Self :: Output , TranslateErr < E > >
663- where
664- T : Translator < P , Q , E > ,
665- {
666- let tree = match & self . tree {
667- Some ( tree) => Some ( tree. translate_helper ( translate) ?) ,
668- None => None ,
669- } ;
670- let translate_desc = Tr :: new ( translate. pk ( & self . internal_key ) ?, tree)
671- . map_err ( |e| TranslateErr :: OuterError ( e) ) ?;
672- Ok ( translate_desc)
673- }
674- }
675-
676670// Helper function to compute the len of control block at a given depth
677671fn control_block_len ( depth : u8 ) -> usize {
678672 TAPROOT_CONTROL_BASE_SIZE + ( depth as usize ) * TAPROOT_CONTROL_NODE_SIZE
0 commit comments