Skip to content

Commit ca92df2

Browse files
committed
New miniscript compiler
1 parent 9f68b46 commit ca92df2

File tree

7 files changed

+698
-453
lines changed

7 files changed

+698
-453
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "miniscript"
3-
version = "0.6.0"
3+
version = "0.7.0"
44
authors = ["Andrew Poelstra <[email protected]>"]
55
repository = "https://github.com/apoelstra/miniscript"
66
description = "Miniscript: a subset of Bitcoin Script designed for analysis"

examples/compiler.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

fuzz/fuzz_targets/compile_descriptor.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ fn do_test(data: &[u8]) {
1212
let data_str = String::from_utf8_lossy(data);
1313
if let Ok(pol) = DummyPolicy::from_str(&data_str) {
1414
// Compile
15-
let desc = pol.compile();
16-
// Lift
17-
assert_eq!(desc.clone().lift(), pol.clone().lift());
18-
// Try to roundtrip the output of the compiler
19-
let output = desc.to_string();
20-
if let Ok(desc) = DummyScript::from_str(&output) {
21-
let rtt = desc.to_string();
22-
assert_eq!(output, rtt);
23-
} else {
24-
panic!("compiler output something unparseable: {}", output)
15+
if let Ok(desc) = pol.compile() {
16+
// Lift
17+
assert_eq!(desc.clone().lift(), pol.clone().lift());
18+
// Try to roundtrip the output of the compiler
19+
let output = desc.to_string();
20+
if let Ok(desc) = DummyScript::from_str(&output) {
21+
let rtt = desc.to_string();
22+
assert_eq!(output, rtt);
23+
} else {
24+
panic!("compiler output something unparseable: {}", output)
25+
}
2526
}
2627
}
2728
}

src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@ pub enum Error {
307307
BadDescriptor,
308308
///Forward-secp related errors
309309
Secp(secp256k1::Error),
310+
#[cfg(feature = "compiler")]
311+
///Compiler related errors
312+
CompilerError(policy::compiler::CompilerError),
310313
///Interpreter related errors
311314
InterpreterError(descriptor::InterpreterError),
312315
/// Bad Script Sig. As per standardness rules, only pushes are allowed in
@@ -395,6 +398,8 @@ impl fmt::Display for Error {
395398
Error::BadDescriptor => f.write_str("could not create a descriptor"),
396399
Error::Secp(ref e) => fmt::Display::fmt(e, f),
397400
Error::InterpreterError(ref e) => fmt::Display::fmt(e, f),
401+
#[cfg(feature = "compiler")]
402+
Error::CompilerError(ref e) => fmt::Display::fmt(e, f),
398403
Error::BadScriptSig => f.write_str("Script sig must only consist of pushes"),
399404
Error::NonEmptyWitness => f.write_str("Non empty witness for Pk/Pkh"),
400405
Error::NonEmptyScriptSig => f.write_str("Non empty script sig for segwit spend"),
@@ -415,6 +420,14 @@ impl From<psbt::Error> for Error {
415420
}
416421
}
417422

423+
#[doc(hidden)]
424+
#[cfg(feature = "compiler")]
425+
impl From<policy::compiler::CompilerError> for Error {
426+
fn from(e: policy::compiler::CompilerError) -> Error {
427+
Error::CompilerError(e)
428+
}
429+
}
430+
418431
/// The size of an encoding of a number in Script
419432
pub fn script_num_size(n: usize) -> usize {
420433
match n {

src/miniscript/satisfy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfiable<Pk> for Terminal<Pk> {
489489
}
490490
}
491491

492-
impl<Pk: MiniscriptKey> Dissatisfiable<Pk> for Terminal<Pk> {
492+
impl<Pk: MiniscriptKey + ToPublicKey> Dissatisfiable<Pk> for Terminal<Pk> {
493493
fn dissatisfy<S: Satisfier<Pk>>(&self, satisfier: &S) -> Option<Vec<Vec<u8>>> {
494494
match *self {
495495
Terminal::Pk(..) => Some(vec![vec![]]),

0 commit comments

Comments
 (0)