From 47f61ea0b6e4c3772dfd9772945d0ae49a97a13b Mon Sep 17 00:00:00 2001 From: Jon-Becker Date: Tue, 12 Dec 2023 21:46:55 -0500 Subject: [PATCH] fix(inspect): respect empty `--transpose-api-key`, add `--skip-resolving` flag --- core/src/inspect/core/contracts.rs | 23 ++++++++++++++++++++++- core/src/inspect/mod.rs | 5 +++++ core/tests/test_inspect.rs | 3 +++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/core/src/inspect/core/contracts.rs b/core/src/inspect/core/contracts.rs index 58cd8b84..a124f44b 100644 --- a/core/src/inspect/core/contracts.rs +++ b/core/src/inspect/core/contracts.rs @@ -10,15 +10,29 @@ use heimdall_common::{resources::transpose::get_label, utils::hex::ToLowerHex}; pub struct Contracts { pub contracts: HashMap, transpose_api_key: Option, + 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(()); @@ -39,6 +53,13 @@ impl Contracts { } pub async fn extend(&mut self, addresses: HashSet
) -> 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 diff --git a/core/src/inspect/mod.rs b/core/src/inspect/mod.rs index a9c2f1b6..65ffaecb 100644 --- a/core/src/inspect/mod.rs +++ b/core/src/inspect/mod.rs @@ -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 { @@ -68,6 +72,7 @@ impl InspectArgsBuilder { transpose_api_key: None, name: Some(String::new()), output: Some(String::from("output")), + skip_resolving: Some(false), } } } diff --git a/core/tests/test_inspect.rs b/core/tests/test_inspect.rs index 28689534..63339955 100644 --- a/core/tests/test_inspect.rs +++ b/core/tests/test_inspect.rs @@ -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(); @@ -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(); @@ -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();