reth_storage_api/
transactions.rs1use crate::{BlockNumReader, BlockReader};
2use alloc::vec::Vec;
3use alloy_consensus::transaction::TransactionMeta;
4use alloy_eips::BlockHashOrNumber;
5use alloy_primitives::{Address, BlockNumber, TxHash, TxNumber};
6use core::ops::{Range, RangeBounds, RangeInclusive};
7use reth_primitives_traits::SignedTransaction;
8use reth_storage_errors::provider::{ProviderError, ProviderResult};
9
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
15pub enum TransactionVariant {
16 NoHash,
18 #[default]
20 WithHash,
21}
22
23#[auto_impl::auto_impl(&, Arc)]
25pub trait TransactionsProvider: BlockNumReader + Send + Sync {
26 type Transaction: Send + Sync + SignedTransaction;
28
29 fn transaction_id(&self, tx_hash: TxHash) -> ProviderResult<Option<TxNumber>>;
34
35 fn transaction_by_id(&self, id: TxNumber) -> ProviderResult<Option<Self::Transaction>>;
37
38 fn transaction_by_id_unhashed(&self, id: TxNumber)
40 -> ProviderResult<Option<Self::Transaction>>;
41
42 fn transaction_by_hash(&self, hash: TxHash) -> ProviderResult<Option<Self::Transaction>>;
44
45 fn transaction_by_hash_with_meta(
48 &self,
49 hash: TxHash,
50 ) -> ProviderResult<Option<(Self::Transaction, TransactionMeta)>>;
51
52 fn transaction_block(&self, id: TxNumber) -> ProviderResult<Option<BlockNumber>>;
54
55 fn transactions_by_block(
57 &self,
58 block: BlockHashOrNumber,
59 ) -> ProviderResult<Option<Vec<Self::Transaction>>>;
60
61 fn transactions_by_block_range(
63 &self,
64 range: impl RangeBounds<BlockNumber>,
65 ) -> ProviderResult<Vec<Vec<Self::Transaction>>>;
66
67 fn transactions_by_tx_range(
69 &self,
70 range: impl RangeBounds<TxNumber>,
71 ) -> ProviderResult<Vec<Self::Transaction>>;
72
73 fn senders_by_tx_range(
75 &self,
76 range: impl RangeBounds<TxNumber>,
77 ) -> ProviderResult<Vec<Address>>;
78
79 fn transaction_sender(&self, id: TxNumber) -> ProviderResult<Option<Address>>;
83}
84
85pub type ProviderTx<P> = <P as TransactionsProvider>::Transaction;
87
88#[auto_impl::auto_impl(&, Arc)]
90pub trait TransactionsProviderExt: BlockReader {
91 fn transaction_range_by_block_range(
93 &self,
94 block_range: RangeInclusive<BlockNumber>,
95 ) -> ProviderResult<RangeInclusive<TxNumber>> {
96 let from = self
97 .block_body_indices(*block_range.start())?
98 .ok_or_else(|| ProviderError::BlockBodyIndicesNotFound(*block_range.start()))?
99 .first_tx_num();
100
101 let to = self
102 .block_body_indices(*block_range.end())?
103 .ok_or_else(|| ProviderError::BlockBodyIndicesNotFound(*block_range.end()))?
104 .last_tx_num();
105
106 Ok(from..=to)
107 }
108
109 fn transaction_hashes_by_range(
111 &self,
112 tx_range: Range<TxNumber>,
113 ) -> ProviderResult<Vec<(TxHash, TxNumber)>>;
114}