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::{
9    error::Error,
10    fmt::{self},
11};
12
13/// Network specific `eth` API types.
14///
15/// This trait defines the network specific rpc types and helpers required for the `eth_` and
16/// adjacent endpoints. `NetworkTypes` is [`alloy_network::Network`] as defined by the alloy crate,
17/// see also [`alloy_network::Ethereum`].
18///
19/// This type is stateful so that it can provide additional context if necessary, e.g. populating
20/// receipts with additional data.
21pub trait EthApiTypes: Send + Sync + Clone {
22    /// Extension of [`FromEthApiError`], with network specific errors.
23    type Error: Into<jsonrpsee_types::error::ErrorObject<'static>>
24        + FromEthApiError
25        + AsEthApiError
26        + Error
27        + Send
28        + Sync;
29    /// Blockchain primitive types, specific to network, e.g. block and transaction.
30    type NetworkTypes: RpcTypes;
31    /// Conversion methods for transaction RPC type.
32    type RpcConvert: Send + Sync + fmt::Debug;
33
34    /// Returns reference to transaction response builder.
35    fn tx_resp_builder(&self) -> &Self::RpcConvert;
36}
37
38/// Adapter for network specific block type.
39pub type RpcBlock<T> = Block<RpcTransaction<T>, RpcHeader<T>>;
40
41/// Adapter for network specific receipt type.
42pub type RpcReceipt<T> = <T as RpcTypes>::Receipt;
43
44/// Adapter for network specific header type.
45pub type RpcHeader<T> = <T as RpcTypes>::Header;
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        + EthApiTypes<
55            NetworkTypes: RpcTypes<
56                TransactionRequest: SignableTxRequest<ProviderTx<Self::Provider>>,
57            >,
58            RpcConvert: RpcConvert<
59                Primitives = Self::Primitives,
60                Network = Self::NetworkTypes,
61                Error = RpcError<Self>,
62            >,
63        >,
64{
65}
66
67impl<T> FullEthApiTypes for T where
68    T: RpcNodeCore
69        + EthApiTypes<
70            NetworkTypes: RpcTypes<
71                TransactionRequest: SignableTxRequest<ProviderTx<Self::Provider>>,
72            >,
73            RpcConvert: RpcConvert<
74                Primitives = <Self as RpcNodeCore>::Primitives,
75                Network = Self::NetworkTypes,
76                Error = RpcError<T>,
77            >,
78        >
79{
80}