diff --git a/crates/rpc/rpc-builder/src/lib.rs b/crates/rpc/rpc-builder/src/lib.rs index 2ed928f58e..04abc3fd5e 100644 --- a/crates/rpc/rpc-builder/src/lib.rs +++ b/crates/rpc/rpc-builder/src/lib.rs @@ -393,7 +393,10 @@ where } let methods: Methods = match namespace { RethRpcModule::Admin => AdminApi::new(self.network.clone()).into_rpc().into(), - RethRpcModule::Debug => DebugApi::new().into_rpc().into(), + RethRpcModule::Debug => { + let eth_api = self.eth_api(); + DebugApi::new(eth_api).into_rpc().into() + } RethRpcModule::Eth => self.eth_api().into_rpc().into(), RethRpcModule::Net => { let eth_api = self.eth_api(); diff --git a/crates/rpc/rpc/src/debug.rs b/crates/rpc/rpc/src/debug.rs index 98dae72d03..3f120d81a9 100644 --- a/crates/rpc/rpc/src/debug.rs +++ b/crates/rpc/rpc/src/debug.rs @@ -1,4 +1,4 @@ -use crate::result::internal_rpc_err; +use crate::{result::internal_rpc_err, EthApiSpec}; use async_trait::async_trait; use jsonrpsee::core::RpcResult as Result; use reth_primitives::{rpc::BlockId, Bytes, H256}; @@ -9,23 +9,25 @@ use reth_rpc_types::RichBlock; /// /// This type provides the functionality for handling `debug` related requests. #[non_exhaustive] -pub struct DebugApi { - // TODO: add proper handler when implementing functions +pub struct DebugApi { + /// The implementation of `eth` API + eth: Eth, } // === impl DebugApi === -impl DebugApi { +impl DebugApi { /// Create a new instance of the [DebugApi] - #[allow(clippy::new_without_default)] - // TODO add necessary types - pub fn new() -> Self { - Self {} + pub fn new(eth: Eth) -> Self { + Self { eth } } } #[async_trait] -impl DebugApiServer for DebugApi { +impl DebugApiServer for DebugApi +where + Eth: EthApiSpec + 'static, +{ async fn raw_header(&self, _block_id: BlockId) -> Result { Err(internal_rpc_err("unimplemented")) } @@ -34,6 +36,7 @@ impl DebugApiServer for DebugApi { Err(internal_rpc_err("unimplemented")) } + /// Returns the bytes of the transaction for the given hash. async fn raw_transaction(&self, _hash: H256) -> Result { Err(internal_rpc_err("unimplemented")) } @@ -47,7 +50,7 @@ impl DebugApiServer for DebugApi { } } -impl std::fmt::Debug for DebugApi { +impl std::fmt::Debug for DebugApi { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("DebugApi").finish_non_exhaustive() } diff --git a/crates/rpc/rpc/src/eth/api/mod.rs b/crates/rpc/rpc/src/eth/api/mod.rs index 12c925579c..2173a20910 100644 --- a/crates/rpc/rpc/src/eth/api/mod.rs +++ b/crates/rpc/rpc/src/eth/api/mod.rs @@ -9,9 +9,10 @@ use reth_interfaces::Result; use reth_network_api::NetworkInfo; use reth_primitives::{ rpc::{BlockId, BlockNumber}, - Address, ChainInfo, H256, U64, + Address, ChainInfo, TransactionSigned, H256, U64, }; use reth_provider::{BlockProvider, StateProviderFactory}; + use reth_transaction_pool::TransactionPool; use std::sync::Arc; @@ -36,6 +37,9 @@ pub trait EthApiSpec: Send + Sync { /// Returns a list of addresses owned by client. fn accounts(&self) -> Vec
; + + /// Returns the transaction by hash + async fn transaction_by_hash(&self, hash: H256) -> Result>; } /// `Eth` API implementation. @@ -175,6 +179,10 @@ where fn accounts(&self) -> Vec
{ self.inner.signers.iter().flat_map(|s| s.accounts()).collect() } + + async fn transaction_by_hash(&self, _hash: H256) -> Result> { + todo!() + } } /// Container type `EthApi`