Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement: use alloc & core for Arc impl #367

Merged
merged 1 commit into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/primitives/src/db/components/block_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
//! it is used inside [crate::db::DatabaseComponents`]

use crate::{B256, U256};
use alloc::sync::Arc;
use auto_impl::auto_impl;
use core::ops::Deref;

#[auto_impl(& mut, Box)]
pub trait BlockHash {
Expand Down Expand Up @@ -31,15 +33,13 @@ where
}
}

#[cfg(feature = "std")]
impl<T> BlockHash for std::sync::Arc<T>
impl<T> BlockHash for 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)
}
}
8 changes: 3 additions & 5 deletions crates/primitives/src/db/components/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
//! it is used inside [crate::db::DatabaseComponents`]

use crate::{AccountInfo, Bytecode, B160, B256, U256};
use alloc::sync::Arc;
use auto_impl::auto_impl;
use core::ops::Deref;

#[auto_impl(& mut, Box)]
pub trait State {
Expand Down Expand Up @@ -49,25 +51,21 @@ where
}
}

#[cfg(feature = "std")]
impl<T> State for std::sync::Arc<T>
impl<T> State for 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)
}
}