Skip to content

Commit a60c642

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

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

src/miniscript/mod.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,9 @@ 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 =
206+
satisfy::Satisfaction::satisfy(&self.node, &satisfier, self.ty.mall.safe, &leaf_hash);
207+
self._satisfy(satisfaction)
216208
}
217209

218210
/// Attempt to produce a malleable satisfying witness for the
@@ -225,14 +217,20 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
225217
Pk: ToPublicKey,
226218
{
227219
let leaf_hash = TapLeafHash::from_script(&self.encode(), LeafVersion::TapScript);
228-
match satisfy::Satisfaction::satisfy_mall(
220+
let satisfaction = satisfy::Satisfaction::satisfy_mall(
229221
&self.node,
230222
&satisfier,
231223
self.ty.mall.safe,
232224
&leaf_hash,
233-
)
234-
.stack
235-
{
225+
);
226+
self._satisfy(satisfaction)
227+
}
228+
229+
fn _satisfy(&self, satisfaction: satisfy::Satisfaction) -> Result<Vec<Vec<u8>>, Error>
230+
where
231+
Pk: ToPublicKey,
232+
{
233+
match satisfaction.stack {
236234
satisfy::Witness::Stack(stack) => {
237235
Ctx::check_witness::<Pk>(&stack)?;
238236
Ok(stack)

0 commit comments

Comments
 (0)