From 53b2d45d19c4272a355ae2fadd0fc579c9a920cc Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 5 Oct 2024 14:56:40 +0200 Subject: [PATCH] feat: add helpers to configure GethDebugTracingOptions properly --- crates/rpc-types-trace/src/geth/mod.rs | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/crates/rpc-types-trace/src/geth/mod.rs b/crates/rpc-types-trace/src/geth/mod.rs index 48cee5bc61c..be94c42375d 100644 --- a/crates/rpc-types-trace/src/geth/mod.rs +++ b/crates/rpc-types-trace/src/geth/mod.rs @@ -374,6 +374,11 @@ impl From for GethDebugTracerConfig { Self(serde_json::to_value(value).expect("is serializable")) } } +impl From for GethDebugTracerConfig { + fn from(value: FlatCallConfig) -> Self { + Self(serde_json::to_value(value).expect("is serializable")) + } +} impl From for GethDebugTracerConfig { fn from(value: PreStateConfig) -> Self { @@ -418,12 +423,47 @@ pub struct GethDebugTracingOptions { } impl GethDebugTracingOptions { + /// Creates a new instance with given [`GethDebugTracerType`] configured + pub fn new_tracer(tracer: impl Into) -> Self { + Self::default().with_tracer(tracer.into()) + } + /// Sets the tracer to use pub fn with_tracer(mut self, tracer: GethDebugTracerType) -> Self { self.tracer = Some(tracer); self } + /// Creates new Options for [`GethDebugBuiltInTracerType::CallTracer`]. + pub fn call_tracer(config: CallConfig) -> Self { + Self::new_tracer(GethDebugBuiltInTracerType::CallTracer).with_call_config(config) + } + + /// Creates new Options for [`GethDebugBuiltInTracerType::FlatCallTracer`]. + pub fn flat_call_tracer(config: FlatCallConfig) -> Self { + Self::new_tracer(GethDebugBuiltInTracerType::FlatCallTracer).with_config(config) + } + + /// Creates new Options for [`GethDebugBuiltInTracerType::MuxTracer`]. + pub fn mux_tracer(config: MuxConfig) -> Self { + Self::new_tracer(GethDebugBuiltInTracerType::MuxTracer).with_config(config) + } + + /// Creates new options for [`GethDebugBuiltInTracerType::PreStateTracer`] + pub fn prestate_tracer(config: PreStateConfig) -> Self { + Self::new_tracer(GethDebugBuiltInTracerType::PreStateTracer).with_prestate_config(config) + } + + /// Creates new options for [`GethDebugBuiltInTracerType::FourByteTracer`] + pub fn four_byte_tracer() -> Self { + Self::new_tracer(GethDebugBuiltInTracerType::FourByteTracer) + } + + /// Creates an [`GethDebugTracerType::JsTracer`] with the given js code. + pub fn js_tracer(code: impl Into) -> Self { + Self::new_tracer(GethDebugTracerType::JsTracer(code.into())) + } + /// Sets the timeout to use for tracing pub fn with_timeout(mut self, duration: Duration) -> Self { self.timeout = Some(format!("{}ms", duration.as_millis()));