@@ -33,7 +33,7 @@ use crate::expression::{self, FromTree};
33
33
use crate :: extensions:: { CovExtArgs , CovenantExt } ;
34
34
use crate :: policy:: { semantic, Liftable } ;
35
35
use crate :: {
36
- BtcDescriptor , BtcError , BtcFromTree , BtcLiftable , BtcPolicy , BtcSatisfier , BtcTree ,
36
+ tweak_key , BtcDescriptor , BtcError , BtcFromTree , BtcLiftable , BtcPolicy , BtcSatisfier , BtcTree ,
37
37
Descriptor , Error , MiniscriptKey , ToPublicKey ,
38
38
} ;
39
39
@@ -198,7 +198,7 @@ impl<Pk: MiniscriptKey> Pegin<Pk> {
198
198
/// for the others it is the witness script.
199
199
pub fn bitcoin_witness_script < C : secp256k1_zkp:: Verification > (
200
200
& self ,
201
- _secp : & secp256k1_zkp:: Secp256k1 < C > ,
201
+ secp : & secp256k1_zkp:: Secp256k1 < C > ,
202
202
) -> Result < BtcScript , Error >
203
203
where
204
204
Pk : ToPublicKey ,
@@ -208,36 +208,31 @@ impl<Pk: MiniscriptKey> Pegin<Pk> {
208
208
. explicit_script ( )
209
209
. expect ( "Tr pegins unknown yet" )
210
210
. into_bytes ( ) ;
211
- let _tweak = hashes:: sha256:: Hash :: hash ( & tweak_vec) ;
211
+ let tweak = hashes:: sha256:: Hash :: hash ( & tweak_vec) ;
212
212
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
+ ) ;
215
217
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
+ }
229
226
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) ;
238
232
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 ( ) ?)
241
236
}
242
237
243
238
/// Returns satisfying witness and scriptSig to spend an
0 commit comments