mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: add ChainState type (#1249)
This commit is contained in:
@ -10,6 +10,7 @@ use std::sync::Arc;
|
||||
|
||||
mod state;
|
||||
pub use state::{
|
||||
chain::ChainState,
|
||||
historical::{HistoricalStateProvider, HistoricalStateProviderRef},
|
||||
latest::{LatestStateProvider, LatestStateProviderRef},
|
||||
};
|
||||
|
||||
18
crates/storage/provider/src/providers/state/chain.rs
Normal file
18
crates/storage/provider/src/providers/state/chain.rs
Normal file
@ -0,0 +1,18 @@
|
||||
use crate::StateProvider;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
/// A type that can access the state at a specific access point (block number or tag)
|
||||
///
|
||||
/// Depending on the desired access point, the state must be accessed differently. For example, the
|
||||
/// "Latest" state is stored in a different location than previous blocks. And the "Pending" state
|
||||
/// is accessed differently than the "Latest" state.
|
||||
///
|
||||
/// This unifies [StateProvider] access when the caller does not know or care where the state is
|
||||
/// being accessed from, e.g. in RPC where the requested access point may be
|
||||
/// `Pending|Latest|Number|Hash`.
|
||||
///
|
||||
/// Note: The lifetime of this type is limited by the type that created it.
|
||||
pub struct ChainState<'a> {
|
||||
_inner: Box<dyn StateProvider>,
|
||||
_phantom: PhantomData<&'a ()>,
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
//! [StateProvider](crate::StateProvider) implementations
|
||||
pub(crate) mod chain;
|
||||
pub(crate) mod historical;
|
||||
pub(crate) mod latest;
|
||||
|
||||
@ -7,7 +7,7 @@ use reth_primitives::{
|
||||
};
|
||||
|
||||
/// An abstraction for a type that provides state data.
|
||||
#[auto_impl(&)]
|
||||
#[auto_impl(&, Box)]
|
||||
pub trait StateProvider: BlockHashProvider + AccountProvider + Send + Sync {
|
||||
/// Get storage.
|
||||
fn storage(&self, account: Address, storage_key: StorageKey) -> Result<Option<StorageValue>>;
|
||||
|
||||
Reference in New Issue
Block a user