Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion crates/verify/src/etherscan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,9 @@ impl EtherscanVerificationProvider {
};

let compiler_version = if matches!(lang, ContractLanguage::Vyper) {
format!("vyper:{}", compiler_version.to_string().split('+').next().unwrap_or("0.0.0"))
let base = crate::utils::version_without_build(&compiler_version.to_string());
let base = if base.is_empty() { "0.0.0".to_string() } else { base };
format!("vyper:{}", base)
} else {
format!("v{}", ensure_solc_build_metadata(context.compiler_version.clone()).await?)
};
Expand Down
12 changes: 10 additions & 2 deletions crates/verify/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ pub struct JsonResult {
pub message: Option<String>,
}

pub fn version_without_build(version: &str) -> String {
version.split('+').next().unwrap_or("").to_string()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like it should just be an Option<_> since all we do is check if it's empty and then provide a better default.

}

pub fn normalize_compiler_version_str(version: &str) -> String {
version_without_build(version).trim_start_matches('v').to_string()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are only used in this crate, so please do not mark them pub.

please also add a small doc comment explaining what they do so you don't need to look up the fn definition


pub fn match_bytecodes(
local_bytecode: &[u8],
bytecode: &[u8],
Expand Down Expand Up @@ -113,8 +121,8 @@ pub fn build_using_cache(
if version.starts_with("vyper:") {
eyre::bail!("Vyper contracts are not supported")
}
// Parse etherscan version string
let version = version.split('+').next().unwrap_or("").trim_start_matches('v').to_string();
// Parse etherscan version string using a shared normalizer
let version = normalize_compiler_version_str(&version);

// Check if `out/directory` name matches the contract name
if key.ends_with(name.as_str()) {
Expand Down
Loading