Skip to content

Commit 6775430

Browse files
committed
Refactor satisfy* functions
Reduce duplicate code by factoring out a helper function. Refactor only, no logic changes.
1 parent 0e96460 commit 6775430

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

src/miniscript/mod.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,8 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
202202
{
203203
// Only satisfactions for default versions (0xc0) are allowed.
204204
let leaf_hash = TapLeafHash::from_script(&self.encode(), LeafVersion::TapScript);
205-
match satisfy::Satisfaction::satisfy(&self.node, &satisfier, self.ty.mall.safe, &leaf_hash)
206-
.stack
207-
{
208-
satisfy::Witness::Stack(stack) => {
209-
Ctx::check_witness::<Pk>(&stack)?;
210-
Ok(stack)
211-
}
212-
satisfy::Witness::Unavailable | satisfy::Witness::Impossible => {
213-
Err(Error::CouldNotSatisfy)
214-
}
215-
}
205+
let satisfaction = satisfy::Satisfaction::satisfy(&self.node, &satisfier, self.ty.mall.safe, &leaf_hash);
206+
self._satisfy(satisfaction)
216207
}
217208

218209
/// Attempt to produce a malleable satisfying witness for the
@@ -225,14 +216,15 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
225216
Pk: ToPublicKey,
226217
{
227218
let leaf_hash = TapLeafHash::from_script(&self.encode(), LeafVersion::TapScript);
228-
match satisfy::Satisfaction::satisfy_mall(
229-
&self.node,
230-
&satisfier,
231-
self.ty.mall.safe,
232-
&leaf_hash,
233-
)
234-
.stack
235-
{
219+
let satisfaction = satisfy::Satisfaction::satisfy_mall(&self.node, &satisfier, self.ty.mall.safe, &leaf_hash);
220+
self._satisfy(satisfaction)
221+
}
222+
223+
fn _satisfy(&self, satisfaction: satisfy::Satisfaction) -> Result<Vec<Vec<u8>>, Error>
224+
where
225+
Pk: ToPublicKey,
226+
{
227+
match satisfaction.stack {
236228
satisfy::Witness::Stack(stack) => {
237229
Ctx::check_witness::<Pk>(&stack)?;
238230
Ok(stack)

0 commit comments

Comments
 (0)