Skip to content

Commit

Permalink
chore: add some geth tracer ergonomics
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Oct 8, 2023
1 parent 98bc2b5 commit 8d1cf02
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
14 changes: 14 additions & 0 deletions crates/rpc/rpc-types/src/eth/trace/geth/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ pub struct CallConfig {
pub with_log: Option<bool>,
}

impl CallConfig {
/// Sets the only top call flag
pub fn only_top_call(mut self) -> Self {
self.only_top_call = Some(true);
self
}

/// Sets the with log flag
pub fn with_log(mut self) -> Self {
self.with_log = Some(true);
self
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
36 changes: 35 additions & 1 deletion crates/rpc/rpc-types/src/eth/trace/geth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::{state::StateOverride, BlockOverrides};
use reth_primitives::{Bytes, B256, U256};
use serde::{de::DeserializeOwned, ser::SerializeMap, Deserialize, Serialize, Serializer};
use std::collections::BTreeMap;
use std::{collections::BTreeMap, time::Duration};

// re-exports
pub use self::{
Expand Down Expand Up @@ -186,6 +186,12 @@ pub enum GethDebugTracerType {
JsTracer(String),
}

impl From<GethDebugBuiltInTracerType> for GethDebugTracerType {
fn from(value: GethDebugBuiltInTracerType) -> Self {
GethDebugTracerType::BuiltInTracer(value)
}
}

/// Configuration of the tracer
///
/// This is a simple wrapper around serde_json::Value.
Expand Down Expand Up @@ -264,6 +270,34 @@ pub struct GethDebugTracingOptions {
pub timeout: Option<String>,
}

impl GethDebugTracingOptions {
/// Sets the tracer to use
pub fn with_tracer(mut self, tracer: GethDebugTracerType) -> Self {
self.tracer = Some(tracer);
self
}

/// Sets the timeout to use for tracing
pub fn with_timeout(mut self, duration: Duration) -> Self {
self.timeout = Some(format!("{}ms", duration.as_millis()));
self
}

/// Configures a [CallConfig]
pub fn call_config(mut self, config: CallConfig) -> Self {
self.tracer_config =
GethDebugTracerConfig(serde_json::to_value(config).expect("is serializable"));
self
}

/// Configures a [PreStateConfig]
pub fn prestate_config(mut self, config: PreStateConfig) -> Self {
self.tracer_config =
GethDebugTracerConfig(serde_json::to_value(config).expect("is serializable"));
self
}
}

/// Default tracing options for the struct looger.
///
/// These are all known general purpose tracer options that may or not be supported by a given
Expand Down

0 comments on commit 8d1cf02

Please sign in to comment.