Skip to content

Commit 81b25cd

Browse files
committed
move only: move TranslateTweak out so that is usable in other fn
1 parent cfe6306 commit 81b25cd

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/descriptor/pegin/dynafed_pegin.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -280,32 +280,33 @@ fn bitcoin_witness_script<C: secp256k1_zkp::Verification, Pk: ToPublicKey>(
280280
claim_script: &[u8],
281281
secp: &secp256k1_zkp::Secp256k1<C>,
282282
) -> Result<BtcScript, Error> {
283-
struct TranslateTweak<'a, 'b, C: secp256k1_zkp::Verification>(
284-
&'a [u8],
285-
&'b secp256k1_zkp::Secp256k1<C>,
286-
);
287-
288-
impl<'a, 'b, Pk, C> bitcoin_miniscript::Translator<Pk, bitcoin::PublicKey, ()>
289-
for TranslateTweak<'a, 'b, C>
290-
where
291-
Pk: MiniscriptKey + ToPublicKey,
292-
C: secp256k1_zkp::Verification,
293-
{
294-
fn pk(&mut self, pk: &Pk) -> Result<bitcoin::PublicKey, ()> {
295-
Ok(tweak_key(&pk.to_public_key(), self.1, &self.0[..]))
296-
}
297-
298-
// We don't need to implement these methods as we are not using them in the policy.
299-
// Fail if we encounter any hash fragments. See also translate_hash_clone! macro.
300-
translate_hash_fail!(Pk, bitcoin::PublicKey, ());
301-
}
302283
let mut t = TranslateTweak(claim_script, secp);
303284

304285
let tweaked_desc = bitcoin_miniscript::TranslatePk::translate_pk(fed_desc, &mut t)
305286
.expect("Tweaking must succeed");
306287
Ok(tweaked_desc.explicit_script()?)
307288
}
308289

290+
struct TranslateTweak<'a, 'b, C: secp256k1_zkp::Verification>(
291+
&'a [u8],
292+
&'b secp256k1_zkp::Secp256k1<C>,
293+
);
294+
295+
impl<'a, 'b, Pk, C> bitcoin_miniscript::Translator<Pk, bitcoin::PublicKey, ()>
296+
for TranslateTweak<'a, 'b, C>
297+
where
298+
Pk: MiniscriptKey + ToPublicKey,
299+
C: secp256k1_zkp::Verification,
300+
{
301+
fn pk(&mut self, pk: &Pk) -> Result<bitcoin::PublicKey, ()> {
302+
Ok(tweak_key(&pk.to_public_key(), self.1, &self.0[..]))
303+
}
304+
305+
// We don't need to implement these methods as we are not using them in the policy.
306+
// Fail if we encounter any hash fragments. See also translate_hash_clone! macro.
307+
translate_hash_fail!(Pk, bitcoin::PublicKey, ());
308+
}
309+
309310
#[cfg(test)]
310311
mod tests {
311312
use elements::hex::FromHex;

0 commit comments

Comments
 (0)