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

Semver parsing / comparison #510

Closed
ethanfrey opened this issue Oct 26, 2021 · 1 comment · Fixed by #525
Closed

Semver parsing / comparison #510

ethanfrey opened this issue Oct 26, 2021 · 1 comment · Fixed by #525
Assignees

Comments

@ethanfrey
Copy link
Member

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.

@ethanfrey
Copy link
Member Author

Can be closed by using semver crate in #511

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants