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
impl Miniscript
Sourcepub fn is_sane(&self) -> bool
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
Sourcepub fn get_type(&self) -> Option<String>
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.
Sourcepub fn max_satisfaction_size(&self) -> Option<usize>
pub fn max_satisfaction_size(&self) -> Option<usize>
Get the maximum witness size for satisfying this miniscript.
Sourcepub fn is_non_malleable(&self) -> bool
pub fn is_non_malleable(&self) -> bool
Check if the miniscript is non-malleable.
Sourcepub fn needs_signature(&self) -> bool
pub fn needs_signature(&self) -> bool
Check if the miniscript requires a signature to satisfy.
Sourcepub fn has_timelock_mix(&self) -> bool
pub fn has_timelock_mix(&self) -> bool
Check if the miniscript has a timelock mix (mixing height and time locks).
Sourcepub fn is_valid_top_level(&self) -> bool
pub fn is_valid_top_level(&self) -> bool
Check if the miniscript is valid at the top level.
Sourcepub fn check_ops_limit(&self) -> bool
pub fn check_ops_limit(&self) -> bool
Check if the miniscript is within the ops limit.
Sourcepub fn check_stack_size(&self) -> bool
pub fn check_stack_size(&self) -> bool
Check if the miniscript is within the stack size limit.
Sourcepub fn check_duplicate_key(&self) -> bool
pub fn check_duplicate_key(&self) -> bool
Check if the miniscript has no duplicate keys.
Sourcepub fn get_stack_size(&self) -> Option<u32>
pub fn get_stack_size(&self) -> Option<u32>
Get the maximum stack size needed to satisfy this miniscript.
Sourcepub fn get_exec_stack_size(&self) -> Option<u32>
pub fn get_exec_stack_size(&self) -> Option<u32>
Get the maximum execution stack size.
Sourcepub fn get_script_size(&self) -> Option<usize>
pub fn get_script_size(&self) -> Option<usize>
Get the script size.
Sourcepub fn valid_satisfactions(&self) -> bool
pub fn valid_satisfactions(&self) -> bool
Check if the miniscript has valid satisfactions.
Sourcepub fn get_static_ops(&self) -> Option<u32>
pub fn get_static_ops(&self) -> Option<u32>
Get the static ops count (for Tapscript).
Sourcepub fn to_script_bytes(&self) -> Option<Vec<u8>>
pub fn to_script_bytes(&self) -> Option<Vec<u8>>
Convert the miniscript to raw script bytes.
Sourcepub fn to_script(&self) -> Option<ScriptBuf>
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.
Sourcepub fn satisfy<S: Satisfier + 'static>(
&self,
satisfier: S,
nonmalleable: bool,
) -> Result<SatisfyResult, Error>
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.