diff --git a/crates/primitives/src/db.rs b/crates/primitives/src/db.rs index d6851b6ecb..5d6fa75b80 100644 --- a/crates/primitives/src/db.rs +++ b/crates/primitives/src/db.rs @@ -13,6 +13,7 @@ pub use components::{ /// EVM database interface. #[auto_impl(&mut, Box)] pub trait Database { + /// The database error type. type Error; /// Get basic account information. @@ -28,20 +29,21 @@ pub trait Database { fn block_hash(&mut self, number: U256) -> Result; } -impl From for WrapDatabaseRef { - fn from(f: F) -> Self { - WrapDatabaseRef(f) - } -} - +/// EVM database commit interface. #[auto_impl(&mut, Box)] pub trait DatabaseCommit { fn commit(&mut self, changes: Map); } -/// Same as [Database], but uses immutable references. -#[auto_impl(&, Box, Arc)] +/// EVM database interface. +/// +/// Contains the same methods as [`Database`], but with `&self` receivers instead of `&mut self`. +/// +/// Use [`WrapDatabaseRef`] to provide [`Database`] implementation for a type +/// that only implements this trait. +#[auto_impl(&, &mut, Box, Rc, Arc)] pub trait DatabaseRef { + /// The database error type. type Error; /// Get basic account information. @@ -60,6 +62,13 @@ pub trait DatabaseRef { /// Wraps a [`DatabaseRef`] to provide a [`Database`] implementation. pub struct WrapDatabaseRef(pub T); +impl From for WrapDatabaseRef { + #[inline] + fn from(f: F) -> Self { + WrapDatabaseRef(f) + } +} + impl Database for WrapDatabaseRef { type Error = T::Error; diff --git a/crates/primitives/src/db/components/block_hash.rs b/crates/primitives/src/db/components/block_hash.rs index f5b6959003..300f4d6dc8 100644 --- a/crates/primitives/src/db/components/block_hash.rs +++ b/crates/primitives/src/db/components/block_hash.rs @@ -6,7 +6,7 @@ use alloc::sync::Arc; use auto_impl::auto_impl; use core::ops::Deref; -#[auto_impl(& mut, Box)] +#[auto_impl(&mut, Box)] pub trait BlockHash { type Error; @@ -14,7 +14,7 @@ pub trait BlockHash { fn block_hash(&mut self, number: U256) -> Result; } -#[auto_impl(&, Box, Arc)] +#[auto_impl(&, &mut, Box, Rc, Arc)] pub trait BlockHashRef { type Error; diff --git a/crates/primitives/src/db/components/state.rs b/crates/primitives/src/db/components/state.rs index c59b4408d0..8aaac55b0f 100644 --- a/crates/primitives/src/db/components/state.rs +++ b/crates/primitives/src/db/components/state.rs @@ -6,7 +6,7 @@ use alloc::sync::Arc; use auto_impl::auto_impl; use core::ops::Deref; -#[auto_impl(& mut, Box)] +#[auto_impl(&mut, Box)] pub trait State { type Error; @@ -18,7 +18,7 @@ pub trait State { fn storage(&mut self, address: Address, index: U256) -> Result; } -#[auto_impl(&, Box, Arc)] +#[auto_impl(&, &mut, Box, Rc, Arc)] pub trait StateRef { type Error; diff --git a/crates/revm/src/evm_impl.rs b/crates/revm/src/evm_impl.rs index d86f1cbffb..4a5b572c1e 100644 --- a/crates/revm/src/evm_impl.rs +++ b/crates/revm/src/evm_impl.rs @@ -13,6 +13,7 @@ use crate::primitives::{ use crate::{db::Database, journaled_state::JournaledState, precompile, Inspector}; use alloc::boxed::Box; use alloc::vec::Vec; +use auto_impl::auto_impl; use core::marker::PhantomData; use revm_interpreter::gas::initial_tx_gas; use revm_interpreter::MAX_CODE_SIZE; @@ -65,6 +66,8 @@ struct CallResult { return_value: Bytes, } +/// EVM transaction interface. +#[auto_impl(&mut, Box)] pub trait Transact { /// Run checks that could make transaction fail before call/create. fn preverify_transaction(&mut self) -> Result<(), EVMError>; @@ -76,7 +79,7 @@ pub trait Transact { #[inline] fn transact(&mut self) -> EVMResult { self.preverify_transaction() - .and_then(|_| self.transact_preverified()) + .and_then(|()| self.transact_preverified()) } }