Skip to content

Commit

Permalink
Allow for migrating of infinity global and infinity router for testne…
Browse files Browse the repository at this point in the history
…t update
  • Loading branch information
tasiov committed Aug 29, 2023
1 parent 9e2c5db commit 95060a7
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/infinity-global/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "infinity-global"
version = "0.1.0"
version = "0.1.1"
edition = { workspace = true }
repository = { workspace = true }
license = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion contracts/infinity-global/schema/infinity-global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"contract_name": "infinity-global",
"contract_version": "0.1.0",
"contract_version": "0.1.1",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down
35 changes: 33 additions & 2 deletions contracts/infinity-global/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{
coin, to_binary, Addr, Binary, Deps, DepsMut, Empty, Env, Event, MessageInfo, QuerierWrapper,
StdError, StdResult, Uint128,
coin, ensure, to_binary, Addr, Binary, Deps, DepsMut, Empty, Env, Event, MessageInfo,
QuerierWrapper, StdError, StdResult, Uint128,
};
use cosmwasm_std::{Api, Coin, Decimal};
use cw2::set_contract_version;
Expand Down Expand Up @@ -305,3 +305,34 @@ pub fn sudo_remove_min_prices(deps: DepsMut, denoms: Vec<String>) -> Result<Resp

Ok(Response::new())
}

#[cfg_attr(not(feature = "library"), entry_point)]
#[allow(clippy::cmp_owned)]
pub fn migrate(mut deps: DepsMut, env: Env, msg: SudoMsg) -> Result<Response, StdError> {
let prev_contract_version = cw2::get_contract_version(deps.storage)?;

let valid_contract_names = vec![CONTRACT_NAME.to_string()];
ensure!(
valid_contract_names.contains(&prev_contract_version.contract),
StdError::generic_err("Invalid contract name for migration")
);

ensure!(
prev_contract_version.version < CONTRACT_VERSION.to_string(),
StdError::generic_err("Must upgrade contract version")
);

sudo(deps.branch(), env, msg)?;

cw2::set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

let response = Response::new().add_event(
Event::new("migrate")
.add_attribute("from_name", prev_contract_version.contract)
.add_attribute("from_version", prev_contract_version.version)
.add_attribute("to_name", CONTRACT_NAME)
.add_attribute("to_version", CONTRACT_VERSION),
);

Ok(response)
}
2 changes: 1 addition & 1 deletion contracts/infinity-router/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "infinity-router"
version = "0.1.0"
version = "0.1.1"
edition = { workspace = true }
repository = { workspace = true }
license = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion contracts/infinity-router/schema/infinity-router.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"contract_name": "infinity-router",
"contract_version": "0.1.0",
"contract_version": "0.1.1",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down
1 change: 1 addition & 0 deletions contracts/infinity-router/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod execute;
pub mod helpers;
pub mod instantiate;
pub mod migrate;
pub mod msg;
pub mod nfts_for_tokens_iterators;
pub mod query;
Expand Down
39 changes: 39 additions & 0 deletions contracts/infinity-router/src/migrate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use crate::{
error::ContractError,
instantiate::{CONTRACT_NAME, CONTRACT_VERSION},
};

use cosmwasm_std::{ensure, DepsMut, Empty, Env, Event, StdError};
use sg_std::Response;

#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;

#[cfg_attr(not(feature = "library"), entry_point)]
#[allow(clippy::cmp_owned)]
pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, ContractError> {
let prev_contract_version = cw2::get_contract_version(deps.storage)?;

let valid_contract_names = vec![CONTRACT_NAME.to_string()];
ensure!(
valid_contract_names.contains(&prev_contract_version.contract),
StdError::generic_err("Invalid contract name for migration")
);

ensure!(
prev_contract_version.version < CONTRACT_VERSION.to_string(),
StdError::generic_err("Must upgrade contract version")
);

cw2::set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

let response = Response::new().add_event(
Event::new("migrate")
.add_attribute("from_name", prev_contract_version.contract)
.add_attribute("from_version", prev_contract_version.version)
.add_attribute("to_name", CONTRACT_NAME)
.add_attribute("to_version", CONTRACT_VERSION),
);

Ok(response)
}

0 comments on commit 95060a7

Please sign in to comment.