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,
gas_costs: GasCosts
) -> Self
pub fn with_storage( storage: S, params: ConsensusParameters, gas_costs: GasCosts ) -> 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<Record<S>, Tx>where
S: InterpreterStorage,
Tx: ExecutableTransaction,
impl<S, Tx> Interpreter<Record<S>, Tx>where S: InterpreterStorage, Tx: ExecutableTransaction,
sourcepub fn remove_recording(self) -> Interpreter<S, Tx>
pub fn remove_recording(self) -> Interpreter<S, Tx>
Remove the [Recording
] wrapper from the storage.
Recording storage changes has an overhead so it’s
useful to be able to remove it once the diff is generated.
sourcepub fn storage_diff(&self) -> Diff<Deltas>
pub fn storage_diff(&self) -> Diff<Deltas>
Get the diff of changes to this VMs storage.
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 add_recording(self) -> Interpreter<Record<S>, Tx>
pub fn add_recording(self) -> Interpreter<Record<S>, Tx>
Add a [Recording
] wrapper around the storage to
record any changes this VM makes to it’s storage.
Recording storage changes has an overhead so should
be used in production.
sourcepub fn reset_vm_state(&mut self, diff: &Diff<InitialVmState>)where
Tx: Clone + 'static,
pub fn reset_vm_state(&mut self, diff: &Diff<InitialVmState>)where Tx: Clone + 'static,
Change this VMs internal state to match the initial state from this diff.
source§impl<S, Tx> Interpreter<S, Tx>
impl<S, Tx> Interpreter<S, Tx>
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<R: Into<RawInstruction> + Copy>(
&mut self,
raw: R
) -> Result<ExecuteState, InterpreterError>
pub fn instruction<R: Into<RawInstruction> + Copy>( &mut self, raw: R ) -> 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,
gas_costs: GasCosts
) -> Result<PredicatesChecked, PredicateVerificationFailed>where
Tx: ExecutableTransaction,
<Tx as IntoChecked>::Metadata: CheckedMetadata,
pub fn check_predicates<Tx>( checked: Checked<Tx>, params: ConsensusParameters, gas_costs: GasCosts ) -> Result<PredicatesChecked, PredicateVerificationFailed>where 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,
gas_costs: GasCosts
) -> Result<StateTransition<Tx>, InterpreterError>
pub fn transact_owned( storage: S, tx: Checked<Tx>, params: ConsensusParameters, gas_costs: GasCosts ) -> 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: RegId,
rb: RegId,
rc: RegId,
rd: RegId
) -> Result<(), RuntimeError>
pub fn prepare_call( &mut self, ra: RegId, rb: RegId, rc: RegId, rd: RegId ) -> 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
source§impl<S, Tx> PartialEq<Interpreter<S, Tx>> for Interpreter<S, Tx>where
Tx: PartialEq,
impl<S, Tx> PartialEq<Interpreter<S, Tx>> for Interpreter<S, Tx>where Tx: PartialEq,
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§
source§impl<T> AnyDebug for Twhere
T: Any + Debug,
impl<T> AnyDebug for Twhere T: Any + Debug,
source§fn as_any_ref(&self) -> &(dyn Any + 'static)
fn as_any_ref(&self) -> &(dyn Any + 'static)
Any
.§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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> StorageAsMut for T
impl<T> StorageAsMut for T
fn storage<Type>(&mut self) -> StorageMut<'_, Self, Type>where Type: Mappable,
fn storage_as_mut<Type>(&mut self) -> StorageMut<'_, Self, Type>where Type: Mappable,
source§impl<T> StorageAsRef for T
impl<T> StorageAsRef for T
fn storage<Type>(&self) -> StorageRef<'_, Self, Type>where Type: Mappable,
fn storage_as_ref<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
)source§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
)