reth_storage_api/
storage.rs
1use alloc::{
2 collections::{BTreeMap, BTreeSet},
3 vec::Vec,
4};
5use alloy_primitives::{Address, BlockNumber, B256};
6use core::ops::RangeInclusive;
7use reth_primitives_traits::StorageEntry;
8use reth_storage_errors::provider::ProviderResult;
9
10#[auto_impl::auto_impl(&, Arc, Box)]
12pub trait StorageReader: Send + Sync {
13 fn plain_state_storages(
15 &self,
16 addresses_with_keys: impl IntoIterator<Item = (Address, impl IntoIterator<Item = B256>)>,
17 ) -> ProviderResult<Vec<(Address, Vec<StorageEntry>)>>;
18
19 fn changed_storages_with_range(
21 &self,
22 range: RangeInclusive<BlockNumber>,
23 ) -> ProviderResult<BTreeMap<Address, BTreeSet<B256>>>;
24
25 fn changed_storages_and_blocks_with_range(
30 &self,
31 range: RangeInclusive<BlockNumber>,
32 ) -> ProviderResult<BTreeMap<(Address, B256), Vec<u64>>>;
33}
34
35#[cfg(feature = "db-api")]
37#[auto_impl::auto_impl(&, Arc, Box)]
38pub trait StorageChangeSetReader: Send + Sync {
39 fn storage_changeset(
41 &self,
42 block_number: BlockNumber,
43 ) -> ProviderResult<Vec<(reth_db_api::models::BlockNumberAddress, StorageEntry)>>;
44}
45
46#[derive(Debug, Copy, Clone, PartialEq, Eq)]
48pub enum StorageLocation {
49 StaticFiles,
51 Database,
53 Both,
55}
56
57impl StorageLocation {
58 pub const fn static_files(&self) -> bool {
60 matches!(self, Self::StaticFiles | Self::Both)
61 }
62
63 pub const fn database(&self) -> bool {
65 matches!(self, Self::Database | Self::Both)
66 }
67}