Skip to main content

reth_rpc_convert/
rpc.rs

1use std::fmt::Debug;
2
3use alloy_json_rpc::RpcObject;
4use alloy_network::{primitives::HeaderResponse, Network, ReceiptResponse, TransactionResponse};
5use alloy_rpc_types_eth::TransactionRequest;
6
7/// RPC types used by the `eth_` RPC API.
8///
9/// This is a subset of [`Network`] trait with only RPC response types kept.
10pub trait RpcTypes: Send + Sync + Clone + Unpin + Debug + 'static {
11    /// Header response type.
12    type Header: RpcObject + HeaderResponse;
13    /// Receipt response type.
14    type Receipt: RpcObject + ReceiptResponse;
15    /// Log response type.
16    type Log: RpcObject;
17    /// Transaction response type.
18    type TransactionResponse: RpcObject + TransactionResponse;
19    /// Transaction response type.
20    type TransactionRequest: RpcObject + AsRef<TransactionRequest> + AsMut<TransactionRequest>;
21}
22
23impl<T> RpcTypes for T
24where
25    T: Network<TransactionRequest: AsRef<TransactionRequest> + AsMut<TransactionRequest>> + Unpin,
26{
27    type Header = T::HeaderResponse;
28    type Receipt = T::ReceiptResponse;
29    // Default network implementations to Ethereum logs until Alloy exposes a log response type.
30    type Log = alloy_rpc_types_eth::Log;
31    type TransactionResponse = T::TransactionResponse;
32    type TransactionRequest = T::TransactionRequest;
33}
34
35/// Adapter for network specific transaction response.
36pub type RpcTransaction<T> = <T as RpcTypes>::TransactionResponse;
37
38/// Adapter for network specific receipt response.
39pub type RpcReceipt<T> = <T as RpcTypes>::Receipt;
40
41/// Adapter for network specific log response.
42pub type RpcLog<T> = <T as RpcTypes>::Log;
43
44/// Adapter for network specific header response.
45pub type RpcHeader<T> = <T as RpcTypes>::Header;
46
47/// Adapter for network specific block type.
48pub type RpcBlock<T> = alloy_rpc_types_eth::Block<RpcTransaction<T>, RpcHeader<T>>;
49
50/// Adapter for network specific transaction request.
51pub type RpcTxReq<T> = <T as RpcTypes>::TransactionRequest;