mod call;
mod four_byte;
mod noop;
mod pre_state;
pub use self::{
call::{CallConfig, CallFrame, CallLogFrame},
four_byte::FourByteFrame,
noop::NoopFrame,
pre_state::{PreStateConfig, PreStateFrame},
};
use crate::{
types::{Bytes, H256, U256},
utils::from_int_or_hex,
};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::BTreeMap;
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct DefaultFrame {
pub failed: bool,
#[serde(deserialize_with = "from_int_or_hex")]
pub gas: U256,
#[serde(rename = "returnValue")]
pub return_value: Bytes,
#[serde(rename = "structLogs")]
pub struct_logs: Vec<StructLog>,
}
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct StructLog {
pub depth: u64,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub error: Option<String>,
pub gas: u64,
#[serde(rename = "gasCost")]
pub gas_cost: u64,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub memory: Option<Vec<String>>,
pub op: String,
pub pc: u64,
#[serde(default, rename = "refund", skip_serializing_if = "Option::is_none")]
pub refund_counter: Option<u64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub stack: Option<Vec<U256>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub storage: Option<BTreeMap<H256, H256>>,
}
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum GethTraceFrame {
Default(DefaultFrame),
NoopTracer(NoopFrame),
FourByteTracer(FourByteFrame),
CallTracer(CallFrame),
PreStateTracer(PreStateFrame),
}
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)
}
}
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum GethTrace {
Known(GethTraceFrame),
Unknown(Value),
}
impl From<GethTraceFrame> for GethTrace {
fn from(value: GethTraceFrame) -> Self {
GethTrace::Known(value)
}
}
impl From<Value> for GethTrace {
fn from(value: Value) -> Self {
GethTrace::Unknown(value)
}
}
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
pub enum GethDebugBuiltInTracerType {
#[serde(rename = "4byteTracer")]
FourByteTracer,
#[serde(rename = "callTracer")]
CallTracer,
#[serde(rename = "prestateTracer")]
PreStateTracer,
#[serde(rename = "noopTracer")]
NoopTracer,
}
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum GethDebugBuiltInTracerConfig {
CallTracer(CallConfig),
PreStateTracer(PreStateConfig),
}
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum GethDebugTracerType {
BuiltInTracer(GethDebugBuiltInTracerType),
JsTracer(String),
}
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum GethDebugTracerConfig {
BuiltInTracer(GethDebugBuiltInTracerConfig),
JsTracer(Value),
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct GethDebugTracingOptions {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub disable_storage: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub disable_stack: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub enable_memory: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub enable_return_data: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub tracer: Option<GethDebugTracerType>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub tracer_config: Option<GethDebugTracerConfig>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub timeout: Option<String>,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct GethDebugTracingCallOptions {
#[serde(flatten)]
pub tracing_options: GethDebugTracingOptions,
}