reth_storage_api/
account.rs

1use alloy_primitives::{Address, BlockNumber};
2use auto_impl::auto_impl;
3use reth_db_models::AccountBeforeTx;
4use reth_primitives::Account;
5use reth_storage_errors::provider::ProviderResult;
6use std::{
7    collections::{BTreeMap, BTreeSet},
8    ops::{RangeBounds, RangeInclusive},
9};
10
11/// Account reader
12#[auto_impl(&, Arc, Box)]
13pub trait AccountReader: Send + Sync {
14    /// Get basic account information.
15    ///
16    /// Returns `None` if the account doesn't exist.
17    fn basic_account(&self, address: Address) -> ProviderResult<Option<Account>>;
18}
19
20/// Account reader
21#[auto_impl(&, Arc, Box)]
22pub trait AccountExtReader: Send + Sync {
23    /// Iterate over account changesets and return all account address that were changed.
24    fn changed_accounts_with_range(
25        &self,
26        _range: impl RangeBounds<BlockNumber>,
27    ) -> ProviderResult<BTreeSet<Address>>;
28
29    /// Get basic account information for multiple accounts. A more efficient version than calling
30    /// [`AccountReader::basic_account`] repeatedly.
31    ///
32    /// Returns `None` if the account doesn't exist.
33    fn basic_accounts(
34        &self,
35        _iter: impl IntoIterator<Item = Address>,
36    ) -> ProviderResult<Vec<(Address, Option<Account>)>>;
37
38    /// Iterate over account changesets and return all account addresses that were changed alongside
39    /// each specific set of blocks.
40    ///
41    /// NOTE: Get inclusive range of blocks.
42    fn changed_accounts_and_blocks_with_range(
43        &self,
44        range: RangeInclusive<BlockNumber>,
45    ) -> ProviderResult<BTreeMap<Address, Vec<BlockNumber>>>;
46}
47
48/// AccountChange reader
49#[auto_impl(&, Arc, Box)]
50pub trait ChangeSetReader: Send + Sync {
51    /// Iterate over account changesets and return the account state from before this block.
52    fn account_block_changeset(
53        &self,
54        block_number: BlockNumber,
55    ) -> ProviderResult<Vec<AccountBeforeTx>>;
56}