Skip to content

Commit

Permalink
chore(inspect): pass --skip-resolving to tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-Becker committed Dec 13, 2023
1 parent 47f61ea commit b953442
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 17 deletions.
9 changes: 9 additions & 0 deletions common/src/utils/env.rs
Original file line number Diff line number Diff line change
@@ -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<String> {
std::env::var(key).ok()
}
1 change: 1 addition & 0 deletions common/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod env;
pub mod hex;
pub mod http;
pub mod integers;
Expand Down
40 changes: 24 additions & 16 deletions core/src/inspect/core/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -74,21 +74,29 @@ impl TryFrom<Log> for DecodedLog {
type Error = crate::error::Error;

async fn try_from(value: Log) -> Result<Self, Self::Error> {
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::<bool>()
.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,
Expand Down
7 changes: 7 additions & 0 deletions core/src/inspect/core/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use ethers::{
use heimdall_common::{
ether::signatures::ResolvedFunction,
utils::{
env::get_env,
hex::ToLowerHex,
io::{logging::TraceFactory, types::Parameterize},
},
Expand Down Expand Up @@ -196,6 +197,12 @@ impl TryFrom<Call> for DecodedCall {
let result = crate::decode::decode(
DecodeArgsBuilder::new()
.target(calldata)
.skip_resolving(
get_env("SKIP_RESOLVING")
.unwrap_or("false".to_string())
.parse::<bool>()
.unwrap_or(false),
)
.build()
.map_err(|_e| Error::DecodeError)?,
)
Expand Down
6 changes: 5 additions & 1 deletion core/src/inspect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
Expand Down Expand Up @@ -87,7 +88,6 @@ pub struct InspectResult {
#[allow(deprecated)]
pub async fn inspect(args: InspectArgs) -> Result<InspectResult, Error> {
// 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",
Expand All @@ -98,6 +98,10 @@ pub async fn inspect(args: InspectArgs) -> Result<InspectResult, Error> {
);
}

// 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(),
Expand Down

0 comments on commit b953442

Please sign in to comment.