Skip to content

Commit

Permalink
fix(inspect): respect empty --transpose-api-key, add `--skip-resolv…
Browse files Browse the repository at this point in the history
…ing` flag
  • Loading branch information
Jon-Becker committed Dec 13, 2023
1 parent 23addf5 commit 47f61ea
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
23 changes: 22 additions & 1 deletion core/src/inspect/core/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,29 @@ use heimdall_common::{resources::transpose::get_label, utils::hex::ToLowerHex};
pub struct Contracts {
pub contracts: HashMap<Address, String>,
transpose_api_key: Option<String>,
skip_resolving: bool,
}

#[allow(dead_code)]
impl Contracts {
pub fn new(args: &InspectArgs) -> Self {
Self { contracts: HashMap::new(), transpose_api_key: args.transpose_api_key.clone() }
Self {
contracts: HashMap::new(),
transpose_api_key: match args.transpose_api_key {
Some(ref key) if !key.is_empty() => Some(key.clone()),
_ => None,
},
skip_resolving: args.skip_resolving,
}
}

pub async fn add(&mut self, address: Address) -> Result<(), Error> {
// if skip resolving, just add the address
if self.skip_resolving {
self.contracts.insert(address, address.to_lower_hex());
return Ok(());
}

// if alias already exists, don't overwrite
if self.contracts.contains_key(&address) {
return Ok(());
Expand All @@ -39,6 +53,13 @@ impl Contracts {
}

pub async fn extend(&mut self, addresses: HashSet<Address>) -> Result<(), Error> {
// if skip resolving, just add the address
if self.skip_resolving {
self.contracts
.extend(addresses.into_iter().map(|address| (address, address.to_lower_hex())));
return Ok(());
}

// for each address, get the label
if let Some(transpose_api_key) = &self.transpose_api_key {
let handles: Vec<_> = addresses
Expand Down
5 changes: 5 additions & 0 deletions core/src/inspect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ pub struct InspectArgs {
/// The output directory to write the output to, or 'print' to print to the console.
#[clap(long = "output", short = 'o', default_value = "output", hide_default_value = true)]
pub output: String,

/// Whether to skip resolving function selectors and contract labels.
#[clap(long = "skip-resolving")]
pub skip_resolving: bool,
}

impl InspectArgsBuilder {
Expand All @@ -68,6 +72,7 @@ impl InspectArgsBuilder {
transpose_api_key: None,
name: Some(String::new()),
output: Some(String::from("output")),
skip_resolving: Some(false),
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions core/tests/test_inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod integration_tests {
transpose_api_key: None,
name: String::from(""),
output: String::from("output"),
skip_resolving: true,
};

let _ = heimdall_core::inspect::inspect(args).await.unwrap();
Expand All @@ -34,6 +35,7 @@ mod integration_tests {
transpose_api_key: None,
name: String::from(""),
output: String::from("output"),
skip_resolving: true,
};

let _ = heimdall_core::inspect::inspect(args).await.unwrap();
Expand Down Expand Up @@ -63,6 +65,7 @@ mod integration_tests {
.target(txid.to_string())
.verbose(Verbosity::new(-1, 0))
.rpc_url("https://eth.llamarpc.com".to_string())
.skip_resolving(true)
.build()
.unwrap();

Expand Down

0 comments on commit 47f61ea

Please sign in to comment.