Skip to content

Commit 30f125f

Browse files
committed
Satisfy program with optional pruning
1 parent 818f017 commit 30f125f

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/lib.rs

Lines changed: 21 additions & 4 deletions
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;
@@ -133,15 +134,31 @@ impl CompiledProgram {
133134
/// - Witness values have a different type than declared in the Simfony program.
134135
/// - There are missing witness values.
135136
pub fn satisfy(&self, witness_values: WitnessValues) -> Result<SatisfiedProgram, String> {
137+
self.satisfy_with_env(witness_values, None)
138+
}
139+
140+
/// Satisfy the Simfony program with the given `witness_values`.
141+
/// If `env` is `None`, the program is not pruned, otherwise it is pruned with the given environment.
142+
///
143+
/// ## Errors
144+
///
145+
/// - Witness values have a different type than declared in the Simfony program.
146+
/// - There are missing witness values.
147+
pub fn satisfy_with_env(
148+
&self,
149+
witness_values: WitnessValues,
150+
env: Option<&ElementsEnv<Arc<elements::Transaction>>>,
151+
) -> Result<SatisfiedProgram, String> {
136152
witness_values
137153
.is_consistent(&self.witness_types)
138154
.map_err(|e| e.to_string())?;
139155
let simplicity_witness = named::to_witness_node(&self.simplicity, witness_values);
140-
let simplicity_redeem = simplicity_witness
141-
.finalize_unpruned()
142-
.map_err(|e| e.to_string())?;
156+
let simplicity_redeem = match env {
157+
Some(env) => simplicity_witness.finalize_pruned(env),
158+
None => simplicity_witness.finalize_unpruned(),
159+
};
143160
Ok(SatisfiedProgram {
144-
simplicity: simplicity_redeem,
161+
simplicity: simplicity_redeem.map_err(|e| e.to_string())?,
145162
debug_symbols: self.debug_symbols.clone(),
146163
})
147164
}

0 commit comments

Comments
 (0)