Miniscript

Struct Miniscript 

Source
pub struct Miniscript { /* private fields */ }
Expand description

A parsed miniscript node.

This is a safe wrapper around Bitcoin Core’s C++ miniscript implementation. It provides methods for parsing, validating, analyzing, and satisfying miniscript expressions.

§Thread Safety

Miniscript implements Send and Sync, making it safe to share across threads. The underlying C++ object is immutable after creation.

§Memory Management

The struct owns the underlying C++ object and will free it when dropped. Do not attempt to use the raw pointer after the Miniscript is dropped.

§Example

use miniscript_core_ffi::{Miniscript, Context};

// Parse a miniscript
let ms = Miniscript::from_str("and_v(v:pk(A),pk(B))", Context::Wsh)
    .expect("valid miniscript");

// Check properties
assert!(ms.is_valid());
assert!(ms.is_sane());
println!("Type: {}", ms.get_type().unwrap());
println!("Max witness size: {:?}", ms.max_satisfaction_size());

Implementations§

Source§

impl Miniscript

Source

pub fn from_str(input: &str, context: Context) -> Result<Self, Error>

Parse a miniscript from a string.

§Arguments
  • input - The miniscript string (e.g., “and_v(v:pk(A),pk(B))”)
  • context - The script context (WSH or Tapscript)
§Errors

Returns an error if parsing fails.

Source

pub fn to_string(&self) -> Option<String>

Convert the miniscript back to a string.

Source

pub fn is_valid(&self) -> bool

Check if the miniscript is valid (type-checks correctly).

Source

pub fn is_sane(&self) -> bool

Check if the miniscript is sane.

This includes checks for:

  • No duplicate keys
  • No timelock mixing
  • Within resource limits
Source

pub fn get_type(&self) -> Option<String>

Get the type properties of the miniscript.

Returns a string like “Bdems” where each letter indicates a property.

Source

pub fn max_satisfaction_size(&self) -> Option<usize>

Get the maximum witness size for satisfying this miniscript.

Source

pub const fn context(&self) -> Context

Get the context this miniscript was parsed with.

Source

pub fn is_non_malleable(&self) -> bool

Check if the miniscript is non-malleable.

Source

pub fn needs_signature(&self) -> bool

Check if the miniscript requires a signature to satisfy.

Source

pub fn has_timelock_mix(&self) -> bool

Check if the miniscript has a timelock mix (mixing height and time locks).

Source

pub fn is_valid_top_level(&self) -> bool

Check if the miniscript is valid at the top level.

Source

pub fn check_ops_limit(&self) -> bool

Check if the miniscript is within the ops limit.

Source

pub fn check_stack_size(&self) -> bool

Check if the miniscript is within the stack size limit.

Source

pub fn check_duplicate_key(&self) -> bool

Check if the miniscript has no duplicate keys.

Source

pub fn get_ops(&self) -> Option<u32>

Get the number of ops in the miniscript.

Source

pub fn get_stack_size(&self) -> Option<u32>

Get the maximum stack size needed to satisfy this miniscript.

Source

pub fn get_exec_stack_size(&self) -> Option<u32>

Get the maximum execution stack size.

Source

pub fn get_script_size(&self) -> Option<usize>

Get the script size.

Source

pub fn valid_satisfactions(&self) -> bool

Check if the miniscript has valid satisfactions.

Source

pub fn get_static_ops(&self) -> Option<u32>

Get the static ops count (for Tapscript).

Source

pub fn to_script_bytes(&self) -> Option<Vec<u8>>

Convert the miniscript to raw script bytes.

Source

pub fn to_script(&self) -> Option<ScriptBuf>

Convert the miniscript to a bitcoin::ScriptBuf.

This returns the script as a proper Bitcoin script type from the bitcoin crate.

Source

pub fn from_script_bytes(script: &[u8], context: Context) -> Result<Self, Error>

Parse a miniscript from raw script bytes.

§Errors

Returns an error if parsing fails.

Source

pub fn satisfy<S: Satisfier + 'static>( &self, satisfier: S, nonmalleable: bool, ) -> Result<SatisfyResult, Error>

Produce a witness that satisfies this miniscript.

§Arguments
  • satisfier - An implementation of the Satisfier trait that provides signatures, hash preimages, and timelock information.
  • nonmalleable - If true, only produce non-malleable satisfactions.
§Returns

A SatisfyResult containing the availability and witness stack.

§Errors

Returns an error if satisfaction fails.

Trait Implementations§

Source§

impl Debug for Miniscript

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Miniscript

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Miniscript

Source§

impl Sync for Miniscript

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.