pub trait ExecuteEvm {
type ExecutionResult;
type State;
type Error;
type Tx: Transaction;
type Block: Block;
// Required methods
fn set_block(&mut self, block: Self::Block);
fn transact(
&mut self,
tx: Self::Tx,
) -> Result<Self::ExecutionResult, Self::Error>;
fn finalize(&mut self) -> Self::State;
fn replay(
&mut self,
) -> Result<ResultAndState<Self::ExecutionResult, Self::State>, Self::Error>;
// Provided methods
fn transact_finalize(
&mut self,
tx: Self::Tx,
) -> Result<ResultAndState<Self::ExecutionResult, Self::State>, Self::Error> { ... }
fn transact_multi(
&mut self,
txs: impl Iterator<Item = Self::Tx>,
) -> Result<Vec<Self::ExecutionResult>, Self::Error> { ... }
fn transact_multi_finalize(
&mut self,
txs: impl Iterator<Item = Self::Tx>,
) -> Result<ResultVecAndState<Self::ExecutionResult, Self::State>, Self::Error> { ... }
}
Expand description
Execute EVM transactions. Main trait for transaction execution.
Required Associated Types§
Sourcetype ExecutionResult
type ExecutionResult
Output of transaction execution.
type State
Required Methods§
Sourcefn transact(
&mut self,
tx: Self::Tx,
) -> Result<Self::ExecutionResult, Self::Error>
fn transact( &mut self, tx: Self::Tx, ) -> Result<Self::ExecutionResult, Self::Error>
Execute transaction and store state inside journal. Returns output of transaction execution.
§Return Value
Returns only the execution result
§Error Handling
If the transaction fails, the journal will revert all changes of given transaction.
For quicker error handling, use ExecuteEvm::transact_finalize
that will drop the journal.
§State Management
State changes are stored in the internal journal.
To retrieve the state, call ExecuteEvm::finalize
after transaction execution.
§History Note
Previously this function returned both output and state. Now it follows a two-step process: execute then finalize.
Provided Methods§
Sourcefn transact_finalize(
&mut self,
tx: Self::Tx,
) -> Result<ResultAndState<Self::ExecutionResult, Self::State>, Self::Error>
fn transact_finalize( &mut self, tx: Self::Tx, ) -> Result<ResultAndState<Self::ExecutionResult, Self::State>, Self::Error>
Transact the given transaction and finalize in a single operation.
Internally calls ExecuteEvm::transact
followed by ExecuteEvm::finalize
.
§Outcome of Error
If the transaction fails, the journal is considered broken.
Sourcefn transact_multi(
&mut self,
txs: impl Iterator<Item = Self::Tx>,
) -> Result<Vec<Self::ExecutionResult>, Self::Error>
fn transact_multi( &mut self, txs: impl Iterator<Item = Self::Tx>, ) -> Result<Vec<Self::ExecutionResult>, Self::Error>
Execute multiple transactions without finalizing the state.
Returns a vector of execution results. State changes are accumulated in the journal
but not finalized. Call ExecuteEvm::finalize
after execution to retrieve state changes.
§Outcome of Error
If any transaction fails, the journal is finalized and the last error is returned.
TODO add tx index to the error.
Sourcefn transact_multi_finalize(
&mut self,
txs: impl Iterator<Item = Self::Tx>,
) -> Result<ResultVecAndState<Self::ExecutionResult, Self::State>, Self::Error>
fn transact_multi_finalize( &mut self, txs: impl Iterator<Item = Self::Tx>, ) -> Result<ResultVecAndState<Self::ExecutionResult, Self::State>, Self::Error>
Execute multiple transactions and finalize the state in a single operation.
Internally calls ExecuteEvm::transact_multi
followed by ExecuteEvm::finalize
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.