reth_rpc_eth_api/
types.rs
1use crate::{AsEthApiError, FromEthApiError, RpcNodeCore};
4use alloy_json_rpc::RpcObject;
5use alloy_network::{Network, ReceiptResponse, TransactionResponse};
6use alloy_rpc_types_eth::Block;
7use reth_provider::{ProviderTx, ReceiptProvider, TransactionsProvider};
8use reth_rpc_types_compat::TransactionCompat;
9use reth_transaction_pool::{PoolTransaction, TransactionPool};
10use std::{
11 error::Error,
12 fmt::{self},
13};
14
15pub trait RpcTypes {
19 type Header: RpcObject;
21 type Receipt: RpcObject + ReceiptResponse;
23 type Transaction: RpcObject + TransactionResponse;
25}
26
27impl<T> RpcTypes for T
28where
29 T: Network,
30{
31 type Header = T::HeaderResponse;
32 type Receipt = T::ReceiptResponse;
33 type Transaction = T::TransactionResponse;
34}
35
36pub trait EthApiTypes: Send + Sync + Clone {
45 type Error: Into<jsonrpsee_types::error::ErrorObject<'static>>
47 + FromEthApiError
48 + AsEthApiError
49 + Error
50 + Send
51 + Sync;
52 type NetworkTypes: RpcTypes;
54 type TransactionCompat: Send + Sync + Clone + fmt::Debug;
56
57 fn tx_resp_builder(&self) -> &Self::TransactionCompat;
59}
60
61pub type RpcTransaction<T> = <T as RpcTypes>::Transaction;
63
64pub type RpcBlock<T> = Block<RpcTransaction<T>, RpcHeader<T>>;
66
67pub type RpcReceipt<T> = <T as RpcTypes>::Receipt;
69
70pub type RpcHeader<T> = <T as RpcTypes>::Header;
72
73pub type RpcError<T> = <T as EthApiTypes>::Error;
75
76pub trait FullEthApiTypes
78where
79 Self: RpcNodeCore<
80 Provider: TransactionsProvider + ReceiptProvider,
81 Pool: TransactionPool<
82 Transaction: PoolTransaction<Consensus = ProviderTx<Self::Provider>>,
83 >,
84 > + EthApiTypes<
85 TransactionCompat: TransactionCompat<
86 <Self::Provider as TransactionsProvider>::Transaction,
87 Transaction = RpcTransaction<Self::NetworkTypes>,
88 Error = RpcError<Self>,
89 >,
90 >,
91{
92}
93
94impl<T> FullEthApiTypes for T where
95 T: RpcNodeCore<
96 Provider: TransactionsProvider + ReceiptProvider,
97 Pool: TransactionPool<
98 Transaction: PoolTransaction<Consensus = ProviderTx<Self::Provider>>,
99 >,
100 > + EthApiTypes<
101 TransactionCompat: TransactionCompat<
102 <Self::Provider as TransactionsProvider>::Transaction,
103 Transaction = RpcTransaction<T::NetworkTypes>,
104 Error = RpcError<T>,
105 >,
106 >
107{
108}