diff --git a/contracts/cw20-ics20/src/contract.rs b/contracts/cw20-ics20/src/contract.rs index ac0e26894..2be1f3b4b 100644 --- a/contracts/cw20-ics20/src/contract.rs +++ b/contracts/cw20-ics20/src/contract.rs @@ -3,14 +3,15 @@ use cosmwasm_std::{ IbcQuery, MessageInfo, Order, PortIdResponse, Response, StdResult, }; -use cw2::set_contract_version; +use cw2::{get_contract_version, set_contract_version}; use cw20::{Cw20CoinHuman, Cw20ReceiveMsg}; use crate::amount::Amount; use crate::error::ContractError; use crate::ibc::Ics20Packet; use crate::msg::{ - ChannelResponse, ExecuteMsg, InitMsg, ListChannelsResponse, PortResponse, QueryMsg, TransferMsg, + ChannelResponse, ExecuteMsg, InitMsg, ListChannelsResponse, MigrateMsg, PortResponse, QueryMsg, + TransferMsg, }; use crate::state::{Config, CHANNEL_INFO, CHANNEL_STATE, CONFIG}; use cw0::{nonpayable, one_coin}; @@ -130,6 +131,17 @@ pub fn execute_transfer( Ok(res) } +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { + let version = get_contract_version(deps.storage)?; + if version.contract != CONTRACT_NAME { + return Err(ContractError::CannotMigrate { + previous_contract: version.contract, + }); + } + Ok(Response::default()) +} + #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { diff --git a/contracts/cw20-ics20/src/error.rs b/contracts/cw20-ics20/src/error.rs index 668b2eb18..a3f05a780 100644 --- a/contracts/cw20-ics20/src/error.rs +++ b/contracts/cw20-ics20/src/error.rs @@ -46,6 +46,9 @@ pub enum ContractError { #[error("Parsed channel from denom ({channel}) doesn't match packet")] FromOtherChannel { channel: String }, + + #[error("Cannot migrate from different contract type: {previous_contract}")] + CannotMigrate { previous_contract: String }, } impl From for ContractError { diff --git a/contracts/cw20-ics20/src/msg.rs b/contracts/cw20-ics20/src/msg.rs index 744b98fda..6c4e1054b 100644 --- a/contracts/cw20-ics20/src/msg.rs +++ b/contracts/cw20-ics20/src/msg.rs @@ -8,12 +8,15 @@ use cw20::Cw20ReceiveMsg; use crate::amount::Amount; use crate::state::ChannelInfo; -#[derive(Serialize, Deserialize, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)] pub struct InitMsg { /// default timeout for ics20 packets, specified in seconds pub default_timeout: u64, } +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)] +pub struct MigrateMsg {} + #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum ExecuteMsg {