Skip to content

Instantly share code, notes, and snippets.

@sanket1729
Last active July 16, 2019 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanket1729/5c8a541abcdc0c8b3d5e29ee919c27a8 to your computer and use it in GitHub Desktop.
Save sanket1729/5c8a541abcdc0c8b3d5e29ee919c27a8 to your computer and use it in GitHub Desktop.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct Miniscript<Pk, Pkh=hash160::Hash>{
///A node in the Abstract Syntax Tree(
node: astelem::AstElem<Pk, Pkh>,
///The correctness and malleability type information for the AST node
ty: Option<types::Type>,
///Additional information helpful for extra analysis.
ext: Option<types::extra_props::ExtData>
}
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum AstElem<Pk, Pkh=hash160::Hash> {
/// `1`
True,
/// `0`
False,
// pubkey checks
/// `<key>`
Pk(Pk),
/// `DUP HASH160 <keyhash> EQUALVERIFY`
PkH(Pkh),
// timelocks
/// `n CHECKSEQUENCEVERIFY`
After(u32),
/// `n CHECKLOCKTIMEVERIFY`
Older(u32),
// hashlocks
/// `SIZE 32 EQUALVERIFY SHA256 <hash> EQUAL`
Sha256(sha256::Hash),
/// `SIZE 32 EQUALVERIFY HASH256 <hash> EQUAL`
Hash256(sha256d::Hash),
/// `SIZE 32 EQUALVERIFY RIPEMD160 <hash> EQUAL`
Ripemd160(ripemd160::Hash),
/// `SIZE 32 EQUALVERIFY HASH160 <hash> EQUAL`
Hash160(hash160::Hash),
// Wrappers
/// `TOALTSTACK [E] FROMALTSTACK`
Alt(Box<Miniscript<Pk, Pkh>>),
/// `SWAP [E1]`
Swap(Box<Miniscript<Pk, Pkh>>),
/// `[Kt]/[Ke] CHECKSIG`
Check(Box<Miniscript<Pk, Pkh>>),
/// `DUP IF [V] ENDIF`
DupIf(Box<Miniscript<Pk, Pkh>>),
/// [T] VERIFY
Verify(Box<Miniscript<Pk, Pkh>>),
/// SIZE 0NOTEQUAL IF [Fn] ENDIF
NonZero(Box<Miniscript<Pk, Pkh>>),
/// [X] 0NOTEQUAL
ZeroNotEqual(Box<Miniscript<Pk, Pkh>>),
// Conjunctions
/// [V] [T]/[V]/[F]/[Kt]
AndV(Box<Miniscript<Pk, Pkh>>, Box<Miniscript<Pk, Pkh>>),
/// [E] [W] BOOLAND
AndB(Box<Miniscript<Pk, Pkh>>, Box<Miniscript<Pk, Pkh>>),
/// [various] NOTIF [various] ELSE [various] ENDIF
AndOr(Box<Miniscript<Pk, Pkh>>, Box<Miniscript<Pk, Pkh>>, Box<Miniscript<Pk, Pkh>>),
// Disjunctions
/// [E] [W] BOOLOR
OrB(Box<Miniscript<Pk, Pkh>>, Box<Miniscript<Pk, Pkh>>),
/// [E] IFDUP NOTIF [T]/[E] ENDIF
OrD(Box<Miniscript<Pk, Pkh>>, Box<Miniscript<Pk, Pkh>>),
/// [E] NOTIF [V] ENDIF
OrC(Box<Miniscript<Pk, Pkh>>, Box<Miniscript<Pk, Pkh>>),
/// IF [various] ELSE [various] ENDIF
OrI(Box<Miniscript<Pk, Pkh>>, Box<Miniscript<Pk, Pkh>>),
// Thresholds
/// [E] ([W] ADD)* k EQUAL
Thresh(usize, Vec<Miniscript<Pk, Pkh>>),
/// k (<key>)* n CHECKMULTISIG
ThreshM(usize, Vec<Pk>),
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment