reth_storage_api/
transactions.rsuse crate::{BlockNumReader, BlockReader};
use alloy_eips::BlockHashOrNumber;
use alloy_primitives::{Address, BlockNumber, TxHash, TxNumber};
use reth_primitives::TransactionMeta;
use reth_primitives_traits::SignedTransaction;
use reth_storage_errors::provider::{ProviderError, ProviderResult};
use std::ops::{Range, RangeBounds, RangeInclusive};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum TransactionVariant {
NoHash,
#[default]
WithHash,
}
#[auto_impl::auto_impl(&, Arc)]
pub trait TransactionsProvider: BlockNumReader + Send + Sync {
type Transaction: Send + Sync + SignedTransaction;
fn transaction_id(&self, tx_hash: TxHash) -> ProviderResult<Option<TxNumber>>;
fn transaction_by_id(&self, id: TxNumber) -> ProviderResult<Option<Self::Transaction>>;
fn transaction_by_id_unhashed(&self, id: TxNumber)
-> ProviderResult<Option<Self::Transaction>>;
fn transaction_by_hash(&self, hash: TxHash) -> ProviderResult<Option<Self::Transaction>>;
fn transaction_by_hash_with_meta(
&self,
hash: TxHash,
) -> ProviderResult<Option<(Self::Transaction, TransactionMeta)>>;
fn transaction_block(&self, id: TxNumber) -> ProviderResult<Option<BlockNumber>>;
fn transactions_by_block(
&self,
block: BlockHashOrNumber,
) -> ProviderResult<Option<Vec<Self::Transaction>>>;
fn transactions_by_block_range(
&self,
range: impl RangeBounds<BlockNumber>,
) -> ProviderResult<Vec<Vec<Self::Transaction>>>;
fn transactions_by_tx_range(
&self,
range: impl RangeBounds<TxNumber>,
) -> ProviderResult<Vec<Self::Transaction>>;
fn senders_by_tx_range(
&self,
range: impl RangeBounds<TxNumber>,
) -> ProviderResult<Vec<Address>>;
fn transaction_sender(&self, id: TxNumber) -> ProviderResult<Option<Address>>;
}
pub type ProviderTx<P> = <P as TransactionsProvider>::Transaction;
#[auto_impl::auto_impl(&, Arc)]
pub trait TransactionsProviderExt: BlockReader {
fn transaction_range_by_block_range(
&self,
block_range: RangeInclusive<BlockNumber>,
) -> ProviderResult<RangeInclusive<TxNumber>> {
let from = self
.block_body_indices(*block_range.start())?
.ok_or_else(|| ProviderError::BlockBodyIndicesNotFound(*block_range.start()))?
.first_tx_num();
let to = self
.block_body_indices(*block_range.end())?
.ok_or_else(|| ProviderError::BlockBodyIndicesNotFound(*block_range.end()))?
.last_tx_num();
Ok(from..=to)
}
fn transaction_hashes_by_range(
&self,
tx_range: Range<TxNumber>,
) -> ProviderResult<Vec<(TxHash, TxNumber)>>;
}