reth_rpc/
engine.rs
1use alloy_eips::{BlockId, BlockNumberOrTag};
2use alloy_primitives::{Address, Bytes, B256, U256, U64};
3use alloy_rpc_types_eth::{
4 state::StateOverride, transaction::TransactionRequest, BlockOverrides,
5 EIP1186AccountProofResponse, Filter, Log, SyncStatus,
6};
7use alloy_serde::JsonStorageKey;
8use jsonrpsee::core::RpcResult as Result;
9use reth_rpc_api::{EngineEthApiServer, EthApiServer};
10pub use reth_rpc_engine_api::EngineApi;
12use reth_rpc_eth_api::{
13 EngineEthFilter, FullEthApiTypes, QueryLimits, RpcBlock, RpcHeader, RpcReceipt, RpcTransaction,
14};
15use tracing_futures::Instrument;
16
17macro_rules! engine_span {
18 () => {
19 tracing::trace_span!(target: "rpc", "engine")
20 };
21}
22
23#[derive(Debug, Clone)]
26pub struct EngineEthApi<Eth, EthFilter> {
27 eth: Eth,
28 eth_filter: EthFilter,
29}
30
31impl<Eth, EthFilter> EngineEthApi<Eth, EthFilter> {
32 pub const fn new(eth: Eth, eth_filter: EthFilter) -> Self {
34 Self { eth, eth_filter }
35 }
36}
37
38#[async_trait::async_trait]
39impl<Eth, EthFilter> EngineEthApiServer<RpcBlock<Eth::NetworkTypes>, RpcReceipt<Eth::NetworkTypes>>
40 for EngineEthApi<Eth, EthFilter>
41where
42 Eth: EthApiServer<
43 RpcTransaction<Eth::NetworkTypes>,
44 RpcBlock<Eth::NetworkTypes>,
45 RpcReceipt<Eth::NetworkTypes>,
46 RpcHeader<Eth::NetworkTypes>,
47 > + FullEthApiTypes,
48 EthFilter: EngineEthFilter,
49{
50 fn syncing(&self) -> Result<SyncStatus> {
52 let span = engine_span!();
53 let _enter = span.enter();
54 self.eth.syncing()
55 }
56
57 async fn chain_id(&self) -> Result<Option<U64>> {
59 let span = engine_span!();
60 let _enter = span.enter();
61 self.eth.chain_id().await
62 }
63
64 fn block_number(&self) -> Result<U256> {
66 let span = engine_span!();
67 let _enter = span.enter();
68 self.eth.block_number()
69 }
70
71 async fn call(
73 &self,
74 request: TransactionRequest,
75 block_id: Option<BlockId>,
76 state_overrides: Option<StateOverride>,
77 block_overrides: Option<Box<BlockOverrides>>,
78 ) -> Result<Bytes> {
79 self.eth
80 .call(request, block_id, state_overrides, block_overrides)
81 .instrument(engine_span!())
82 .await
83 }
84
85 async fn get_code(&self, address: Address, block_id: Option<BlockId>) -> Result<Bytes> {
87 self.eth.get_code(address, block_id).instrument(engine_span!()).await
88 }
89
90 async fn block_by_hash(
92 &self,
93 hash: B256,
94 full: bool,
95 ) -> Result<Option<RpcBlock<Eth::NetworkTypes>>> {
96 self.eth.block_by_hash(hash, full).instrument(engine_span!()).await
97 }
98
99 async fn block_by_number(
101 &self,
102 number: BlockNumberOrTag,
103 full: bool,
104 ) -> Result<Option<RpcBlock<Eth::NetworkTypes>>> {
105 self.eth.block_by_number(number, full).instrument(engine_span!()).await
106 }
107
108 async fn block_receipts(
109 &self,
110 block_id: BlockId,
111 ) -> Result<Option<Vec<RpcReceipt<Eth::NetworkTypes>>>> {
112 self.eth.block_receipts(block_id).instrument(engine_span!()).await
113 }
114
115 async fn send_raw_transaction(&self, bytes: Bytes) -> Result<B256> {
117 self.eth.send_raw_transaction(bytes).instrument(engine_span!()).await
118 }
119
120 async fn transaction_receipt(
121 &self,
122 hash: B256,
123 ) -> Result<Option<RpcReceipt<Eth::NetworkTypes>>> {
124 self.eth.transaction_receipt(hash).instrument(engine_span!()).await
125 }
126
127 async fn logs(&self, filter: Filter) -> Result<Vec<Log>> {
129 self.eth_filter.logs(filter, QueryLimits::no_limits()).instrument(engine_span!()).await
130 }
131
132 async fn get_proof(
134 &self,
135 address: Address,
136 keys: Vec<JsonStorageKey>,
137 block_number: Option<BlockId>,
138 ) -> Result<EIP1186AccountProofResponse> {
139 self.eth.get_proof(address, keys, block_number).instrument(engine_span!()).await
140 }
141}