1use crate::{
4 helpers::{EthApiSpec, EthBlocks, EthCall, EthFees, EthState, EthTransactions, FullEthApi},
5 RpcBlock, RpcHeader, RpcReceipt, RpcTransaction,
6};
7use alloy_dyn_abi::TypedData;
8use alloy_eip7928::BlockAccessList;
9use alloy_eips::{eip2930::AccessListResult, BlockId, BlockNumberOrTag};
10use alloy_json_rpc::RpcObject;
11use alloy_primitives::{Address, Bytes, B256, B64, U256, U64};
12use alloy_rpc_types_eth::{
13 simulate::{SimulatePayload, SimulatedBlock},
14 state::{EvmOverrides, StateOverride},
15 BlockOverrides, Bundle, EIP1186AccountProofResponse, EthCallResponse, FeeHistory, Index,
16 StateContext, SyncStatus, Work,
17};
18use alloy_serde::JsonStorageKey;
19use jsonrpsee::{core::RpcResult, proc_macros::rpc};
20use reth_primitives_traits::TxTy;
21use reth_rpc_convert::RpcTxReq;
22use reth_rpc_eth_types::{EthApiError, FillTransaction};
23use reth_rpc_server_types::{result::internal_rpc_err, ToRpcResult};
24use serde_json::Value;
25use std::collections::HashMap;
26use tracing::trace;
27
28pub trait FullEthApiServer:
31 EthApiServer<
32 RpcTxReq<Self::NetworkTypes>,
33 RpcTransaction<Self::NetworkTypes>,
34 RpcBlock<Self::NetworkTypes>,
35 RpcReceipt<Self::NetworkTypes>,
36 RpcHeader<Self::NetworkTypes>,
37 TxTy<Self::Primitives>,
38 > + FullEthApi
39 + Clone
40{
41}
42
43impl<T> FullEthApiServer for T where
44 T: EthApiServer<
45 RpcTxReq<T::NetworkTypes>,
46 RpcTransaction<T::NetworkTypes>,
47 RpcBlock<T::NetworkTypes>,
48 RpcReceipt<T::NetworkTypes>,
49 RpcHeader<T::NetworkTypes>,
50 TxTy<T::Primitives>,
51 > + FullEthApi
52 + Clone
53{
54}
55
56#[cfg_attr(not(feature = "client"), rpc(server, namespace = "eth"))]
58#[cfg_attr(feature = "client", rpc(server, client, namespace = "eth"))]
59pub trait EthApi<
60 TxReq: RpcObject,
61 T: RpcObject,
62 B: RpcObject,
63 R: RpcObject,
64 H: RpcObject,
65 RawTx: RpcObject,
66>
67{
68 #[method(name = "protocolVersion")]
70 async fn protocol_version(&self) -> RpcResult<U64>;
71
72 #[method(name = "syncing")]
74 fn syncing(&self) -> RpcResult<SyncStatus>;
75
76 #[method(name = "coinbase")]
78 async fn author(&self) -> RpcResult<Address>;
79
80 #[method(name = "accounts")]
82 fn accounts(&self) -> RpcResult<Vec<Address>>;
83
84 #[method(name = "blockNumber")]
86 fn block_number(&self) -> RpcResult<U256>;
87
88 #[method(name = "chainId")]
90 async fn chain_id(&self) -> RpcResult<Option<U64>>;
91
92 #[method(name = "getBlockByHash")]
94 async fn block_by_hash(&self, hash: B256, full: bool) -> RpcResult<Option<B>>;
95
96 #[method(name = "getBlockByNumber")]
98 async fn block_by_number(&self, number: BlockNumberOrTag, full: bool) -> RpcResult<Option<B>>;
99
100 #[method(name = "getBlockTransactionCountByHash")]
102 async fn block_transaction_count_by_hash(&self, hash: B256) -> RpcResult<Option<U256>>;
103
104 #[method(name = "getBlockTransactionCountByNumber")]
106 async fn block_transaction_count_by_number(
107 &self,
108 number: BlockNumberOrTag,
109 ) -> RpcResult<Option<U256>>;
110
111 #[method(name = "getUncleCountByBlockHash")]
113 async fn block_uncles_count_by_hash(&self, hash: B256) -> RpcResult<Option<U256>>;
114
115 #[method(name = "getUncleCountByBlockNumber")]
117 async fn block_uncles_count_by_number(
118 &self,
119 number: BlockNumberOrTag,
120 ) -> RpcResult<Option<U256>>;
121
122 #[method(name = "getBlockReceipts")]
124 async fn block_receipts(&self, block_id: BlockId) -> RpcResult<Option<Vec<R>>>;
125
126 #[method(name = "getUncleByBlockHashAndIndex")]
128 async fn uncle_by_block_hash_and_index(&self, hash: B256, index: Index)
129 -> RpcResult<Option<B>>;
130
131 #[method(name = "getUncleByBlockNumberAndIndex")]
133 async fn uncle_by_block_number_and_index(
134 &self,
135 number: BlockNumberOrTag,
136 index: Index,
137 ) -> RpcResult<Option<B>>;
138
139 #[method(name = "getRawTransactionByHash")]
143 async fn raw_transaction_by_hash(&self, hash: B256) -> RpcResult<Option<Bytes>>;
144
145 #[method(name = "getTransactionByHash")]
147 async fn transaction_by_hash(&self, hash: B256) -> RpcResult<Option<T>>;
148
149 #[method(name = "getRawTransactionByBlockHashAndIndex")]
151 async fn raw_transaction_by_block_hash_and_index(
152 &self,
153 hash: B256,
154 index: Index,
155 ) -> RpcResult<Option<Bytes>>;
156
157 #[method(name = "getTransactionByBlockHashAndIndex")]
159 async fn transaction_by_block_hash_and_index(
160 &self,
161 hash: B256,
162 index: Index,
163 ) -> RpcResult<Option<T>>;
164
165 #[method(name = "getRawTransactionByBlockNumberAndIndex")]
168 async fn raw_transaction_by_block_number_and_index(
169 &self,
170 number: BlockNumberOrTag,
171 index: Index,
172 ) -> RpcResult<Option<Bytes>>;
173
174 #[method(name = "getTransactionByBlockNumberAndIndex")]
176 async fn transaction_by_block_number_and_index(
177 &self,
178 number: BlockNumberOrTag,
179 index: Index,
180 ) -> RpcResult<Option<T>>;
181
182 #[method(name = "getTransactionBySenderAndNonce")]
184 async fn transaction_by_sender_and_nonce(
185 &self,
186 address: Address,
187 nonce: U64,
188 ) -> RpcResult<Option<T>>;
189
190 #[method(name = "getTransactionReceipt")]
192 async fn transaction_receipt(&self, hash: B256) -> RpcResult<Option<R>>;
193
194 #[method(name = "getBalance")]
196 async fn balance(&self, address: Address, block_number: Option<BlockId>) -> RpcResult<U256>;
197
198 #[method(name = "getStorageAt")]
200 async fn storage_at(
201 &self,
202 address: Address,
203 index: JsonStorageKey,
204 block_number: Option<BlockId>,
205 ) -> RpcResult<B256>;
206
207 #[method(name = "getStorageValues")]
209 async fn storage_values(
210 &self,
211 requests: HashMap<Address, Vec<JsonStorageKey>>,
212 block_number: Option<BlockId>,
213 ) -> RpcResult<HashMap<Address, Vec<B256>>>;
214
215 #[method(name = "getTransactionCount")]
217 async fn transaction_count(
218 &self,
219 address: Address,
220 block_number: Option<BlockId>,
221 ) -> RpcResult<U256>;
222
223 #[method(name = "getCode")]
225 async fn get_code(&self, address: Address, block_number: Option<BlockId>) -> RpcResult<Bytes>;
226
227 #[method(name = "getHeaderByNumber")]
229 async fn header_by_number(&self, hash: BlockNumberOrTag) -> RpcResult<Option<H>>;
230
231 #[method(name = "getHeaderByHash")]
233 async fn header_by_hash(&self, hash: B256) -> RpcResult<Option<H>>;
234
235 #[method(name = "simulateV1")]
238 async fn simulate_v1(
239 &self,
240 opts: SimulatePayload<TxReq>,
241 block_number: Option<BlockId>,
242 ) -> RpcResult<Vec<SimulatedBlock<B>>>;
243
244 #[method(name = "call")]
246 async fn call(
247 &self,
248 request: TxReq,
249 block_number: Option<BlockId>,
250 state_overrides: Option<StateOverride>,
251 block_overrides: Option<Box<BlockOverrides>>,
252 ) -> RpcResult<Bytes>;
253
254 #[method(name = "fillTransaction")]
256 async fn fill_transaction(&self, request: TxReq) -> RpcResult<FillTransaction<RawTx>>;
257
258 #[method(name = "callMany")]
261 async fn call_many(
262 &self,
263 bundles: Vec<Bundle<TxReq>>,
264 state_context: Option<StateContext>,
265 state_override: Option<StateOverride>,
266 ) -> RpcResult<Vec<Vec<EthCallResponse>>>;
267
268 #[method(name = "createAccessList")]
283 async fn create_access_list(
284 &self,
285 request: TxReq,
286 block_number: Option<BlockId>,
287 state_override: Option<StateOverride>,
288 ) -> RpcResult<AccessListResult>;
289
290 #[method(name = "estimateGas")]
293 async fn estimate_gas(
294 &self,
295 request: TxReq,
296 block_number: Option<BlockId>,
297 state_override: Option<StateOverride>,
298 ) -> RpcResult<U256>;
299
300 #[method(name = "gasPrice")]
302 async fn gas_price(&self) -> RpcResult<U256>;
303
304 #[method(name = "getAccount")]
306 async fn get_account(
307 &self,
308 address: Address,
309 block: BlockId,
310 ) -> RpcResult<Option<alloy_rpc_types_eth::Account>>;
311
312 #[method(name = "maxPriorityFeePerGas")]
314 async fn max_priority_fee_per_gas(&self) -> RpcResult<U256>;
315
316 #[method(name = "blobBaseFee")]
318 async fn blob_base_fee(&self) -> RpcResult<U256>;
319
320 #[method(name = "feeHistory")]
328 async fn fee_history(
329 &self,
330 block_count: U64,
331 newest_block: BlockNumberOrTag,
332 reward_percentiles: Option<Vec<f64>>,
333 ) -> RpcResult<FeeHistory>;
334
335 #[method(name = "mining")]
337 async fn is_mining(&self) -> RpcResult<bool>;
338
339 #[method(name = "hashrate")]
341 async fn hashrate(&self) -> RpcResult<U256>;
342
343 #[method(name = "getWork")]
346 async fn get_work(&self) -> RpcResult<Work>;
347
348 #[method(name = "submitHashrate")]
354 async fn submit_hashrate(&self, hashrate: U256, id: B256) -> RpcResult<bool>;
355
356 #[method(name = "submitWork")]
358 async fn submit_work(&self, nonce: B64, pow_hash: B256, mix_digest: B256) -> RpcResult<bool>;
359
360 #[method(name = "sendTransaction")]
363 async fn send_transaction(&self, request: TxReq) -> RpcResult<B256>;
364
365 #[method(name = "sendRawTransaction")]
367 async fn send_raw_transaction(&self, bytes: Bytes) -> RpcResult<B256>;
368
369 #[method(name = "sendRawTransactionSync")]
373 async fn send_raw_transaction_sync(&self, bytes: Bytes) -> RpcResult<R>;
374
375 #[method(name = "sign")]
378 async fn sign(&self, address: Address, message: Bytes) -> RpcResult<Bytes>;
379
380 #[method(name = "signTransaction")]
383 async fn sign_transaction(&self, transaction: TxReq) -> RpcResult<Bytes>;
384
385 #[method(name = "signTypedData")]
387 async fn sign_typed_data(&self, address: Address, data: TypedData) -> RpcResult<Bytes>;
388
389 #[method(name = "getProof")]
392 async fn get_proof(
393 &self,
394 address: Address,
395 keys: Vec<JsonStorageKey>,
396 block_number: Option<BlockId>,
397 ) -> RpcResult<EIP1186AccountProofResponse>;
398
399 #[method(name = "getAccountInfo")]
403 async fn get_account_info(
404 &self,
405 address: Address,
406 block: BlockId,
407 ) -> RpcResult<alloy_rpc_types_eth::AccountInfo>;
408
409 #[method(name = "getBlockAccessListByBlockHash")]
411 async fn block_access_list_by_block_hash(&self, hash: B256) -> RpcResult<Option<Value>>;
412
413 #[method(name = "getBlockAccessListByBlockNumber")]
415 async fn block_access_list_by_block_number(
416 &self,
417 number: BlockNumberOrTag,
418 ) -> RpcResult<Option<Value>>;
419
420 #[method(name = "getBlockAccessListRaw")]
422 async fn block_access_list_raw(&self, number: BlockNumberOrTag) -> RpcResult<Option<Bytes>>;
423}
424
425#[async_trait::async_trait]
426impl<T>
427 EthApiServer<
428 RpcTxReq<T::NetworkTypes>,
429 RpcTransaction<T::NetworkTypes>,
430 RpcBlock<T::NetworkTypes>,
431 RpcReceipt<T::NetworkTypes>,
432 RpcHeader<T::NetworkTypes>,
433 TxTy<T::Primitives>,
434 > for T
435where
436 T: FullEthApi,
437 jsonrpsee_types::error::ErrorObject<'static>: From<T::Error>,
438{
439 async fn protocol_version(&self) -> RpcResult<U64> {
441 trace!(target: "rpc::eth", "Serving eth_protocolVersion");
442 EthApiSpec::protocol_version(self).await.to_rpc_result()
443 }
444
445 fn syncing(&self) -> RpcResult<SyncStatus> {
447 trace!(target: "rpc::eth", "Serving eth_syncing");
448 EthApiSpec::sync_status(self).to_rpc_result()
449 }
450
451 async fn author(&self) -> RpcResult<Address> {
453 Err(internal_rpc_err("unimplemented"))
454 }
455
456 fn accounts(&self) -> RpcResult<Vec<Address>> {
458 trace!(target: "rpc::eth", "Serving eth_accounts");
459 Ok(EthTransactions::accounts(self))
460 }
461
462 fn block_number(&self) -> RpcResult<U256> {
464 trace!(target: "rpc::eth", "Serving eth_blockNumber");
465 Ok(U256::from(
466 EthApiSpec::chain_info(self).with_message("failed to read chain info")?.best_number,
467 ))
468 }
469
470 async fn chain_id(&self) -> RpcResult<Option<U64>> {
472 trace!(target: "rpc::eth", "Serving eth_chainId");
473 Ok(Some(EthApiSpec::chain_id(self)))
474 }
475
476 async fn block_by_hash(
478 &self,
479 hash: B256,
480 full: bool,
481 ) -> RpcResult<Option<RpcBlock<T::NetworkTypes>>> {
482 trace!(target: "rpc::eth", ?hash, ?full, "Serving eth_getBlockByHash");
483 Ok(EthBlocks::rpc_block(self, hash.into(), full).await?)
484 }
485
486 async fn block_by_number(
488 &self,
489 number: BlockNumberOrTag,
490 full: bool,
491 ) -> RpcResult<Option<RpcBlock<T::NetworkTypes>>> {
492 trace!(target: "rpc::eth", ?number, ?full, "Serving eth_getBlockByNumber");
493 Ok(EthBlocks::rpc_block(self, number.into(), full).await?)
494 }
495
496 async fn block_transaction_count_by_hash(&self, hash: B256) -> RpcResult<Option<U256>> {
498 trace!(target: "rpc::eth", ?hash, "Serving eth_getBlockTransactionCountByHash");
499 Ok(EthBlocks::block_transaction_count(self, hash.into()).await?.map(U256::from))
500 }
501
502 async fn block_transaction_count_by_number(
504 &self,
505 number: BlockNumberOrTag,
506 ) -> RpcResult<Option<U256>> {
507 trace!(target: "rpc::eth", ?number, "Serving eth_getBlockTransactionCountByNumber");
508 Ok(EthBlocks::block_transaction_count(self, number.into()).await?.map(U256::from))
509 }
510
511 async fn block_uncles_count_by_hash(&self, hash: B256) -> RpcResult<Option<U256>> {
513 trace!(target: "rpc::eth", ?hash, "Serving eth_getUncleCountByBlockHash");
514
515 if let Some(block) = self.block_by_hash(hash, false).await? {
516 Ok(Some(U256::from(block.uncles.len())))
517 } else {
518 Ok(None)
519 }
520 }
521
522 async fn block_uncles_count_by_number(
524 &self,
525 number: BlockNumberOrTag,
526 ) -> RpcResult<Option<U256>> {
527 trace!(target: "rpc::eth", ?number, "Serving eth_getUncleCountByBlockNumber");
528
529 if let Some(block) = self.block_by_number(number, false).await? {
530 Ok(Some(U256::from(block.uncles.len())))
531 } else {
532 Ok(None)
533 }
534 }
535
536 async fn block_receipts(
538 &self,
539 block_id: BlockId,
540 ) -> RpcResult<Option<Vec<RpcReceipt<T::NetworkTypes>>>> {
541 trace!(target: "rpc::eth", ?block_id, "Serving eth_getBlockReceipts");
542 Ok(EthBlocks::block_receipts(self, block_id).await?)
543 }
544
545 async fn uncle_by_block_hash_and_index(
547 &self,
548 hash: B256,
549 index: Index,
550 ) -> RpcResult<Option<RpcBlock<T::NetworkTypes>>> {
551 trace!(target: "rpc::eth", ?hash, ?index, "Serving eth_getUncleByBlockHashAndIndex");
552 Ok(EthBlocks::ommer_by_block_and_index(self, hash.into(), index).await?)
553 }
554
555 async fn uncle_by_block_number_and_index(
557 &self,
558 number: BlockNumberOrTag,
559 index: Index,
560 ) -> RpcResult<Option<RpcBlock<T::NetworkTypes>>> {
561 trace!(target: "rpc::eth", ?number, ?index, "Serving eth_getUncleByBlockNumberAndIndex");
562 Ok(EthBlocks::ommer_by_block_and_index(self, number.into(), index).await?)
563 }
564
565 async fn raw_transaction_by_hash(&self, hash: B256) -> RpcResult<Option<Bytes>> {
567 trace!(target: "rpc::eth", ?hash, "Serving eth_getRawTransactionByHash");
568 Ok(EthTransactions::raw_transaction_by_hash(self, hash).await?)
569 }
570
571 async fn transaction_by_hash(
573 &self,
574 hash: B256,
575 ) -> RpcResult<Option<RpcTransaction<T::NetworkTypes>>> {
576 trace!(target: "rpc::eth", ?hash, "Serving eth_getTransactionByHash");
577 Ok(EthTransactions::transaction_by_hash(self, hash)
578 .await?
579 .map(|tx| tx.into_transaction(self.converter()))
580 .transpose()
581 .map_err(T::Error::from)?)
582 }
583
584 async fn raw_transaction_by_block_hash_and_index(
586 &self,
587 hash: B256,
588 index: Index,
589 ) -> RpcResult<Option<Bytes>> {
590 trace!(target: "rpc::eth", ?hash, ?index, "Serving eth_getRawTransactionByBlockHashAndIndex");
591 Ok(EthTransactions::raw_transaction_by_block_and_tx_index(self, hash.into(), index.into())
592 .await?)
593 }
594
595 async fn transaction_by_block_hash_and_index(
597 &self,
598 hash: B256,
599 index: Index,
600 ) -> RpcResult<Option<RpcTransaction<T::NetworkTypes>>> {
601 trace!(target: "rpc::eth", ?hash, ?index, "Serving eth_getTransactionByBlockHashAndIndex");
602 Ok(EthTransactions::transaction_by_block_and_tx_index(self, hash.into(), index.into())
603 .await?)
604 }
605
606 async fn raw_transaction_by_block_number_and_index(
608 &self,
609 number: BlockNumberOrTag,
610 index: Index,
611 ) -> RpcResult<Option<Bytes>> {
612 trace!(target: "rpc::eth", ?number, ?index, "Serving eth_getRawTransactionByBlockNumberAndIndex");
613 Ok(EthTransactions::raw_transaction_by_block_and_tx_index(
614 self,
615 number.into(),
616 index.into(),
617 )
618 .await?)
619 }
620
621 async fn transaction_by_block_number_and_index(
623 &self,
624 number: BlockNumberOrTag,
625 index: Index,
626 ) -> RpcResult<Option<RpcTransaction<T::NetworkTypes>>> {
627 trace!(target: "rpc::eth", ?number, ?index, "Serving eth_getTransactionByBlockNumberAndIndex");
628 Ok(EthTransactions::transaction_by_block_and_tx_index(self, number.into(), index.into())
629 .await?)
630 }
631
632 async fn transaction_by_sender_and_nonce(
634 &self,
635 sender: Address,
636 nonce: U64,
637 ) -> RpcResult<Option<RpcTransaction<T::NetworkTypes>>> {
638 trace!(target: "rpc::eth", ?sender, ?nonce, "Serving eth_getTransactionBySenderAndNonce");
639 Ok(EthTransactions::get_transaction_by_sender_and_nonce(self, sender, nonce.to(), true)
640 .await?)
641 }
642
643 async fn transaction_receipt(
645 &self,
646 hash: B256,
647 ) -> RpcResult<Option<RpcReceipt<T::NetworkTypes>>> {
648 trace!(target: "rpc::eth", ?hash, "Serving eth_getTransactionReceipt");
649 Ok(EthTransactions::transaction_receipt(self, hash).await?)
650 }
651
652 async fn balance(&self, address: Address, block_number: Option<BlockId>) -> RpcResult<U256> {
654 trace!(target: "rpc::eth", ?address, ?block_number, "Serving eth_getBalance");
655 Ok(EthState::balance(self, address, block_number).await?)
656 }
657
658 async fn storage_at(
660 &self,
661 address: Address,
662 index: JsonStorageKey,
663 block_number: Option<BlockId>,
664 ) -> RpcResult<B256> {
665 trace!(target: "rpc::eth", ?address, ?block_number, "Serving eth_getStorageAt");
666 Ok(EthState::storage_at(self, address, index, block_number).await?)
667 }
668
669 async fn storage_values(
671 &self,
672 requests: HashMap<Address, Vec<JsonStorageKey>>,
673 block_number: Option<BlockId>,
674 ) -> RpcResult<HashMap<Address, Vec<B256>>> {
675 trace!(target: "rpc::eth", ?block_number, "Serving eth_getStorageValues");
676 Ok(EthState::storage_values(self, requests, block_number).await?)
677 }
678
679 async fn transaction_count(
681 &self,
682 address: Address,
683 block_number: Option<BlockId>,
684 ) -> RpcResult<U256> {
685 trace!(target: "rpc::eth", ?address, ?block_number, "Serving eth_getTransactionCount");
686 Ok(EthState::transaction_count(self, address, block_number).await?)
687 }
688
689 async fn get_code(&self, address: Address, block_number: Option<BlockId>) -> RpcResult<Bytes> {
691 trace!(target: "rpc::eth", ?address, ?block_number, "Serving eth_getCode");
692 Ok(EthState::get_code(self, address, block_number).await?)
693 }
694
695 async fn header_by_number(
697 &self,
698 block_number: BlockNumberOrTag,
699 ) -> RpcResult<Option<RpcHeader<T::NetworkTypes>>> {
700 trace!(target: "rpc::eth", ?block_number, "Serving eth_getHeaderByNumber");
701 Ok(EthBlocks::rpc_block_header(self, block_number.into()).await?)
702 }
703
704 async fn header_by_hash(&self, hash: B256) -> RpcResult<Option<RpcHeader<T::NetworkTypes>>> {
706 trace!(target: "rpc::eth", ?hash, "Serving eth_getHeaderByHash");
707 Ok(EthBlocks::rpc_block_header(self, hash.into()).await?)
708 }
709
710 async fn simulate_v1(
712 &self,
713 payload: SimulatePayload<RpcTxReq<T::NetworkTypes>>,
714 block_number: Option<BlockId>,
715 ) -> RpcResult<Vec<SimulatedBlock<RpcBlock<T::NetworkTypes>>>> {
716 trace!(target: "rpc::eth", ?block_number, "Serving eth_simulateV1");
717 let _permit = self.tracing_task_guard().clone().acquire_owned().await;
718 Ok(EthCall::simulate_v1(self, payload, block_number).await?)
719 }
720
721 async fn call(
723 &self,
724 request: RpcTxReq<T::NetworkTypes>,
725 block_number: Option<BlockId>,
726 state_overrides: Option<StateOverride>,
727 block_overrides: Option<Box<BlockOverrides>>,
728 ) -> RpcResult<Bytes> {
729 trace!(target: "rpc::eth", ?request, ?block_number, ?state_overrides, ?block_overrides, "Serving eth_call");
730 Ok(EthCall::call(
731 self,
732 request,
733 block_number,
734 EvmOverrides::new(state_overrides, block_overrides),
735 )
736 .await?)
737 }
738
739 async fn fill_transaction(
741 &self,
742 request: RpcTxReq<T::NetworkTypes>,
743 ) -> RpcResult<FillTransaction<TxTy<T::Primitives>>> {
744 trace!(target: "rpc::eth", ?request, "Serving eth_fillTransaction");
745 Ok(EthTransactions::fill_transaction(self, request).await?)
746 }
747
748 async fn call_many(
750 &self,
751 bundles: Vec<Bundle<RpcTxReq<T::NetworkTypes>>>,
752 state_context: Option<StateContext>,
753 state_override: Option<StateOverride>,
754 ) -> RpcResult<Vec<Vec<EthCallResponse>>> {
755 trace!(target: "rpc::eth", ?bundles, ?state_context, ?state_override, "Serving eth_callMany");
756 Ok(EthCall::call_many(self, bundles, state_context, state_override).await?)
757 }
758
759 async fn create_access_list(
761 &self,
762 request: RpcTxReq<T::NetworkTypes>,
763 block_number: Option<BlockId>,
764 state_override: Option<StateOverride>,
765 ) -> RpcResult<AccessListResult> {
766 trace!(target: "rpc::eth", ?request, ?block_number, ?state_override, "Serving eth_createAccessList");
767 Ok(EthCall::create_access_list_at(self, request, block_number, state_override).await?)
768 }
769
770 async fn estimate_gas(
772 &self,
773 request: RpcTxReq<T::NetworkTypes>,
774 block_number: Option<BlockId>,
775 state_override: Option<StateOverride>,
776 ) -> RpcResult<U256> {
777 trace!(target: "rpc::eth", ?request, ?block_number, "Serving eth_estimateGas");
778 Ok(EthCall::estimate_gas_at(
779 self,
780 request,
781 block_number.unwrap_or_default(),
782 state_override,
783 )
784 .await?)
785 }
786
787 async fn gas_price(&self) -> RpcResult<U256> {
789 trace!(target: "rpc::eth", "Serving eth_gasPrice");
790 Ok(EthFees::gas_price(self).await?)
791 }
792
793 async fn get_account(
795 &self,
796 address: Address,
797 block: BlockId,
798 ) -> RpcResult<Option<alloy_rpc_types_eth::Account>> {
799 trace!(target: "rpc::eth", "Serving eth_getAccount");
800 Ok(EthState::get_account(self, address, block).await?)
801 }
802
803 async fn max_priority_fee_per_gas(&self) -> RpcResult<U256> {
805 trace!(target: "rpc::eth", "Serving eth_maxPriorityFeePerGas");
806 Ok(EthFees::suggested_priority_fee(self).await?)
807 }
808
809 async fn blob_base_fee(&self) -> RpcResult<U256> {
811 trace!(target: "rpc::eth", "Serving eth_blobBaseFee");
812 Ok(EthFees::blob_base_fee(self).await?)
813 }
814
815 async fn fee_history(
825 &self,
826 block_count: U64,
827 newest_block: BlockNumberOrTag,
828 reward_percentiles: Option<Vec<f64>>,
829 ) -> RpcResult<FeeHistory> {
830 trace!(target: "rpc::eth", ?block_count, ?newest_block, ?reward_percentiles, "Serving eth_feeHistory");
831 Ok(EthFees::fee_history(self, block_count.to(), newest_block, reward_percentiles).await?)
832 }
833
834 async fn is_mining(&self) -> RpcResult<bool> {
836 Err(internal_rpc_err("unimplemented"))
837 }
838
839 async fn hashrate(&self) -> RpcResult<U256> {
841 Ok(U256::ZERO)
842 }
843
844 async fn get_work(&self) -> RpcResult<Work> {
846 Err(internal_rpc_err("unimplemented"))
847 }
848
849 async fn submit_hashrate(&self, _hashrate: U256, _id: B256) -> RpcResult<bool> {
851 Ok(false)
852 }
853
854 async fn submit_work(
856 &self,
857 _nonce: B64,
858 _pow_hash: B256,
859 _mix_digest: B256,
860 ) -> RpcResult<bool> {
861 Err(internal_rpc_err("unimplemented"))
862 }
863
864 async fn send_transaction(&self, request: RpcTxReq<T::NetworkTypes>) -> RpcResult<B256> {
866 trace!(target: "rpc::eth", ?request, "Serving eth_sendTransaction");
867 Ok(EthTransactions::send_transaction_request(self, request).await?)
868 }
869
870 async fn send_raw_transaction(&self, tx: Bytes) -> RpcResult<B256> {
872 trace!(target: "rpc::eth", ?tx, "Serving eth_sendRawTransaction");
873 Ok(EthTransactions::send_raw_transaction(self, tx).await?)
874 }
875
876 async fn send_raw_transaction_sync(&self, tx: Bytes) -> RpcResult<RpcReceipt<T::NetworkTypes>> {
878 trace!(target: "rpc::eth", ?tx, "Serving eth_sendRawTransactionSync");
879 Ok(EthTransactions::send_raw_transaction_sync(self, tx).await?)
880 }
881
882 async fn sign(&self, address: Address, message: Bytes) -> RpcResult<Bytes> {
884 trace!(target: "rpc::eth", ?address, ?message, "Serving eth_sign");
885 Ok(EthTransactions::sign(self, address, message).await?)
886 }
887
888 async fn sign_transaction(&self, request: RpcTxReq<T::NetworkTypes>) -> RpcResult<Bytes> {
890 trace!(target: "rpc::eth", ?request, "Serving eth_signTransaction");
891 Ok(EthTransactions::sign_transaction(self, request).await?)
892 }
893
894 async fn sign_typed_data(&self, address: Address, data: TypedData) -> RpcResult<Bytes> {
896 trace!(target: "rpc::eth", ?address, ?data, "Serving eth_signTypedData");
897 Ok(EthTransactions::sign_typed_data(self, &data, address)?)
898 }
899
900 async fn get_proof(
902 &self,
903 address: Address,
904 keys: Vec<JsonStorageKey>,
905 block_number: Option<BlockId>,
906 ) -> RpcResult<EIP1186AccountProofResponse> {
907 trace!(target: "rpc::eth", ?address, ?keys, ?block_number, "Serving eth_getProof");
908 Ok(EthState::get_proof(self, address, keys, block_number)?.await?)
909 }
910
911 async fn get_account_info(
913 &self,
914 address: Address,
915 block: BlockId,
916 ) -> RpcResult<alloy_rpc_types_eth::AccountInfo> {
917 trace!(target: "rpc::eth", "Serving eth_getAccountInfo");
918 Ok(EthState::get_account_info(self, address, block).await?)
919 }
920
921 async fn block_access_list_by_block_hash(&self, block_hash: B256) -> RpcResult<Option<Value>> {
923 trace!(target: "rpc::eth", ?block_hash, "Serving eth_getBlockAccessListByBlockHash");
924
925 let bal = self.get_block_access_list(block_hash.into()).await?;
926 let json = serde_json::to_value(&bal)
927 .map_err(|e| EthApiError::Internal(reth_errors::RethError::msg(e.to_string())))?;
928
929 Ok(Some(json))
930 }
931 async fn block_access_list_by_block_number(
933 &self,
934 number: BlockNumberOrTag,
935 ) -> RpcResult<Option<Value>> {
936 trace!(target: "rpc::eth", ?number, "Serving eth_getBlockAccessListByBlockNumber");
937
938 let bal = self.get_block_access_list(number.into()).await?;
939 let json = serde_json::to_value(&bal)
940 .map_err(|e| EthApiError::Internal(reth_errors::RethError::msg(e.to_string())))?;
941
942 Ok(Some(json))
943 }
944 async fn block_access_list_raw(&self, number: BlockNumberOrTag) -> RpcResult<Option<Bytes>> {
946 trace!(target: "rpc::eth", ?number, "Serving eth_getBlockAccessListRaw");
947
948 let bal = self.get_block_access_list(number.into()).await?;
949 Ok(bal.map(|b: BlockAccessList| alloy_rlp::encode(b).into()))
950 }
951}