Skip to content

Commit

Permalink
Cleanup from pr review
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed Feb 2, 2022
1 parent b255685 commit 2a0d550
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
18 changes: 10 additions & 8 deletions contracts/cw20-ics20/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Response, ContractError> {
let version: Version = CONTRACT_VERSION.parse().map_err(from_semver)?;
Expand All @@ -212,26 +216,24 @@ pub fn migrate(mut deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Respons
}

// Then, run the proper migration
// unsupported old version
if storage_version < "0.11.1".parse().map_err(from_semver)? {
if storage_version < MIGRATE_MIN_VERSION.parse().map_err(from_semver)? {
return Err(ContractError::CannotMigrateVersion {
previous_version: stored.version,
});
}
// for 0.12.0-alpha1 or earlier, migrate from the config.gov_contract to ADMIN
if storage_version <= "0.12.0-alpha1".parse().map_err(from_semver)? {
// Do v1 migration
let old_config = crate::migrations::v1::CONFIG.load(deps.storage)?;
// run the v1->v2 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)?;
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/cw20-ics20/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConfigV1> = Item::new("ics20_config");
pub const CONFIG: Item<Config> = Item::new("ics20_config");
}

0 comments on commit 2a0d550

Please sign in to comment.