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_one(
&mut self,
tx: Self::Tx,
) -> Result<Self::ExecutionResult, Self::Error>;
fn finalize(&mut self) -> Self::State;
fn replay(
&mut self,
) -> Result<ExecResultAndState<Self::ExecutionResult, Self::State>, Self::Error>;
// Provided methods
fn transact(
&mut self,
tx: Self::Tx,
) -> Result<ExecResultAndState<Self::ExecutionResult, Self::State>, Self::Error> { ... }
fn transact_many(
&mut self,
txs: impl Iterator<Item = Self::Tx>,
) -> Result<Vec<Self::ExecutionResult>, Self::Error> { ... }
fn transact_many_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.
Sourcetype Tx: Transaction
type Tx: Transaction
Transaction type.
Required Methods§
Sourcefn transact_one(
&mut self,
tx: Self::Tx,
) -> Result<Self::ExecutionResult, Self::Error>
fn transact_one( &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
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.
Sourcefn finalize(&mut self) -> Self::State
fn finalize(&mut self) -> Self::State
Finalize execution, clearing the journal and returning the accumulated state changes.
§State Management
Journal is cleared and can be used for next transaction.
Sourcefn replay(
&mut self,
) -> Result<ExecResultAndState<Self::ExecutionResult, Self::State>, Self::Error>
fn replay( &mut self, ) -> Result<ExecResultAndState<Self::ExecutionResult, Self::State>, Self::Error>
Execute previous transaction and finalize it.
Doint it without finalization
Provided Methods§
Sourcefn transact(
&mut self,
tx: Self::Tx,
) -> Result<ExecResultAndState<Self::ExecutionResult, Self::State>, Self::Error>
fn transact( &mut self, tx: Self::Tx, ) -> Result<ExecResultAndState<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_many(
&mut self,
txs: impl Iterator<Item = Self::Tx>,
) -> Result<Vec<Self::ExecutionResult>, Self::Error>
fn transact_many( &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_many_finalize(
&mut self,
txs: impl Iterator<Item = Self::Tx>,
) -> Result<ResultVecAndState<Self::ExecutionResult, Self::State>, Self::Error>
fn transact_many_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_many
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.