reth_storage_api/
transactions.rs1use crate::{BlockNumReader, BlockReader};
2use alloy_eips::BlockHashOrNumber;
3use alloy_primitives::{Address, BlockNumber, TxHash, TxNumber};
4use reth_primitives::TransactionMeta;
5use reth_primitives_traits::SignedTransaction;
6use reth_storage_errors::provider::{ProviderError, ProviderResult};
7use std::ops::{Range, RangeBounds, RangeInclusive};
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
14pub enum TransactionVariant {
15 NoHash,
17 #[default]
19 WithHash,
20}
21
22#[auto_impl::auto_impl(&, Arc)]
24pub trait TransactionsProvider: BlockNumReader + Send + Sync {
25 type Transaction: Send + Sync + SignedTransaction;
27
28 fn transaction_id(&self, tx_hash: TxHash) -> ProviderResult<Option<TxNumber>>;
33
34 fn transaction_by_id(&self, id: TxNumber) -> ProviderResult<Option<Self::Transaction>>;
36
37 fn transaction_by_id_unhashed(&self, id: TxNumber)
39 -> ProviderResult<Option<Self::Transaction>>;
40
41 fn transaction_by_hash(&self, hash: TxHash) -> ProviderResult<Option<Self::Transaction>>;
43
44 fn transaction_by_hash_with_meta(
47 &self,
48 hash: TxHash,
49 ) -> ProviderResult<Option<(Self::Transaction, TransactionMeta)>>;
50
51 fn transaction_block(&self, id: TxNumber) -> ProviderResult<Option<BlockNumber>>;
53
54 fn transactions_by_block(
56 &self,
57 block: BlockHashOrNumber,
58 ) -> ProviderResult<Option<Vec<Self::Transaction>>>;
59
60 fn transactions_by_block_range(
62 &self,
63 range: impl RangeBounds<BlockNumber>,
64 ) -> ProviderResult<Vec<Vec<Self::Transaction>>>;
65
66 fn transactions_by_tx_range(
68 &self,
69 range: impl RangeBounds<TxNumber>,
70 ) -> ProviderResult<Vec<Self::Transaction>>;
71
72 fn senders_by_tx_range(
74 &self,
75 range: impl RangeBounds<TxNumber>,
76 ) -> ProviderResult<Vec<Address>>;
77
78 fn transaction_sender(&self, id: TxNumber) -> ProviderResult<Option<Address>>;
82}
83
84pub type ProviderTx<P> = <P as TransactionsProvider>::Transaction;
86
87#[auto_impl::auto_impl(&, Arc)]
89pub trait TransactionsProviderExt: BlockReader + Send + Sync {
90 fn transaction_range_by_block_range(
92 &self,
93 block_range: RangeInclusive<BlockNumber>,
94 ) -> ProviderResult<RangeInclusive<TxNumber>> {
95 let from = self
96 .block_body_indices(*block_range.start())?
97 .ok_or_else(|| ProviderError::BlockBodyIndicesNotFound(*block_range.start()))?
98 .first_tx_num();
99
100 let to = self
101 .block_body_indices(*block_range.end())?
102 .ok_or_else(|| ProviderError::BlockBodyIndicesNotFound(*block_range.end()))?
103 .last_tx_num();
104
105 Ok(from..=to)
106 }
107
108 fn transaction_hashes_by_range(
110 &self,
111 tx_range: Range<TxNumber>,
112 ) -> ProviderResult<Vec<(TxHash, TxNumber)>>;
113}