Skip to main content

Stack

Struct Stack 

Source
pub struct Stack {
    pub stk: Vec<Vec<u8>>,
    pub max_num_length: usize,
    pub after_genesis: bool,
    pub verify_minimal_data: bool,
}
Expand description

The main data/alt stack used by the script interpreter.

Fields§

§stk: Vec<Vec<u8>>

The underlying stack storage, where the last element is the top.

§max_num_length: usize

Maximum allowed byte length for numeric values on this stack.

§after_genesis: bool

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

§verify_minimal_data: bool

Whether to enforce minimal data encoding for numeric conversions.

Implementations§

Source§

impl Stack

Source

pub fn new( max_num_length: usize, after_genesis: bool, verify_minimal_data: bool, ) -> Self

Create a new empty stack with the given numeric limits and flags.

Source

pub fn depth(&self) -> i32

Return the number of elements on the stack.

Source

pub fn push_byte_array(&mut self, data: Vec<u8>)

Push a raw byte array onto the top of the stack.

Source

pub fn push_int(&mut self, n: &ScriptNumber)

Push a script number onto the stack, serialized to bytes.

Source

pub fn push_bool(&mut self, val: bool)

Push a boolean value onto the stack.

Source

pub fn pop_byte_array(&mut self) -> Result<Vec<u8>, InterpreterError>

Pop and return the top byte array from the stack.

Source

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

Pop the top element and decode it as a script number.

Source

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

Pop the top element and interpret it as a boolean.

Source

pub fn peek_byte_array(&self, idx: i32) -> Result<Vec<u8>, InterpreterError>

Peek at a byte array at the given depth index (0 = top) without removing it.

Source

pub fn peek_int(&self, idx: i32) -> Result<ScriptNumber, InterpreterError>

Peek at a script number at the given depth index without removing it.

Source

pub fn peek_bool(&self, idx: i32) -> Result<bool, InterpreterError>

Peek at a boolean at the given depth index without removing it.

Source

pub fn nip_n_discard(&mut self, idx: i32) -> Result<(), InterpreterError>

Remove and discard the element at the given depth index (0 = top).

Source

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

Copy the top element and insert it before the second-to-top element (OP_TUCK).

Source

pub fn drop_n(&mut self, n: i32) -> Result<(), InterpreterError>

Remove the top n elements from the stack.

Source

pub fn dup_n(&mut self, n: i32) -> Result<(), InterpreterError>

Duplicate the top n elements on the stack.

Source

pub fn rot_n(&mut self, n: i32) -> Result<(), InterpreterError>

Rotate the top 3*n elements: move the bottom n of that group to the top.

Source

pub fn swap_n(&mut self, n: i32) -> Result<(), InterpreterError>

Swap the top n elements with the n elements below them.

Source

pub fn over_n(&mut self, n: i32) -> Result<(), InterpreterError>

Copy n elements from below the top n elements and push them on top.

Source

pub fn pick_n(&mut self, n: i32) -> Result<(), InterpreterError>

Copy the element at depth n and push it on top (OP_PICK).

Source

pub fn roll_n(&mut self, n: i32) -> Result<(), InterpreterError>

Remove the element at depth n and push it on top (OP_ROLL).

Source

pub fn get_stack(&self) -> Vec<Vec<u8>>

Get stack contents as array (bottom to top).

Source

pub fn set_stack(&mut self, data: Vec<Vec<u8>>)

Set stack contents from array (last = top).

Source

pub fn clear(&mut self)

Clear all items.

Auto Trait Implementations§

§

impl Freeze for Stack

§

impl RefUnwindSafe for Stack

§

impl Send for Stack

§

impl Sync for Stack

§

impl Unpin for Stack

§

impl UnsafeUnpin for Stack

§

impl UnwindSafe for Stack

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