Skip to content

Commit

Permalink
feat: implement DatabaseCommit for DatabaseComponents (#1163)
Browse files Browse the repository at this point in the history
* feat: implement DatabaseCommit for DatabaseComponents

* misc: apply review suggestions
  • Loading branch information
Wodann authored Mar 7, 2024
1 parent ac99931 commit f36f90e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 7 additions & 0 deletions crates/primitives/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ impl<T: DatabaseRef> Database for WrapDatabaseRef<T> {
}
}

impl<T: DatabaseRef + DatabaseCommit> DatabaseCommit for WrapDatabaseRef<T> {
#[inline]
fn commit(&mut self, changes: HashMap<Address, Account>) {
self.0.commit(changes)
}
}

/// Wraps a `dyn DatabaseRef` to provide a [`Database`] implementation.
#[doc(hidden)]
#[deprecated = "use `WrapDatabaseRef` instead"]
Expand Down
10 changes: 9 additions & 1 deletion crates/primitives/src/db/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ pub use state::{State, StateRef};

use crate::{
db::{Database, DatabaseRef},
AccountInfo, Address, Bytecode, B256, U256,
Account, AccountInfo, Address, Bytecode, HashMap, B256, U256,
};

use super::DatabaseCommit;

#[derive(Debug)]
pub struct DatabaseComponents<S, BH> {
pub state: S,
Expand Down Expand Up @@ -73,3 +75,9 @@ impl<S: StateRef, BH: BlockHashRef> DatabaseRef for DatabaseComponents<S, BH> {
.map_err(Self::Error::BlockHash)
}
}

impl<S: DatabaseCommit, BH: BlockHashRef> DatabaseCommit for DatabaseComponents<S, BH> {
fn commit(&mut self, changes: HashMap<Address, Account>) {
self.state.commit(changes);
}
}

0 comments on commit f36f90e

Please sign in to comment.