Skip to content

Commit 5182529

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

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
@@ -200,17 +200,8 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
200200
{
201201
// Only satisfactions for default versions (0xc0) are allowed.
202202
let leaf_hash = TapLeafHash::from_script(&self.encode(), LeafVersion::TapScript);
203-
match satisfy::Satisfaction::satisfy(&self.node, &satisfier, self.ty.mall.safe, &leaf_hash)
204-
.stack
205-
{
206-
satisfy::Witness::Stack(stack) => {
207-
Ctx::check_witness::<Pk>(&stack)?;
208-
Ok(stack)
209-
}
210-
satisfy::Witness::Unavailable | satisfy::Witness::Impossible => {
211-
Err(Error::CouldNotSatisfy)
212-
}
213-
}
203+
let satisfaction = satisfy::Satisfaction::satisfy(&self.node, &satisfier, self.ty.mall.safe, &leaf_hash);
204+
self._satisfy(satisfaction)
214205
}
215206

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

0 commit comments

Comments
 (0)