diff --git a/Cargo.lock b/Cargo.lock index 91b7e1a96..7563ba502 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -855,6 +855,7 @@ dependencies = [ "regex", "report", "schemars", + "semver 1.0.23", "serde", "serde_json", "serde_with 3.11.0", @@ -5099,6 +5100,7 @@ dependencies = [ "prost 0.12.6", "report", "router-api", + "semver 1.0.23", "serde_json", "service-registry", "service-registry-api", diff --git a/Cargo.toml b/Cargo.toml index f8b73745e..94af7cf71 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,6 +56,7 @@ rewards = { version = "^1.2.0", path = "contracts/rewards" } router = { version = "^1.1.0", path = "contracts/router" } router-api = { version = "^1.0.0", path = "packages/router-api" } schemars = "0.8.10" +semver = "1.0" serde = { version = "1.0.145", default-features = false, features = ["derive"] } serde_json = "1.0.89" service-registry = { version = "^1.1.0", path = "contracts/service-registry" } diff --git a/contracts/multisig-prover/Cargo.toml b/contracts/multisig-prover/Cargo.toml index 59ea5a93c..fb3fbac50 100644 --- a/contracts/multisig-prover/Cargo.toml +++ b/contracts/multisig-prover/Cargo.toml @@ -54,6 +54,7 @@ msgs-derive = { workspace = true } multisig = { workspace = true, features = ["library"] } report = { workspace = true } router-api = { workspace = true } +semver = { workspace = true } serde_json = "1.0.89" service-registry = { workspace = true } service-registry-api = { workspace = true } diff --git a/contracts/multisig-prover/src/contract.rs b/contracts/multisig-prover/src/contract.rs index a2bf58512..d3ee3e71c 100644 --- a/contracts/multisig-prover/src/contract.rs +++ b/contracts/multisig-prover/src/contract.rs @@ -5,6 +5,7 @@ use cosmwasm_std::{ to_json_binary, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Reply, Response, }; use error_stack::ResultExt; +use semver::{Version, VersionReq}; use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; @@ -116,19 +117,15 @@ pub fn query( .map_err(axelar_wasm_std::error::ContractError::from) } -// It is valid to migrate from any of the below versions -const BASE_VERSION: &str = "1.1.0"; -const OLD_BASE_VERSION: &str = "1.0.0"; -const PATCH_VERSION: &str = "1.0.1"; #[cfg_attr(not(feature = "library"), entry_point)] pub fn migrate( deps: DepsMut, _env: Env, _msg: Empty, ) -> Result { - cw2::assert_contract_version(deps.storage, CONTRACT_NAME, BASE_VERSION) - .or_else(|_| cw2::assert_contract_version(deps.storage, CONTRACT_NAME, PATCH_VERSION)) - .or_else(|_| cw2::assert_contract_version(deps.storage, CONTRACT_NAME, OLD_BASE_VERSION))?; + let old_version = Version::parse(&cw2::get_contract_version(deps.storage)?.version)?; + let version_requirement = VersionReq::parse(">= 1.1.0, < 1.2.0")?; + assert!(version_requirement.matches(&old_version)); cw2::set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; diff --git a/packages/axelar-wasm-std/Cargo.toml b/packages/axelar-wasm-std/Cargo.toml index 3472b6de8..8395706cf 100644 --- a/packages/axelar-wasm-std/Cargo.toml +++ b/packages/axelar-wasm-std/Cargo.toml @@ -43,6 +43,7 @@ num-traits = { workspace = true } regex = { version = "1.10.0", default-features = false, features = ["perf", "std"] } report = { workspace = true } schemars = "0.8.10" +semver = { workspace = true } serde = { version = "1.0.145", default-features = false, features = ["derive"] } serde_json = "1.0.89" serde_with = { version = "3.11.0", features = ["macros"] } diff --git a/packages/axelar-wasm-std/src/error.rs b/packages/axelar-wasm-std/src/error.rs index d08977ca8..7e161f893 100644 --- a/packages/axelar-wasm-std/src/error.rs +++ b/packages/axelar-wasm-std/src/error.rs @@ -39,6 +39,14 @@ impl From for ContractError { } } +impl From for ContractError { + fn from(err: semver::Error) -> Self { + ContractError { + report: report!(err).change_context(Error::Report), + } + } +} + impl From for ContractError { fn from(err: permission_control::Error) -> Self { ContractError {