reth_rpc_eth_api/
types.rs

1//! Trait for specifying `eth` network dependent API types.
2
3use std::{
4    error::Error,
5    fmt::{self},
6};
7
8use alloy_network::Network;
9use alloy_rpc_types_eth::Block;
10use reth_provider::{ProviderTx, ReceiptProvider, TransactionsProvider};
11use reth_rpc_types_compat::TransactionCompat;
12use reth_transaction_pool::{PoolTransaction, TransactionPool};
13
14use crate::{AsEthApiError, FromEthApiError, FromEvmError, RpcNodeCore};
15
16/// Network specific `eth` API types.
17pub trait EthApiTypes: Send + Sync + Clone {
18    /// Extension of [`FromEthApiError`], with network specific errors.
19    type Error: Into<jsonrpsee_types::error::ErrorObject<'static>>
20        + FromEthApiError
21        + AsEthApiError
22        + FromEvmError
23        + Error
24        + Send
25        + Sync;
26    /// Blockchain primitive types, specific to network, e.g. block and transaction.
27    type NetworkTypes: Network;
28    /// Conversion methods for transaction RPC type.
29    type TransactionCompat: Send + Sync + Clone + fmt::Debug;
30
31    /// Returns reference to transaction response builder.
32    fn tx_resp_builder(&self) -> &Self::TransactionCompat;
33}
34
35/// Adapter for network specific transaction type.
36pub type RpcTransaction<T> = <T as Network>::TransactionResponse;
37
38/// Adapter for network specific block type.
39pub type RpcBlock<T> = Block<RpcTransaction<T>, <T as Network>::HeaderResponse>;
40
41/// Adapter for network specific receipt type.
42pub type RpcReceipt<T> = <T as Network>::ReceiptResponse;
43
44/// Adapter for network specific header type.
45pub type RpcHeader<T> = <T as Network>::HeaderResponse;
46
47/// Adapter for network specific error type.
48pub type RpcError<T> = <T as EthApiTypes>::Error;
49
50/// Helper trait holds necessary trait bounds on [`EthApiTypes`] to implement `eth` API.
51pub trait FullEthApiTypes
52where
53    Self: RpcNodeCore<
54            Provider: TransactionsProvider + ReceiptProvider,
55            Pool: TransactionPool<
56                Transaction: PoolTransaction<Consensus = ProviderTx<Self::Provider>>,
57            >,
58        > + EthApiTypes<
59            TransactionCompat: TransactionCompat<
60                <Self::Provider as TransactionsProvider>::Transaction,
61                Transaction = RpcTransaction<Self::NetworkTypes>,
62                Error = RpcError<Self>,
63            >,
64        >,
65{
66}
67
68impl<T> FullEthApiTypes for T where
69    T: RpcNodeCore<
70            Provider: TransactionsProvider + ReceiptProvider,
71            Pool: TransactionPool<
72                Transaction: PoolTransaction<Consensus = ProviderTx<Self::Provider>>,
73            >,
74        > + EthApiTypes<
75            TransactionCompat: TransactionCompat<
76                <Self::Provider as TransactionsProvider>::Transaction,
77                Transaction = RpcTransaction<T::NetworkTypes>,
78                Error = RpcError<T>,
79            >,
80        >
81{
82}