Skip to content

Commit

Permalink
feat(rpc-testing-utils) : implement debug_traceCall JSON-RPC method (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
DoTheBestToGetTheBest authored Nov 24, 2023
1 parent c37f187 commit 2624f46
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions crates/rpc/rpc-testing-util/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ use futures::{Stream, StreamExt};
use jsonrpsee::core::Error as RpcError;
use reth_primitives::{BlockId, TxHash, B256};
use reth_rpc_api::{clients::DebugApiClient, EthApiClient};
use reth_rpc_types::trace::geth::{GethDebugTracerType, GethDebugTracingOptions};
use reth_rpc_types::{
trace::geth::{GethDebugTracerType, GethDebugTracingOptions},
CallRequest,
};
use std::{
pin::Pin,
task::{Context, Poll},
};

const NOOP_TRACER: &str = include_str!("../assets/noop-tracer.js");
const JS_TRACER_TEMPLATE: &str = include_str!("../assets/tracer-template.js");

Expand Down Expand Up @@ -37,6 +39,19 @@ pub trait DebugApiExt {
) -> Result<DebugTraceTransactionsStream<'_>, jsonrpsee::core::Error>
where
B: Into<BlockId> + Send;
/// method for debug_traceCall
async fn debug_trace_call_json(
&self,
request: CallRequest,
opts: GethDebugTracingOptions,
) -> Result<serde_json::Value, jsonrpsee::core::Error>;

/// method for debug_traceCall using raw JSON strings for the request and options.
async fn debug_trace_call_raw_json(
&self,
request_json: String,
opts_json: String,
) -> Result<serde_json::Value, RpcError>;
}

#[async_trait::async_trait]
Expand Down Expand Up @@ -81,6 +96,29 @@ where

Ok(DebugTraceTransactionsStream { stream: Box::pin(stream) })
}
async fn debug_trace_call_json(
&self,
request: CallRequest,
opts: GethDebugTracingOptions,
) -> Result<serde_json::Value, jsonrpsee::core::Error> {
let mut params = jsonrpsee::core::params::ArrayParams::new();
params.insert(request).unwrap();
params.insert(opts).unwrap();
self.request("debug_traceCall", params).await
}

async fn debug_trace_call_raw_json(
&self,
request_json: String,
opts_json: String,
) -> Result<serde_json::Value, RpcError> {
let request = serde_json::from_str::<CallRequest>(&request_json)
.map_err(|e| RpcError::Custom(e.to_string()))?;
let opts = serde_json::from_str::<GethDebugTracingOptions>(&opts_json)
.map_err(|e| RpcError::Custom(e.to_string()))?;

self.debug_trace_call_json(request, opts).await
}
}

/// A helper type that can be used to build a javascript tracer.
Expand Down

0 comments on commit 2624f46

Please sign in to comment.