diff --git a/contracts/cw20-ics20/src/contract.rs b/contracts/cw20-ics20/src/contract.rs index cbcd8767b..35f946fd4 100644 --- a/contracts/cw20-ics20/src/contract.rs +++ b/contracts/cw20-ics20/src/contract.rs @@ -13,6 +13,7 @@ use cw_storage_plus::Bound; use crate::amount::Amount; use crate::error::ContractError; use crate::ibc::Ics20Packet; +use crate::migrations::v1; use crate::msg::{ AllowMsg, AllowedInfo, AllowedResponse, ChannelResponse, ConfigResponse, ExecuteMsg, InitMsg, ListAllowedResponse, ListChannelsResponse, MigrateMsg, PortResponse, QueryMsg, TransferMsg, @@ -191,6 +192,9 @@ pub fn execute_allow( Ok(res) } +const MIGRATE_MIN_VERSION: &str = "0.11.1"; +const MIGRATE_VERSION_2: &str = "0.12.0-alpha1"; + #[cfg_attr(not(feature = "library"), entry_point)] pub fn migrate(mut deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { let version: Version = CONTRACT_VERSION.parse().map_err(from_semver)?; @@ -212,26 +216,24 @@ pub fn migrate(mut deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Resultv2 converstion if we are v1 style + if storage_version <= MIGRATE_VERSION_2.parse().map_err(from_semver)? { + let old_config = v1::CONFIG.load(deps.storage)?; ADMIN.set(deps.branch(), Some(old_config.gov_contract))?; let config = Config { default_timeout: old_config.default_timeout, }; CONFIG.save(deps.storage, &config)?; } - // otherwise no migration (yet) + // otherwise no migration (yet) - add them here + // we don't need to save anything if migrating from the same version if storage_version < version { - // we don't need to save anything if migrating from the same version set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; } diff --git a/contracts/cw20-ics20/src/migrations.rs b/contracts/cw20-ics20/src/migrations.rs index 888df9418..e874569a0 100644 --- a/contracts/cw20-ics20/src/migrations.rs +++ b/contracts/cw20-ics20/src/migrations.rs @@ -7,10 +7,10 @@ pub mod v1 { use cw_storage_plus::Item; #[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] - pub struct ConfigV1 { + pub struct Config { pub default_timeout: u64, pub gov_contract: Addr, } - pub const CONFIG: Item = Item::new("ics20_config"); + pub const CONFIG: Item = Item::new("ics20_config"); }