Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sanket1729 committed Jan 10, 2024
1 parent f8717e4 commit 94c415d
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 124 deletions.
36 changes: 20 additions & 16 deletions src/miniscript/astelem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use bitcoin::hashes::{hash160, Hash};
use bitcoin::{absolute, opcodes, script, Sequence};
use sync::Arc;

use super::MsUnChecked;
use crate::miniscript::context::SigType;
use crate::miniscript::types::{self, Property};
use crate::miniscript::ScriptContext;
Expand Down Expand Up @@ -242,17 +243,15 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> fmt::Display for Terminal<Pk, Ctx> {
}

impl_from_tree!(
;Ctx; ScriptContext,
Arc<Terminal<Pk, Ctx>>,
fn from_tree(top: &expression::Tree) -> Result<Arc<Terminal<Pk, Ctx>>, Error> {
Arc<Terminal<Pk>>,
fn from_tree(top: &expression::Tree) -> Result<Arc<Terminal<Pk>>, Error> {
Ok(Arc::new(expression::FromTree::from_tree(top)?))
}
);

impl_from_tree!(
;Ctx; ScriptContext,
Terminal<Pk, Ctx>,
fn from_tree(top: &expression::Tree) -> Result<Terminal<Pk, Ctx>, Error> {
Terminal<Pk>,
fn from_tree(top: &expression::Tree) -> Result<Terminal<Pk>, Error> {
let mut aliased_wrap;
let frag_name;
let frag_wrap;
Expand Down Expand Up @@ -304,9 +303,13 @@ impl_from_tree!(
("pk_k", 1) => {
expression::terminal(&top.args[0], |x| Pk::from_str(x).map(Terminal::PkK))
}
("pk_h", 1) => expression::terminal(&top.args[0], |x| Pk::from_str(x).map(Terminal::PkH)),
("pk_h", 1) => {
expression::terminal(&top.args[0], |x| Pk::from_str(x).map(Terminal::PkH))
}
("after", 1) => expression::terminal(&top.args[0], |x| {
expression::parse_num(x).map(|x| Terminal::After(AbsLockTime::from(absolute::LockTime::from_consensus(x))))
expression::parse_num(x).map(|x| {
Terminal::After(AbsLockTime::from(absolute::LockTime::from_consensus(x)))
})
}),
("older", 1) => expression::terminal(&top.args[0], |x| {
expression::parse_num(x).map(|x| Terminal::Older(Sequence::from_consensus(x)))
Expand Down Expand Up @@ -353,7 +356,7 @@ impl_from_tree!(
return Err(errstr("empty thresholds not allowed in descriptors"));
}

let subs: Result<Vec<Arc<Miniscript<Pk, Ctx>>>, _> = top.args[1..]
let subs: Result<Vec<Arc<MsUnChecked<Pk>>>, _> = top.args[1..]
.iter()
.map(expression::FromTree::from_tree)
.collect();
Expand Down Expand Up @@ -424,9 +427,9 @@ impl_from_tree!(
}
}
// Check whether the unwrapped miniscript is valid under the current context
let ms = Miniscript::from_ast(unwrapped)?;
Ctx::check_global_validity(&ms)?;
Ok(ms.node)
// let ms = Miniscript::from_ast(unwrapped)?;
// Ctx::check_global_validity(&ms)?;
Ok(unwrapped)
}
);

Expand All @@ -446,11 +449,12 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> PushAstElem<Pk, Ctx> for script::Bui
}
}

impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
/// Encode the element as a fragment of Bitcoin Script. The inverse
/// function, from Script to an AST element, is implemented in the
impl<Pk: MiniscriptKey> Terminal<Pk> {
/// Encode the element as a fragment of Bitcoin Script under the given ScriptContext.
///
/// The inverse function, from Script to an AST element, is implemented in the
/// `parse` module.
pub fn encode(&self, mut builder: script::Builder) -> script::Builder
pub fn encode<Ctx: ScriptContext>(&self, mut builder: script::Builder) -> script::Builder
where
Pk: ToPublicKey,
{
Expand Down
Loading

0 comments on commit 94c415d

Please sign in to comment.