Skip to content

Commit b72118a

Browse files
committed
compiler: use Miniscript terminal constructors directly
This eliminates some expect()s and is plausibly faster.
1 parent be8af0f commit b72118a

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

src/policy/compiler.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -520,11 +520,8 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> AstElemExt<Pk, Ctx> {
520520
}
521521

522522
impl<Pk: MiniscriptKey, Ctx: ScriptContext> AstElemExt<Pk, Ctx> {
523-
fn terminal(ast: Terminal<Pk, Ctx>) -> AstElemExt<Pk, Ctx> {
524-
AstElemExt {
525-
comp_ext_data: CompilerExtData::type_check(&ast),
526-
ms: Arc::new(Miniscript::from_ast(ast).expect("Terminal creation must always succeed")),
527-
}
523+
fn terminal(ms: Miniscript<Pk, Ctx>) -> AstElemExt<Pk, Ctx> {
524+
AstElemExt { comp_ext_data: CompilerExtData::type_check(ms.as_inner()), ms: Arc::new(ms) }
528525
}
529526

530527
fn binary(
@@ -817,29 +814,29 @@ where
817814

818815
match *policy {
819816
Concrete::Unsatisfiable => {
820-
insert_wrap!(AstElemExt::terminal(Terminal::False));
817+
insert_wrap!(AstElemExt::terminal(Miniscript::FALSE));
821818
}
822819
Concrete::Trivial => {
823-
insert_wrap!(AstElemExt::terminal(Terminal::True));
820+
insert_wrap!(AstElemExt::terminal(Miniscript::TRUE));
824821
}
825822
Concrete::Key(ref pk) => {
826-
insert_wrap!(AstElemExt::terminal(Terminal::PkH(pk.clone())));
827-
insert_wrap!(AstElemExt::terminal(Terminal::PkK(pk.clone())));
823+
insert_wrap!(AstElemExt::terminal(Miniscript::pk_h(pk.clone())));
824+
insert_wrap!(AstElemExt::terminal(Miniscript::pk_k(pk.clone())));
828825
}
829-
Concrete::After(n) => insert_wrap!(AstElemExt::terminal(Terminal::After(n))),
830-
Concrete::Older(n) => insert_wrap!(AstElemExt::terminal(Terminal::Older(n))),
826+
Concrete::After(n) => insert_wrap!(AstElemExt::terminal(Miniscript::after(n))),
827+
Concrete::Older(n) => insert_wrap!(AstElemExt::terminal(Miniscript::older(n))),
831828
Concrete::Sha256(ref hash) => {
832-
insert_wrap!(AstElemExt::terminal(Terminal::Sha256(hash.clone())))
829+
insert_wrap!(AstElemExt::terminal(Miniscript::sha256(hash.clone())))
833830
}
834831
// Satisfaction-cost + script-cost
835832
Concrete::Hash256(ref hash) => {
836-
insert_wrap!(AstElemExt::terminal(Terminal::Hash256(hash.clone())))
833+
insert_wrap!(AstElemExt::terminal(Miniscript::hash256(hash.clone())))
837834
}
838835
Concrete::Ripemd160(ref hash) => {
839-
insert_wrap!(AstElemExt::terminal(Terminal::Ripemd160(hash.clone())))
836+
insert_wrap!(AstElemExt::terminal(Miniscript::ripemd160(hash.clone())))
840837
}
841838
Concrete::Hash160(ref hash) => {
842-
insert_wrap!(AstElemExt::terminal(Terminal::Hash160(hash.clone())))
839+
insert_wrap!(AstElemExt::terminal(Miniscript::hash160(hash.clone())))
843840
}
844841
Concrete::And(ref subs) => {
845842
assert_eq!(subs.len(), 2, "and takes 2 args");
@@ -859,7 +856,7 @@ where
859856
let mut zero_comp = BTreeMap::new();
860857
zero_comp.insert(
861858
CompilationKey::from_type(Type::FALSE, ExtData::FALSE.has_free_verify, dissat_prob),
862-
AstElemExt::terminal(Terminal::False),
859+
AstElemExt::terminal(Miniscript::FALSE),
863860
);
864861
compile_tern!(&mut left, &mut q_zero_right, &mut zero_comp, [1.0, 0.0]);
865862
compile_tern!(&mut right, &mut q_zero_left, &mut zero_comp, [1.0, 0.0]);
@@ -1046,12 +1043,12 @@ where
10461043
match Ctx::sig_type() {
10471044
SigType::Schnorr => {
10481045
if let Ok(pk_thresh) = pk_thresh.set_maximum() {
1049-
insert_wrap!(AstElemExt::terminal(Terminal::MultiA(pk_thresh)))
1046+
insert_wrap!(AstElemExt::terminal(Miniscript::multi_a(pk_thresh)))
10501047
}
10511048
}
10521049
SigType::Ecdsa => {
10531050
if let Ok(pk_thresh) = pk_thresh.set_maximum() {
1054-
insert_wrap!(AstElemExt::terminal(Terminal::Multi(pk_thresh)))
1051+
insert_wrap!(AstElemExt::terminal(Miniscript::multi(pk_thresh)))
10551052
}
10561053
}
10571054
}

0 commit comments

Comments
 (0)