Skip to content

Commit

Permalink
feat: implement State trait for Arc<StateRef>
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodann committed Jan 16, 2023
1 parent 4eda20b commit 33c6fdc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
13 changes: 13 additions & 0 deletions crates/revm/src/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,16 @@ where
BlockHashRef::block_hash(*self, number)
}
}

#[cfg(feature = "std")]
impl<T> BlockHash for std::sync::Arc<T>
where
T: BlockHashRef,
{
type Error = <T as BlockHashRef>::Error;

fn block_hash(&mut self, number: U256) -> Result<B256, Self::Error> {
use std::ops::Deref;
self.deref().block_hash(number)
}
}
4 changes: 2 additions & 2 deletions crates/revm/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ where
}

pub struct DatabaseComponents<BH: BlockHash, S: State> {
block_hash: BH,
state: S,
pub block_hash: BH,
pub state: S,
}

pub enum ComponentError<BHE, SE> {
Expand Down
23 changes: 23 additions & 0 deletions crates/revm/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,26 @@ where
StateRef::storage(*self, address, index)
}
}

#[cfg(feature = "std")]
impl<T> State for std::sync::Arc<T>
where
T: StateRef,
{
type Error = <T as StateRef>::Error;

fn basic(&mut self, address: B160) -> Result<Option<AccountInfo>, Self::Error> {
use std::ops::Deref;
self.deref().basic(address)
}

fn code_by_hash(&mut self, code_hash: B256) -> Result<Bytecode, Self::Error> {
use std::ops::Deref;
self.deref().code_by_hash(code_hash)
}

fn storage(&mut self, address: B160, index: U256) -> Result<U256, Self::Error> {
use std::ops::Deref;
self.deref().storage(address, index)
}
}

0 comments on commit 33c6fdc

Please sign in to comment.