diff --git a/src/contract.rs b/src/contract.rs index a27f0ff..f04baa4 100644 --- a/src/contract.rs +++ b/src/contract.rs @@ -3,10 +3,11 @@ use crate::delegate_info::{get_delegate, get_delegated, get_delegates}; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult}; +use cw2::{get_contract_version, set_contract_version, ContractVersion}; // use cw2::set_contract_version; use crate::error::ContractError; -use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; +use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, SudoMsg}; use crate::neuron_info::{get_neuron, get_neuron_lite, get_neurons, get_neurons_lite}; use crate::registration::{do_burned_registration, do_registration, do_sudo_registration}; use crate::root::{do_root_register, get_network_lock_cost, user_add_network, user_remove_network}; @@ -67,6 +68,8 @@ pub fn instantiate( info: MessageInfo, msg: InstantiateMsg, ) -> Result { + set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + ROOT.save(deps.storage, &info.sender)?; ALLOW_FAUCET.save(deps.storage, &true)?; @@ -509,6 +512,13 @@ pub fn execute( } } +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn sudo(deps: DepsMut, env: Env, msg: SudoMsg) -> Result { + match msg { + SudoMsg::BlockStep {} => block_step(deps, env), + } +} + #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { match msg { @@ -552,3 +562,16 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { } } } + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { + let storage_version: ContractVersion = get_contract_version(deps.storage)?; + + // Only migrate if newer + if storage_version.version.as_str() < CONTRACT_VERSION { + // Set contract to version to latest + set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + } + + Ok(Response::new().add_attribute("action", "migrate")) +} diff --git a/src/msg.rs b/src/msg.rs index 57468fc..3a2d451 100644 --- a/src/msg.rs +++ b/src/msg.rs @@ -218,6 +218,11 @@ pub enum ExecuteMsg { }, } +#[cw_serde] +pub enum SudoMsg { + BlockStep {}, +} + #[cw_serde] #[derive(QueryResponses)] pub enum QueryMsg { @@ -256,3 +261,6 @@ pub enum QueryMsg { #[returns(Vec>)] GetWeights { netuid: u16 }, } + +#[cw_serde] +pub struct MigrateMsg {} diff --git a/src/root.rs b/src/root.rs index 81c8306..0efaf15 100644 --- a/src/root.rs +++ b/src/root.rs @@ -552,7 +552,7 @@ pub fn do_root_register( )); } - // TODO revisit this as we don't have a senate and subnetwork n is 0 and account don't have stake + // TODO revisit this as we don't have a senate and need migration to dao // let current_stake = get_total_stake_for_hotkey(deps.storage, hotkey.clone()); // If we're full, we'll swap out the lowest stake member. // let members = T::SenateMembers::members();