mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
69 lines
2.3 KiB
Rust
69 lines
2.3 KiB
Rust
use auto_impl::auto_impl;
|
|
use reth_interfaces::Result;
|
|
use reth_primitives::{Account, Address, BlockNumber};
|
|
use std::{
|
|
collections::{BTreeMap, BTreeSet},
|
|
ops::{RangeBounds, RangeInclusive},
|
|
};
|
|
|
|
/// Account reader
|
|
#[auto_impl(&, Arc, Box)]
|
|
pub trait AccountReader: Send + Sync {
|
|
/// Get basic account information.
|
|
///
|
|
/// Returns `None` if the account doesn't exist.
|
|
fn basic_account(&self, address: Address) -> Result<Option<Account>>;
|
|
}
|
|
|
|
/// Account reader
|
|
#[auto_impl(&, Arc, Box)]
|
|
pub trait AccountExtReader: Send + Sync {
|
|
/// Iterate over account changesets and return all account address that were changed.
|
|
fn changed_accounts_with_range(
|
|
&self,
|
|
_range: impl RangeBounds<BlockNumber>,
|
|
) -> Result<BTreeSet<Address>>;
|
|
|
|
/// Get basic account information for multiple accounts. A more efficient version than calling
|
|
/// [`AccountReader::basic_account`] repeatedly.
|
|
///
|
|
/// Returns `None` if the account doesn't exist.
|
|
fn basic_accounts(
|
|
&self,
|
|
_iter: impl IntoIterator<Item = Address>,
|
|
) -> Result<Vec<(Address, Option<Account>)>>;
|
|
|
|
/// Iterate over account changesets and return all account addresses that were changed alongside
|
|
/// each specific set of blocks.
|
|
///
|
|
/// NOTE: Get inclusive range of blocks.
|
|
fn changed_accounts_and_blocks_with_range(
|
|
&self,
|
|
range: RangeInclusive<BlockNumber>,
|
|
) -> Result<BTreeMap<Address, Vec<BlockNumber>>>;
|
|
}
|
|
|
|
/// Account reader
|
|
#[auto_impl(&, Arc, Box)]
|
|
pub trait AccountWriter: Send + Sync {
|
|
/// Unwind and clear account hashing
|
|
fn unwind_account_hashing(&self, range: RangeInclusive<BlockNumber>) -> Result<()>;
|
|
|
|
/// Unwind and clear account history indices.
|
|
///
|
|
/// Returns number of changesets walked.
|
|
fn unwind_account_history_indices(&self, range: RangeInclusive<BlockNumber>) -> Result<usize>;
|
|
|
|
/// Insert account change index to database. Used inside AccountHistoryIndex stage
|
|
fn insert_account_history_index(
|
|
&self,
|
|
account_transitions: BTreeMap<Address, Vec<u64>>,
|
|
) -> Result<()>;
|
|
|
|
/// iterate over accounts and insert them to hashing table
|
|
fn insert_account_for_hashing(
|
|
&self,
|
|
accounts: impl IntoIterator<Item = (Address, Option<Account>)>,
|
|
) -> Result<()>;
|
|
}
|