Skip to content

Commit

Permalink
Added sudo and migrate messages
Browse files Browse the repository at this point in the history
  • Loading branch information
cyborgshead committed Nov 22, 2023
1 parent 5f086be commit 80bb898
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
25 changes: 24 additions & 1 deletion src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -67,6 +68,8 @@ pub fn instantiate(
info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response, ContractError> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

ROOT.save(deps.storage, &info.sender)?;
ALLOW_FAUCET.save(deps.storage, &true)?;

Expand Down Expand Up @@ -509,6 +512,13 @@ pub fn execute(
}
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn sudo(deps: DepsMut, env: Env, msg: SudoMsg) -> Result<Response, ContractError> {
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<Binary> {
match msg {
Expand Down Expand Up @@ -552,3 +562,16 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
}
}
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Response, ContractError> {
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"))
}
8 changes: 8 additions & 0 deletions src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ pub enum ExecuteMsg {
},
}

#[cw_serde]
pub enum SudoMsg {
BlockStep {},
}

#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
Expand Down Expand Up @@ -256,3 +261,6 @@ pub enum QueryMsg {
#[returns(Vec<Vec<u16>>)]
GetWeights { netuid: u16 },
}

#[cw_serde]
pub struct MigrateMsg {}
2 changes: 1 addition & 1 deletion src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 80bb898

Please sign in to comment.