Skip to content

Commit

Permalink
feat(forge): allow --verifier custom option (#9311)
Browse files Browse the repository at this point in the history
* feat(forge): allow `--verifier custom` option

* Changes after review: add description of custom verifier, reorg err message, add custom verifier api key

* Fix descriptions

* Update crates/verify/src/provider.rs

Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>

---------

Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
  • Loading branch information
grandizzy and zerosnacks authored Nov 14, 2024
1 parent a65a5b1 commit 36cbce7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/common/src/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ 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!("{} ({} tries remaining)", err.root_cause(), self.retries);
}
}
5 changes: 5 additions & 0 deletions crates/verify/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ impl figment::Provider for VerifyBytecodeArgs {
&self,
) -> Result<figment::value::Map<figment::Profile, figment::value::Dict>, 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)?);
}
Expand Down
7 changes: 7 additions & 0 deletions crates/verify/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}")),
}
}
Expand All @@ -144,6 +145,9 @@ impl fmt::Display for VerificationProviderType {
Self::Oklink => {
write!(f, "oklink")?;
}
Self::Custom => {
write!(f, "custom")?;
}
};
Ok(())
}
Expand All @@ -156,6 +160,8 @@ pub enum VerificationProviderType {
Sourcify,
Blockscout,
Oklink,
/// Custom verification provider, requires compatibility with the Etherscan API.
Custom,
}

impl VerificationProviderType {
Expand All @@ -171,6 +177,7 @@ impl VerificationProviderType {
Self::Sourcify => Ok(Box::<SourcifyVerificationProvider>::default()),
Self::Blockscout => Ok(Box::<EtherscanVerificationProvider>::default()),
Self::Oklink => Ok(Box::<EtherscanVerificationProvider>::default()),
Self::Custom => Ok(Box::<EtherscanVerificationProvider>::default()),
}
}
}
17 changes: 15 additions & 2 deletions crates/verify/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,22 @@ 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<String>,

/// The verifier URL, if using a custom provider.
#[arg(long, help_heading = "Verifier options", env = "VERIFIER_URL")]
pub verifier_url: Option<String>,
}

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,
}
}
}

Expand Down Expand Up @@ -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)]))
}
}
Expand Down

0 comments on commit 36cbce7

Please sign in to comment.