Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(decode): dont output trace if --quiet is set #351

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ use heimdall_cache::{cache, CacheArgs};
use heimdall_common::{
fatal, info,
utils::{
io::file::{write_file, write_lines_to_file},
io::{
file::{write_file, write_lines_to_file},
logging::set_logger_env,
},
version::{current_version, remote_version},
},
};
Expand Down Expand Up @@ -112,6 +115,9 @@ async fn main() -> Result<(), Error> {
.map_err(|e| Error::Generic(format!("failed to load configuration: {}", e)))?;
match args.sub {
Subcommands::Disassemble(mut cmd) => {
// set logger env
set_logger_env(&cmd.verbose);

// if the user has not specified a rpc url, use the default
if cmd.rpc_url.as_str() == "" {
cmd.rpc_url = configuration.rpc_url;
Expand Down Expand Up @@ -147,6 +153,9 @@ async fn main() -> Result<(), Error> {
}

Subcommands::Decompile(mut cmd) => {
// set logger env
set_logger_env(&cmd.verbose);

// if the user has not specified a rpc url, use the default
if cmd.rpc_url.as_str() == "" {
cmd.rpc_url = configuration.rpc_url;
Expand Down Expand Up @@ -265,6 +274,9 @@ async fn main() -> Result<(), Error> {
}

Subcommands::Decode(mut cmd) => {
// set logger env
set_logger_env(&cmd.verbose);

// if the user has not specified a rpc url, use the default
if cmd.rpc_url.as_str() == "" {
cmd.rpc_url = configuration.rpc_url;
Expand All @@ -284,6 +296,9 @@ async fn main() -> Result<(), Error> {
}

Subcommands::CFG(mut cmd) => {
// set logger env
set_logger_env(&cmd.verbose);

// if the user has not specified a rpc url, use the default
if cmd.rpc_url.as_str() == "" {
cmd.rpc_url = configuration.rpc_url;
Expand Down Expand Up @@ -318,6 +333,9 @@ async fn main() -> Result<(), Error> {
}

Subcommands::Dump(mut cmd) => {
// set logger env
set_logger_env(&cmd.verbose);

// if the user has not specified a rpc url, use the default
if cmd.rpc_url.as_str() == "" {
cmd.rpc_url = configuration.rpc_url;
Expand Down Expand Up @@ -370,6 +388,9 @@ async fn main() -> Result<(), Error> {
}

Subcommands::Snapshot(mut cmd) => {
// set logger env
set_logger_env(&cmd.verbose);

// if the user has not specified a rpc url, use the default
if cmd.rpc_url.as_str() == "" {
cmd.rpc_url = configuration.rpc_url;
Expand Down Expand Up @@ -410,6 +431,9 @@ async fn main() -> Result<(), Error> {
}

Subcommands::Inspect(mut cmd) => {
// set logger env
set_logger_env(&cmd.verbose);

// if the user has not specified a rpc url, use the default
if cmd.rpc_url.as_str() == "" {
cmd.rpc_url = configuration.rpc_url;
Expand Down
1 change: 0 additions & 1 deletion core/src/cfg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ pub async fn cfg(args: CFGArgs) -> Result<Graph<String, String>, Error> {
use std::time::Instant;
let now = Instant::now();

set_logger_env(&args.verbose);
let mut trace = TraceFactory::default();

// add the call to the trace
Expand Down
8 changes: 4 additions & 4 deletions core/src/decode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use heimdall_common::{
info_spinner, success,
utils::{
io::{
logging::{set_logger_env, Logger, TraceFactory},
logging::{Logger, TraceFactory},
types::display,
},
strings::{encode_hex, StringExt},
Expand Down Expand Up @@ -100,8 +100,6 @@ impl DecodeArgsBuilder {
/// calldata, without the ABI of the target contract.
#[allow(deprecated)]
pub async fn decode(args: DecodeArgs) -> Result<Vec<ResolvedFunction>, Error> {
set_logger_env(&args.verbose);

// get a new logger and trace
let logger = Logger::default();
let mut trace = TraceFactory::default();
Expand Down Expand Up @@ -351,7 +349,9 @@ pub async fn decode(args: DecodeArgs) -> Result<Vec<ResolvedFunction>, Error> {
}

// display trace (pretty print decoded calldata)
trace.display();
if args.verbose.log_level().is_some() {
trace.display();
}

if args.explain {
// get a new progress bar
Expand Down
2 changes: 0 additions & 2 deletions core/src/decompile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ pub async fn decompile(args: DecompilerArgs) -> Result<DecompileResult, Error> {
use std::time::Instant;
let now = Instant::now();

set_logger_env(&args.verbose);

// get a new logger
let logger = Logger::default();
let mut trace = TraceFactory::default();
Expand Down
4 changes: 1 addition & 3 deletions core/src/disassemble/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use heimdall_common::{
debug,
ether::{bytecode::get_bytecode_from_target, evm::core::opcodes::Opcode},
info,
utils::{io::logging::set_logger_env, strings::encode_hex},
utils::strings::encode_hex,
};
use heimdall_config::parse_url_arg;

Expand Down Expand Up @@ -60,8 +60,6 @@ pub async fn disassemble(args: DisassemblerArgs) -> Result<String, Error> {
use std::time::Instant;
let now = Instant::now();

set_logger_env(&args.verbose);

let contract_bytecode = get_bytecode_from_target(&args.target, &args.rpc_url)
.await
.map_err(|e| Error::Generic(format!("failed to get bytecode from target: {}", e)))?;
Expand Down
3 changes: 0 additions & 3 deletions core/src/dump/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use ethers::types::H160;
use heimdall_common::{
error, info,
resources::transpose::{get_contract_creation, get_transaction_list},
utils::io::logging::*,
};
use heimdall_config::parse_url_arg;
use std::{collections::HashMap, env, str::FromStr, time::Instant};
Expand Down Expand Up @@ -99,8 +98,6 @@ impl DumpArgsBuilder {
/// entry point for the dump module. Will fetch all storage slots accessed by the target contract,
/// and dump them to a CSV file or the TUI.
pub async fn dump(args: DumpArgs) -> Result<Vec<DumpRow>, Error> {
set_logger_env(&args.verbose);

// parse the output directory
let mut output_dir = args.output.clone();
if args.output.is_empty() {
Expand Down
2 changes: 2 additions & 0 deletions core/src/inspect/core/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ impl TryFrom<Call> for DecodedCall {
.parse::<bool>()
.unwrap_or(false),
)
.verbose(clap_verbosity_flag::Verbosity::new(0, 1))
.build()
.map_err(|_e| Error::DecodeError)?,
)
Expand Down Expand Up @@ -240,6 +241,7 @@ impl TryFrom<CallResult> for DecodedCallResult {
DecodeArgsBuilder::new()
.target(output)
.skip_resolving(true)
.verbose(clap_verbosity_flag::Verbosity::new(0, 1))
.build()
.map_err(|_e| Error::DecodeError)?,
)
Expand Down
8 changes: 1 addition & 7 deletions core/src/inspect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ use futures::future::try_join_all;
use heimdall_common::{
debug_max,
ether::rpc::{get_block_logs, get_trace, get_transaction},
utils::{
env::set_env,
hex::ToLowerHex,
io::logging::{set_logger_env, TraceFactory},
},
utils::{env::set_env, hex::ToLowerHex, io::logging::TraceFactory},
warn,
};
use heimdall_config::parse_url_arg;
Expand Down Expand Up @@ -90,8 +86,6 @@ pub struct InspectResult {
/// visualization, and more.
#[allow(deprecated)]
pub async fn inspect(args: InspectArgs) -> Result<InspectResult, Error> {
set_logger_env(&args.verbose);

// 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());
Expand Down
3 changes: 0 additions & 3 deletions core/src/snapshot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ pub struct SnapshotResult {
/// signatures, access control, gas consumption, storage accesses, event emissions, and more.
pub async fn snapshot(args: SnapshotArgs) -> Result<SnapshotResult, Error> {
use std::time::Instant;

set_logger_env(&args.verbose);

let now = Instant::now();
let mut trace = TraceFactory::default();
let snapshot_call = trace.add_call(
Expand Down
Loading