1use crate::{
4 helpers::{EthApiSpec, EthBlocks, EthCall, EthFees, EthState, EthTransactions, FullEthApi},
5 RpcBlock, RpcHeader, RpcReceipt, RpcTransaction,
6};
7use alloy_dyn_abi::TypedData;
8use alloy_eips::{eip2930::AccessListResult, BlockId, BlockNumberOrTag};
9use alloy_json_rpc::RpcObject;
10use alloy_primitives::{Address, Bytes, B256, B64, U256, U64};
11use alloy_rpc_types_eth::{
12 simulate::{SimulatePayload, SimulatedBlock},
13 state::{EvmOverrides, StateOverride},
14 BlockOverrides, Bundle, EIP1186AccountProofResponse, EthCallResponse, FeeHistory, Index,
15 StateContext, SyncStatus, Work,
16};
17use alloy_serde::JsonStorageKey;
18use jsonrpsee::{core::RpcResult, proc_macros::rpc};
19use reth_primitives_traits::TxTy;
20use reth_rpc_convert::RpcTxReq;
21use reth_rpc_eth_types::{EthApiError, EthCapabilities, FillTransaction};
22use reth_rpc_server_types::{result::internal_rpc_err, ToRpcResult};
23use serde_json::Value;
24use std::collections::HashMap;
25use tracing::trace;
26
27pub trait FullEthApiServer:
30 EthApiServer<
31 RpcTxReq<Self::NetworkTypes>,
32 RpcTransaction<Self::NetworkTypes>,
33 RpcBlock<Self::NetworkTypes>,
34 RpcReceipt<Self::NetworkTypes>,
35 RpcHeader<Self::NetworkTypes>,
36 TxTy<Self::Primitives>,
37 > + FullEthApi
38 + Clone
39{
40}
41
42impl<T> FullEthApiServer for T where
43 T: EthApiServer<
44 RpcTxReq<T::NetworkTypes>,
45 RpcTransaction<T::NetworkTypes>,
46 RpcBlock<T::NetworkTypes>,
47 RpcReceipt<T::NetworkTypes>,
48 RpcHeader<T::NetworkTypes>,
49 TxTy<T::Primitives>,
50 > + FullEthApi
51 + Clone
52{
53}
54
55#[cfg_attr(not(feature = "client"), rpc(server, namespace = "eth"))]
57#[cfg_attr(feature = "client", rpc(server, client, namespace = "eth"))]
58pub trait EthApi<
59 TxReq: RpcObject,
60 T: RpcObject,
61 B: RpcObject,
62 R: RpcObject,
63 H: RpcObject,
64 RawTx: RpcObject,
65>
66{
67 #[method(name = "protocolVersion")]
69 async fn protocol_version(&self) -> RpcResult<U64>;
70
71 #[method(name = "syncing")]
73 fn syncing(&self) -> RpcResult<SyncStatus>;
74
75 #[method(name = "coinbase")]
77 async fn author(&self) -> RpcResult<Address>;
78
79 #[method(name = "accounts")]
81 fn accounts(&self) -> RpcResult<Vec<Address>>;
82
83 #[method(name = "blockNumber")]
85 fn block_number(&self) -> RpcResult<U256>;
86
87 #[method(name = "chainId")]
89 async fn chain_id(&self) -> RpcResult<Option<U64>>;
90
91 #[method(name = "capabilities")]
96 fn capabilities(&self) -> RpcResult<EthCapabilities>;
97
98 #[method(name = "getBlockByHash")]
100 async fn block_by_hash(&self, hash: B256, full: bool) -> RpcResult<Option<B>>;
101
102 #[method(name = "getBlockByNumber")]
104 async fn block_by_number(&self, number: BlockNumberOrTag, full: bool) -> RpcResult<Option<B>>;
105
106 #[method(name = "getBlockTransactionCountByHash")]
108 async fn block_transaction_count_by_hash(&self, hash: B256) -> RpcResult<Option<U256>>;
109
110 #[method(name = "getBlockTransactionCountByNumber")]
112 async fn block_transaction_count_by_number(
113 &self,
114 number: BlockNumberOrTag,
115 ) -> RpcResult<Option<U256>>;
116
117 #[method(name = "getUncleCountByBlockHash")]
119 async fn block_uncles_count_by_hash(&self, hash: B256) -> RpcResult<Option<U256>>;
120
121 #[method(name = "getUncleCountByBlockNumber")]
123 async fn block_uncles_count_by_number(
124 &self,
125 number: BlockNumberOrTag,
126 ) -> RpcResult<Option<U256>>;
127
128 #[method(name = "getBlockReceipts")]
130 async fn block_receipts(&self, block_id: BlockId) -> RpcResult<Option<Vec<R>>>;
131
132 #[method(name = "getUncleByBlockHashAndIndex")]
134 async fn uncle_by_block_hash_and_index(&self, hash: B256, index: Index)
135 -> RpcResult<Option<B>>;
136
137 #[method(name = "getUncleByBlockNumberAndIndex")]
139 async fn uncle_by_block_number_and_index(
140 &self,
141 number: BlockNumberOrTag,
142 index: Index,
143 ) -> RpcResult<Option<B>>;
144
145 #[method(name = "getRawTransactionByHash")]
149 async fn raw_transaction_by_hash(&self, hash: B256) -> RpcResult<Option<Bytes>>;
150
151 #[method(name = "getTransactionByHash")]
153 async fn transaction_by_hash(&self, hash: B256) -> RpcResult<Option<T>>;
154
155 #[method(name = "getRawTransactionByBlockHashAndIndex")]
157 async fn raw_transaction_by_block_hash_and_index(
158 &self,
159 hash: B256,
160 index: Index,
161 ) -> RpcResult<Option<Bytes>>;
162
163 #[method(name = "getTransactionByBlockHashAndIndex")]
165 async fn transaction_by_block_hash_and_index(
166 &self,
167 hash: B256,
168 index: Index,
169 ) -> RpcResult<Option<T>>;
170
171 #[method(name = "getRawTransactionByBlockNumberAndIndex")]
174 async fn raw_transaction_by_block_number_and_index(
175 &self,
176 number: BlockNumberOrTag,
177 index: Index,
178 ) -> RpcResult<Option<Bytes>>;
179
180 #[method(name = "getTransactionByBlockNumberAndIndex")]
182 async fn transaction_by_block_number_and_index(
183 &self,
184 number: BlockNumberOrTag,
185 index: Index,
186 ) -> RpcResult<Option<T>>;
187
188 #[method(name = "getTransactionBySenderAndNonce")]
190 async fn transaction_by_sender_and_nonce(
191 &self,
192 address: Address,
193 nonce: U64,
194 ) -> RpcResult<Option<T>>;
195
196 #[method(name = "pendingTransactions")]
198 fn pending_transactions(&self) -> RpcResult<Vec<T>>;
199
200 #[method(name = "getTransactionReceipt")]
202 async fn transaction_receipt(&self, hash: B256) -> RpcResult<Option<R>>;
203
204 #[method(name = "getBalance")]
206 async fn balance(&self, address: Address, block_number: Option<BlockId>) -> RpcResult<U256>;
207
208 #[method(name = "getStorageAt")]
210 async fn storage_at(
211 &self,
212 address: Address,
213 index: JsonStorageKey,
214 block_number: Option<BlockId>,
215 ) -> RpcResult<B256>;
216
217 #[method(name = "getStorageValues")]
219 async fn storage_values(
220 &self,
221 requests: HashMap<Address, Vec<JsonStorageKey>>,
222 block_number: Option<BlockId>,
223 ) -> RpcResult<HashMap<Address, Vec<B256>>>;
224
225 #[method(name = "getTransactionCount")]
227 async fn transaction_count(
228 &self,
229 address: Address,
230 block_number: Option<BlockId>,
231 ) -> RpcResult<U256>;
232
233 #[method(name = "getCode")]
235 async fn get_code(&self, address: Address, block_number: Option<BlockId>) -> RpcResult<Bytes>;
236
237 #[method(name = "getHeaderByNumber")]
239 async fn header_by_number(&self, hash: BlockNumberOrTag) -> RpcResult<Option<H>>;
240
241 #[method(name = "getHeaderByHash")]
243 async fn header_by_hash(&self, hash: B256) -> RpcResult<Option<H>>;
244
245 #[method(name = "simulateV1")]
248 async fn simulate_v1(
249 &self,
250 opts: SimulatePayload<TxReq>,
251 block_number: Option<BlockId>,
252 ) -> RpcResult<Vec<SimulatedBlock<B>>>;
253
254 #[method(name = "call")]
256 async fn call(
257 &self,
258 request: TxReq,
259 block_number: Option<BlockId>,
260 state_overrides: Option<StateOverride>,
261 block_overrides: Option<Box<BlockOverrides>>,
262 ) -> RpcResult<Bytes>;
263
264 #[method(name = "fillTransaction")]
266 async fn fill_transaction(&self, request: TxReq) -> RpcResult<FillTransaction<RawTx>>;
267
268 #[method(name = "callMany")]
271 async fn call_many(
272 &self,
273 bundles: Vec<Bundle<TxReq>>,
274 state_context: Option<StateContext>,
275 state_override: Option<StateOverride>,
276 ) -> RpcResult<Vec<Vec<EthCallResponse>>>;
277
278 #[method(name = "createAccessList")]
293 async fn create_access_list(
294 &self,
295 request: TxReq,
296 block_number: Option<BlockId>,
297 state_override: Option<StateOverride>,
298 ) -> RpcResult<AccessListResult>;
299
300 #[method(name = "estimateGas")]
303 async fn estimate_gas(
304 &self,
305 request: TxReq,
306 block_number: Option<BlockId>,
307 state_override: Option<StateOverride>,
308 block_overrides: Option<Box<BlockOverrides>>,
309 ) -> RpcResult<U256>;
310
311 #[method(name = "gasPrice")]
313 async fn gas_price(&self) -> RpcResult<U256>;
314
315 #[method(name = "getAccount")]
317 async fn get_account(
318 &self,
319 address: Address,
320 block: BlockId,
321 ) -> RpcResult<Option<alloy_rpc_types_eth::Account>>;
322
323 #[method(name = "maxPriorityFeePerGas")]
325 async fn max_priority_fee_per_gas(&self) -> RpcResult<U256>;
326
327 #[method(name = "baseFee")]
329 async fn base_fee(&self) -> RpcResult<Option<U256>>;
330
331 #[method(name = "blobBaseFee")]
333 async fn blob_base_fee(&self) -> RpcResult<U256>;
334
335 #[method(name = "feeHistory")]
343 async fn fee_history(
344 &self,
345 block_count: U64,
346 newest_block: BlockNumberOrTag,
347 reward_percentiles: Option<Vec<f64>>,
348 ) -> RpcResult<FeeHistory>;
349
350 #[method(name = "mining")]
352 async fn is_mining(&self) -> RpcResult<bool>;
353
354 #[method(name = "hashrate")]
356 async fn hashrate(&self) -> RpcResult<U256>;
357
358 #[method(name = "getWork")]
361 async fn get_work(&self) -> RpcResult<Work>;
362
363 #[method(name = "submitHashrate")]
369 async fn submit_hashrate(&self, hashrate: U256, id: B256) -> RpcResult<bool>;
370
371 #[method(name = "submitWork")]
373 async fn submit_work(&self, nonce: B64, pow_hash: B256, mix_digest: B256) -> RpcResult<bool>;
374
375 #[method(name = "sendTransaction")]
378 async fn send_transaction(&self, request: TxReq) -> RpcResult<B256>;
379
380 #[method(name = "sendRawTransaction")]
382 async fn send_raw_transaction(&self, bytes: Bytes) -> RpcResult<B256>;
383
384 #[method(name = "sendRawTransactionSync")]
388 async fn send_raw_transaction_sync(&self, bytes: Bytes) -> RpcResult<R>;
389
390 #[method(name = "sign")]
393 async fn sign(&self, address: Address, message: Bytes) -> RpcResult<Bytes>;
394
395 #[method(name = "signTransaction")]
398 async fn sign_transaction(&self, transaction: TxReq) -> RpcResult<Bytes>;
399
400 #[method(name = "signTypedData")]
402 async fn sign_typed_data(&self, address: Address, data: TypedData) -> RpcResult<Bytes>;
403
404 #[method(name = "getProof")]
407 async fn get_proof(
408 &self,
409 address: Address,
410 keys: Vec<JsonStorageKey>,
411 block_number: Option<BlockId>,
412 ) -> RpcResult<EIP1186AccountProofResponse>;
413
414 #[method(name = "getAccountInfo")]
418 async fn get_account_info(
419 &self,
420 address: Address,
421 block: BlockId,
422 ) -> RpcResult<alloy_rpc_types_eth::AccountInfo>;
423
424 #[method(name = "getBlockAccessListByBlockHash")]
426 async fn block_access_list_by_block_hash(&self, hash: B256) -> RpcResult<Option<Value>>;
427
428 #[method(name = "getBlockAccessListByBlockNumber")]
430 async fn block_access_list_by_block_number(
431 &self,
432 number: BlockNumberOrTag,
433 ) -> RpcResult<Option<Value>>;
434
435 #[method(name = "getBlockAccessList")]
437 async fn block_access_list(&self, block_id: BlockId) -> RpcResult<Option<Value>>;
438
439 #[method(name = "getBlockAccessListRaw")]
441 async fn block_access_list_raw(&self, block: BlockId) -> RpcResult<Option<Bytes>>;
442}
443
444#[async_trait::async_trait]
445impl<T>
446 EthApiServer<
447 RpcTxReq<T::NetworkTypes>,
448 RpcTransaction<T::NetworkTypes>,
449 RpcBlock<T::NetworkTypes>,
450 RpcReceipt<T::NetworkTypes>,
451 RpcHeader<T::NetworkTypes>,
452 TxTy<T::Primitives>,
453 > for T
454where
455 T: FullEthApi,
456 jsonrpsee_types::error::ErrorObject<'static>: From<T::Error>,
457{
458 async fn protocol_version(&self) -> RpcResult<U64> {
460 trace!(target: "rpc::eth", "Serving eth_protocolVersion");
461 EthApiSpec::protocol_version(self).await.to_rpc_result()
462 }
463
464 fn syncing(&self) -> RpcResult<SyncStatus> {
466 trace!(target: "rpc::eth", "Serving eth_syncing");
467 EthApiSpec::sync_status(self).to_rpc_result()
468 }
469
470 async fn author(&self) -> RpcResult<Address> {
472 Err(internal_rpc_err("unimplemented"))
473 }
474
475 fn accounts(&self) -> RpcResult<Vec<Address>> {
477 trace!(target: "rpc::eth", "Serving eth_accounts");
478 Ok(EthTransactions::accounts(self))
479 }
480
481 fn block_number(&self) -> RpcResult<U256> {
483 trace!(target: "rpc::eth", "Serving eth_blockNumber");
484 Ok(U256::from(
485 EthApiSpec::chain_info(self).with_message("failed to read chain info")?.best_number,
486 ))
487 }
488
489 async fn chain_id(&self) -> RpcResult<Option<U64>> {
491 trace!(target: "rpc::eth", "Serving eth_chainId");
492 Ok(Some(EthApiSpec::chain_id(self)))
493 }
494
495 fn capabilities(&self) -> RpcResult<EthCapabilities> {
497 trace!(target: "rpc::eth", "Serving eth_capabilities");
498 EthApiSpec::capabilities(self).to_rpc_result()
499 }
500
501 async fn block_by_hash(
503 &self,
504 hash: B256,
505 full: bool,
506 ) -> RpcResult<Option<RpcBlock<T::NetworkTypes>>> {
507 trace!(target: "rpc::eth", ?hash, ?full, "Serving eth_getBlockByHash");
508 Ok(EthBlocks::rpc_block(self, hash.into(), full).await?)
509 }
510
511 async fn block_by_number(
513 &self,
514 number: BlockNumberOrTag,
515 full: bool,
516 ) -> RpcResult<Option<RpcBlock<T::NetworkTypes>>> {
517 trace!(target: "rpc::eth", ?number, ?full, "Serving eth_getBlockByNumber");
518 Ok(EthBlocks::rpc_block(self, number.into(), full).await?)
519 }
520
521 async fn block_transaction_count_by_hash(&self, hash: B256) -> RpcResult<Option<U256>> {
523 trace!(target: "rpc::eth", ?hash, "Serving eth_getBlockTransactionCountByHash");
524 Ok(EthBlocks::block_transaction_count(self, hash.into()).await?.map(U256::from))
525 }
526
527 async fn block_transaction_count_by_number(
529 &self,
530 number: BlockNumberOrTag,
531 ) -> RpcResult<Option<U256>> {
532 trace!(target: "rpc::eth", ?number, "Serving eth_getBlockTransactionCountByNumber");
533 Ok(EthBlocks::block_transaction_count(self, number.into()).await?.map(U256::from))
534 }
535
536 async fn block_uncles_count_by_hash(&self, hash: B256) -> RpcResult<Option<U256>> {
538 trace!(target: "rpc::eth", ?hash, "Serving eth_getUncleCountByBlockHash");
539
540 if let Some(block) = self.block_by_hash(hash, false).await? {
541 Ok(Some(U256::from(block.uncles.len())))
542 } else {
543 Ok(None)
544 }
545 }
546
547 async fn block_uncles_count_by_number(
549 &self,
550 number: BlockNumberOrTag,
551 ) -> RpcResult<Option<U256>> {
552 trace!(target: "rpc::eth", ?number, "Serving eth_getUncleCountByBlockNumber");
553
554 if let Some(block) = self.block_by_number(number, false).await? {
555 Ok(Some(U256::from(block.uncles.len())))
556 } else {
557 Ok(None)
558 }
559 }
560
561 async fn block_receipts(
563 &self,
564 block_id: BlockId,
565 ) -> RpcResult<Option<Vec<RpcReceipt<T::NetworkTypes>>>> {
566 trace!(target: "rpc::eth", ?block_id, "Serving eth_getBlockReceipts");
567 Ok(EthBlocks::block_receipts(self, block_id).await?)
568 }
569
570 async fn uncle_by_block_hash_and_index(
572 &self,
573 hash: B256,
574 index: Index,
575 ) -> RpcResult<Option<RpcBlock<T::NetworkTypes>>> {
576 trace!(target: "rpc::eth", ?hash, ?index, "Serving eth_getUncleByBlockHashAndIndex");
577 Ok(EthBlocks::ommer_by_block_and_index(self, hash.into(), index).await?)
578 }
579
580 async fn uncle_by_block_number_and_index(
582 &self,
583 number: BlockNumberOrTag,
584 index: Index,
585 ) -> RpcResult<Option<RpcBlock<T::NetworkTypes>>> {
586 trace!(target: "rpc::eth", ?number, ?index, "Serving eth_getUncleByBlockNumberAndIndex");
587 Ok(EthBlocks::ommer_by_block_and_index(self, number.into(), index).await?)
588 }
589
590 async fn raw_transaction_by_hash(&self, hash: B256) -> RpcResult<Option<Bytes>> {
592 trace!(target: "rpc::eth", ?hash, "Serving eth_getRawTransactionByHash");
593 Ok(EthTransactions::raw_transaction_by_hash(self, hash).await?)
594 }
595
596 async fn transaction_by_hash(
598 &self,
599 hash: B256,
600 ) -> RpcResult<Option<RpcTransaction<T::NetworkTypes>>> {
601 trace!(target: "rpc::eth", ?hash, "Serving eth_getTransactionByHash");
602 Ok(EthTransactions::transaction_by_hash(self, hash)
603 .await?
604 .map(|tx| tx.into_transaction(self.converter()))
605 .transpose()
606 .map_err(T::Error::from)?)
607 }
608
609 async fn raw_transaction_by_block_hash_and_index(
611 &self,
612 hash: B256,
613 index: Index,
614 ) -> RpcResult<Option<Bytes>> {
615 trace!(target: "rpc::eth", ?hash, ?index, "Serving eth_getRawTransactionByBlockHashAndIndex");
616 Ok(EthTransactions::raw_transaction_by_block_and_tx_index(self, hash.into(), index.into())
617 .await?)
618 }
619
620 async fn transaction_by_block_hash_and_index(
622 &self,
623 hash: B256,
624 index: Index,
625 ) -> RpcResult<Option<RpcTransaction<T::NetworkTypes>>> {
626 trace!(target: "rpc::eth", ?hash, ?index, "Serving eth_getTransactionByBlockHashAndIndex");
627 Ok(EthTransactions::transaction_by_block_and_tx_index(self, hash.into(), index.into())
628 .await?)
629 }
630
631 async fn raw_transaction_by_block_number_and_index(
633 &self,
634 number: BlockNumberOrTag,
635 index: Index,
636 ) -> RpcResult<Option<Bytes>> {
637 trace!(target: "rpc::eth", ?number, ?index, "Serving eth_getRawTransactionByBlockNumberAndIndex");
638 Ok(EthTransactions::raw_transaction_by_block_and_tx_index(
639 self,
640 number.into(),
641 index.into(),
642 )
643 .await?)
644 }
645
646 async fn transaction_by_block_number_and_index(
648 &self,
649 number: BlockNumberOrTag,
650 index: Index,
651 ) -> RpcResult<Option<RpcTransaction<T::NetworkTypes>>> {
652 trace!(target: "rpc::eth", ?number, ?index, "Serving eth_getTransactionByBlockNumberAndIndex");
653 Ok(EthTransactions::transaction_by_block_and_tx_index(self, number.into(), index.into())
654 .await?)
655 }
656
657 async fn transaction_by_sender_and_nonce(
659 &self,
660 sender: Address,
661 nonce: U64,
662 ) -> RpcResult<Option<RpcTransaction<T::NetworkTypes>>> {
663 trace!(target: "rpc::eth", ?sender, ?nonce, "Serving eth_getTransactionBySenderAndNonce");
664 Ok(EthTransactions::get_transaction_by_sender_and_nonce(self, sender, nonce.to(), true)
665 .await?)
666 }
667
668 fn pending_transactions(&self) -> RpcResult<Vec<RpcTransaction<T::NetworkTypes>>> {
670 trace!(target: "rpc::eth", "Serving eth_pendingTransactions");
671 Ok(EthTransactions::pending_transactions(self)?)
672 }
673
674 async fn transaction_receipt(
676 &self,
677 hash: B256,
678 ) -> RpcResult<Option<RpcReceipt<T::NetworkTypes>>> {
679 trace!(target: "rpc::eth", ?hash, "Serving eth_getTransactionReceipt");
680 Ok(EthTransactions::transaction_receipt(self, hash).await?)
681 }
682
683 async fn balance(&self, address: Address, block_number: Option<BlockId>) -> RpcResult<U256> {
685 trace!(target: "rpc::eth", ?address, ?block_number, "Serving eth_getBalance");
686 Ok(EthState::balance(self, address, block_number).await?)
687 }
688
689 async fn storage_at(
691 &self,
692 address: Address,
693 index: JsonStorageKey,
694 block_number: Option<BlockId>,
695 ) -> RpcResult<B256> {
696 trace!(target: "rpc::eth", ?address, ?block_number, "Serving eth_getStorageAt");
697 Ok(EthState::storage_at(self, address, index, block_number).await?)
698 }
699
700 async fn storage_values(
702 &self,
703 requests: HashMap<Address, Vec<JsonStorageKey>>,
704 block_number: Option<BlockId>,
705 ) -> RpcResult<HashMap<Address, Vec<B256>>> {
706 trace!(target: "rpc::eth", ?block_number, "Serving eth_getStorageValues");
707 Ok(EthState::storage_values(self, requests, block_number).await?)
708 }
709
710 async fn transaction_count(
712 &self,
713 address: Address,
714 block_number: Option<BlockId>,
715 ) -> RpcResult<U256> {
716 trace!(target: "rpc::eth", ?address, ?block_number, "Serving eth_getTransactionCount");
717 Ok(EthState::transaction_count(self, address, block_number).await?)
718 }
719
720 async fn get_code(&self, address: Address, block_number: Option<BlockId>) -> RpcResult<Bytes> {
722 trace!(target: "rpc::eth", ?address, ?block_number, "Serving eth_getCode");
723 Ok(EthState::get_code(self, address, block_number).await?)
724 }
725
726 async fn header_by_number(
728 &self,
729 block_number: BlockNumberOrTag,
730 ) -> RpcResult<Option<RpcHeader<T::NetworkTypes>>> {
731 trace!(target: "rpc::eth", ?block_number, "Serving eth_getHeaderByNumber");
732 Ok(EthBlocks::rpc_block_header(self, block_number.into()).await?)
733 }
734
735 async fn header_by_hash(&self, hash: B256) -> RpcResult<Option<RpcHeader<T::NetworkTypes>>> {
737 trace!(target: "rpc::eth", ?hash, "Serving eth_getHeaderByHash");
738 Ok(EthBlocks::rpc_block_header(self, hash.into()).await?)
739 }
740
741 async fn simulate_v1(
743 &self,
744 payload: SimulatePayload<RpcTxReq<T::NetworkTypes>>,
745 block_number: Option<BlockId>,
746 ) -> RpcResult<Vec<SimulatedBlock<RpcBlock<T::NetworkTypes>>>> {
747 trace!(target: "rpc::eth", ?block_number, "Serving eth_simulateV1");
748 let _permit = self.tracing_task_guard().clone().acquire_owned().await;
749 Ok(EthCall::simulate_v1(self, payload, block_number).await?)
750 }
751
752 async fn call(
754 &self,
755 request: RpcTxReq<T::NetworkTypes>,
756 block_number: Option<BlockId>,
757 state_overrides: Option<StateOverride>,
758 block_overrides: Option<Box<BlockOverrides>>,
759 ) -> RpcResult<Bytes> {
760 trace!(target: "rpc::eth", ?request, ?block_number, ?state_overrides, ?block_overrides, "Serving eth_call");
761 Ok(EthCall::call(
762 self,
763 request,
764 block_number,
765 EvmOverrides::new(state_overrides, block_overrides),
766 )
767 .await?)
768 }
769
770 async fn fill_transaction(
772 &self,
773 request: RpcTxReq<T::NetworkTypes>,
774 ) -> RpcResult<FillTransaction<TxTy<T::Primitives>>> {
775 trace!(target: "rpc::eth", ?request, "Serving eth_fillTransaction");
776 Ok(EthTransactions::fill_transaction(self, request).await?)
777 }
778
779 async fn call_many(
781 &self,
782 bundles: Vec<Bundle<RpcTxReq<T::NetworkTypes>>>,
783 state_context: Option<StateContext>,
784 state_override: Option<StateOverride>,
785 ) -> RpcResult<Vec<Vec<EthCallResponse>>> {
786 trace!(target: "rpc::eth", ?bundles, ?state_context, ?state_override, "Serving eth_callMany");
787 Ok(EthCall::call_many(self, bundles, state_context, state_override).await?)
788 }
789
790 async fn create_access_list(
792 &self,
793 request: RpcTxReq<T::NetworkTypes>,
794 block_number: Option<BlockId>,
795 state_override: Option<StateOverride>,
796 ) -> RpcResult<AccessListResult> {
797 trace!(target: "rpc::eth", ?request, ?block_number, ?state_override, "Serving eth_createAccessList");
798 Ok(EthCall::create_access_list_at(self, request, block_number, state_override).await?)
799 }
800
801 async fn estimate_gas(
803 &self,
804 request: RpcTxReq<T::NetworkTypes>,
805 block_number: Option<BlockId>,
806 state_override: Option<StateOverride>,
807 block_overrides: Option<Box<BlockOverrides>>,
808 ) -> RpcResult<U256> {
809 trace!(target: "rpc::eth", ?request, ?block_number, "Serving eth_estimateGas");
810 Ok(EthCall::estimate_gas_at(
811 self,
812 request,
813 block_number.unwrap_or_default(),
814 EvmOverrides::new(state_override, block_overrides),
815 )
816 .await?)
817 }
818
819 async fn gas_price(&self) -> RpcResult<U256> {
821 trace!(target: "rpc::eth", "Serving eth_gasPrice");
822 Ok(EthFees::gas_price(self).await?)
823 }
824
825 async fn get_account(
827 &self,
828 address: Address,
829 block: BlockId,
830 ) -> RpcResult<Option<alloy_rpc_types_eth::Account>> {
831 trace!(target: "rpc::eth", "Serving eth_getAccount");
832 Ok(EthState::get_account(self, address, block).await?)
833 }
834
835 async fn max_priority_fee_per_gas(&self) -> RpcResult<U256> {
837 trace!(target: "rpc::eth", "Serving eth_maxPriorityFeePerGas");
838 Ok(EthFees::suggested_priority_fee(self).await?)
839 }
840
841 async fn blob_base_fee(&self) -> RpcResult<U256> {
843 trace!(target: "rpc::eth", "Serving eth_blobBaseFee");
844 Ok(EthFees::blob_base_fee(self).await?)
845 }
846
847 async fn base_fee(&self) -> RpcResult<Option<U256>> {
849 trace!(target: "rpc::eth", "Serving eth_baseFee");
850 Ok(EthFees::base_fee(self).await?)
851 }
852
853 async fn fee_history(
863 &self,
864 block_count: U64,
865 newest_block: BlockNumberOrTag,
866 reward_percentiles: Option<Vec<f64>>,
867 ) -> RpcResult<FeeHistory> {
868 trace!(target: "rpc::eth", ?block_count, ?newest_block, ?reward_percentiles, "Serving eth_feeHistory");
869 Ok(EthFees::fee_history(self, block_count.to(), newest_block, reward_percentiles).await?)
870 }
871
872 async fn is_mining(&self) -> RpcResult<bool> {
874 Err(internal_rpc_err("unimplemented"))
875 }
876
877 async fn hashrate(&self) -> RpcResult<U256> {
879 Ok(U256::ZERO)
880 }
881
882 async fn get_work(&self) -> RpcResult<Work> {
884 Err(internal_rpc_err("unimplemented"))
885 }
886
887 async fn submit_hashrate(&self, _hashrate: U256, _id: B256) -> RpcResult<bool> {
889 Ok(false)
890 }
891
892 async fn submit_work(
894 &self,
895 _nonce: B64,
896 _pow_hash: B256,
897 _mix_digest: B256,
898 ) -> RpcResult<bool> {
899 Err(internal_rpc_err("unimplemented"))
900 }
901
902 async fn send_transaction(&self, request: RpcTxReq<T::NetworkTypes>) -> RpcResult<B256> {
904 trace!(target: "rpc::eth", ?request, "Serving eth_sendTransaction");
905 Ok(EthTransactions::send_transaction_request(self, request).await?)
906 }
907
908 async fn send_raw_transaction(&self, tx: Bytes) -> RpcResult<B256> {
910 trace!(target: "rpc::eth", ?tx, "Serving eth_sendRawTransaction");
911 Ok(EthTransactions::send_raw_transaction(self, tx).await?)
912 }
913
914 async fn send_raw_transaction_sync(&self, tx: Bytes) -> RpcResult<RpcReceipt<T::NetworkTypes>> {
916 trace!(target: "rpc::eth", ?tx, "Serving eth_sendRawTransactionSync");
917 Ok(EthTransactions::send_raw_transaction_sync(self, tx).await?)
918 }
919
920 async fn sign(&self, address: Address, message: Bytes) -> RpcResult<Bytes> {
922 trace!(target: "rpc::eth", ?address, ?message, "Serving eth_sign");
923 Ok(EthTransactions::sign(self, address, message).await?)
924 }
925
926 async fn sign_transaction(&self, request: RpcTxReq<T::NetworkTypes>) -> RpcResult<Bytes> {
928 trace!(target: "rpc::eth", ?request, "Serving eth_signTransaction");
929 Ok(EthTransactions::sign_transaction(self, request).await?)
930 }
931
932 async fn sign_typed_data(&self, address: Address, data: TypedData) -> RpcResult<Bytes> {
934 trace!(target: "rpc::eth", ?address, ?data, "Serving eth_signTypedData");
935 Ok(EthTransactions::sign_typed_data(self, &data, address)?)
936 }
937
938 async fn get_proof(
940 &self,
941 address: Address,
942 keys: Vec<JsonStorageKey>,
943 block_number: Option<BlockId>,
944 ) -> RpcResult<EIP1186AccountProofResponse> {
945 trace!(target: "rpc::eth", ?address, ?keys, ?block_number, "Serving eth_getProof");
946 Ok(EthState::get_proof(self, address, keys, block_number)?.await?)
947 }
948
949 async fn get_account_info(
951 &self,
952 address: Address,
953 block: BlockId,
954 ) -> RpcResult<alloy_rpc_types_eth::AccountInfo> {
955 trace!(target: "rpc::eth", "Serving eth_getAccountInfo");
956 Ok(EthState::get_account_info(self, address, block).await?)
957 }
958
959 async fn block_access_list_by_block_hash(&self, block_hash: B256) -> RpcResult<Option<Value>> {
961 trace!(target: "rpc::eth", ?block_hash, "Serving eth_getBlockAccessListByBlockHash");
962
963 let bal = self.get_block_access_list(block_hash.into()).await?;
964 let json = serde_json::to_value(&bal)
965 .map_err(|e| EthApiError::Internal(reth_errors::RethError::msg(e.to_string())))?;
966
967 Ok(Some(json))
968 }
969
970 async fn block_access_list_by_block_number(
972 &self,
973 number: BlockNumberOrTag,
974 ) -> RpcResult<Option<Value>> {
975 trace!(target: "rpc::eth", ?number, "Serving eth_getBlockAccessListByBlockNumber");
976
977 let bal = self.get_block_access_list(number.into()).await?;
978 let json = serde_json::to_value(&bal)
979 .map_err(|e| EthApiError::Internal(reth_errors::RethError::msg(e.to_string())))?;
980
981 Ok(Some(json))
982 }
983
984 async fn block_access_list(&self, block_id: BlockId) -> RpcResult<Option<Value>> {
986 trace!(target: "rpc::eth", ?block_id, "Serving eth_getBlockAccessList");
987
988 let bal = self.get_block_access_list(block_id).await?;
989 let json = serde_json::to_value(&bal)
990 .map_err(|e| EthApiError::Internal(reth_errors::RethError::msg(e.to_string())))?;
991
992 Ok(Some(json))
993 }
994
995 async fn block_access_list_raw(&self, block: BlockId) -> RpcResult<Option<Bytes>> {
997 trace!(target: "rpc::eth", ?block, "Serving eth_getBlockAccessListRaw");
998
999 Ok(self.get_raw_block_access_list(block).await?)
1000 }
1001}