reth_rpc_eth_api/
types.rs

1//! Trait for specifying `eth` network dependent API types.
2
3use crate::{AsEthApiError, FromEthApiError, RpcNodeCore};
4use alloy_rpc_types_eth::Block;
5use reth_rpc_convert::{RpcConvert, SignableTxRequest};
6pub use reth_rpc_convert::{RpcTransaction, RpcTxReq, RpcTypes};
7use reth_storage_api::ProviderTx;
8use std::error::Error;
9
10/// Network specific `eth` API types.
11///
12/// This trait defines the network specific rpc types and helpers required for the `eth_` and
13/// adjacent endpoints. `NetworkTypes` is [`alloy_network::Network`] as defined by the alloy crate,
14/// see also [`alloy_network::Ethereum`].
15///
16/// This type is stateful so that it can provide additional context if necessary, e.g. populating
17/// receipts with additional data.
18pub trait EthApiTypes: Send + Sync + Clone {
19    /// Extension of [`FromEthApiError`], with network specific errors.
20    type Error: Into<jsonrpsee_types::error::ErrorObject<'static>>
21        + FromEthApiError
22        + AsEthApiError
23        + From<<Self::RpcConvert as RpcConvert>::Error>
24        + Error
25        + Send
26        + Sync;
27    /// Blockchain primitive types, specific to network, e.g. block and transaction.
28    type NetworkTypes: RpcTypes;
29    /// Conversion methods for transaction RPC type.
30    type RpcConvert: RpcConvert<Network = Self::NetworkTypes>;
31
32    /// Returns reference to transaction response builder.
33    fn converter(&self) -> &Self::RpcConvert;
34}
35
36/// Adapter for network specific block type.
37pub type RpcBlock<T> = Block<RpcTransaction<T>, RpcHeader<T>>;
38
39/// Adapter for network specific receipt type.
40pub type RpcReceipt<T> = <T as RpcTypes>::Receipt;
41
42/// Adapter for network specific header type.
43pub type RpcHeader<T> = <T as RpcTypes>::Header;
44
45/// Adapter for network specific error type.
46pub type RpcError<T> = <T as EthApiTypes>::Error;
47
48/// Helper trait holds necessary trait bounds on [`EthApiTypes`] to implement `eth` API.
49pub trait FullEthApiTypes
50where
51    Self: RpcNodeCore
52        + EthApiTypes<
53            NetworkTypes: RpcTypes<
54                TransactionRequest: SignableTxRequest<ProviderTx<Self::Provider>>,
55            >,
56            RpcConvert: RpcConvert<Primitives = Self::Primitives>,
57        >,
58{
59}
60
61impl<T> FullEthApiTypes for T where
62    T: RpcNodeCore
63        + EthApiTypes<
64            NetworkTypes: RpcTypes<
65                TransactionRequest: SignableTxRequest<ProviderTx<Self::Provider>>,
66            >,
67            RpcConvert: RpcConvert<Primitives = Self::Primitives>,
68        >
69{
70}