anvil::eth::backend::db

Trait Db

Source
pub trait Db:
    DatabaseRef<Error = DatabaseError>
    + Database<Error = DatabaseError>
    + DatabaseCommit
    + MaybeFullDatabase
    + MaybeForkedDatabase
    + Debug
    + Send
    + Sync {
    // Required methods
    fn insert_account(&mut self, address: Address, account: AccountInfo);
    fn set_storage_at(
        &mut self,
        address: Address,
        slot: B256,
        val: B256,
    ) -> DatabaseResult<()>;
    fn insert_block_hash(&mut self, number: U256, hash: B256);
    fn dump_state(
        &self,
        at: BlockEnv,
        best_number: U64,
        blocks: Vec<SerializableBlock>,
        transactions: Vec<SerializableTransaction>,
        historical_states: Option<SerializableHistoricalStates>,
    ) -> DatabaseResult<Option<SerializableState>>;
    fn snapshot_state(&mut self) -> U256;
    fn revert_state(
        &mut self,
        state_snapshot: U256,
        action: RevertStateSnapshotAction,
    ) -> bool;
    fn current_state(&self) -> StateDb;

    // Provided methods
    fn set_nonce(&mut self, address: Address, nonce: u64) -> DatabaseResult<()> { ... }
    fn set_balance(
        &mut self,
        address: Address,
        balance: U256,
    ) -> DatabaseResult<()> { ... }
    fn set_code(&mut self, address: Address, code: Bytes) -> DatabaseResult<()> { ... }
    fn load_state(&mut self, state: SerializableState) -> DatabaseResult<bool> { ... }
    fn maybe_state_root(&self) -> Option<B256> { ... }
}
Expand description

This bundles all required revm traits

Required Methods§

Source

fn insert_account(&mut self, address: Address, account: AccountInfo)

Inserts an account

Source

fn set_storage_at( &mut self, address: Address, slot: B256, val: B256, ) -> DatabaseResult<()>

Sets the balance of the given address

Source

fn insert_block_hash(&mut self, number: U256, hash: B256)

inserts a blockhash for the given number

Source

fn dump_state( &self, at: BlockEnv, best_number: U64, blocks: Vec<SerializableBlock>, transactions: Vec<SerializableTransaction>, historical_states: Option<SerializableHistoricalStates>, ) -> DatabaseResult<Option<SerializableState>>

Write all chain data to serialized bytes buffer

Source

fn snapshot_state(&mut self) -> U256

Creates a new state snapshot.

Source

fn revert_state( &mut self, state_snapshot: U256, action: RevertStateSnapshotAction, ) -> bool

Reverts a state snapshot.

Returns true if the state snapshot was reverted.

Source

fn current_state(&self) -> StateDb

Returns the current, standalone state of the Db

Provided Methods§

Source

fn set_nonce(&mut self, address: Address, nonce: u64) -> DatabaseResult<()>

Sets the nonce of the given address

Source

fn set_balance(&mut self, address: Address, balance: U256) -> DatabaseResult<()>

Sets the balance of the given address

Source

fn set_code(&mut self, address: Address, code: Bytes) -> DatabaseResult<()>

Sets the balance of the given address

Source

fn load_state(&mut self, state: SerializableState) -> DatabaseResult<bool>

Deserialize and add all chain data to the backend storage

Source

fn maybe_state_root(&self) -> Option<B256>

Returns the state root if possible to compute

Implementations§

Source§

impl dyn Db

Source

pub fn as_dbref(&self) -> &dyn DatabaseRef<Error = DatabaseError>

Implementations on Foreign Types§

Source§

impl<T: DatabaseRef<Error = DatabaseError> + Send + Sync + Clone + Debug> Db for CacheDB<T>

Convenience impl only used to use any Db on the fly as the db layer for revm’s CacheDB This is useful to create blocks without actually writing to the Db, but rather in the cache of the CacheDB see also Backend::pending_block()

Source§

fn insert_account(&mut self, address: Address, account: AccountInfo)

Source§

fn set_storage_at( &mut self, address: Address, slot: B256, val: B256, ) -> DatabaseResult<()>

Source§

fn insert_block_hash(&mut self, number: U256, hash: B256)

Source§

fn dump_state( &self, _at: BlockEnv, _best_number: U64, _blocks: Vec<SerializableBlock>, _transaction: Vec<SerializableTransaction>, _historical_states: Option<SerializableHistoricalStates>, ) -> DatabaseResult<Option<SerializableState>>

Source§

fn snapshot_state(&mut self) -> U256

Source§

fn revert_state( &mut self, _state_snapshot: U256, _action: RevertStateSnapshotAction, ) -> bool

Source§

fn current_state(&self) -> StateDb

Implementors§