mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore(rpc): simplify GethTrace type (#3180)
This commit is contained in:
@ -2,7 +2,7 @@ use jsonrpsee::{core::RpcResult, proc_macros::rpc};
|
||||
use reth_primitives::{BlockId, BlockNumberOrTag, Bytes, H256};
|
||||
use reth_rpc_types::{
|
||||
trace::geth::{
|
||||
BlockTraceResult, GethDebugTracingCallOptions, GethDebugTracingOptions, GethTraceFrame,
|
||||
BlockTraceResult, GethDebugTracingCallOptions, GethDebugTracingOptions, GethTrace,
|
||||
TraceResult,
|
||||
},
|
||||
CallRequest, RichBlock,
|
||||
@ -84,7 +84,7 @@ pub trait DebugApi {
|
||||
&self,
|
||||
tx_hash: H256,
|
||||
opts: Option<GethDebugTracingOptions>,
|
||||
) -> RpcResult<GethTraceFrame>;
|
||||
) -> RpcResult<GethTrace>;
|
||||
|
||||
/// The `debug_traceCall` method lets you run an `eth_call` within the context of the given
|
||||
/// block execution using the final state of parent block as the base.
|
||||
@ -101,5 +101,5 @@ pub trait DebugApi {
|
||||
request: CallRequest,
|
||||
block_number: Option<BlockId>,
|
||||
opts: Option<GethDebugTracingCallOptions>,
|
||||
) -> RpcResult<GethTraceFrame>;
|
||||
) -> RpcResult<GethTrace>;
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ mod noop;
|
||||
mod pre_state;
|
||||
|
||||
/// Result type for geth style transaction trace
|
||||
pub type TraceResult = crate::trace::common::TraceResult<GethTraceFrame, String>;
|
||||
pub type TraceResult = crate::trace::common::TraceResult<GethTrace, String>;
|
||||
|
||||
/// blockTraceResult represents the results of tracing a single block when an entire chain is being
|
||||
/// traced. ref <https://github.com/ethereum/go-ethereum/blob/ee530c0d5aa70d2c00ab5691a89ab431b73f8165/eth/tracers/api.go#L218-L222>
|
||||
@ -34,7 +34,7 @@ pub struct BlockTraceResult {
|
||||
pub traces: Vec<TraceResult>,
|
||||
}
|
||||
|
||||
/// Geth Default trace frame
|
||||
/// Geth Default struct log trace frame
|
||||
///
|
||||
/// <https://github.com/ethereum/go-ethereum/blob/a9ef135e2dd53682d106c6a2aede9187026cc1de/eth/tracers/logger/logger.go#L406-L411>
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
@ -91,64 +91,55 @@ pub struct StructLog {
|
||||
pub error: Option<String>,
|
||||
}
|
||||
|
||||
/// Tracing response
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum GethTraceFrame {
|
||||
Default(DefaultFrame),
|
||||
NoopTracer(NoopFrame),
|
||||
FourByteTracer(FourByteFrame),
|
||||
CallTracer(CallFrame),
|
||||
PreStateTracer(PreStateFrame),
|
||||
JS(serde_json::Value),
|
||||
}
|
||||
|
||||
impl From<DefaultFrame> for GethTraceFrame {
|
||||
fn from(value: DefaultFrame) -> Self {
|
||||
GethTraceFrame::Default(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FourByteFrame> for GethTraceFrame {
|
||||
fn from(value: FourByteFrame) -> Self {
|
||||
GethTraceFrame::FourByteTracer(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CallFrame> for GethTraceFrame {
|
||||
fn from(value: CallFrame) -> Self {
|
||||
GethTraceFrame::CallTracer(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PreStateFrame> for GethTraceFrame {
|
||||
fn from(value: PreStateFrame) -> Self {
|
||||
GethTraceFrame::PreStateTracer(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<NoopFrame> for GethTraceFrame {
|
||||
fn from(value: NoopFrame) -> Self {
|
||||
GethTraceFrame::NoopTracer(value)
|
||||
}
|
||||
}
|
||||
|
||||
/// Tracing response objects
|
||||
///
|
||||
/// Note: This deserializes untagged, so it's possible that a custom javascript tracer response
|
||||
/// matches another variant, for example a js tracer that returns `{}` would be deserialized as
|
||||
/// [GethTrace::NoopTracer]
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum GethTrace {
|
||||
Known(GethTraceFrame),
|
||||
Unknown(serde_json::Value),
|
||||
/// The response for the default struct log tracer
|
||||
Default(DefaultFrame),
|
||||
/// The response for call tracer
|
||||
CallTracer(CallFrame),
|
||||
/// The response for four byte tracer
|
||||
FourByteTracer(FourByteFrame),
|
||||
/// The response for pre-state byte tracer
|
||||
PreStateTracer(PreStateFrame),
|
||||
/// An empty json response
|
||||
NoopTracer(NoopFrame),
|
||||
/// Any other trace response, such as custom javascript response objects
|
||||
JS(serde_json::Value),
|
||||
}
|
||||
|
||||
impl From<GethTraceFrame> for GethTrace {
|
||||
fn from(value: GethTraceFrame) -> Self {
|
||||
GethTrace::Known(value)
|
||||
impl From<DefaultFrame> for GethTrace {
|
||||
fn from(value: DefaultFrame) -> Self {
|
||||
GethTrace::Default(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<serde_json::Value> for GethTrace {
|
||||
fn from(value: serde_json::Value) -> Self {
|
||||
GethTrace::Unknown(value)
|
||||
impl From<FourByteFrame> for GethTrace {
|
||||
fn from(value: FourByteFrame) -> Self {
|
||||
GethTrace::FourByteTracer(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CallFrame> for GethTrace {
|
||||
fn from(value: CallFrame) -> Self {
|
||||
GethTrace::CallTracer(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PreStateFrame> for GethTrace {
|
||||
fn from(value: PreStateFrame) -> Self {
|
||||
GethTrace::PreStateTracer(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<NoopFrame> for GethTrace {
|
||||
fn from(value: NoopFrame) -> Self {
|
||||
GethTrace::NoopTracer(value)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
/// An empty frame response that's only an empty json object `{}`
|
||||
/// <https://github.com/ethereum/go-ethereum/blob/91cb6f863a965481e51d5d9c0e5ccd54796fd967/eth/tracers/native/noop.go#L34>
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct NoopFrame(BTreeMap<Null, Null>);
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, PartialOrd, Ord)]
|
||||
struct Null;
|
||||
|
||||
|
||||
@ -14,6 +14,7 @@ pub enum PreStateFrame {
|
||||
pub struct PreStateMode(pub BTreeMap<Address, AccountState>);
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct DiffMode {
|
||||
pub pre: BTreeMap<Address, AccountState>,
|
||||
pub post: BTreeMap<Address, AccountState>,
|
||||
|
||||
@ -26,8 +26,7 @@ use reth_rpc_api::DebugApiServer;
|
||||
use reth_rpc_types::{
|
||||
trace::geth::{
|
||||
BlockTraceResult, FourByteFrame, GethDebugBuiltInTracerType, GethDebugTracerType,
|
||||
GethDebugTracingCallOptions, GethDebugTracingOptions, GethTraceFrame, NoopFrame,
|
||||
TraceResult,
|
||||
GethDebugTracingCallOptions, GethDebugTracingOptions, GethTrace, NoopFrame, TraceResult,
|
||||
},
|
||||
BlockError, CallRequest, RichBlock,
|
||||
};
|
||||
@ -203,7 +202,7 @@ where
|
||||
&self,
|
||||
tx_hash: H256,
|
||||
opts: GethDebugTracingOptions,
|
||||
) -> EthResult<GethTraceFrame> {
|
||||
) -> EthResult<GethTrace> {
|
||||
let (transaction, block) = match self.inner.eth_api.transaction_and_block(tx_hash).await? {
|
||||
None => return Err(EthApiError::TransactionNotFound),
|
||||
Some(res) => res,
|
||||
@ -244,7 +243,7 @@ where
|
||||
call: CallRequest,
|
||||
block_id: Option<BlockId>,
|
||||
opts: GethDebugTracingCallOptions,
|
||||
) -> EthResult<GethTraceFrame> {
|
||||
) -> EthResult<GethTrace> {
|
||||
self.on_blocking_task(|this| async move {
|
||||
this.try_debug_trace_call(call, block_id, opts).await
|
||||
})
|
||||
@ -260,7 +259,7 @@ where
|
||||
call: CallRequest,
|
||||
block_id: Option<BlockId>,
|
||||
opts: GethDebugTracingCallOptions,
|
||||
) -> EthResult<GethTraceFrame> {
|
||||
) -> EthResult<GethTrace> {
|
||||
let at = block_id.unwrap_or(BlockId::Number(BlockNumberOrTag::Latest));
|
||||
let GethDebugTracingCallOptions { tracing_options, state_overrides, block_overrides } =
|
||||
opts;
|
||||
@ -319,7 +318,7 @@ where
|
||||
let (res, env) = inspect(db, env, &mut inspector)?;
|
||||
|
||||
let result = inspector.json_result(res, &env)?;
|
||||
Ok(GethTraceFrame::JS(result))
|
||||
Ok(GethTrace::JS(result))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -349,7 +348,7 @@ where
|
||||
env: Env,
|
||||
at: BlockId,
|
||||
db: &mut SubState<StateProviderBox<'_>>,
|
||||
) -> EthResult<(GethTraceFrame, revm_primitives::State)> {
|
||||
) -> EthResult<(GethTrace, revm_primitives::State)> {
|
||||
let GethDebugTracingOptions { config, tracer, tracer_config, .. } = opts;
|
||||
|
||||
if let Some(tracer) = tracer {
|
||||
@ -395,7 +394,7 @@ where
|
||||
|
||||
let state = res.state.clone();
|
||||
let result = inspector.json_result(res, &env)?;
|
||||
Ok((GethTraceFrame::JS(result), state))
|
||||
Ok((GethTrace::JS(result), state))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -598,7 +597,7 @@ where
|
||||
&self,
|
||||
tx_hash: H256,
|
||||
opts: Option<GethDebugTracingOptions>,
|
||||
) -> RpcResult<GethTraceFrame> {
|
||||
) -> RpcResult<GethTrace> {
|
||||
let _permit = self.acquire_trace_permit().await;
|
||||
Ok(DebugApi::debug_trace_transaction(self, tx_hash, opts.unwrap_or_default()).await?)
|
||||
}
|
||||
@ -609,7 +608,7 @@ where
|
||||
request: CallRequest,
|
||||
block_number: Option<BlockId>,
|
||||
opts: Option<GethDebugTracingCallOptions>,
|
||||
) -> RpcResult<GethTraceFrame> {
|
||||
) -> RpcResult<GethTrace> {
|
||||
let _permit = self.acquire_trace_permit().await;
|
||||
Ok(DebugApi::debug_trace_call(self, request, block_number, opts.unwrap_or_default())
|
||||
.await?)
|
||||
|
||||
Reference in New Issue
Block a user