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: usizeMaximum allowed byte length for numeric values on this stack.
after_genesis: boolWhether post-genesis rules are active (relaxed limits).
verify_minimal_data: boolWhether to enforce minimal data encoding for numeric conversions.
Implementations§
Source§impl Stack
impl Stack
Sourcepub fn new(
max_num_length: usize,
after_genesis: bool,
verify_minimal_data: bool,
) -> Self
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.
Sourcepub fn push_byte_array(&mut self, data: Vec<u8>)
pub fn push_byte_array(&mut self, data: Vec<u8>)
Push a raw byte array onto the top of the stack.
Sourcepub fn push_int(&mut self, n: &ScriptNumber)
pub fn push_int(&mut self, n: &ScriptNumber)
Push a script number onto the stack, serialized to bytes.
Sourcepub fn pop_byte_array(&mut self) -> Result<Vec<u8>, InterpreterError>
pub fn pop_byte_array(&mut self) -> Result<Vec<u8>, InterpreterError>
Pop and return the top byte array from the stack.
Sourcepub fn pop_int(&mut self) -> Result<ScriptNumber, InterpreterError>
pub fn pop_int(&mut self) -> Result<ScriptNumber, InterpreterError>
Pop the top element and decode it as a script number.
Sourcepub fn pop_bool(&mut self) -> Result<bool, InterpreterError>
pub fn pop_bool(&mut self) -> Result<bool, InterpreterError>
Pop the top element and interpret it as a boolean.
Sourcepub fn peek_byte_array(&self, idx: i32) -> Result<Vec<u8>, InterpreterError>
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.
Sourcepub fn peek_int(&self, idx: i32) -> Result<ScriptNumber, InterpreterError>
pub fn peek_int(&self, idx: i32) -> Result<ScriptNumber, InterpreterError>
Peek at a script number at the given depth index without removing it.
Sourcepub fn peek_bool(&self, idx: i32) -> Result<bool, InterpreterError>
pub fn peek_bool(&self, idx: i32) -> Result<bool, InterpreterError>
Peek at a boolean at the given depth index without removing it.
Sourcepub fn nip_n_discard(&mut self, idx: i32) -> Result<(), InterpreterError>
pub fn nip_n_discard(&mut self, idx: i32) -> Result<(), InterpreterError>
Remove and discard the element at the given depth index (0 = top).
Sourcepub fn tuck(&mut self) -> Result<(), InterpreterError>
pub fn tuck(&mut self) -> Result<(), InterpreterError>
Copy the top element and insert it before the second-to-top element (OP_TUCK).
Sourcepub fn drop_n(&mut self, n: i32) -> Result<(), InterpreterError>
pub fn drop_n(&mut self, n: i32) -> Result<(), InterpreterError>
Remove the top n elements from the stack.
Sourcepub fn dup_n(&mut self, n: i32) -> Result<(), InterpreterError>
pub fn dup_n(&mut self, n: i32) -> Result<(), InterpreterError>
Duplicate the top n elements on the stack.
Sourcepub fn rot_n(&mut self, n: i32) -> Result<(), InterpreterError>
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.
Sourcepub fn swap_n(&mut self, n: i32) -> Result<(), InterpreterError>
pub fn swap_n(&mut self, n: i32) -> Result<(), InterpreterError>
Swap the top n elements with the n elements below them.
Sourcepub fn over_n(&mut self, n: i32) -> Result<(), InterpreterError>
pub fn over_n(&mut self, n: i32) -> Result<(), InterpreterError>
Copy n elements from below the top n elements and push them on top.
Sourcepub fn pick_n(&mut self, n: i32) -> Result<(), InterpreterError>
pub fn pick_n(&mut self, n: i32) -> Result<(), InterpreterError>
Copy the element at depth n and push it on top (OP_PICK).