From 33c6fdc660e99b9f2a81a623294b1c6ec2b966c2 Mon Sep 17 00:00:00 2001 From: Wodann Date: Mon, 16 Jan 2023 00:51:31 -0600 Subject: [PATCH] feat: implement State trait for Arc --- crates/revm/src/blockchain.rs | 13 +++++++++++++ crates/revm/src/db.rs | 4 ++-- crates/revm/src/state.rs | 23 +++++++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/crates/revm/src/blockchain.rs b/crates/revm/src/blockchain.rs index f74ca1a7f8..8dabfce55d 100644 --- a/crates/revm/src/blockchain.rs +++ b/crates/revm/src/blockchain.rs @@ -27,3 +27,16 @@ where BlockHashRef::block_hash(*self, number) } } + +#[cfg(feature = "std")] +impl BlockHash for std::sync::Arc +where + T: BlockHashRef, +{ + type Error = ::Error; + + fn block_hash(&mut self, number: U256) -> Result { + use std::ops::Deref; + self.deref().block_hash(number) + } +} diff --git a/crates/revm/src/db.rs b/crates/revm/src/db.rs index c8f099c110..f7404c70f0 100644 --- a/crates/revm/src/db.rs +++ b/crates/revm/src/db.rs @@ -40,8 +40,8 @@ where } pub struct DatabaseComponents { - block_hash: BH, - state: S, + pub block_hash: BH, + pub state: S, } pub enum ComponentError { diff --git a/crates/revm/src/state.rs b/crates/revm/src/state.rs index c5864d22bb..fe13f0ebc1 100644 --- a/crates/revm/src/state.rs +++ b/crates/revm/src/state.rs @@ -51,3 +51,26 @@ where StateRef::storage(*self, address, index) } } + +#[cfg(feature = "std")] +impl State for std::sync::Arc +where + T: StateRef, +{ + type Error = ::Error; + + fn basic(&mut self, address: B160) -> Result, Self::Error> { + use std::ops::Deref; + self.deref().basic(address) + } + + fn code_by_hash(&mut self, code_hash: B256) -> Result { + use std::ops::Deref; + self.deref().code_by_hash(code_hash) + } + + fn storage(&mut self, address: B160, index: U256) -> Result { + use std::ops::Deref; + self.deref().storage(address, index) + } +}