Skip to content

Commit

Permalink
Add migrate entry point from an previous cw20-ics20 contract
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed Mar 11, 2021
1 parent 31e7b4c commit 27ecc50
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
16 changes: 14 additions & 2 deletions contracts/cw20-ics20/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<Response, ContractError> {
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<Binary> {
match msg {
Expand Down
3 changes: 3 additions & 0 deletions contracts/cw20-ics20/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FromUtf8Error> for ContractError {
Expand Down
5 changes: 4 additions & 1 deletion contracts/cw20-ics20/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 27ecc50

Please sign in to comment.