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::FillTransaction;
22use reth_rpc_server_types::{result::internal_rpc_err, ToRpcResult};
23use tracing::trace;
24
25pub trait FullEthApiServer:
28 EthApiServer<
29 RpcTxReq<Self::NetworkTypes>,
30 RpcTransaction<Self::NetworkTypes>,
31 RpcBlock<Self::NetworkTypes>,
32 RpcReceipt<Self::NetworkTypes>,
33 RpcHeader<Self::NetworkTypes>,
34 TxTy<Self::Primitives>,
35 > + FullEthApi
36 + Clone
37{
38}
39
40impl<T> FullEthApiServer for T where
41 T: EthApiServer<
42 RpcTxReq<T::NetworkTypes>,
43 RpcTransaction<T::NetworkTypes>,
44 RpcBlock<T::NetworkTypes>,
45 RpcReceipt<T::NetworkTypes>,
46 RpcHeader<T::NetworkTypes>,
47 TxTy<T::Primitives>,
48 > + FullEthApi
49 + Clone
50{
51}
52
53#[cfg_attr(not(feature = "client"), rpc(server, namespace = "eth"))]
55#[cfg_attr(feature = "client", rpc(server, client, namespace = "eth"))]
56pub trait EthApi<
57 TxReq: RpcObject,
58 T: RpcObject,
59 B: RpcObject,
60 R: RpcObject,
61 H: RpcObject,
62 RawTx: RpcObject,
63>
64{
65 #[method(name = "protocolVersion")]
67 async fn protocol_version(&self) -> RpcResult<U64>;
68
69 #[method(name = "syncing")]
71 fn syncing(&self) -> RpcResult<SyncStatus>;
72
73 #[method(name = "coinbase")]
75 async fn author(&self) -> RpcResult<Address>;
76
77 #[method(name = "accounts")]
79 fn accounts(&self) -> RpcResult<Vec<Address>>;
80
81 #[method(name = "blockNumber")]
83 fn block_number(&self) -> RpcResult<U256>;
84
85 #[method(name = "chainId")]
87 async fn chain_id(&self) -> RpcResult<Option<U64>>;
88
89 #[method(name = "getBlockByHash")]
91 async fn block_by_hash(&self, hash: B256, full: bool) -> RpcResult<Option<B>>;
92
93 #[method(name = "getBlockByNumber")]
95 async fn block_by_number(&self, number: BlockNumberOrTag, full: bool) -> RpcResult<Option<B>>;
96
97 #[method(name = "getBlockTransactionCountByHash")]
99 async fn block_transaction_count_by_hash(&self, hash: B256) -> RpcResult<Option<U256>>;
100
101 #[method(name = "getBlockTransactionCountByNumber")]
103 async fn block_transaction_count_by_number(
104 &self,
105 number: BlockNumberOrTag,
106 ) -> RpcResult<Option<U256>>;
107
108 #[method(name = "getUncleCountByBlockHash")]
110 async fn block_uncles_count_by_hash(&self, hash: B256) -> RpcResult<Option<U256>>;
111
112 #[method(name = "getUncleCountByBlockNumber")]
114 async fn block_uncles_count_by_number(
115 &self,
116 number: BlockNumberOrTag,
117 ) -> RpcResult<Option<U256>>;
118
119 #[method(name = "getBlockReceipts")]
121 async fn block_receipts(&self, block_id: BlockId) -> RpcResult<Option<Vec<R>>>;
122
123 #[method(name = "getUncleByBlockHashAndIndex")]
125 async fn uncle_by_block_hash_and_index(&self, hash: B256, index: Index)
126 -> RpcResult<Option<B>>;
127
128 #[method(name = "getUncleByBlockNumberAndIndex")]
130 async fn uncle_by_block_number_and_index(
131 &self,
132 number: BlockNumberOrTag,
133 index: Index,
134 ) -> RpcResult<Option<B>>;
135
136 #[method(name = "getRawTransactionByHash")]
140 async fn raw_transaction_by_hash(&self, hash: B256) -> RpcResult<Option<Bytes>>;
141
142 #[method(name = "getTransactionByHash")]
144 async fn transaction_by_hash(&self, hash: B256) -> RpcResult<Option<T>>;
145
146 #[method(name = "getRawTransactionByBlockHashAndIndex")]
148 async fn raw_transaction_by_block_hash_and_index(
149 &self,
150 hash: B256,
151 index: Index,
152 ) -> RpcResult<Option<Bytes>>;
153
154 #[method(name = "getTransactionByBlockHashAndIndex")]
156 async fn transaction_by_block_hash_and_index(
157 &self,
158 hash: B256,
159 index: Index,
160 ) -> RpcResult<Option<T>>;
161
162 #[method(name = "getRawTransactionByBlockNumberAndIndex")]
165 async fn raw_transaction_by_block_number_and_index(
166 &self,
167 number: BlockNumberOrTag,
168 index: Index,
169 ) -> RpcResult<Option<Bytes>>;
170
171 #[method(name = "getTransactionByBlockNumberAndIndex")]
173 async fn transaction_by_block_number_and_index(
174 &self,
175 number: BlockNumberOrTag,
176 index: Index,
177 ) -> RpcResult<Option<T>>;
178
179 #[method(name = "getTransactionBySenderAndNonce")]
181 async fn transaction_by_sender_and_nonce(
182 &self,
183 address: Address,
184 nonce: U64,
185 ) -> RpcResult<Option<T>>;
186
187 #[method(name = "getTransactionReceipt")]
189 async fn transaction_receipt(&self, hash: B256) -> RpcResult<Option<R>>;
190
191 #[method(name = "getBalance")]
193 async fn balance(&self, address: Address, block_number: Option<BlockId>) -> RpcResult<U256>;
194
195 #[method(name = "getStorageAt")]
197 async fn storage_at(
198 &self,
199 address: Address,
200 index: JsonStorageKey,
201 block_number: Option<BlockId>,
202 ) -> RpcResult<B256>;
203
204 #[method(name = "getTransactionCount")]
206 async fn transaction_count(
207 &self,
208 address: Address,
209 block_number: Option<BlockId>,
210 ) -> RpcResult<U256>;
211
212 #[method(name = "getCode")]
214 async fn get_code(&self, address: Address, block_number: Option<BlockId>) -> RpcResult<Bytes>;
215
216 #[method(name = "getHeaderByNumber")]
218 async fn header_by_number(&self, hash: BlockNumberOrTag) -> RpcResult<Option<H>>;
219
220 #[method(name = "getHeaderByHash")]
222 async fn header_by_hash(&self, hash: B256) -> RpcResult<Option<H>>;
223
224 #[method(name = "simulateV1")]
227 async fn simulate_v1(
228 &self,
229 opts: SimulatePayload<TxReq>,
230 block_number: Option<BlockId>,
231 ) -> RpcResult<Vec<SimulatedBlock<B>>>;
232
233 #[method(name = "call")]
235 async fn call(
236 &self,
237 request: TxReq,
238 block_number: Option<BlockId>,
239 state_overrides: Option<StateOverride>,
240 block_overrides: Option<Box<BlockOverrides>>,
241 ) -> RpcResult<Bytes>;
242
243 #[method(name = "fillTransaction")]
245 async fn fill_transaction(&self, request: TxReq) -> RpcResult<FillTransaction<RawTx>>;
246
247 #[method(name = "callMany")]
250 async fn call_many(
251 &self,
252 bundles: Vec<Bundle<TxReq>>,
253 state_context: Option<StateContext>,
254 state_override: Option<StateOverride>,
255 ) -> RpcResult<Vec<Vec<EthCallResponse>>>;
256
257 #[method(name = "createAccessList")]
272 async fn create_access_list(
273 &self,
274 request: TxReq,
275 block_number: Option<BlockId>,
276 state_override: Option<StateOverride>,
277 ) -> RpcResult<AccessListResult>;
278
279 #[method(name = "estimateGas")]
282 async fn estimate_gas(
283 &self,
284 request: TxReq,
285 block_number: Option<BlockId>,
286 state_override: Option<StateOverride>,
287 ) -> RpcResult<U256>;
288
289 #[method(name = "gasPrice")]
291 async fn gas_price(&self) -> RpcResult<U256>;
292
293 #[method(name = "getAccount")]
295 async fn get_account(
296 &self,
297 address: Address,
298 block: BlockId,
299 ) -> RpcResult<Option<alloy_rpc_types_eth::Account>>;
300
301 #[method(name = "maxPriorityFeePerGas")]
303 async fn max_priority_fee_per_gas(&self) -> RpcResult<U256>;
304
305 #[method(name = "blobBaseFee")]
307 async fn blob_base_fee(&self) -> RpcResult<U256>;
308
309 #[method(name = "feeHistory")]
317 async fn fee_history(
318 &self,
319 block_count: U64,
320 newest_block: BlockNumberOrTag,
321 reward_percentiles: Option<Vec<f64>>,
322 ) -> RpcResult<FeeHistory>;
323
324 #[method(name = "mining")]
326 async fn is_mining(&self) -> RpcResult<bool>;
327
328 #[method(name = "hashrate")]
330 async fn hashrate(&self) -> RpcResult<U256>;
331
332 #[method(name = "getWork")]
335 async fn get_work(&self) -> RpcResult<Work>;
336
337 #[method(name = "submitHashrate")]
343 async fn submit_hashrate(&self, hashrate: U256, id: B256) -> RpcResult<bool>;
344
345 #[method(name = "submitWork")]
347 async fn submit_work(&self, nonce: B64, pow_hash: B256, mix_digest: B256) -> RpcResult<bool>;
348
349 #[method(name = "sendTransaction")]
352 async fn send_transaction(&self, request: TxReq) -> RpcResult<B256>;
353
354 #[method(name = "sendRawTransaction")]
356 async fn send_raw_transaction(&self, bytes: Bytes) -> RpcResult<B256>;
357
358 #[method(name = "sendRawTransactionSync")]
362 async fn send_raw_transaction_sync(&self, bytes: Bytes) -> RpcResult<R>;
363
364 #[method(name = "sign")]
367 async fn sign(&self, address: Address, message: Bytes) -> RpcResult<Bytes>;
368
369 #[method(name = "signTransaction")]
372 async fn sign_transaction(&self, transaction: TxReq) -> RpcResult<Bytes>;
373
374 #[method(name = "signTypedData")]
376 async fn sign_typed_data(&self, address: Address, data: TypedData) -> RpcResult<Bytes>;
377
378 #[method(name = "getProof")]
381 async fn get_proof(
382 &self,
383 address: Address,
384 keys: Vec<JsonStorageKey>,
385 block_number: Option<BlockId>,
386 ) -> RpcResult<EIP1186AccountProofResponse>;
387
388 #[method(name = "getAccountInfo")]
392 async fn get_account_info(
393 &self,
394 address: Address,
395 block: BlockId,
396 ) -> RpcResult<alloy_rpc_types_eth::AccountInfo>;
397
398 #[method(name = "getBlockAccessListByBlockHash")]
400 async fn block_access_list_by_block_hash(&self, hash: B256) -> RpcResult<Option<Bytes>>;
401
402 #[method(name = "getBlockAccessListByBlockNumber")]
404 async fn block_access_list_by_block_number(
405 &self,
406 number: BlockNumberOrTag,
407 ) -> RpcResult<Option<Bytes>>;
408}
409
410#[async_trait::async_trait]
411impl<T>
412 EthApiServer<
413 RpcTxReq<T::NetworkTypes>,
414 RpcTransaction<T::NetworkTypes>,
415 RpcBlock<T::NetworkTypes>,
416 RpcReceipt<T::NetworkTypes>,
417 RpcHeader<T::NetworkTypes>,
418 TxTy<T::Primitives>,
419 > for T
420where
421 T: FullEthApi,
422 jsonrpsee_types::error::ErrorObject<'static>: From<T::Error>,
423{
424 async fn protocol_version(&self) -> RpcResult<U64> {
426 trace!(target: "rpc::eth", "Serving eth_protocolVersion");
427 EthApiSpec::protocol_version(self).await.to_rpc_result()
428 }
429
430 fn syncing(&self) -> RpcResult<SyncStatus> {
432 trace!(target: "rpc::eth", "Serving eth_syncing");
433 EthApiSpec::sync_status(self).to_rpc_result()
434 }
435
436 async fn author(&self) -> RpcResult<Address> {
438 Err(internal_rpc_err("unimplemented"))
439 }
440
441 fn accounts(&self) -> RpcResult<Vec<Address>> {
443 trace!(target: "rpc::eth", "Serving eth_accounts");
444 Ok(EthTransactions::accounts(self))
445 }
446
447 fn block_number(&self) -> RpcResult<U256> {
449 trace!(target: "rpc::eth", "Serving eth_blockNumber");
450 Ok(U256::from(
451 EthApiSpec::chain_info(self).with_message("failed to read chain info")?.best_number,
452 ))
453 }
454
455 async fn chain_id(&self) -> RpcResult<Option<U64>> {
457 trace!(target: "rpc::eth", "Serving eth_chainId");
458 Ok(Some(EthApiSpec::chain_id(self)))
459 }
460
461 async fn block_by_hash(
463 &self,
464 hash: B256,
465 full: bool,
466 ) -> RpcResult<Option<RpcBlock<T::NetworkTypes>>> {
467 trace!(target: "rpc::eth", ?hash, ?full, "Serving eth_getBlockByHash");
468 Ok(EthBlocks::rpc_block(self, hash.into(), full).await?)
469 }
470
471 async fn block_by_number(
473 &self,
474 number: BlockNumberOrTag,
475 full: bool,
476 ) -> RpcResult<Option<RpcBlock<T::NetworkTypes>>> {
477 trace!(target: "rpc::eth", ?number, ?full, "Serving eth_getBlockByNumber");
478 Ok(EthBlocks::rpc_block(self, number.into(), full).await?)
479 }
480
481 async fn block_transaction_count_by_hash(&self, hash: B256) -> RpcResult<Option<U256>> {
483 trace!(target: "rpc::eth", ?hash, "Serving eth_getBlockTransactionCountByHash");
484 Ok(EthBlocks::block_transaction_count(self, hash.into()).await?.map(U256::from))
485 }
486
487 async fn block_transaction_count_by_number(
489 &self,
490 number: BlockNumberOrTag,
491 ) -> RpcResult<Option<U256>> {
492 trace!(target: "rpc::eth", ?number, "Serving eth_getBlockTransactionCountByNumber");
493 Ok(EthBlocks::block_transaction_count(self, number.into()).await?.map(U256::from))
494 }
495
496 async fn block_uncles_count_by_hash(&self, hash: B256) -> RpcResult<Option<U256>> {
498 trace!(target: "rpc::eth", ?hash, "Serving eth_getUncleCountByBlockHash");
499
500 if let Some(block) = self.block_by_hash(hash, false).await? {
501 Ok(Some(U256::from(block.uncles.len())))
502 } else {
503 Ok(None)
504 }
505 }
506
507 async fn block_uncles_count_by_number(
509 &self,
510 number: BlockNumberOrTag,
511 ) -> RpcResult<Option<U256>> {
512 trace!(target: "rpc::eth", ?number, "Serving eth_getUncleCountByBlockNumber");
513
514 if let Some(block) = self.block_by_number(number, false).await? {
515 Ok(Some(U256::from(block.uncles.len())))
516 } else {
517 Ok(None)
518 }
519 }
520
521 async fn block_receipts(
523 &self,
524 block_id: BlockId,
525 ) -> RpcResult<Option<Vec<RpcReceipt<T::NetworkTypes>>>> {
526 trace!(target: "rpc::eth", ?block_id, "Serving eth_getBlockReceipts");
527 Ok(EthBlocks::block_receipts(self, block_id).await?)
528 }
529
530 async fn uncle_by_block_hash_and_index(
532 &self,
533 hash: B256,
534 index: Index,
535 ) -> RpcResult<Option<RpcBlock<T::NetworkTypes>>> {
536 trace!(target: "rpc::eth", ?hash, ?index, "Serving eth_getUncleByBlockHashAndIndex");
537 Ok(EthBlocks::ommer_by_block_and_index(self, hash.into(), index).await?)
538 }
539
540 async fn uncle_by_block_number_and_index(
542 &self,
543 number: BlockNumberOrTag,
544 index: Index,
545 ) -> RpcResult<Option<RpcBlock<T::NetworkTypes>>> {
546 trace!(target: "rpc::eth", ?number, ?index, "Serving eth_getUncleByBlockNumberAndIndex");
547 Ok(EthBlocks::ommer_by_block_and_index(self, number.into(), index).await?)
548 }
549
550 async fn raw_transaction_by_hash(&self, hash: B256) -> RpcResult<Option<Bytes>> {
552 trace!(target: "rpc::eth", ?hash, "Serving eth_getRawTransactionByHash");
553 Ok(EthTransactions::raw_transaction_by_hash(self, hash).await?)
554 }
555
556 async fn transaction_by_hash(
558 &self,
559 hash: B256,
560 ) -> RpcResult<Option<RpcTransaction<T::NetworkTypes>>> {
561 trace!(target: "rpc::eth", ?hash, "Serving eth_getTransactionByHash");
562 Ok(EthTransactions::transaction_by_hash(self, hash)
563 .await?
564 .map(|tx| tx.into_transaction(self.converter()))
565 .transpose()
566 .map_err(T::Error::from)?)
567 }
568
569 async fn raw_transaction_by_block_hash_and_index(
571 &self,
572 hash: B256,
573 index: Index,
574 ) -> RpcResult<Option<Bytes>> {
575 trace!(target: "rpc::eth", ?hash, ?index, "Serving eth_getRawTransactionByBlockHashAndIndex");
576 Ok(EthTransactions::raw_transaction_by_block_and_tx_index(self, hash.into(), index.into())
577 .await?)
578 }
579
580 async fn transaction_by_block_hash_and_index(
582 &self,
583 hash: B256,
584 index: Index,
585 ) -> RpcResult<Option<RpcTransaction<T::NetworkTypes>>> {
586 trace!(target: "rpc::eth", ?hash, ?index, "Serving eth_getTransactionByBlockHashAndIndex");
587 Ok(EthTransactions::transaction_by_block_and_tx_index(self, hash.into(), index.into())
588 .await?)
589 }
590
591 async fn raw_transaction_by_block_number_and_index(
593 &self,
594 number: BlockNumberOrTag,
595 index: Index,
596 ) -> RpcResult<Option<Bytes>> {
597 trace!(target: "rpc::eth", ?number, ?index, "Serving eth_getRawTransactionByBlockNumberAndIndex");
598 Ok(EthTransactions::raw_transaction_by_block_and_tx_index(
599 self,
600 number.into(),
601 index.into(),
602 )
603 .await?)
604 }
605
606 async fn transaction_by_block_number_and_index(
608 &self,
609 number: BlockNumberOrTag,
610 index: Index,
611 ) -> RpcResult<Option<RpcTransaction<T::NetworkTypes>>> {
612 trace!(target: "rpc::eth", ?number, ?index, "Serving eth_getTransactionByBlockNumberAndIndex");
613 Ok(EthTransactions::transaction_by_block_and_tx_index(self, number.into(), index.into())
614 .await?)
615 }
616
617 async fn transaction_by_sender_and_nonce(
619 &self,
620 sender: Address,
621 nonce: U64,
622 ) -> RpcResult<Option<RpcTransaction<T::NetworkTypes>>> {
623 trace!(target: "rpc::eth", ?sender, ?nonce, "Serving eth_getTransactionBySenderAndNonce");
624 Ok(EthTransactions::get_transaction_by_sender_and_nonce(self, sender, nonce.to(), true)
625 .await?)
626 }
627
628 async fn transaction_receipt(
630 &self,
631 hash: B256,
632 ) -> RpcResult<Option<RpcReceipt<T::NetworkTypes>>> {
633 trace!(target: "rpc::eth", ?hash, "Serving eth_getTransactionReceipt");
634 Ok(EthTransactions::transaction_receipt(self, hash).await?)
635 }
636
637 async fn balance(&self, address: Address, block_number: Option<BlockId>) -> RpcResult<U256> {
639 trace!(target: "rpc::eth", ?address, ?block_number, "Serving eth_getBalance");
640 Ok(EthState::balance(self, address, block_number).await?)
641 }
642
643 async fn storage_at(
645 &self,
646 address: Address,
647 index: JsonStorageKey,
648 block_number: Option<BlockId>,
649 ) -> RpcResult<B256> {
650 trace!(target: "rpc::eth", ?address, ?block_number, "Serving eth_getStorageAt");
651 Ok(EthState::storage_at(self, address, index, block_number).await?)
652 }
653
654 async fn transaction_count(
656 &self,
657 address: Address,
658 block_number: Option<BlockId>,
659 ) -> RpcResult<U256> {
660 trace!(target: "rpc::eth", ?address, ?block_number, "Serving eth_getTransactionCount");
661 Ok(EthState::transaction_count(self, address, block_number).await?)
662 }
663
664 async fn get_code(&self, address: Address, block_number: Option<BlockId>) -> RpcResult<Bytes> {
666 trace!(target: "rpc::eth", ?address, ?block_number, "Serving eth_getCode");
667 Ok(EthState::get_code(self, address, block_number).await?)
668 }
669
670 async fn header_by_number(
672 &self,
673 block_number: BlockNumberOrTag,
674 ) -> RpcResult<Option<RpcHeader<T::NetworkTypes>>> {
675 trace!(target: "rpc::eth", ?block_number, "Serving eth_getHeaderByNumber");
676 Ok(EthBlocks::rpc_block_header(self, block_number.into()).await?)
677 }
678
679 async fn header_by_hash(&self, hash: B256) -> RpcResult<Option<RpcHeader<T::NetworkTypes>>> {
681 trace!(target: "rpc::eth", ?hash, "Serving eth_getHeaderByHash");
682 Ok(EthBlocks::rpc_block_header(self, hash.into()).await?)
683 }
684
685 async fn simulate_v1(
687 &self,
688 payload: SimulatePayload<RpcTxReq<T::NetworkTypes>>,
689 block_number: Option<BlockId>,
690 ) -> RpcResult<Vec<SimulatedBlock<RpcBlock<T::NetworkTypes>>>> {
691 trace!(target: "rpc::eth", ?block_number, "Serving eth_simulateV1");
692 let _permit = self.tracing_task_guard().clone().acquire_owned().await;
693 Ok(EthCall::simulate_v1(self, payload, block_number).await?)
694 }
695
696 async fn call(
698 &self,
699 request: RpcTxReq<T::NetworkTypes>,
700 block_number: Option<BlockId>,
701 state_overrides: Option<StateOverride>,
702 block_overrides: Option<Box<BlockOverrides>>,
703 ) -> RpcResult<Bytes> {
704 trace!(target: "rpc::eth", ?request, ?block_number, ?state_overrides, ?block_overrides, "Serving eth_call");
705 Ok(EthCall::call(
706 self,
707 request,
708 block_number,
709 EvmOverrides::new(state_overrides, block_overrides),
710 )
711 .await?)
712 }
713
714 async fn fill_transaction(
716 &self,
717 request: RpcTxReq<T::NetworkTypes>,
718 ) -> RpcResult<FillTransaction<TxTy<T::Primitives>>> {
719 trace!(target: "rpc::eth", ?request, "Serving eth_fillTransaction");
720 Ok(EthTransactions::fill_transaction(self, request).await?)
721 }
722
723 async fn call_many(
725 &self,
726 bundles: Vec<Bundle<RpcTxReq<T::NetworkTypes>>>,
727 state_context: Option<StateContext>,
728 state_override: Option<StateOverride>,
729 ) -> RpcResult<Vec<Vec<EthCallResponse>>> {
730 trace!(target: "rpc::eth", ?bundles, ?state_context, ?state_override, "Serving eth_callMany");
731 Ok(EthCall::call_many(self, bundles, state_context, state_override).await?)
732 }
733
734 async fn create_access_list(
736 &self,
737 request: RpcTxReq<T::NetworkTypes>,
738 block_number: Option<BlockId>,
739 state_override: Option<StateOverride>,
740 ) -> RpcResult<AccessListResult> {
741 trace!(target: "rpc::eth", ?request, ?block_number, ?state_override, "Serving eth_createAccessList");
742 Ok(EthCall::create_access_list_at(self, request, block_number, state_override).await?)
743 }
744
745 async fn estimate_gas(
747 &self,
748 request: RpcTxReq<T::NetworkTypes>,
749 block_number: Option<BlockId>,
750 state_override: Option<StateOverride>,
751 ) -> RpcResult<U256> {
752 trace!(target: "rpc::eth", ?request, ?block_number, "Serving eth_estimateGas");
753 Ok(EthCall::estimate_gas_at(
754 self,
755 request,
756 block_number.unwrap_or_default(),
757 state_override,
758 )
759 .await?)
760 }
761
762 async fn gas_price(&self) -> RpcResult<U256> {
764 trace!(target: "rpc::eth", "Serving eth_gasPrice");
765 Ok(EthFees::gas_price(self).await?)
766 }
767
768 async fn get_account(
770 &self,
771 address: Address,
772 block: BlockId,
773 ) -> RpcResult<Option<alloy_rpc_types_eth::Account>> {
774 trace!(target: "rpc::eth", "Serving eth_getAccount");
775 Ok(EthState::get_account(self, address, block).await?)
776 }
777
778 async fn max_priority_fee_per_gas(&self) -> RpcResult<U256> {
780 trace!(target: "rpc::eth", "Serving eth_maxPriorityFeePerGas");
781 Ok(EthFees::suggested_priority_fee(self).await?)
782 }
783
784 async fn blob_base_fee(&self) -> RpcResult<U256> {
786 trace!(target: "rpc::eth", "Serving eth_blobBaseFee");
787 Ok(EthFees::blob_base_fee(self).await?)
788 }
789
790 async fn fee_history(
800 &self,
801 block_count: U64,
802 newest_block: BlockNumberOrTag,
803 reward_percentiles: Option<Vec<f64>>,
804 ) -> RpcResult<FeeHistory> {
805 trace!(target: "rpc::eth", ?block_count, ?newest_block, ?reward_percentiles, "Serving eth_feeHistory");
806 Ok(EthFees::fee_history(self, block_count.to(), newest_block, reward_percentiles).await?)
807 }
808
809 async fn is_mining(&self) -> RpcResult<bool> {
811 Err(internal_rpc_err("unimplemented"))
812 }
813
814 async fn hashrate(&self) -> RpcResult<U256> {
816 Ok(U256::ZERO)
817 }
818
819 async fn get_work(&self) -> RpcResult<Work> {
821 Err(internal_rpc_err("unimplemented"))
822 }
823
824 async fn submit_hashrate(&self, _hashrate: U256, _id: B256) -> RpcResult<bool> {
826 Ok(false)
827 }
828
829 async fn submit_work(
831 &self,
832 _nonce: B64,
833 _pow_hash: B256,
834 _mix_digest: B256,
835 ) -> RpcResult<bool> {
836 Err(internal_rpc_err("unimplemented"))
837 }
838
839 async fn send_transaction(&self, request: RpcTxReq<T::NetworkTypes>) -> RpcResult<B256> {
841 trace!(target: "rpc::eth", ?request, "Serving eth_sendTransaction");
842 Ok(EthTransactions::send_transaction_request(self, request).await?)
843 }
844
845 async fn send_raw_transaction(&self, tx: Bytes) -> RpcResult<B256> {
847 trace!(target: "rpc::eth", ?tx, "Serving eth_sendRawTransaction");
848 Ok(EthTransactions::send_raw_transaction(self, tx).await?)
849 }
850
851 async fn send_raw_transaction_sync(&self, tx: Bytes) -> RpcResult<RpcReceipt<T::NetworkTypes>> {
853 trace!(target: "rpc::eth", ?tx, "Serving eth_sendRawTransactionSync");
854 Ok(EthTransactions::send_raw_transaction_sync(self, tx).await?)
855 }
856
857 async fn sign(&self, address: Address, message: Bytes) -> RpcResult<Bytes> {
859 trace!(target: "rpc::eth", ?address, ?message, "Serving eth_sign");
860 Ok(EthTransactions::sign(self, address, message).await?)
861 }
862
863 async fn sign_transaction(&self, request: RpcTxReq<T::NetworkTypes>) -> RpcResult<Bytes> {
865 trace!(target: "rpc::eth", ?request, "Serving eth_signTransaction");
866 Ok(EthTransactions::sign_transaction(self, request).await?)
867 }
868
869 async fn sign_typed_data(&self, address: Address, data: TypedData) -> RpcResult<Bytes> {
871 trace!(target: "rpc::eth", ?address, ?data, "Serving eth_signTypedData");
872 Ok(EthTransactions::sign_typed_data(self, &data, address)?)
873 }
874
875 async fn get_proof(
877 &self,
878 address: Address,
879 keys: Vec<JsonStorageKey>,
880 block_number: Option<BlockId>,
881 ) -> RpcResult<EIP1186AccountProofResponse> {
882 trace!(target: "rpc::eth", ?address, ?keys, ?block_number, "Serving eth_getProof");
883 Ok(EthState::get_proof(self, address, keys, block_number)?.await?)
884 }
885
886 async fn get_account_info(
888 &self,
889 address: Address,
890 block: BlockId,
891 ) -> RpcResult<alloy_rpc_types_eth::AccountInfo> {
892 trace!(target: "rpc::eth", "Serving eth_getAccountInfo");
893 Ok(EthState::get_account_info(self, address, block).await?)
894 }
895
896 async fn block_access_list_by_block_hash(&self, hash: B256) -> RpcResult<Option<Bytes>> {
898 trace!(target: "rpc::eth", ?hash, "Serving eth_getBlockAccessListByBlockHash");
899 Err(internal_rpc_err("unimplemented"))
900 }
901
902 async fn block_access_list_by_block_number(
904 &self,
905 number: BlockNumberOrTag,
906 ) -> RpcResult<Option<Bytes>> {
907 trace!(target: "rpc::eth", ?number, "Serving eth_getBlockAccessListByBlockNumber");
908 Err(internal_rpc_err("unimplemented"))
909 }
910}