Skip to content

Commit

Permalink
Update version and add migrate functions (#226)
Browse files Browse the repository at this point in the history
* Use QueryResponses

* Use QueryResponses for name mitner

* Use QueryResponses for name whitelist

* Remove ParamResponse

* Use single value queries for Name Marketplace

* Update schema

* Upgraded ts-codegen

* Update version and add migrate to marketplace

* Removed profile
  • Loading branch information
shanev authored Dec 7, 2022
1 parent 2e6e681 commit 780ff74
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 28 deletions.
19 changes: 10 additions & 9 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["packages/*", "contracts/*"]
resolver = "2"

[workspace.package]
version = "1.0.0"
version = "1.1.0"
edition = "2021"
homepage = "https://stargaze.zone"
repository = "https://github.com/public-awesome/names"
Expand Down
2 changes: 1 addition & 1 deletion contracts/marketplace/schema/name-marketplace.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"contract_name": "name-marketplace",
"contract_version": "1.0.0",
"contract_version": "1.1.0",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down
28 changes: 28 additions & 0 deletions contracts/marketplace/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use cw2::set_contract_version;
use cw721::{Cw721ExecuteMsg, OwnerOfResponse};
use cw721_base::helpers::Cw721Contract;
use cw_utils::{must_pay, nonpayable};
use semver::Version;
use sg_name_common::{charge_fees, SECONDS_PER_YEAR};
use sg_std::{Response, SubMsg, NATIVE_DENOM};

Expand Down Expand Up @@ -584,3 +585,30 @@ fn check_rate_limit(store: &dyn Storage, block_time: Timestamp, seller: Addr) ->

Ok(())
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, ContractError> {
let current_version = cw2::get_contract_version(deps.storage)?;
if current_version.contract != CONTRACT_NAME {
return Err(StdError::generic_err("Cannot upgrade to a different contract").into());
}
let version: Version = current_version
.version
.parse()
.map_err(|_| StdError::generic_err("Invalid contract version"))?;
let new_version: Version = CONTRACT_VERSION
.parse()
.map_err(|_| StdError::generic_err("Invalid contract version"))?;

if version > new_version {
return Err(StdError::generic_err("Cannot upgrade to a previous contract version").into());
}
// if same version return
if version == new_version {
return Ok(Response::new());
}

// set new contract version
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
Ok(Response::new())
}
2 changes: 1 addition & 1 deletion contracts/name-minter/schema/name-minter.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"contract_name": "name-minter",
"contract_version": "1.0.0",
"contract_version": "1.1.0",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down
2 changes: 1 addition & 1 deletion contracts/sg721-name/schema/sg721-name.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"contract_name": "sg721-name",
"contract_version": "1.0.0",
"contract_version": "1.1.0",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down
18 changes: 4 additions & 14 deletions contracts/whitelist-updatable/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@ exclude = [
[lib]
crate-type = ["cdylib", "rlib"]

[profile.release]
opt-level = 3
debug = false
rpath = false
lto = true
debug-assertions = false
codegen-units = 1
panic = 'abort'
incremental = false
overflow-checks = true

[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
Expand All @@ -50,15 +39,16 @@ cw-controllers = { workspace = true }
cw2 = { workspace = true }
cw-utils = { workspace = true }
schemars = { workspace = true }
semver = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }
sg-whitelist-basic = { path = "../../packages/sg-whitelist-basic" }
sg-name-minter = { path = "../../packages/sg-name-minter" }
sg-std = { workspace = true }
sg-whitelist-basic = { path = "../../packages/sg-whitelist-basic" }
thiserror = { workspace = true }

[dev-dependencies]
cw-multi-test = { workspace = true }
name-minter = { path = "../name-minter", features = ["library"] }
sg-name = { path = "../../packages/sg-name" }
sg-multi-test = { workspace = true }
sg721-name = { path = "../sg721-name" }
name-minter = { path = "../name-minter", features = ["library"] }
31 changes: 30 additions & 1 deletion contracts/whitelist-updatable/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ use crate::state::{Config, CONFIG, TOTAL_ADDRESS_COUNT, WHITELIST};
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_binary, Addr, Binary, Decimal, Deps, DepsMut, Env, Event, MessageInfo, Order, StdResult,
to_binary, Addr, Binary, Decimal, Deps, DepsMut, Empty, Env, Event, MessageInfo, Order,
StdError, StdResult,
};
use cw2::set_contract_version;
use semver::Version;
use sg_name_minter::SgNameMinterQueryMsg;

use crate::error::ContractError;
Expand Down Expand Up @@ -301,3 +303,30 @@ pub fn query_mint_discount_percent(deps: Deps) -> StdResult<Option<Decimal>> {
.mint_discount_bps
.map(|x| Decimal::from_ratio(x, 10_000u128)))
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, ContractError> {
let current_version = cw2::get_contract_version(deps.storage)?;
if current_version.contract != CONTRACT_NAME {
return Err(StdError::generic_err("Cannot upgrade to a different contract").into());
}
let version: Version = current_version
.version
.parse()
.map_err(|_| StdError::generic_err("Invalid contract version"))?;
let new_version: Version = CONTRACT_VERSION
.parse()
.map_err(|_| StdError::generic_err("Invalid contract version"))?;

if version > new_version {
return Err(StdError::generic_err("Cannot upgrade to a previous contract version").into());
}
// if same version return
if version == new_version {
return Ok(Response::new());
}

// set new contract version
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
Ok(Response::new())
}

0 comments on commit 780ff74

Please sign in to comment.