chore(rpc): add required fields to Trace handler (#1683)

This commit is contained in:
Matthias Seitz
2023-03-09 21:51:35 +01:00
committed by GitHub
parent 89305b883a
commit ea11461126
2 changed files with 21 additions and 11 deletions

View File

@ -559,6 +559,7 @@ where
namespaces: impl Iterator<Item = RethRpcModule>,
) -> Vec<Methods> {
let eth_api = self.eth_api();
let eth_cache = self.eth_cache();
namespaces
.map(|namespace| {
self.modules
@ -572,7 +573,9 @@ where
RethRpcModule::Net => {
NetApi::new(self.network.clone(), eth_api.clone()).into_rpc().into()
}
RethRpcModule::Trace => TraceApi::new().into_rpc().into(),
RethRpcModule::Trace => {
TraceApi::new(self.client.clone(), eth_cache.clone()).into_rpc().into()
}
RethRpcModule::Web3 => Web3Api::new(self.network.clone()).into_rpc().into(),
})
.clone()

View File

@ -1,7 +1,8 @@
use crate::result::internal_rpc_err;
use crate::{eth::cache::EthStateCache, result::internal_rpc_err};
use async_trait::async_trait;
use jsonrpsee::core::RpcResult as Result;
use reth_primitives::{BlockId, Bytes, H256};
use reth_provider::{BlockProvider, EvmEnvProvider, StateProviderFactory};
use reth_rpc_api::TraceApiServer;
use reth_rpc_types::{
trace::{filter::TraceFilter, parity::*},
@ -12,22 +13,28 @@ use std::collections::HashSet;
/// `trace` API implementation.
///
/// This type provides the functionality for handling `trace` related requests.
#[non_exhaustive]
pub struct TraceApi {}
#[derive(Clone)]
pub struct TraceApi<Client> {
/// The client that can interact with the chain.
client: Client,
/// The async cache frontend for eth related data
eth_cache: EthStateCache,
}
// === impl TraceApi ===
impl TraceApi {
impl<Client> TraceApi<Client> {
/// Create a new instance of the [TraceApi]
#[allow(clippy::new_without_default)]
// TODO add necessary types
pub fn new() -> Self {
Self {}
pub fn new(client: Client, eth_cache: EthStateCache) -> Self {
Self { client, eth_cache }
}
}
#[async_trait]
impl TraceApiServer for TraceApi {
impl<Client> TraceApiServer for TraceApi<Client>
where
Client: BlockProvider + StateProviderFactory + EvmEnvProvider + 'static,
{
async fn call(
&self,
_call: CallRequest,
@ -91,7 +98,7 @@ impl TraceApiServer for TraceApi {
}
}
impl std::fmt::Debug for TraceApi {
impl<Client> std::fmt::Debug for TraceApi<Client> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("TraceApi").finish_non_exhaustive()
}