feat(rpc): add EthApiSpec to DebugApi (#1246)

This commit is contained in:
Matthias Seitz
2023-02-09 14:06:30 +01:00
committed by GitHub
parent 9470943bab
commit f070412064
3 changed files with 26 additions and 12 deletions

View File

@@ -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();

View File

@@ -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<Eth> {
/// The implementation of `eth` API
eth: Eth,
}
// === impl DebugApi ===
impl DebugApi {
impl<Eth> DebugApi<Eth> {
/// 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<Eth> DebugApiServer for DebugApi<Eth>
where
Eth: EthApiSpec + 'static,
{
async fn raw_header(&self, _block_id: BlockId) -> Result<Bytes> {
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<Bytes> {
Err(internal_rpc_err("unimplemented"))
}
@@ -47,7 +50,7 @@ impl DebugApiServer for DebugApi {
}
}
impl std::fmt::Debug for DebugApi {
impl<Eth> std::fmt::Debug for DebugApi<Eth> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("DebugApi").finish_non_exhaustive()
}

View File

@@ -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<Address>;
/// Returns the transaction by hash
async fn transaction_by_hash(&self, hash: H256) -> Result<Option<TransactionSigned>>;
}
/// `Eth` API implementation.
@@ -175,6 +179,10 @@ where
fn accounts(&self) -> Vec<Address> {
self.inner.signers.iter().flat_map(|s| s.accounts()).collect()
}
async fn transaction_by_hash(&self, _hash: H256) -> Result<Option<TransactionSigned>> {
todo!()
}
}
/// Container type `EthApi`