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,

source

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.

source

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,

source

pub fn build(&mut self) -> Self

Build the interpreter

source§

impl<Tx> Interpreter<(), Tx>where Tx: ExecutableTransaction,

source

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,

source

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,

source

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.

source

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,

source

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.

source

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>

source

pub fn diff(&self, other: &Self) -> Diff<Deltas>where Tx: PartialEq + Clone + Debug + 'static,

The diff function generates a diff of VM state, represented by the Diff struct, between two VMs internal states.

source§

impl<S, Tx> Interpreter<S, Tx>where S: InterpreterStorage, Tx: ExecutableTransaction,

source

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

Execute the current instruction pair located in $m[$pc].

source

pub fn instruction<R: Into<RawInstruction> + Copy>( &mut self, raw: R ) -> Result<ExecuteState, InterpreterError>

Execute a provided instruction

source§

impl<T> Interpreter<PredicateStorage, T>

source

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,

source

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

source

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,

source

pub fn deploy( &mut self, tx: Checked<Create> ) -> Result<Create, InterpreterError>

Deploys Create transaction without initialization VM and without invalidation of the last state of execution of the Script transaction.

Returns Create transaction with all modifications after execution.

source§

impl<S, Tx> Interpreter<S, Tx>where S: InterpreterStorage, Tx: ExecutableTransaction,

source

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,

source

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,

source

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>

source

pub fn memory(&self) -> &[u8]

Returns the current state of the VM memory

source

pub const fn registers(&self) -> &[Word]

Returns the current state of the registers

source

pub const fn debugger(&self) -> &Debugger

Debug handler

source

pub fn transaction(&self) -> &Tx

The current transaction.

source

pub fn initial_balances(&self) -> &InitialBalances

The initial balances.

source

pub const fn params(&self) -> &ConsensusParameters

Consensus parameters

source

pub fn gas_costs(&self) -> &GasCosts

Gas costs for opcodes

source

pub fn receipts(&self) -> &[Receipt]

Receipts generated by a transaction execution.

Trait Implementations§

source§

impl<S, Tx> AsMut<S> for Interpreter<S, Tx>

source§

fn as_mut(&mut self) -> &mut S

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<S, Tx> AsRef<Interpreter<S, Tx>> for Transactor<S, Tx>where Tx: ExecutableTransaction,

source§

fn as_ref(&self) -> &Interpreter<S, Tx>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<S, Tx> AsRef<S> for Interpreter<S, Tx>

source§

fn as_ref(&self) -> &S

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<S: Clone, Tx: Clone> Clone for Interpreter<S, Tx>

source§

fn clone(&self) -> Interpreter<S, Tx>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<S: Debug, Tx: Debug> Debug for Interpreter<S, Tx>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<S, Tx> Default for Interpreter<S, Tx>where S: Default, Tx: ExecutableTransaction,

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<S, Tx> From<Interpreter<S, Tx>> for Transactor<S, Tx>where Tx: ExecutableTransaction,

source§

fn from(interpreter: Interpreter<S, Tx>) -> Self

Converts to this type from the input type.
source§

impl<S, Tx> From<Transactor<S, Tx>> for Interpreter<S, Tx>where Tx: ExecutableTransaction,

source§

fn from(transactor: Transactor<S, Tx>) -> Self

Converts to this type from the input type.
source§

impl<S, Tx> PartialEq<Interpreter<S, Tx>> for Interpreter<S, Tx>where Tx: PartialEq,

source§

fn eq(&self, other: &Self) -> bool

Does not compare storage, debugger or profiler

1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> AnyDebug for Twhere T: Any + Debug,

source§

fn as_any_ref(&self) -> &(dyn Any + 'static)

Returns a reference to the underlying type as Any.
§

impl<T> Base32Len for Twhere T: AsRef<[u8]>,

§

fn base32_len(&self) -> usize

Calculate the base32 serialized length
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<'f, T> CheckBase32<Vec<u5, Global>> for Twhere T: AsRef<[u8]>,

§

type Err = Error

Error type if conversion fails
§

fn check_base32( self ) -> Result<Vec<u5, Global>, <T as CheckBase32<Vec<u5, Global>>>::Err>

Check if all values are in range and return array-like struct of u5 values
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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<T> for T

§

type Output = T

Should always be Self
source§

impl<T> StorageAsMut for T

source§

fn storage<Type>(&mut self) -> StorageMut<'_, Self, Type>where Type: Mappable,

source§

fn storage_as_mut<Type>(&mut self) -> StorageMut<'_, Self, Type>where Type: Mappable,

source§

impl<T> StorageAsRef for T

source§

fn storage<Type>(&self) -> StorageRef<'_, Self, Type>where Type: Mappable,

source§

fn storage_as_ref<Type>(&self) -> StorageRef<'_, Self, Type>where Type: Mappable,

§

impl<T> ToBase32 for Twhere T: AsRef<[u8]>,

§

fn write_base32<W>(&self, writer: &mut W) -> Result<(), <W as WriteBase32>::Err>where W: WriteBase32,

Encode as base32 and write it to the supplied writer Implementations shouldn’t allocate.
§

fn to_base32(&self) -> Vec<u5, Global>

Convert Self to base32 vector
source§

impl<T> ToHex for Twhere T: AsRef<[u8]>,

source§

fn encode_hex<U>(&self) -> Uwhere U: FromIterator<char>,

Encode the hex strict representing self into the result. Lower case letters are used (e.g. f9b4ca)
source§

fn encode_hex_upper<U>(&self) -> Uwhere U: FromIterator<char>,

Encode the hex strict representing self into the result. Upper case letters are used (e.g. F9B4CA)
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V