Skip to content

Instantly share code, notes, and snippets.

@sanket1729
Created November 2, 2020 10:43
Show Gist options
  • Save sanket1729/7cc1392c27a43d5580edeee2f33d835f to your computer and use it in GitHub Desktop.
Save sanket1729/7cc1392c27a43d5580edeee2f33d835f to your computer and use it in GitHub Desktop.
Sorted Multi
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct SortedMultiVec<Pk: MiniscriptKey, Ctx: ScriptContext>{
/// public keys inside sorted Multi
pub pks: Vec<Pk>,
/// The current ScriptContext for sortedmulti
pub(crate) phantom: PhantomData<Ctx>
}
impl SortedMultiVec{
fn new(pks: &[Pk]) -> Result<Self, Error>{
// Check the limits before creating a new SortedMultiVec
// For example, under p2sh context the scriptlen can only be
// upto 520 bytes.
let ms = Miniscript::from_ast(Terminal::Multi(Vec::from(pks)));
// This would check all the consensus rules for p2sh/p2wsh and
// even tapscript in future
Ctx::check_frag_validity(&ms)?;
// Create new self
}
}
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum Descriptor<Pk: MiniscriptKey> {
/// Sorted Multi under P2SH
ShSortedMulti(SortedMultiVec<Pk, Legacy>),
/// Sorted Multi under P2WSH
WshSortedMulti(SortedMultiVec<Pk, Segwitv0>),
/// Sorted Multi under P2SH-P2WSH
ShWshSortedMulti(SortedMultiVec<Pk, Segwitv0>),
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment