From b01ffa29b9c72237bb87a1a1e38d2c4bc51c2b85 Mon Sep 17 00:00:00 2001 From: Jon-Becker Date: Tue, 12 Dec 2023 22:13:11 -0500 Subject: [PATCH] chore(inspect): `--transpose-api-key` should be `String`, not `Option` --- cli/src/main.rs | 4 ++-- core/src/inspect/core/contracts.rs | 18 ++++++++---------- core/src/inspect/mod.rs | 8 ++++---- core/tests/test_inspect.rs | 4 ++-- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index d710d85f..8f612dc8 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -345,8 +345,8 @@ async fn main() -> Result<(), Box> { } // if the user has not specified a transpose api key, use the default - if cmd.transpose_api_key.is_none() { - cmd.transpose_api_key = Some(configuration.transpose_api_key); + if cmd.transpose_api_key.is_empty() { + cmd.transpose_api_key = configuration.transpose_api_key; } // if the user has passed an output filename, override the default filename diff --git a/core/src/inspect/core/contracts.rs b/core/src/inspect/core/contracts.rs index a124f44b..bf251b2a 100644 --- a/core/src/inspect/core/contracts.rs +++ b/core/src/inspect/core/contracts.rs @@ -9,7 +9,7 @@ use heimdall_common::{resources::transpose::get_label, utils::hex::ToLowerHex}; #[derive(Debug, Clone)] pub struct Contracts { pub contracts: HashMap, - transpose_api_key: Option, + transpose_api_key: String, skip_resolving: bool, } @@ -18,10 +18,7 @@ impl Contracts { pub fn new(args: &InspectArgs) -> Self { Self { contracts: HashMap::new(), - transpose_api_key: match args.transpose_api_key { - Some(ref key) if !key.is_empty() => Some(key.clone()), - _ => None, - }, + transpose_api_key: args.transpose_api_key.clone(), skip_resolving: args.skip_resolving, } } @@ -38,10 +35,10 @@ impl Contracts { return Ok(()); } - if let Some(transpose_api_key) = &self.transpose_api_key { + if !self.transpose_api_key.is_empty() { self.contracts.insert( address, - get_label(&address.to_lower_hex(), transpose_api_key) + get_label(&address.to_lower_hex(), &self.transpose_api_key) .await .unwrap_or(address.to_lower_hex()), ); @@ -61,14 +58,15 @@ impl Contracts { } // for each address, get the label - if let Some(transpose_api_key) = &self.transpose_api_key { + if !self.transpose_api_key.is_empty() { + let transpose_api_key_clone = self.transpose_api_key.clone(); let handles: Vec<_> = addresses .clone() .into_iter() .map(move |address| { - let transpose_api_key = transpose_api_key.clone(); + let transpose_api_key_clone = transpose_api_key_clone.clone(); tokio::spawn(async move { - get_label(&address.to_lower_hex(), &transpose_api_key).await + get_label(&address.to_lower_hex(), &transpose_api_key_clone).await }) }) .collect(); diff --git a/core/src/inspect/mod.rs b/core/src/inspect/mod.rs index b9d9c318..2bc37821 100644 --- a/core/src/inspect/mod.rs +++ b/core/src/inspect/mod.rs @@ -46,9 +46,9 @@ pub struct InspectArgs { #[clap(long, short)] pub default: bool, - /// Your OPTIONAL Transpose.io API Key, used for labeling contract addresses. - #[clap(long = "transpose-api-key", short, hide_default_value = true)] - pub transpose_api_key: Option, + /// Your OPTIONAL Transpose.io API Key. Used to resolve contract labels. + #[clap(long = "transpose-api-key", short, default_value = "", hide_default_value = true)] + pub transpose_api_key: String, /// Name for the output files. #[clap(long, short, default_value = "", hide_default_value = true)] @@ -70,7 +70,7 @@ impl InspectArgsBuilder { verbose: Some(clap_verbosity_flag::Verbosity::new(0, 1)), rpc_url: Some(String::new()), default: Some(true), - transpose_api_key: None, + transpose_api_key: Some(String::new()), 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 63339955..c3bca568 100644 --- a/core/tests/test_inspect.rs +++ b/core/tests/test_inspect.rs @@ -14,7 +14,7 @@ mod integration_tests { verbose: Verbosity::new(0, 0), rpc_url: String::from("https://eth.llamarpc.com"), default: true, - transpose_api_key: None, + transpose_api_key: String::from(""), name: String::from(""), output: String::from("output"), skip_resolving: true, @@ -32,7 +32,7 @@ mod integration_tests { verbose: Verbosity::new(0, 0), rpc_url: String::from("https://eth.llamarpc.com"), default: true, - transpose_api_key: None, + transpose_api_key: String::from(""), name: String::from(""), output: String::from("output"), skip_resolving: true,