chore: add some geth tracer ergonomics (#4952)

This commit is contained in:
Matthias Seitz
2023-10-08 19:37:16 +02:00
committed by GitHub
parent 98bc2b5c84
commit 18c4891238
2 changed files with 49 additions and 1 deletions

View File

@ -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::*;

View File

@ -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::{
@ -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.
@ -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