Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update royalty time on migration #684

Draft
wants to merge 3 commits into
base: release/v3.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

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

28 changes: 9 additions & 19 deletions contracts/collections/sg721-base/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use cw721_base::state::TokenInfo;
use url::Url;

use cosmwasm_std::{
to_json_binary, Addr, Binary, ContractInfoResponse, Decimal, Deps, DepsMut, Empty, Env, Event,
MessageInfo, StdError, StdResult, Storage, Timestamp, WasmQuery,
};
use cw721_base::state::TokenInfo;
use cw_storage_plus::Item;
use url::Url;

use cw721::{ContractInfoResponse as CW721ContractInfoResponse, Cw721Execute};
use cw_utils::nonpayable;
Expand Down Expand Up @@ -385,33 +385,23 @@ where
})
}

pub fn migrate(mut deps: DepsMut, env: Env, _msg: Empty) -> Result<Response, ContractError> {
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()];
if !valid_contract_names.contains(&prev_contract_version.contract) {
return Err(StdError::generic_err("Invalid contract name for migration").into());
}

#[allow(clippy::cmp_owned)]
if prev_contract_version.version >= CONTRACT_VERSION.to_string() {
return Err(StdError::generic_err("Must upgrade contract version").into());
}

let mut response = Response::new();

#[allow(clippy::cmp_owned)]
if prev_contract_version.version < "3.0.0".to_string() {
response = crate::upgrades::v3_0_0::upgrade(deps.branch(), &env, response)?;
}

#[allow(clippy::cmp_owned)]
if prev_contract_version.version < "3.1.0".to_string() {
response = crate::upgrades::v3_1_0::upgrade(deps.branch(), &env, response)?;
}

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

// substract 1 day on migration
let royalty_updated_at = Item::new("royalty_updated_at");
let last_royalty_update: Timestamp = royalty_updated_at.load(deps.storage)?;
royalty_updated_at.save(deps.storage, &last_royalty_update.minus_days(1))?;

response = response.add_event(
Event::new("migrate")
.add_attribute("from_name", prev_contract_version.contract)
Expand Down
5 changes: 5 additions & 0 deletions contracts/collections/sg721-base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,9 @@ pub mod entry {
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
Sg721Contract::<Extension>::default().query(deps, env, msg)
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, env: Env, msg: Empty) -> Result<Response, ContractError> {
Sg721Contract::<Extension>::migrate(deps, env, msg)
}
}
Loading