Struct miniscript::interpreter::Interpreter
source · pub struct Interpreter<'txin> { /* private fields */ }
Expand description
An iterable Miniscript-structured representation of the spending of a coin
Implementations§
source§impl<'txin> Interpreter<'txin>
impl<'txin> Interpreter<'txin>
sourcepub fn from_txdata(
spk: &ScriptBuf,
script_sig: &'txin Script,
witness: &'txin Witness,
sequence: Sequence,
lock_time: LockTime
) -> Result<Self, Error>
pub fn from_txdata( spk: &ScriptBuf, script_sig: &'txin Script, witness: &'txin Witness, sequence: Sequence, lock_time: LockTime ) -> Result<Self, Error>
Constructs an interpreter from the data of a spending transaction
Accepts a signature-validating function. If you are willing to trust that ECSDA signatures are valid, this can be set to the constant true function; otherwise, it should be a closure containing a sighash and secp context, which can actually verify a given signature.
sourcepub fn iter_custom<'iter>(
&'iter self,
verify_sig: Box<dyn FnMut(&KeySigPair) -> bool + 'iter>
) -> Iter<'txin, 'iter> ⓘ
pub fn iter_custom<'iter>( &'iter self, verify_sig: Box<dyn FnMut(&KeySigPair) -> bool + 'iter> ) -> Iter<'txin, 'iter> ⓘ
Same as Interpreter::iter
, but allows for a custom verification function.
See Self::iter_assume_sigs for a simpler API without information about Prevouts
but skips the signature verification
sourcepub fn verify_sig<C: Verification, T: Borrow<TxOut>>(
&self,
secp: &Secp256k1<C>,
tx: &Transaction,
input_idx: usize,
prevouts: &Prevouts<'_, T>,
sig: &KeySigPair
) -> bool
pub fn verify_sig<C: Verification, T: Borrow<TxOut>>( &self, secp: &Secp256k1<C>, tx: &Transaction, input_idx: usize, prevouts: &Prevouts<'_, T>, sig: &KeySigPair ) -> bool
Verify a signature for a given transaction and prevout information
This is a low level API, Interpreter::iter
or Interpreter::iter_assume_sigs
should satisfy most use-cases.
Returns false if
- the signature verification fails
- the input index is out of range
- Insufficient sighash information is present
- sighash single without corresponding output
sourcepub fn iter<'iter, C: Verification, T: Borrow<TxOut>>(
&'iter self,
secp: &'iter Secp256k1<C>,
tx: &'txin Transaction,
input_idx: usize,
prevouts: &'iter Prevouts<'_, T>
) -> Iter<'txin, 'iter> ⓘ
pub fn iter<'iter, C: Verification, T: Borrow<TxOut>>( &'iter self, secp: &'iter Secp256k1<C>, tx: &'txin Transaction, input_idx: usize, prevouts: &'iter Prevouts<'_, T> ) -> Iter<'txin, 'iter> ⓘ
Creates an iterator over the satisfied spending conditions
Returns all satisfied constraints, even if they were redundant (i.e. did
not contribute to the script being satisfied). For example, if a signature
were provided for an and_b(Pk,false)
fragment, that signature will be
returned, even though the entire and_b must have failed and must not have
been used.
In case the script is actually dissatisfied, this may return several values before ultimately returning an error.
Not all fields are used by legacy/segwitv0 descriptors; if you are sure this is a legacy
spend (you can check with the is_legacy\is_segwitv0
method) you can provide dummy data for
the amount/prevouts.
- For legacy outputs, no information about prevouts is required
- For segwitv0 outputs, prevout at corresponding index with correct amount must be provided
- For taproot outputs, information about all prevouts must be supplied
sourcepub fn iter_assume_sigs<'iter>(&'iter self) -> Iter<'txin, 'iter> ⓘ
pub fn iter_assume_sigs<'iter>(&'iter self) -> Iter<'txin, 'iter> ⓘ
Creates an iterator over the satisfied spending conditions without checking signatures
sourcepub fn inferred_descriptor_string(&self) -> String
pub fn inferred_descriptor_string(&self) -> String
Outputs a “descriptor” string which reproduces the spent coins
This may not represent the original descriptor used to produce the transaction, since it cannot distinguish between sorted and unsorted multisigs (and anyway it can only see the final keys, keyorigin info is lost in serializing to Bitcoin).
If you are using the interpreter as a sanity check on a transaction,
it is worthwhile to try to parse this as a descriptor using from_str
which will check standardness and consensus limits, which the interpreter
does not do on its own. Or use the inferred_descriptor
method which
does this for you.
sourcepub fn is_segwit_v0(&self) -> bool
pub fn is_segwit_v0(&self) -> bool
Whether this is a segwit v0 spend (wrapped or native)
sourcepub fn is_taproot_v1_key_spend(&self) -> bool
pub fn is_taproot_v1_key_spend(&self) -> bool
Whether this is a taproot key spend
sourcepub fn is_taproot_v1_script_spend(&self) -> bool
pub fn is_taproot_v1_script_spend(&self) -> bool
Whether this is a taproot script spend
sourcepub fn inferred_descriptor(&self) -> Result<Descriptor<PublicKey>, Error>
pub fn inferred_descriptor(&self) -> Result<Descriptor<PublicKey>, Error>
Outputs a “descriptor” which reproduces the spent coins
This may not represent the original descriptor used to produce the transaction,
since it cannot distinguish between sorted and unsorted multisigs (and anyway
it can only see the final keys, keyorigin info is lost in serializing to Bitcoin).
x-only keys are translated to bitcoin::PublicKey
with 0x02 prefix.