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 /// Transaction response type.
16 type TransactionResponse: RpcObject + TransactionResponse;
17 /// Transaction response type.
18 type TransactionRequest: RpcObject + AsRef<TransactionRequest> + AsMut<TransactionRequest>;
19}
20
21impl<T> RpcTypes for T
22where
23 T: Network<TransactionRequest: AsRef<TransactionRequest> + AsMut<TransactionRequest>> + Unpin,
24{
25 type Header = T::HeaderResponse;
26 type Receipt = T::ReceiptResponse;
27 type TransactionResponse = T::TransactionResponse;
28 type TransactionRequest = T::TransactionRequest;
29}
30
31/// Adapter for network specific transaction response.
32pub type RpcTransaction<T> = <T as RpcTypes>::TransactionResponse;
33
34/// Adapter for network specific receipt response.
35pub type RpcReceipt<T> = <T as RpcTypes>::Receipt;
36
37/// Adapter for network specific header response.
38pub type RpcHeader<T> = <T as RpcTypes>::Header;
39
40/// Adapter for network specific block type.
41pub type RpcBlock<T> = alloy_rpc_types_eth::Block<RpcTransaction<T>, RpcHeader<T>>;
42
43/// Adapter for network specific transaction request.
44pub type RpcTxReq<T> = <T as RpcTypes>::TransactionRequest;