Type Alias FoundryEvmInMemoryDB

pub type FoundryEvmInMemoryDB = CacheDB<EmptyDBWrapper>;
Expand description

Type alias for an in-memory database.

See EmptyDBWrapper.

Aliased Type§

struct FoundryEvmInMemoryDB {
    pub accounts: HashMap<Address, DbAccount, RandomState>,
    pub contracts: HashMap<FixedBytes<32>, Bytecode, RandomState>,
    pub logs: Vec<Log>,
    pub block_hashes: HashMap<Uint<256, 4>, FixedBytes<32>, RandomState>,
    pub db: EmptyDBWrapper,
}

Fields§

§accounts: HashMap<Address, DbAccount, RandomState>

Account info where None means it is not existing. Not existing state is needed for Pre TANGERINE forks. code is always None, and bytecode can be found in contracts.

§contracts: HashMap<FixedBytes<32>, Bytecode, RandomState>

Tracks all contracts by their code hash.

§logs: Vec<Log>

All logs that were committed via [DatabaseCommit::commit].

§block_hashes: HashMap<Uint<256, 4>, FixedBytes<32>, RandomState>

All cached block hashes from the [DatabaseRef].

§db: EmptyDBWrapper

The underlying database ([DatabaseRef]) that is used to load data.

Note: this is read-only, data is never written to this database.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 144 bytes

Implementations

§

impl<ExtDB> CacheDB<ExtDB>

pub fn new(db: ExtDB) -> CacheDB<ExtDB>

pub fn insert_contract(&mut self, account: &mut AccountInfo)

Inserts the account’s code into the cache.

Accounts objects and code are stored separately in the cache, this will take the code from the account and instead map it to the code hash.

Note: This will not insert into the underlying external database.

pub fn insert_account_info(&mut self, address: Address, info: AccountInfo)

Insert account info but not override storage

§

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

pub fn load_account( &mut self, address: Address, ) -> Result<&mut DbAccount, <ExtDB as DatabaseRef>::Error>

Returns the account for the given address.

If the account was not found in the cache, it will be loaded from the underlying database.

pub fn insert_account_storage( &mut self, address: Address, slot: Uint<256, 4>, value: Uint<256, 4>, ) -> Result<(), <ExtDB as DatabaseRef>::Error>

insert account storage without overriding account info

pub fn replace_account_storage( &mut self, address: Address, storage: HashMap<Uint<256, 4>, Uint<256, 4>, RandomState>, ) -> Result<(), <ExtDB as DatabaseRef>::Error>

replace account storage without overriding account info

Trait Implementations

§

impl<ExtDB> Clone for CacheDB<ExtDB>
where ExtDB: Clone,

§

fn clone(&self) -> CacheDB<ExtDB>

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
§

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

§

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

Get the value in an account’s storage slot.

It is assumed that account is already loaded.

§

type Error = <ExtDB as DatabaseRef>::Error

The database error type.
§

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

Get basic account information.
§

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

Get account code by its hash.
§

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

Get block hash by block number.
§

impl<ExtDB> DatabaseCommit for CacheDB<ExtDB>

§

fn commit(&mut self, changes: HashMap<Address, Account, RandomState>)

Commit changes to the database.
§

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

§

type Error = <ExtDB as DatabaseRef>::Error

The database error type.
§

fn basic_ref( &self, address: Address, ) -> Result<Option<AccountInfo>, <CacheDB<ExtDB> as DatabaseRef>::Error>

Get basic account information.
§

fn code_by_hash_ref( &self, code_hash: FixedBytes<32>, ) -> Result<Bytecode, <CacheDB<ExtDB> as DatabaseRef>::Error>

Get account code by its hash.
§

fn storage_ref( &self, address: Address, index: Uint<256, 4>, ) -> Result<Uint<256, 4>, <CacheDB<ExtDB> as DatabaseRef>::Error>

Get storage value of address at index.
§

fn block_hash_ref( &self, number: u64, ) -> Result<FixedBytes<32>, <CacheDB<ExtDB> as DatabaseRef>::Error>

Get block hash by block number.
§

impl<ExtDB> Debug for CacheDB<ExtDB>
where ExtDB: Debug,

§

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

Formats the value using the given formatter. Read more
§

impl<ExtDB> Default for CacheDB<ExtDB>
where ExtDB: Default,

§

fn default() -> CacheDB<ExtDB>

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

impl<'de, ExtDB> Deserialize<'de> for CacheDB<ExtDB>
where ExtDB: Deserialize<'de>,

§

fn deserialize<__D>( __deserializer: __D, ) -> Result<CacheDB<ExtDB>, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl<ExtDB> Serialize for CacheDB<ExtDB>
where ExtDB: Serialize,

§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more