@@ -33,7 +33,7 @@ use crate::expression::{self, FromTree};
3333use crate :: extensions:: { CovExtArgs , CovenantExt } ;
3434use crate :: policy:: { semantic, Liftable } ;
3535use crate :: {
36- BtcDescriptor , BtcError , BtcFromTree , BtcLiftable , BtcPolicy , BtcSatisfier , BtcTree ,
36+ tweak_key , BtcDescriptor , BtcError , BtcFromTree , BtcLiftable , BtcPolicy , BtcSatisfier , BtcTree ,
3737 Descriptor , Error , MiniscriptKey , ToPublicKey ,
3838} ;
3939
@@ -198,7 +198,7 @@ impl<Pk: MiniscriptKey> Pegin<Pk> {
198198 /// for the others it is the witness script.
199199 pub fn bitcoin_witness_script < C : secp256k1_zkp:: Verification > (
200200 & self ,
201- _secp : & secp256k1_zkp:: Secp256k1 < C > ,
201+ secp : & secp256k1_zkp:: Secp256k1 < C > ,
202202 ) -> Result < BtcScript , Error >
203203 where
204204 Pk : ToPublicKey ,
@@ -208,36 +208,31 @@ impl<Pk: MiniscriptKey> Pegin<Pk> {
208208 . explicit_script ( )
209209 . expect ( "Tr pegins unknown yet" )
210210 . into_bytes ( ) ;
211- let _tweak = hashes:: sha256:: Hash :: hash ( & tweak_vec) ;
211+ let tweak = hashes:: sha256:: Hash :: hash ( & tweak_vec) ;
212212
213- unreachable ! ( "TODO: After upstream Refactor for Translator trait" )
214- // let derived = self.fed_desc.derive
213+ struct TranslateTweak < ' a , C : secp256k1_zkp:: Verification > (
214+ hashes:: sha256:: Hash ,
215+ & ' a secp256k1_zkp:: Secp256k1 < C > ,
216+ ) ;
215217
216- // struct TranslateTweak<'a, C: secp256k1_zkp::Verification>(
217- // hashes::sha256::Hash,
218- // &'a secp256k1_zkp::Secp256k1<C>,
219- // );
220-
221- // impl<'a, Pk, C> PkTranslator<Pk, bitcoin::PublicKey, ()> for TranslateTweak<'a, C>
222- // where
223- // Pk: MiniscriptKey,
224- // C: secp256k1_zkp::Verification,
225- // {
226- // fn pk(&mut self, pk: &Pk) -> Result<bitcoin::PublicKey, ()> {
227- // tweak_key(pk, self.1, self.0.as_inner())
228- // }
218+ impl < ' a , Pk , C > bitcoin_miniscript:: Translator < Pk , bitcoin:: PublicKey , ( ) > for TranslateTweak < ' a , C >
219+ where
220+ Pk : MiniscriptKey + ToPublicKey ,
221+ C : secp256k1_zkp:: Verification ,
222+ {
223+ fn pk ( & mut self , pk : & Pk ) -> Result < bitcoin:: PublicKey , ( ) > {
224+ Ok ( tweak_key ( & pk. to_public_key ( ) , self . 1 , & self . 0 [ ..] ) )
225+ }
229226
230- // fn pkh(
231- // &mut self,
232- // pkh: &<Pk as MiniscriptKey>::Hash,
233- // ) -> Result<<bitcoin::PublicKey as MiniscriptKey>::Hash, ()> {
234- // unreachable!("No keyhashes in elements descriptors")
235- // }
236- // }
237- // let mut t = TranslateTweak(tweak, secp);
227+ // We don't need to implement these methods as we are not using them in the policy.
228+ // Fail if we encounter any hash fragments. See also translate_hash_clone! macro.
229+ translate_hash_fail ! ( Pk , bitcoin:: PublicKey , ( ) ) ;
230+ }
231+ let mut t = TranslateTweak ( tweak, secp) ;
238232
239- // let tweaked_desc = <bitcoin_miniscript::TranslatePk>::translate_pk(&self.fed_desc, t).expect("Tweaking must succeed"),
240- // Ok(tweaked_desc.explicit_script()?)
233+ let tweaked_desc = bitcoin_miniscript:: TranslatePk :: translate_pk ( & self . fed_desc , & mut t)
234+ . expect ( "Tweaking must succeed" ) ;
235+ Ok ( tweaked_desc. explicit_script ( ) ?)
241236 }
242237
243238 /// Returns satisfying witness and scriptSig to spend an
0 commit comments