Struct fuel_vm::interpreter::Interpreter
source · [−]pub struct Interpreter<S> { /* private fields */ }
Expand description
VM interpreter.
The internal state of the VM isn’t expose because the intended usage is to either inspect the resulting receipts after a transaction execution, or the resulting mutated transaction.
These can be obtained with the help of a crate::transactor::Transactor
or a client implementation.
Implementations
sourceimpl<S> Interpreter<S>
impl<S> Interpreter<S>
sourcepub fn with_storage(storage: S, params: ConsensusParameters) -> Self
pub fn with_storage(storage: S, params: ConsensusParameters) -> Self
Create a new interpreter instance out of a storage implementation.
If the provided storage implements
crate::storage::InterpreterStorage
, the returned interpreter
will provide full functionality.
sourcepub fn with_params(&mut self, params: ConsensusParameters) -> &mut Self
pub fn with_params(&mut self, params: ConsensusParameters) -> &mut Self
Set the consensus parameters for the interpreter
sourceimpl<S> Interpreter<S> where
S: Clone,
impl<S> Interpreter<S> where
S: Clone,
sourceimpl Interpreter<()>
impl Interpreter<()>
sourcepub fn without_storage() -> Self
pub fn without_storage() -> Self
Create a new interpreter without a storage backend.
It will have restricted capabilities.
sourceimpl Interpreter<MemoryStorage>
impl Interpreter<MemoryStorage>
sourcepub fn with_memory_storage() -> Self
pub fn with_memory_storage() -> Self
Create a new storage with a provided in-memory storage.
It will have full capabilities.
sourceimpl<S> Interpreter<S> where
S: InterpreterStorage,
impl<S> Interpreter<S> where
S: InterpreterStorage,
sourcepub fn execute(&mut self) -> Result<ExecuteState, InterpreterError>
pub fn execute(&mut self) -> Result<ExecuteState, InterpreterError>
Execute the current instruction pair located in $m[$pc]
.
sourcepub fn instruction(
&mut self,
instruction: Instruction
) -> Result<ExecuteState, InterpreterError>
pub fn instruction(
&mut self,
instruction: Instruction
) -> Result<ExecuteState, InterpreterError>
Execute a provided instruction
sourceimpl Interpreter<PredicateStorage>
impl Interpreter<PredicateStorage>
sourcepub fn check_predicates(
tx: CheckedTransaction,
params: ConsensusParameters
) -> bool
pub fn check_predicates(
tx: CheckedTransaction,
params: ConsensusParameters
) -> bool
Initialize the VM with the provided transaction and check all predicates defined in the inputs.
The storage provider is not used since contract opcodes are not allowed for predicates. This way, its possible, for the sake of simplicity, it is possible to use unit as storage provider.
Debug
This is not a valid entrypoint for debug calls. It will only return a bool
, and not the
VM state required to trace the execution steps.
sourcepub fn check_predicate(&mut self, tx: CheckedTransaction, idx: usize) -> bool
pub fn check_predicate(&mut self, tx: CheckedTransaction, idx: usize) -> bool
Initialize the VM with the provided transaction and check the input predicate indexed by
idx
. If the input isn’t of type Input::CoinPredicate
, the function will return
false
.
For additional information, check Self::check_predicates
sourceimpl<S> Interpreter<S> where
S: InterpreterStorage,
impl<S> Interpreter<S> where
S: InterpreterStorage,
sourcepub fn transact_owned(
storage: S,
tx: CheckedTransaction,
params: ConsensusParameters
) -> Result<StateTransition, InterpreterError>
pub fn transact_owned(
storage: S,
tx: CheckedTransaction,
params: ConsensusParameters
) -> Result<StateTransition, InterpreterError>
Allocate internally a new instance of Interpreter
with the provided
storage, initialize it with the provided transaction and return the
result of th execution in form of StateTransition
sourcepub fn transact(
&mut self,
tx: CheckedTransaction
) -> Result<StateTransitionRef<'_>, InterpreterError>
pub fn transact(
&mut self,
tx: CheckedTransaction
) -> Result<StateTransitionRef<'_>, InterpreterError>
Initialize a pre-allocated instance of Interpreter
with the provided
transaction and execute it. The result will be bound to the lifetime
of the interpreter and will avoid unnecessary copy with the data
that can be referenced from the interpreter instance itself.
sourceimpl<S> Interpreter<S>
impl<S> Interpreter<S>
sourcepub fn init_predicate(&mut self, tx: CheckedTransaction) -> bool
pub fn init_predicate(&mut self, tx: CheckedTransaction) -> bool
Initialize the VM for a predicate context
sourceimpl<S> Interpreter<S> where
S: InterpreterStorage,
impl<S> Interpreter<S> where
S: InterpreterStorage,
sourcepub fn init_script(
&mut self,
tx: CheckedTransaction
) -> Result<(), InterpreterError>
pub fn init_script(
&mut self,
tx: CheckedTransaction
) -> Result<(), InterpreterError>
Initialize the VM with a given transaction, backed by a storage provider that allows execution of contract opcodes.
For predicate verification, check Self::init_predicate
sourceimpl<S> Interpreter<S>
impl<S> Interpreter<S>
sourcepub fn memory(&self) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
pub fn memory(&self) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
Returns the current state of the VM memory
sourcepub fn transaction(&self) -> &Transaction
pub fn transaction(&self) -> &Transaction
The current transaction
sourcepub fn checked_transaction(&self) -> &CheckedTransaction
pub fn checked_transaction(&self) -> &CheckedTransaction
The current transaction with checked metadata
sourcepub const fn params(&self) -> &ConsensusParameters
pub const fn params(&self) -> &ConsensusParameters
Consensus parameters
Trait Implementations
sourceimpl<S> AsMut<S> for Interpreter<S>
impl<S> AsMut<S> for Interpreter<S>
sourceimpl<S> AsRef<Interpreter<S>> for Transactor<'_, S>
impl<S> AsRef<Interpreter<S>> for Transactor<'_, S>
sourcefn as_ref(&self) -> &Interpreter<S>
fn as_ref(&self) -> &Interpreter<S>
Converts this type into a shared reference of the (usually inferred) input type.
sourceimpl<S> AsRef<S> for Interpreter<S>
impl<S> AsRef<S> for Interpreter<S>
sourceimpl<S: Clone> Clone for Interpreter<S>
impl<S: Clone> Clone for Interpreter<S>
sourcefn clone(&self) -> Interpreter<S>
fn clone(&self) -> Interpreter<S>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<S: Debug> Debug for Interpreter<S>
impl<S: Debug> Debug for Interpreter<S>
sourceimpl<S> Default for Interpreter<S> where
S: Default,
impl<S> Default for Interpreter<S> where
S: Default,
sourceimpl<S> From<Interpreter<S>> for CheckedTransaction
impl<S> From<Interpreter<S>> for CheckedTransaction
sourcefn from(vm: Interpreter<S>) -> Self
fn from(vm: Interpreter<S>) -> Self
Converts to this type from the input type.
sourceimpl<S> From<Interpreter<S>> for Transaction
impl<S> From<Interpreter<S>> for Transaction
sourcefn from(vm: Interpreter<S>) -> Self
fn from(vm: Interpreter<S>) -> Self
Converts to this type from the input type.
sourceimpl<S> From<Interpreter<S>> for Transactor<'_, S>
impl<S> From<Interpreter<S>> for Transactor<'_, S>
sourcefn from(interpreter: Interpreter<S>) -> Self
fn from(interpreter: Interpreter<S>) -> Self
Converts to this type from the input type.
sourceimpl<S> From<Transactor<'_, S>> for Interpreter<S>
impl<S> From<Transactor<'_, S>> for Interpreter<S>
sourcefn from(transactor: Transactor<'_, S>) -> Self
fn from(transactor: Transactor<'_, S>) -> Self
Converts to this type from the input type.
Auto Trait Implementations
impl<S> RefUnwindSafe for Interpreter<S> where
S: RefUnwindSafe,
impl<S> Send for Interpreter<S> where
S: Send,
impl<S> Sync for Interpreter<S> where
S: Sync,
impl<S> Unpin for Interpreter<S> where
S: Unpin,
impl<S> UnwindSafe for Interpreter<S> where
S: UnwindSafe,
Blanket Implementations
impl<T> Base32Len for T where
T: AsRef<[u8]>,
impl<T> Base32Len for T where
T: AsRef<[u8]>,
fn base32_len(&self) -> usize
fn base32_len(&self) -> usize
Calculate the base32 serialized length
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToHex for T where
T: AsRef<[u8]>,
impl<T> ToHex for T where
T: AsRef<[u8]>,
sourcefn encode_hex<U>(&self) -> U where
U: FromIterator<char>,
fn encode_hex<U>(&self) -> U where
U: FromIterator<char>,
Encode the hex strict representing self
into the result. Lower case
letters are used (e.g. f9b4ca
) Read more
sourcefn encode_hex_upper<U>(&self) -> U where
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> U where
U: FromIterator<char>,
Encode the hex strict representing self
into the result. Upper case
letters are used (e.g. F9B4CA
) Read more