From c11ee2a88b786165e27f7b455e36a1ac09afe0e4 Mon Sep 17 00:00:00 2001 From: ilya Date: Mon, 24 Jun 2024 11:11:06 +0100 Subject: [PATCH] Blockscout API key (#2788) --- crates/shared/src/bad_token/token_owner_finder.rs | 9 +++++++++ .../src/bad_token/token_owner_finder/blockscout.rs | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/crates/shared/src/bad_token/token_owner_finder.rs b/crates/shared/src/bad_token/token_owner_finder.rs index 34058221e5..8a81e39231 100644 --- a/crates/shared/src/bad_token/token_owner_finder.rs +++ b/crates/shared/src/bad_token/token_owner_finder.rs @@ -79,6 +79,10 @@ pub struct Arguments { #[clap(long, env)] pub blockscout_api_url: Option, + /// The blockscout API key. + #[clap(long, env)] + pub blockscout_api_key: Option, + /// Override the default ethplorer API url #[clap(long, env)] pub ethplorer_api_url: Option, @@ -169,6 +173,7 @@ impl Display for Arguments { token_owner_finders, token_owner_finder_uniswap_v3_fee_values, blockscout_api_url, + blockscout_api_key, ethplorer_api_url, ethplorer_api_key, token_owner_finder_rate_limiter, @@ -184,6 +189,7 @@ impl Display for Arguments { token_owner_finder_uniswap_v3_fee_values )?; display_option(f, "blockscout_api_url", blockscout_api_url)?; + display_secret_option(f, "blockscout_api_key", blockscout_api_key)?; display_option(f, "ethplorer_api_url", ethplorer_api_url)?; display_secret_option(f, "ethplorer_api_key", ethplorer_api_key)?; display_option( @@ -256,6 +262,9 @@ pub async fn init( if let Some(base_url) = args.blockscout_api_url.clone() { blockscout.with_base_url(base_url); } + if let Some(api_key) = args.blockscout_api_key.clone() { + blockscout.with_api_key(api_key); + } if let Some(strategy) = args.token_owner_finder_rate_limiter.clone() { blockscout.with_rate_limiter(strategy); } diff --git a/crates/shared/src/bad_token/token_owner_finder/blockscout.rs b/crates/shared/src/bad_token/token_owner_finder/blockscout.rs index e2c653107b..b294826cab 100644 --- a/crates/shared/src/bad_token/token_owner_finder/blockscout.rs +++ b/crates/shared/src/bad_token/token_owner_finder/blockscout.rs @@ -12,6 +12,7 @@ use { pub struct BlockscoutTokenOwnerFinder { client: Client, base: Url, + api_key: Option, rate_limiter: Option, } @@ -29,6 +30,7 @@ impl BlockscoutTokenOwnerFinder { Ok(Self { client, base: Url::parse(base_url)?, + api_key: None, rate_limiter: None, }) } @@ -38,6 +40,11 @@ impl BlockscoutTokenOwnerFinder { self } + pub fn with_api_key(&mut self, api_key: String) -> &mut Self { + self.api_key = Some(api_key); + self + } + pub fn with_rate_limiter(&mut self, strategy: Strategy) -> &mut Self { self.rate_limiter = Some(RateLimiter::from_strategy( strategy, @@ -53,8 +60,13 @@ impl BlockscoutTokenOwnerFinder { .append_pair("action", "getTokenHolders") .append_pair("contractaddress", &format!("{token:#x}")); + // Don't log the API key! tracing::debug!(%url, "Querying Blockscout API"); + if let Some(api_key) = &self.api_key { + url.query_pairs_mut().append_pair("apikey", api_key); + } + let request = self.client.get(url).send(); let response = match &self.rate_limiter { Some(limiter) => limiter.execute(request, back_off::on_http_429).await??,