Struct fuel_vm::interpreter::Interpreter
source · pub struct Interpreter<S, Tx = ()> { /* 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§
source§impl<S, Tx> Interpreter<S, Tx>where
Tx: Default,
impl<S, Tx> Interpreter<S, Tx>where
Tx: Default,
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
source§impl<S, Tx> Interpreter<S, Tx>where
S: Clone,
Tx: ExecutableTransaction,
impl<S, Tx> Interpreter<S, Tx>where
S: Clone,
Tx: ExecutableTransaction,
source§impl<Tx> Interpreter<(), Tx>where
Tx: ExecutableTransaction,
impl<Tx> Interpreter<(), Tx>where
Tx: ExecutableTransaction,
sourcepub fn without_storage() -> Self
pub fn without_storage() -> Self
Create a new interpreter without a storage backend.
It will have restricted capabilities.
source§impl<Tx> Interpreter<MemoryStorage, Tx>where
Tx: ExecutableTransaction,
impl<Tx> Interpreter<MemoryStorage, Tx>where
Tx: ExecutableTransaction,
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.
source§impl<S, Tx> Interpreter<S, Tx>where
S: InterpreterStorage,
Tx: ExecutableTransaction,
impl<S, Tx> Interpreter<S, Tx>where
S: InterpreterStorage,
Tx: ExecutableTransaction,
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
source§impl<T> Interpreter<PredicateStorage, T>
impl<T> Interpreter<PredicateStorage, T>
sourcepub fn check_predicates<Tx>(
checked: Checked<Tx>,
params: ConsensusParameters
) -> boolwhere
Tx: ExecutableTransaction,
<Tx as IntoChecked>::Metadata: CheckedMetadata,
pub fn check_predicates<Tx>(
checked: Checked<Tx>,
params: ConsensusParameters
) -> boolwhere
Tx: ExecutableTransaction,
<Tx as IntoChecked>::Metadata: CheckedMetadata,
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.
source§impl<S, Tx> Interpreter<S, Tx>where
S: InterpreterStorage,
Tx: ExecutableTransaction,
<Tx as IntoChecked>::Metadata: CheckedMetadata,
impl<S, Tx> Interpreter<S, Tx>where
S: InterpreterStorage,
Tx: ExecutableTransaction,
<Tx as IntoChecked>::Metadata: CheckedMetadata,
sourcepub fn transact_owned(
storage: S,
tx: Checked<Tx>,
params: ConsensusParameters
) -> Result<StateTransition<Tx>, InterpreterError>
pub fn transact_owned(
storage: S,
tx: Checked<Tx>,
params: ConsensusParameters
) -> Result<StateTransition<Tx>, 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: Checked<Tx>
) -> Result<StateTransitionRef<'_, Tx>, InterpreterError>
pub fn transact(
&mut self,
tx: Checked<Tx>
) -> Result<StateTransitionRef<'_, Tx>, 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.
source§impl<S, Tx> Interpreter<S, Tx>where
S: InterpreterStorage,
impl<S, Tx> Interpreter<S, Tx>where
S: InterpreterStorage,
source§impl<S, Tx> Interpreter<S, Tx>where
S: InterpreterStorage,
Tx: ExecutableTransaction,
impl<S, Tx> Interpreter<S, Tx>where
S: InterpreterStorage,
Tx: ExecutableTransaction,
sourcepub fn prepare_call(
&mut self,
ra: RegisterId,
rb: RegisterId,
rc: RegisterId,
rd: RegisterId
) -> Result<(), RuntimeError>
pub fn prepare_call(
&mut self,
ra: RegisterId,
rb: RegisterId,
rc: RegisterId,
rd: RegisterId
) -> Result<(), RuntimeError>
Prepare a call instruction for execution
source§impl<S, Tx> Interpreter<S, Tx>where
Tx: ExecutableTransaction,
<Tx as IntoChecked>::Metadata: CheckedMetadata,
impl<S, Tx> Interpreter<S, Tx>where
Tx: ExecutableTransaction,
<Tx as IntoChecked>::Metadata: CheckedMetadata,
sourcepub fn init_predicate(&mut self, checked: Checked<Tx>) -> bool
pub fn init_predicate(&mut self, checked: Checked<Tx>) -> bool
Initialize the VM for a predicate context
source§impl<S, Tx> Interpreter<S, Tx>where
S: InterpreterStorage,
Tx: ExecutableTransaction,
<Tx as IntoChecked>::Metadata: CheckedMetadata,
impl<S, Tx> Interpreter<S, Tx>where
S: InterpreterStorage,
Tx: ExecutableTransaction,
<Tx as IntoChecked>::Metadata: CheckedMetadata,
sourcepub fn init_script(
&mut self,
checked: Checked<Tx>
) -> Result<(), InterpreterError>
pub fn init_script(
&mut self,
checked: Checked<Tx>
) -> 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
source§impl<S, Tx> Interpreter<S, Tx>
impl<S, Tx> Interpreter<S, Tx>
sourcepub fn transaction(&self) -> &Tx
pub fn transaction(&self) -> &Tx
The current transaction.
sourcepub fn initial_balances(&self) -> &InitialBalances
pub fn initial_balances(&self) -> &InitialBalances
The initial balances.
sourcepub const fn params(&self) -> &ConsensusParameters
pub const fn params(&self) -> &ConsensusParameters
Consensus parameters
Trait Implementations§
source§impl<S, Tx> AsMut<S> for Interpreter<S, Tx>
impl<S, Tx> AsMut<S> for Interpreter<S, Tx>
source§impl<S, Tx> AsRef<Interpreter<S, Tx>> for Transactor<S, Tx>where
Tx: ExecutableTransaction,
impl<S, Tx> AsRef<Interpreter<S, Tx>> for Transactor<S, Tx>where
Tx: ExecutableTransaction,
source§fn as_ref(&self) -> &Interpreter<S, Tx>
fn as_ref(&self) -> &Interpreter<S, Tx>
source§impl<S, Tx> AsRef<S> for Interpreter<S, Tx>
impl<S, Tx> AsRef<S> for Interpreter<S, Tx>
source§impl<S: Clone, Tx: Clone> Clone for Interpreter<S, Tx>
impl<S: Clone, Tx: Clone> Clone for Interpreter<S, Tx>
source§fn clone(&self) -> Interpreter<S, Tx>
fn clone(&self) -> Interpreter<S, Tx>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<S, Tx> Default for Interpreter<S, Tx>where
S: Default,
Tx: ExecutableTransaction,
impl<S, Tx> Default for Interpreter<S, Tx>where
S: Default,
Tx: ExecutableTransaction,
source§impl<S, Tx> From<Interpreter<S, Tx>> for Transactor<S, Tx>where
Tx: ExecutableTransaction,
impl<S, Tx> From<Interpreter<S, Tx>> for Transactor<S, Tx>where
Tx: ExecutableTransaction,
source§fn from(interpreter: Interpreter<S, Tx>) -> Self
fn from(interpreter: Interpreter<S, Tx>) -> Self
source§impl<S, Tx> From<Transactor<S, Tx>> for Interpreter<S, Tx>where
Tx: ExecutableTransaction,
impl<S, Tx> From<Transactor<S, Tx>> for Interpreter<S, Tx>where
Tx: ExecutableTransaction,
source§fn from(transactor: Transactor<S, Tx>) -> Self
fn from(transactor: Transactor<S, Tx>) -> Self
Auto Trait Implementations§
impl<S, Tx> RefUnwindSafe for Interpreter<S, Tx>where
S: RefUnwindSafe,
Tx: RefUnwindSafe,
impl<S, Tx> Send for Interpreter<S, Tx>where
S: Send,
Tx: Send,
impl<S, Tx> Sync for Interpreter<S, Tx>where
S: Sync,
Tx: Sync,
impl<S, Tx> Unpin for Interpreter<S, Tx>where
S: Unpin,
Tx: Unpin,
impl<S, Tx> UnwindSafe for Interpreter<S, Tx>where
S: UnwindSafe,
Tx: UnwindSafe,
Blanket Implementations§
§impl<T> Base32Len for Twhere
T: AsRef<[u8]>,
impl<T> Base32Len for Twhere
T: AsRef<[u8]>,
§fn base32_len(&self) -> usize
fn base32_len(&self) -> usize
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<'a, T> StorageAsMut for T
impl<'a, T> StorageAsMut for T
fn storage<Type>(&mut self) -> StorageMut<'_, Self, Type>where
Type: Mappable,
source§impl<'a, T> StorageAsRef for T
impl<'a, T> StorageAsRef for T
fn storage<Type>(&self) -> StorageRef<'_, Self, Type>where
Type: Mappable,
source§impl<T> ToHex for Twhere
T: AsRef<[u8]>,
impl<T> ToHex for Twhere
T: AsRef<[u8]>,
source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Lower case
letters are used (e.g. f9b4ca
) Read moresource§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Upper case
letters are used (e.g. F9B4CA
) Read more