Skip to content

Commit 1f279e2

Browse files
committed
Merge #125: Satisfy program with optional pruning
30f125f Satisfy program with optional pruning (Michael Zaikin) Pull request description: This PR exposes an API for satisfying a program with pruning given an optional environment. The naming might be a bit misleading (maybe `satisfy_pruned` would be better?), pls let me know if you want to change. ACKs for top commit: uncomputable: ACK 30f125f apoelstra: ACK 30f125f; successfully ran local tests Tree-SHA512: 692d980ec3e5ba1e75132349552f0b2180dc222b2f5f2786ceeb3d70dc1587ad346382395582967fa99defc063d4bc0acd7d53c03a107dabcb147fed0311180e
2 parents 2aeb2d4 + 30f125f commit 1f279e2

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/lib.rs

+21-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ mod witness;
2222

2323
use std::sync::Arc;
2424

25+
use simplicity::jet::elements::ElementsEnv;
2526
use simplicity::{jet::Elements, CommitNode, RedeemNode};
2627

2728
pub extern crate either;
@@ -142,15 +143,31 @@ impl CompiledProgram {
142143
/// - Witness values have a different type than declared in the Simfony program.
143144
/// - There are missing witness values.
144145
pub fn satisfy(&self, witness_values: WitnessValues) -> Result<SatisfiedProgram, String> {
146+
self.satisfy_with_env(witness_values, None)
147+
}
148+
149+
/// Satisfy the Simfony program with the given `witness_values`.
150+
/// If `env` is `None`, the program is not pruned, otherwise it is pruned with the given environment.
151+
///
152+
/// ## Errors
153+
///
154+
/// - Witness values have a different type than declared in the Simfony program.
155+
/// - There are missing witness values.
156+
pub fn satisfy_with_env(
157+
&self,
158+
witness_values: WitnessValues,
159+
env: Option<&ElementsEnv<Arc<elements::Transaction>>>,
160+
) -> Result<SatisfiedProgram, String> {
145161
witness_values
146162
.is_consistent(&self.witness_types)
147163
.map_err(|e| e.to_string())?;
148164
let simplicity_witness = named::to_witness_node(&self.simplicity, witness_values);
149-
let simplicity_redeem = simplicity_witness
150-
.finalize_unpruned()
151-
.map_err(|e| e.to_string())?;
165+
let simplicity_redeem = match env {
166+
Some(env) => simplicity_witness.finalize_pruned(env),
167+
None => simplicity_witness.finalize_unpruned(),
168+
};
152169
Ok(SatisfiedProgram {
153-
simplicity: simplicity_redeem,
170+
simplicity: simplicity_redeem.map_err(|e| e.to_string())?,
154171
debug_symbols: self.debug_symbols.clone(),
155172
})
156173
}

0 commit comments

Comments
 (0)