Skip to main content

Thread

Struct Thread 

Source
pub struct Thread<'a> {
Show 17 fields pub dstack: Stack, pub astack: Stack, pub else_stack: BoolStack, pub cfg: Config, pub scripts: Vec<ParsedScript>, pub cond_stack: Vec<i32>, pub saved_first_stack: Vec<Vec<u8>>, pub script_idx: usize, pub script_off: usize, pub last_code_sep: usize, pub num_ops: usize, pub flags: ScriptFlags, pub bip16: bool, pub after_genesis: bool, pub early_return_after_genesis: bool, pub tx_context: Option<&'a dyn TxContext>, pub input_idx: usize,
}
Expand description

The execution thread for the script interpreter.

Fields§

§dstack: Stack

The main data stack used during script execution.

§astack: Stack

The alternate stack used by OP_TOALTSTACK and OP_FROMALTSTACK.

§else_stack: BoolStack

Stack tracking nested IF/ELSE/ENDIF conditional execution state.

§cfg: Config

Interpreter configuration with pre/post-genesis limits.

§scripts: Vec<ParsedScript>

The parsed scripts to execute (unlocking, locking, and optionally P2SH).

§cond_stack: Vec<i32>

Stack of conditional execution flags for nested IF/ELSE blocks.

§saved_first_stack: Vec<Vec<u8>>

Saved copy of the data stack after the first (unlocking) script for BIP16.

§script_idx: usize

Index of the currently executing script in the scripts array.

§script_off: usize

Offset of the currently executing opcode within the current script.

§last_code_sep: usize

Offset of the most recent OP_CODESEPARATOR in the current script.

§num_ops: usize

Running count of non-push opcodes executed (checked against max_ops).

§flags: ScriptFlags

Active script verification flags controlling interpreter behavior.

§bip16: bool

Whether BIP16 (P2SH) evaluation is active for this execution.

§after_genesis: bool

Whether post-genesis rules are active (relaxed limits, OP_RETURN behavior).

§early_return_after_genesis: bool

Whether an OP_RETURN has been encountered in post-genesis mode.

§tx_context: Option<&'a dyn TxContext>

Optional transaction context for signature and locktime verification.

§input_idx: usize

The transaction input index being verified.

Implementations§

Source§

impl<'a> Thread<'a>

Source

pub fn new( unlocking_script: &Script, locking_script: &Script, flags: ScriptFlags, tx_context: Option<&'a dyn TxContext>, input_idx: usize, ) -> Result<Self, InterpreterError>

Create a new execution thread from unlocking and locking scripts.

Validates script sizes, parses both scripts, and initializes the execution environment with the appropriate flags and configuration.

Source

pub fn has_flag(&self, flag: ScriptFlags) -> bool

Check if a specific script verification flag is set.

Source

pub fn has_any(&self, flags: &[ScriptFlags]) -> bool

Check if any of the given script verification flags are set.

Source

pub fn is_branch_executing(&self) -> bool

Return true if the current conditional branch is executing.

Source

pub fn should_exec(&self, pop: &ParsedOpcode) -> bool

Return true if the given opcode should be executed in the current state.

Source

pub fn execute(&mut self) -> Result<(), InterpreterError>

Execute all scripts.

Source

pub fn step(&mut self) -> Result<bool, InterpreterError>

Execute one step. Returns true if execution is complete.

Auto Trait Implementations§

§

impl<'a> Freeze for Thread<'a>

§

impl<'a> !RefUnwindSafe for Thread<'a>

§

impl<'a> !Send for Thread<'a>

§

impl<'a> !Sync for Thread<'a>

§

impl<'a> Unpin for Thread<'a>

§

impl<'a> UnsafeUnpin for Thread<'a>

§

impl<'a> !UnwindSafe for Thread<'a>

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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V