Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(forge): allow --verifier custom option #9311

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()),
zerosnacks marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
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
Loading