feat(rpc-testing-utils) : implement debug_traceCall JSON-RPC method (#5418)

This commit is contained in:
DoTheBestToGetTheBest
2023-11-24 04:04:45 -08:00
committed by GitHub
parent c37f187eed
commit 2624f46675

View File

@ -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");
@ -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]
@ -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.