You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At the end just having a chapter on contract migration would be useful, took me a bit to learn how to do it via docs.
( This may be a good part-2 to #6 's chapter )
Could be as simple as this
pubstructConfigResponse{pubname:String,// cw2 namepubversion:String,// cw2 version from the .toml}pubconstCONFIG = Item<ConfigResponse>
Then a migrate entry point which changes this value on upload
#[entry_point]pubfn migrate(deps:DepsMut,_env:Env,_msg:MigrateMsg) -> Result<Response,ContractError>{let ver = cw2::get_contract_version(deps.storage)?;// ensure we are migrating from an allowed contractif ver.contract != CONTRACT_NAME{returnErr(StdError::generic_err("Can only upgrade from same type").into());}if ver.version >= (*CONTRACT_VERSION).to_string(){returnErr(StdError::generic_err("Cannot upgrade from a newer version").into());}// set the new version
cw2::set_contract_version(deps.storage,CONTRACT_NAME,CONTRACT_VERSION)?;// state breaking migrations here// update the version field in the CONFIG since we have updated the contractletmut config = CONFIG.load(deps.storage)?;
config.version = CONTRACT_VERSION.to_string();CONFIG.save(deps.storage,&config)?;Ok(Response::default().add_attribute("action","migration").add_attribute("version",CONTRACT_VERSION)
The text was updated successfully, but these errors were encountered:
At the end just having a chapter on contract migration would be useful, took me a bit to learn how to do it via docs.
( This may be a good part-2 to #6 's chapter )
Could be as simple as this
Then a migrate entry point which changes this value on upload
The text was updated successfully, but these errors were encountered: