From b9534422a0b2c4b6999e7883eaa4cafde6917742 Mon Sep 17 00:00:00 2001 From: Jon-Becker Date: Tue, 12 Dec 2023 21:58:46 -0500 Subject: [PATCH] chore(inspect): pass `--skip-resolving` to tracing --- common/src/utils/env.rs | 9 +++++++ common/src/utils/mod.rs | 1 + core/src/inspect/core/logs.rs | 40 +++++++++++++++++++------------- core/src/inspect/core/tracing.rs | 7 ++++++ core/src/inspect/mod.rs | 6 ++++- 5 files changed, 46 insertions(+), 17 deletions(-) create mode 100644 common/src/utils/env.rs diff --git a/common/src/utils/env.rs b/common/src/utils/env.rs new file mode 100644 index 00000000..3ab61cd1 --- /dev/null +++ b/common/src/utils/env.rs @@ -0,0 +1,9 @@ +pub fn set_env(key: &str, value: &str) { + if std::env::var(key).is_err() { + std::env::set_var(key, value); + } +} + +pub fn get_env(key: &str) -> Option { + std::env::var(key).ok() +} diff --git a/common/src/utils/mod.rs b/common/src/utils/mod.rs index c817f031..d1de2976 100644 --- a/common/src/utils/mod.rs +++ b/common/src/utils/mod.rs @@ -1,3 +1,4 @@ +pub mod env; pub mod hex; pub mod http; pub mod integers; diff --git a/core/src/inspect/core/logs.rs b/core/src/inspect/core/logs.rs index 52f1ebf7..93a52808 100644 --- a/core/src/inspect/core/logs.rs +++ b/core/src/inspect/core/logs.rs @@ -3,7 +3,7 @@ use ethers::types::{Address, Bytes, Log, H256, U256, U64}; use heimdall_common::{ debug_max, ether::signatures::{ResolveSelector, ResolvedLog}, - utils::hex::ToLowerHex, + utils::{env::get_env, hex::ToLowerHex}, }; use serde::{Deserialize, Serialize}; @@ -74,21 +74,29 @@ impl TryFrom for DecodedLog { type Error = crate::error::Error; async fn try_from(value: Log) -> Result { - let signature = match value.topics.first() { - Some(topic) => { - let topic = topic.to_lower_hex(); - Some(topic) - } - None => None, - }; - - let resolved_logs = match signature { - Some(signature) => { - debug_max!("resolving signature: {}", signature.to_string().to_lowercase()); - ResolvedLog::resolve(&signature).await.unwrap_or(Vec::new()) - } - None => Vec::new(), - }; + let mut resolved_logs = Vec::new(); + let skip_resolving = get_env("SKIP_RESOLVING") + .unwrap_or("false".to_string()) + .parse::() + .unwrap_or(false); + + if !skip_resolving { + let signature = match value.topics.first() { + Some(topic) => { + let topic = topic.to_lower_hex(); + Some(topic) + } + None => None, + }; + + resolved_logs = match signature { + Some(signature) => { + debug_max!("resolving signature: {}", signature.to_string().to_lowercase()); + ResolvedLog::resolve(&signature).await.unwrap_or(Vec::new()) + } + None => Vec::new(), + }; + } Ok(Self { address: value.address, diff --git a/core/src/inspect/core/tracing.rs b/core/src/inspect/core/tracing.rs index 5ef0c680..3ea3364e 100644 --- a/core/src/inspect/core/tracing.rs +++ b/core/src/inspect/core/tracing.rs @@ -14,6 +14,7 @@ use ethers::{ use heimdall_common::{ ether::signatures::ResolvedFunction, utils::{ + env::get_env, hex::ToLowerHex, io::{logging::TraceFactory, types::Parameterize}, }, @@ -196,6 +197,12 @@ impl TryFrom for DecodedCall { let result = crate::decode::decode( DecodeArgsBuilder::new() .target(calldata) + .skip_resolving( + get_env("SKIP_RESOLVING") + .unwrap_or("false".to_string()) + .parse::() + .unwrap_or(false), + ) .build() .map_err(|_e| Error::DecodeError)?, ) diff --git a/core/src/inspect/mod.rs b/core/src/inspect/mod.rs index 65ffaecb..b9d9c318 100644 --- a/core/src/inspect/mod.rs +++ b/core/src/inspect/mod.rs @@ -12,6 +12,7 @@ use heimdall_common::{ debug_max, ether::rpc::{get_block_logs, get_trace, get_transaction}, utils::{ + env::set_env, hex::ToLowerHex, io::logging::{Logger, TraceFactory}, }, @@ -87,7 +88,6 @@ pub struct InspectResult { #[allow(deprecated)] pub async fn inspect(args: InspectArgs) -> Result { // set logger environment variable if not already set - // TODO: abstract this to a heimdall_common util if std::env::var("RUST_LOG").is_err() { std::env::set_var( "RUST_LOG", @@ -98,6 +98,10 @@ pub async fn inspect(args: InspectArgs) -> Result { ); } + // set skip_resolving env variable + // TODO: create a trait that can be added to a struct to set env variables + set_env("SKIP_RESOLVING", &args.skip_resolving.to_string()); + // get a new logger and trace let (logger, _trace) = Logger::new(match args.verbose.log_level() { Some(level) => level.as_str(),