Skip to content

Commit d79a2cf

Browse files
committed
finish to implement get_bitcoin_satisfaction
1 parent 81b25cd commit d79a2cf

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/descriptor/pegin/dynafed_pegin.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ use std::convert::TryFrom;
2424
use std::fmt;
2525

2626
use bitcoin::blockdata::script::{self, PushBytes};
27-
use bitcoin::hashes::Hash;
28-
use bitcoin::{self, hashes, ScriptBuf as BtcScript};
27+
use bitcoin::{self, ScriptBuf as BtcScript};
2928
use elements::secp256k1_zkp;
3029

3130
use crate::descriptor::checksum::{desc_checksum, verify_checksum};
@@ -216,26 +215,25 @@ impl<Pk: MiniscriptKey> Pegin<Pk> {
216215
/// construct one using the satisfier S.
217216
pub fn get_bitcoin_satisfaction<S, C: secp256k1_zkp::Verification>(
218217
&self,
219-
_secp: &secp256k1_zkp::Secp256k1<C>,
220-
_satisfier: S,
218+
secp: &secp256k1_zkp::Secp256k1<C>,
219+
satisfier: S,
221220
) -> Result<(Vec<Vec<u8>>, BtcScript), Error>
222221
where
223222
S: BtcSatisfier<bitcoin::PublicKey>,
224223
Pk: ToPublicKey,
225224
{
226-
let tweak_vec = self
225+
let claim_script = self
227226
.elem_desc
228227
.explicit_script()
229228
.expect("Tr pegins unknown yet")
230229
.into_bytes();
231-
let _tweak = hashes::sha256::Hash::hash(&tweak_vec);
232-
unreachable!("TODO: After upstream refactor");
233-
// let tweaked_desc = self.fed_desc.translate_pk_infallible(
234-
// |pk| tweak_key(pk, secp, tweak.as_inner()),
235-
// |_| unreachable!("No keyhashes in elements descriptors"),
236-
// );
237-
// let res = tweaked_desc.get_satisfaction(satisfier)?;
238-
// Ok(res)
230+
let mut t = TranslateTweak(&claim_script[..], secp);
231+
232+
let tweaked_desc = bitcoin_miniscript::TranslatePk::translate_pk(&self.fed_desc, &mut t)
233+
.expect("Tweaking must succeed");
234+
235+
let res = tweaked_desc.get_satisfaction(satisfier)?;
236+
Ok(res)
239237
}
240238

241239
/// Computes an upper bound on the weight of a satisfying witness to the

0 commit comments

Comments
 (0)