Skip to content

Commit

Permalink
chore(inspect): --transpose-api-key should be String, not Option
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-Becker committed Dec 13, 2023
1 parent b953442 commit b01ffa2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
4 changes: 2 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}

// 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
Expand Down
18 changes: 8 additions & 10 deletions core/src/inspect/core/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use heimdall_common::{resources::transpose::get_label, utils::hex::ToLowerHex};
#[derive(Debug, Clone)]
pub struct Contracts {
pub contracts: HashMap<Address, String>,
transpose_api_key: Option<String>,
transpose_api_key: String,
skip_resolving: bool,
}

Expand All @@ -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,
}
}
Expand All @@ -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()),
);
Expand All @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions core/src/inspect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// 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)]
Expand All @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions core/tests/test_inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit b01ffa2

Please sign in to comment.