Skip to content
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
3 changes: 1 addition & 2 deletions crates/svm-rs/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ pub async fn install(version: &Version) -> Result<PathBuf, SvmError> {

let artifacts = all_releases(platform::platform()).await?;
let artifact = artifacts
.releases
.get(version)
.get_artifact(version)
.ok_or_else(|| SvmError::UnknownVersion(version.clone()))?;
let download_url = artifact_url(platform::platform(), version, artifact.to_string().as_str())?;

Expand Down
43 changes: 35 additions & 8 deletions crates/svm-rs/src/releases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,43 @@ pub struct Releases {

impl Releases {
/// Get the checksum of a solc version's binary if it exists.
/// Checks for exact version match or for prerelease.
pub fn get_checksum(&self, v: &Version) -> Option<Vec<u8>> {
for build in self.builds.iter() {
if build.version.eq(v) {
return Some(build.sha256.clone());
}
}
None
let matches = |build_info: &BuildInfo| {
let matched_release = build_info.version == *v;

let matched_prelease = !v.pre.is_empty()
&& build_info.version == Version::new(v.major, v.minor, v.patch)
&& build_info.prerelease.as_deref() == Some(v.pre.as_str());

matched_release || matched_prelease
Comment on lines +84 to +88
Copy link
Member

Choose a reason for hiding this comment

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

I see, that makes sense

};

self.builds
.iter()
.find(|build_info| matches(build_info))
.map(|build_info| build_info.sha256.clone())
}

/// Returns the artifact of the version if any
/// Returns the artifact of the version if any, by looking it up in releases or in builds (if
/// a prerelease).
pub fn get_artifact(&self, version: &Version) -> Option<&String> {
self.releases.get(version)
// Check version artifact in releases.
if let Some(artifact) = self.releases.get(version) {
return Some(artifact);
}

// If we didn't find any artifact under releases, look up builds for prerelease.
if !version.pre.is_empty()
&& let Some(build_info) = self.builds.iter().find(|b| {
b.version == Version::new(version.major, version.minor, version.patch)
&& b.prerelease == Some(version.pre.to_string())
})
{
return build_info.path.as_ref();
}

None
}

/// Returns a sorted list of all versions
Expand All @@ -104,6 +129,8 @@ pub struct BuildInfo {
pub version: Version,
#[serde(with = "hex_string")]
pub sha256: Vec<u8>,
pub path: Option<String>,
pub prerelease: Option<String>,
Comment on lines +132 to +133
Copy link
Member

Choose a reason for hiding this comment

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

ah I see

}

/// Helper serde module to serialize and deserialize bytes as hex.
Expand Down
Loading