From d7ad0501c9374acc661252f186fe4dbc6ce0d0dd Mon Sep 17 00:00:00 2001 From: grandizzy Date: Wed, 13 Nov 2024 14:43:52 +0200 Subject: [PATCH 1/4] feat(forge): allow `--verifier custom` option --- crates/common/src/retry.rs | 3 ++- crates/verify/src/provider.rs | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/common/src/retry.rs b/crates/common/src/retry.rs index 7f649c7ed35a..606c47e31286 100644 --- a/crates/common/src/retry.rs +++ b/crates/common/src/retry.rs @@ -83,6 +83,7 @@ impl Retry { fn handle_err(&mut self, err: Error) { self.retries -= 1; - warn!("erroneous attempt ({} tries remaining): {}", self.retries, err.root_cause()); + let _ = + sh_warn!("erroneous attempt ({} tries remaining): {}", self.retries, err.root_cause()); } } diff --git a/crates/verify/src/provider.rs b/crates/verify/src/provider.rs index 6e5b29d5e34c..8220c1928b93 100644 --- a/crates/verify/src/provider.rs +++ b/crates/verify/src/provider.rs @@ -124,6 +124,7 @@ impl FromStr for VerificationProviderType { "s" | "sourcify" => Ok(Self::Sourcify), "b" | "blockscout" => Ok(Self::Blockscout), "o" | "oklink" => Ok(Self::Oklink), + "c" | "custom" => Ok(Self::Custom), _ => Err(format!("Unknown provider: {s}")), } } @@ -144,6 +145,9 @@ impl fmt::Display for VerificationProviderType { Self::Oklink => { write!(f, "oklink")?; } + Self::Custom => { + write!(f, "custom")?; + } }; Ok(()) } @@ -156,6 +160,7 @@ pub enum VerificationProviderType { Sourcify, Blockscout, Oklink, + Custom, } impl VerificationProviderType { @@ -171,6 +176,7 @@ impl VerificationProviderType { Self::Sourcify => Ok(Box::::default()), Self::Blockscout => Ok(Box::::default()), Self::Oklink => Ok(Box::::default()), + Self::Custom => Ok(Box::::default()), } } } From 3a9b873127b3915f4ad24c9006ee6476d525344f Mon Sep 17 00:00:00 2001 From: grandizzy Date: Wed, 13 Nov 2024 18:43:30 +0200 Subject: [PATCH 2/4] Changes after review: add description of custom verifier, reorg err message, add custom verifier api key --- crates/common/src/retry.rs | 3 +-- crates/verify/src/bytecode.rs | 5 +++++ crates/verify/src/provider.rs | 1 + crates/verify/src/verify.rs | 15 ++++++++++++++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/crates/common/src/retry.rs b/crates/common/src/retry.rs index 606c47e31286..59ba2055f8a3 100644 --- a/crates/common/src/retry.rs +++ b/crates/common/src/retry.rs @@ -83,7 +83,6 @@ impl Retry { fn handle_err(&mut self, err: Error) { self.retries -= 1; - let _ = - sh_warn!("erroneous attempt ({} tries remaining): {}", self.retries, err.root_cause()); + let _ = sh_warn!("{} ({} tries remaining)", err.root_cause(), self.retries); } } diff --git a/crates/verify/src/bytecode.rs b/crates/verify/src/bytecode.rs index a8fc1ace7066..0c3f9e5b0a91 100644 --- a/crates/verify/src/bytecode.rs +++ b/crates/verify/src/bytecode.rs @@ -96,6 +96,11 @@ impl figment::Provider for VerifyBytecodeArgs { &self, ) -> Result, figment::Error> { let mut dict = self.etherscan.dict(); + + if let Some(api_key) = &self.verifier.verifier_api_key { + dict.insert("etherscan_api_key".into(), api_key.as_str().into()); + } + if let Some(block) = &self.block { dict.insert("block".into(), figment::value::Value::serialize(block)?); } diff --git a/crates/verify/src/provider.rs b/crates/verify/src/provider.rs index 8220c1928b93..bb860288ce2b 100644 --- a/crates/verify/src/provider.rs +++ b/crates/verify/src/provider.rs @@ -160,6 +160,7 @@ pub enum VerificationProviderType { Sourcify, Blockscout, Oklink, + /// Custom verifier type, compatible with Etherscan API. Custom, } diff --git a/crates/verify/src/verify.rs b/crates/verify/src/verify.rs index 5f3e55329d88..3455b0e4f247 100644 --- a/crates/verify/src/verify.rs +++ b/crates/verify/src/verify.rs @@ -31,6 +31,10 @@ pub struct VerifierArgs { #[arg(long, help_heading = "Verifier options", default_value = "etherscan", value_enum)] pub verifier: VerificationProviderType, + /// The verifier URL, if using a custom provider + #[arg(long, help_heading = "Verifier options", env = "VERIFIER_API_KEY")] + pub verifier_api_key: Option, + /// The verifier URL, if using a custom provider #[arg(long, help_heading = "Verifier options", env = "VERIFIER_URL")] pub verifier_url: Option, @@ -38,7 +42,11 @@ pub struct VerifierArgs { impl Default for VerifierArgs { fn default() -> Self { - Self { verifier: VerificationProviderType::Etherscan, verifier_url: None } + Self { + verifier: VerificationProviderType::Etherscan, + verifier_api_key: None, + verifier_url: None, + } } } @@ -162,6 +170,11 @@ impl figment::Provider for VerifyArgs { if self.via_ir { dict.insert("via_ir".to_string(), figment::value::Value::serialize(self.via_ir)?); } + + if let Some(api_key) = &self.verifier.verifier_api_key { + dict.insert("etherscan_api_key".into(), api_key.as_str().into()); + } + Ok(figment::value::Map::from([(Config::selected_profile(), dict)])) } } From 848c2441b4f50cf5efc1f7b5208937fa7a6c1b1a Mon Sep 17 00:00:00 2001 From: grandizzy Date: Wed, 13 Nov 2024 18:51:47 +0200 Subject: [PATCH 3/4] Fix descriptions --- crates/verify/src/provider.rs | 2 +- crates/verify/src/verify.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/verify/src/provider.rs b/crates/verify/src/provider.rs index bb860288ce2b..059f3ed82489 100644 --- a/crates/verify/src/provider.rs +++ b/crates/verify/src/provider.rs @@ -160,7 +160,7 @@ pub enum VerificationProviderType { Sourcify, Blockscout, Oklink, - /// Custom verifier type, compatible with Etherscan API. + /// Custom verification provider, compatible with Etherscan API. Custom, } diff --git a/crates/verify/src/verify.rs b/crates/verify/src/verify.rs index 3455b0e4f247..89cfd99aa676 100644 --- a/crates/verify/src/verify.rs +++ b/crates/verify/src/verify.rs @@ -31,11 +31,11 @@ pub struct VerifierArgs { #[arg(long, help_heading = "Verifier options", default_value = "etherscan", value_enum)] pub verifier: VerificationProviderType, - /// The verifier URL, if using a custom provider + /// The verifier API KEY, if using a custom provider. #[arg(long, help_heading = "Verifier options", env = "VERIFIER_API_KEY")] pub verifier_api_key: Option, - /// The verifier URL, if using a custom provider + /// The verifier URL, if using a custom provider. #[arg(long, help_heading = "Verifier options", env = "VERIFIER_URL")] pub verifier_url: Option, } From b1b37b906d9494df066e5cd931b6253a1fe7af30 Mon Sep 17 00:00:00 2001 From: grandizzy <38490174+grandizzy@users.noreply.github.com> Date: Thu, 14 Nov 2024 11:11:09 +0200 Subject: [PATCH 4/4] Update crates/verify/src/provider.rs Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com> --- crates/verify/src/provider.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/verify/src/provider.rs b/crates/verify/src/provider.rs index 059f3ed82489..bc01bd9e304d 100644 --- a/crates/verify/src/provider.rs +++ b/crates/verify/src/provider.rs @@ -160,7 +160,7 @@ pub enum VerificationProviderType { Sourcify, Blockscout, Oklink, - /// Custom verification provider, compatible with Etherscan API. + /// Custom verification provider, requires compatibility with the Etherscan API. Custom, }