Skip to content

Semver parsing / comparison #510

@ethanfrey

Description

@ethanfrey

Useful feature for migration support.

Pretty much every contract uses cw2 to store the version as defined by cargo:

const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

This is a string however, and not the easiest to use in migrate. to say, "allow migration where version.major == 0 && [8..-=10].contains(version.minor)".

As a first step, is a utility to parse a valid semver string into:

pub Semver struct {
  pub major: u32;
  pub minor: u32;
  pub patch: u32;
  // if you think this needs even more structure here, feel free to add
  pub tag: Option<String>;
}

Also please add some basic constructors and implement Ord, so we can do something like:

if version < Semver::new(0, 8, 0) {
  return Err("too low");
} else if version >= Semver::new(0, 10, 1) {
  return Err("too high");
} else {
  // do migration
}

The types above are meant to give inspiration and you can change them if you have a better idea that fulfills the same purpose.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions