Skip to main content

Database

Trait Database 

pub trait Database {
    type Error: DBErrorMarker;

    // Required methods
    fn basic(
        &mut self,
        address: Address,
    ) -> Result<Option<AccountInfo>, Self::Error>;
    fn code_by_hash(
        &mut self,
        code_hash: FixedBytes<32>,
    ) -> Result<Bytecode, Self::Error>;
    fn storage(
        &mut self,
        address: Address,
        index: Uint<256, 4>,
    ) -> Result<Uint<256, 4>, Self::Error>;
    fn block_hash(&mut self, number: u64) -> Result<FixedBytes<32>, Self::Error>;

    // Provided method
    fn storage_by_account_id(
        &mut self,
        address: Address,
        account_id: AccountId,
        storage_key: Uint<256, 4>,
    ) -> Result<Uint<256, 4>, Self::Error> { ... }
}
Expand description

EVM database interface.

Required Associated Types§

type Error: DBErrorMarker

The database error type.

Required Methods§

fn basic( &mut self, address: Address, ) -> Result<Option<AccountInfo>, Self::Error>

Gets basic account information.

fn code_by_hash( &mut self, code_hash: FixedBytes<32>, ) -> Result<Bytecode, Self::Error>

Gets account code by its hash.

fn storage( &mut self, address: Address, index: Uint<256, 4>, ) -> Result<Uint<256, 4>, Self::Error>

Gets storage value of address at index.

fn block_hash(&mut self, number: u64) -> Result<FixedBytes<32>, Self::Error>

Gets block hash by block number.

Provided Methods§

fn storage_by_account_id( &mut self, address: Address, account_id: AccountId, storage_key: Uint<256, 4>, ) -> Result<Uint<256, 4>, Self::Error>

Gets storage value of account by its id. By default call Database::storage method.

If basic account sets account_id inside AccountInfo::account_id, evm will call this function with that given account_id. This can be useful if IndexMap is used to get faster access to the account.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

§

impl<'a, T> Database for &'a mut T
where T: 'a + Database + ?Sized,

§

type Error = <T as Database>::Error

§

fn basic( &mut self, address: Address, ) -> Result<Option<AccountInfo>, <&'a mut T as Database>::Error>

§

fn code_by_hash( &mut self, code_hash: FixedBytes<32>, ) -> Result<Bytecode, <&'a mut T as Database>::Error>

§

fn storage( &mut self, address: Address, index: Uint<256, 4>, ) -> Result<Uint<256, 4>, <&'a mut T as Database>::Error>

§

fn storage_by_account_id( &mut self, address: Address, account_id: AccountId, storage_key: Uint<256, 4>, ) -> Result<Uint<256, 4>, <&'a mut T as Database>::Error>

§

fn block_hash( &mut self, number: u64, ) -> Result<FixedBytes<32>, <&'a mut T as Database>::Error>

§

impl<DB> Database for CachedReadsDbMut<'_, DB>
where DB: DatabaseRef,

§

type Error = <DB as DatabaseRef>::Error

§

fn basic( &mut self, address: Address, ) -> Result<Option<AccountInfo>, <CachedReadsDbMut<'_, DB> as Database>::Error>

§

fn code_by_hash( &mut self, code_hash: FixedBytes<32>, ) -> Result<Bytecode, <CachedReadsDbMut<'_, DB> as Database>::Error>

§

fn storage( &mut self, address: Address, index: Uint<256, 4>, ) -> Result<Uint<256, 4>, <CachedReadsDbMut<'_, DB> as Database>::Error>

§

fn block_hash( &mut self, number: u64, ) -> Result<FixedBytes<32>, <CachedReadsDbMut<'_, DB> as Database>::Error>

§

impl<DB> Database for StateProviderDatabase<DB>
where DB: EvmStateProvider,

§

fn basic( &mut self, address: Address, ) -> Result<Option<AccountInfo>, <StateProviderDatabase<DB> as Database>::Error>

Retrieves basic account information for a given address.

Returns Ok with Some(AccountInfo) if the account exists, None if it doesn’t, or an error if encountered.

§

fn code_by_hash( &mut self, code_hash: FixedBytes<32>, ) -> Result<Bytecode, <StateProviderDatabase<DB> as Database>::Error>

Retrieves the bytecode associated with a given code hash.

Returns Ok with the bytecode if found, or the default bytecode otherwise.

§

fn storage( &mut self, address: Address, index: Uint<256, 4>, ) -> Result<Uint<256, 4>, <StateProviderDatabase<DB> as Database>::Error>

Retrieves the storage value at a specific index for a given address.

Returns Ok with the storage value, or the default value if not found.

§

fn block_hash( &mut self, number: u64, ) -> Result<FixedBytes<32>, <StateProviderDatabase<DB> as Database>::Error>

Retrieves the block hash for a given block number.

Returns Ok with the block hash if found, or the default hash otherwise. Note: It safely casts the number to u64.

§

type Error = ProviderError

§

impl<T> Database for Box<T>
where T: Database + ?Sized,

§

type Error = <T as Database>::Error

§

fn basic( &mut self, address: Address, ) -> Result<Option<AccountInfo>, <Box<T> as Database>::Error>

§

fn code_by_hash( &mut self, code_hash: FixedBytes<32>, ) -> Result<Bytecode, <Box<T> as Database>::Error>

§

fn storage( &mut self, address: Address, index: Uint<256, 4>, ) -> Result<Uint<256, 4>, <Box<T> as Database>::Error>

§

fn storage_by_account_id( &mut self, address: Address, account_id: AccountId, storage_key: Uint<256, 4>, ) -> Result<Uint<256, 4>, <Box<T> as Database>::Error>

§

fn block_hash( &mut self, number: u64, ) -> Result<FixedBytes<32>, <Box<T> as Database>::Error>

Implementors§

§

impl Database for BenchmarkDB

§

impl Database for MemDb

§

impl<DB> Database for BalDatabase<DB>
where DB: Database,

§

impl<DB> Database for State<DB>
where DB: Database,

§

impl<E> Database for EmptyDBTyped<E>
where E: DBErrorMarker + Error + Send + Sync + 'static,

§

type Error = E

§

impl<ExtDB> Database for CacheDB<ExtDB>
where ExtDB: DatabaseRef,

§

type Error = <ExtDB as DatabaseRef>::Error

§

impl<FEN> Database for Backend<FEN>
where FEN: FoundryEvmNetwork,

§

impl<FEN> Database for CowBackend<'_, FEN>
where FEN: FoundryEvmNetwork,

§

impl<L, R> Database for Either<L, R>
where L: Database, R: Database<Error = <L as Database>::Error>,

§

type Error = <L as Database>::Error

§

impl<N, B> Database for ForkedDatabase<N, B>
where N: Network, B: ForkBlockEnv,

§

impl<T> Database for WrapDatabaseRef<T>
where T: DatabaseRef,

§

type Error = <T as DatabaseRef>::Error