Skip to content

Commit 6e3db47

Browse files
committed
Added missed imports, format
1 parent c171c99 commit 6e3db47

File tree

1 file changed

+70
-48
lines changed

1 file changed

+70
-48
lines changed

src/contract.rs

+70-48
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#[cfg(not(feature = "library"))]
22
use cosmwasm_std::entry_point;
3-
use cosmwasm_std::{to_json_binary, Addr, Binary, Coin, Deps, DepsMut, Env, MessageInfo, StdResult, Storage, Uint128, Order};
3+
use cosmwasm_std::{
4+
to_json_binary, Addr, Binary, Coin, Deps, DepsMut, Env, MessageInfo, Order, StdResult, Storage,
5+
Uint128,
6+
};
47
use cw2::{get_contract_version, set_contract_version, ContractVersion};
58
use cyber_std::{create_creat_thought_msg, Load, Trigger};
69

@@ -17,22 +20,22 @@ use crate::staking::{
1720
do_add_stake, do_become_delegate, do_remove_stake, increase_stake_on_coldkey_hotkey_account,
1821
};
1922
use crate::state::{
20-
ACTIVE, ACTIVITY_CUTOFF, ADJUSTMENTS_ALPHA, ADJUSTMENT_INTERVAL, ALLOW_FAUCET,
21-
BLOCKS_SINCE_LAST_STEP, BLOCK_AT_REGISTRATION, BLOCK_EMISSION, BONDS_MOVING_AVERAGE, BURN,
22-
BURN_REGISTRATIONS_THIS_INTERVAL, CONSENSUS, DEFAULT_TAKE, DELEGATES, DENOM, DIFFICULTY,
23-
DIVIDENDS, EMISSION, EMISSION_VALUES, IMMUNITY_PERIOD, INCENTIVE, IS_NETWORK_MEMBER, KAPPA,
24-
KEYS, LAST_ADJUSTMENT_BLOCK, LAST_UPDATE, MAX_ALLOWED_UIDS, MAX_ALLOWED_VALIDATORS, MAX_BURN,
25-
MAX_DIFFICULTY, MAX_REGISTRATION_PER_BLOCK, MAX_WEIGHTS_LIMIT, MIN_ALLOWED_WEIGHTS, MIN_BURN,
26-
MIN_DIFFICULTY, NETWORKS_ADDED, NETWORK_IMMUNITY_PERIOD, NETWORK_LAST_LOCK_COST,
27-
NETWORK_LAST_REGISTERED, NETWORK_LOCK_REDUCTION_INTERVAL, NETWORK_MIN_ALLOWED_UIDS,
28-
NETWORK_MIN_LOCK_COST, NETWORK_MODALITY, NETWORK_RATE_LIMIT, NETWORK_REGISTERED_AT,
29-
NETWORK_REGISTRATION_ALLOWED, OWNER, PENDING_EMISSION, POW_REGISTRATIONS_THIS_INTERVAL,
30-
PRUNING_SCORES, RANK, RAO_RECYCLED_FOR_REGISTRATION, REGISTRATIONS_THIS_BLOCK,
31-
REGISTRATIONS_THIS_INTERVAL, RHO, ROOT, SCALING_LAW_POWER, SERVING_RATE_LIMIT, STAKE,
32-
SUBNETWORK_N, SUBNET_LIMIT, SUBNET_LOCKED, SUBNET_OWNER, SUBNET_OWNER_CUT,
33-
TARGET_REGISTRATIONS_PER_INTERVAL, TEMPO, TOTAL_ISSUANCE, TOTAL_NETWORKS, TOTAL_STAKE, TRUST,
34-
TX_RATE_LIMIT, UIDS, VALIDATOR_PERMIT, VALIDATOR_TRUST, WEIGHTS_SET_RATE_LIMIT,
35-
WEIGHTS_VERSION_KEY,
23+
AxonInfo, PrometheusInfo, ACTIVE, ACTIVITY_CUTOFF, ADJUSTMENTS_ALPHA, ADJUSTMENT_INTERVAL,
24+
ALLOW_FAUCET, AXONS, BLOCKS_SINCE_LAST_STEP, BLOCK_AT_REGISTRATION, BLOCK_EMISSION,
25+
BONDS_MOVING_AVERAGE, BURN, BURN_REGISTRATIONS_THIS_INTERVAL, CONSENSUS, DEFAULT_TAKE,
26+
DELEGATES, DENOM, DIFFICULTY, DIVIDENDS, EMISSION, EMISSION_VALUES, IMMUNITY_PERIOD, INCENTIVE,
27+
IS_NETWORK_MEMBER, KAPPA, KEYS, LAST_ADJUSTMENT_BLOCK, LAST_UPDATE, MAX_ALLOWED_UIDS,
28+
MAX_ALLOWED_VALIDATORS, MAX_BURN, MAX_DIFFICULTY, MAX_REGISTRATION_PER_BLOCK,
29+
MAX_WEIGHTS_LIMIT, MIN_ALLOWED_WEIGHTS, MIN_BURN, MIN_DIFFICULTY, NETWORKS_ADDED,
30+
NETWORK_IMMUNITY_PERIOD, NETWORK_LAST_LOCK_COST, NETWORK_LAST_REGISTERED,
31+
NETWORK_LOCK_REDUCTION_INTERVAL, NETWORK_MIN_ALLOWED_UIDS, NETWORK_MIN_LOCK_COST,
32+
NETWORK_MODALITY, NETWORK_RATE_LIMIT, NETWORK_REGISTERED_AT, NETWORK_REGISTRATION_ALLOWED,
33+
OWNER, PENDING_EMISSION, POW_REGISTRATIONS_THIS_INTERVAL, PROMETHEUS, PRUNING_SCORES, RANK,
34+
RAO_RECYCLED_FOR_REGISTRATION, REGISTRATIONS_THIS_BLOCK, REGISTRATIONS_THIS_INTERVAL, RHO,
35+
ROOT, SCALING_LAW_POWER, SERVING_RATE_LIMIT, STAKE, SUBNETWORK_N, SUBNET_LIMIT, SUBNET_LOCKED,
36+
SUBNET_OWNER, SUBNET_OWNER_CUT, TARGET_REGISTRATIONS_PER_INTERVAL, TEMPO, TOTAL_COLDKEY_STAKE,
37+
TOTAL_HOTKEY_STAKE, TOTAL_ISSUANCE, TOTAL_NETWORKS, TOTAL_STAKE, TRUST, TX_RATE_LIMIT, UIDS,
38+
VALIDATOR_PERMIT, VALIDATOR_TRUST, WEIGHTS_SET_RATE_LIMIT, WEIGHTS_VERSION_KEY,
3639
};
3740
use crate::state_info::get_state_info;
3841
use crate::subnet_info::{get_subnet_hyperparams, get_subnet_info, get_subnets_info};
@@ -61,8 +64,8 @@ use crate::weights::{do_set_weights, get_network_weights};
6164
const CONTRACT_NAME: &str = "cybernet";
6265
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
6366

64-
use cyber_std::Response;
6567
use crate::uids::get_registered_networks_for_hotkey;
68+
use cyber_std::Response;
6669

6770
#[cfg_attr(not(feature = "library"), entry_point)]
6871
pub fn instantiate(
@@ -262,16 +265,11 @@ pub fn execute(
262265
weights,
263266
version_key,
264267
} => do_set_weights(deps, env, info, netuid, dests, weights, version_key),
265-
ExecuteMsg::BecomeDelegate { hotkey } => {
266-
do_become_delegate(deps, env, info, hotkey)
268+
ExecuteMsg::BecomeDelegate { hotkey } => do_become_delegate(deps, env, info, hotkey),
269+
ExecuteMsg::AddStake { hotkey } => do_add_stake(deps, env, info, hotkey),
270+
ExecuteMsg::RemoveStake { hotkey, amount } => {
271+
do_remove_stake(deps, env, info, hotkey, amount)
267272
}
268-
ExecuteMsg::AddStake {
269-
hotkey,
270-
} => do_add_stake(deps, env, info, hotkey),
271-
ExecuteMsg::RemoveStake {
272-
hotkey,
273-
amount,
274-
} => do_remove_stake(deps, env, info, hotkey, amount),
275273
ExecuteMsg::ServeAxon {
276274
netuid,
277275
version,
@@ -494,12 +492,8 @@ pub fn sudo(deps: DepsMut, env: Env, msg: SudoMsg) -> Result<Response, ContractE
494492
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
495493
match msg {
496494
QueryMsg::GetDelegates {} => to_json_binary(&get_delegates(deps)?),
497-
QueryMsg::GetDelegate { delegate } => {
498-
to_json_binary(&get_delegate(deps, delegate)?)
499-
}
500-
QueryMsg::GetDelegated { delegatee } => {
501-
to_json_binary(&get_delegated(deps, delegatee)?)
502-
}
495+
QueryMsg::GetDelegate { delegate } => to_json_binary(&get_delegate(deps, delegate)?),
496+
QueryMsg::GetDelegated { delegatee } => to_json_binary(&get_delegated(deps, delegatee)?),
503497
QueryMsg::GetNeuronsLite { netuid } => {
504498
to_json_binary(&get_neurons_lite(deps.storage, netuid)?)
505499
}
@@ -568,20 +562,22 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
568562
to_json_binary(&query_delegate_take(deps.storage, &hotkey_address)?)
569563
}
570564
QueryMsg::GetBurn { netuid } => to_json_binary(&query_burn(deps.storage, netuid)?),
571-
QueryMsg::GetDifficulty { netuid } => to_json_binary(&query_difficulty(deps.storage, netuid)?),
565+
QueryMsg::GetDifficulty { netuid } => {
566+
to_json_binary(&query_difficulty(deps.storage, netuid)?)
567+
}
572568
QueryMsg::GetTempo { netuid } => to_json_binary(&query_tempo(deps.storage, netuid)?),
573569
QueryMsg::GetTotalNetworks {} => to_json_binary(&query_total_networks(deps.storage)?),
574570
QueryMsg::GetNetworksAdded {} => to_json_binary(&query_networks_added(deps.storage)?),
575571
QueryMsg::GetEmissionValueBySubnet { netuid } => {
576572
to_json_binary(&query_emission_value_by_subnet(deps, netuid)?)
577-
},
573+
}
578574
QueryMsg::GetAllSubnetNetuids {} => {
579575
to_json_binary(&query_all_subnet_netuids(deps.storage)?)
580-
},
576+
}
581577
QueryMsg::GetNetuidsForHotkey { hotkey } => {
582578
let hotkey_address = deps.api.addr_validate(&hotkey)?;
583579
to_json_binary(&query_netuids_for_hotkey(deps.storage, &hotkey_address)?)
584-
},
580+
}
585581
QueryMsg::GetTotalIssuance {} => to_json_binary(&query_total_issuance(deps.storage)?),
586582
QueryMsg::GetTotalStake {} => to_json_binary(&query_total_stake(deps.storage)?),
587583
QueryMsg::GetTxRateLimit {} => to_json_binary(&query_tx_rate_limit(deps.storage)?),
@@ -592,15 +588,25 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
592588
}
593589
QueryMsg::GetPrometheusInfo { netuid, hotkey } => {
594590
let hotkey_address = deps.api.addr_validate(&hotkey)?;
595-
to_json_binary(&query_get_prometheus_info(deps.storage, netuid, &hotkey_address)?)
591+
to_json_binary(&query_get_prometheus_info(
592+
deps.storage,
593+
netuid,
594+
&hotkey_address,
595+
)?)
596596
}
597597
QueryMsg::GetTotalStakeForHotkey { address } => {
598598
let hotkey_address = deps.api.addr_validate(&address)?;
599-
to_json_binary(&query_get_total_stake_for_hotkey(deps.storage, &hotkey_address)?)
599+
to_json_binary(&query_get_total_stake_for_hotkey(
600+
deps.storage,
601+
&hotkey_address,
602+
)?)
600603
}
601604
QueryMsg::GetTotalStakeForColdkey { address } => {
602605
let hotkey_address = deps.api.addr_validate(&address)?;
603-
to_json_binary(&query_get_total_stake_for_coldkey(deps.storage, &hotkey_address)?)
606+
to_json_binary(&query_get_total_stake_for_coldkey(
607+
deps.storage,
608+
&hotkey_address,
609+
)?)
604610
}
605611
QueryMsg::GetHotkeyExist { hotkey } => {
606612
let hotkey_address = deps.api.addr_validate(&hotkey)?;
@@ -738,7 +744,8 @@ pub fn query_networks_added(store: &dyn Storage) -> StdResult<Vec<u16>> {
738744
.map(|item| {
739745
let (k, _) = item.unwrap();
740746
k
741-
}).collect::<Vec<u16>>();
747+
})
748+
.collect::<Vec<u16>>();
742749
Ok(networks)
743750
}
744751

@@ -753,7 +760,8 @@ pub fn query_all_subnet_netuids(store: &dyn Storage) -> StdResult<Vec<u16>> {
753760
.map(|item| {
754761
let (k, _) = item.unwrap();
755762
k
756-
}).collect::<Vec<u16>>();
763+
})
764+
.collect::<Vec<u16>>();
757765
Ok(netuids)
758766
}
759767

@@ -778,31 +786,45 @@ pub fn query_tx_rate_limit(store: &dyn Storage) -> StdResult<u64> {
778786
Ok(limit)
779787
}
780788

781-
pub fn query_get_axon_info(store: &dyn Storage, netuid: u16, hotkey: &Addr) -> StdResult<Option<AxonInfo>> {
789+
pub fn query_get_axon_info(
790+
store: &dyn Storage,
791+
netuid: u16,
792+
hotkey: &Addr,
793+
) -> StdResult<Option<AxonInfo>> {
782794
let axon = AXONS.may_load(store, (netuid, hotkey))?;
783795
if axon.is_some() {
784796
Ok(Some(axon.unwrap()))
785797
} else {
786798
Ok(None)
787799
}
788800
}
789-
pub fn query_get_prometheus_info(store: &dyn Storage, netuid: u16, hotkey: &Addr) -> StdResult<Option<PrometheusInfo>> {
801+
pub fn query_get_prometheus_info(
802+
store: &dyn Storage,
803+
netuid: u16,
804+
hotkey: &Addr,
805+
) -> StdResult<Option<PrometheusInfo>> {
790806
let axon = PROMETHEUS.may_load(store, (netuid, hotkey))?;
791807
if axon.is_some() {
792808
Ok(Some(axon.unwrap()))
793809
} else {
794810
Ok(None)
795811
}
796812
}
797-
pub fn query_get_total_stake_for_hotkey(store: &dyn Storage, hotkey: &Addr) -> StdResult<Option<u64>> {
813+
pub fn query_get_total_stake_for_hotkey(
814+
store: &dyn Storage,
815+
hotkey: &Addr,
816+
) -> StdResult<Option<u64>> {
798817
let stake = TOTAL_HOTKEY_STAKE.may_load(store, hotkey)?;
799818
if stake.is_some() {
800819
Ok(Some(stake.unwrap()))
801820
} else {
802821
Ok(None)
803822
}
804823
}
805-
pub fn query_get_total_stake_for_coldkey(store: &dyn Storage, coldkey: &Addr) -> StdResult<Option<u64>> {
824+
pub fn query_get_total_stake_for_coldkey(
825+
store: &dyn Storage,
826+
coldkey: &Addr,
827+
) -> StdResult<Option<u64>> {
806828
let stake = TOTAL_COLDKEY_STAKE.may_load(store, coldkey)?;
807829
if stake.is_some() {
808830
Ok(Some(stake.unwrap()))
@@ -825,11 +847,11 @@ pub fn query_get_stake(store: &dyn Storage, hotkey: &Addr) -> StdResult<Vec<(Str
825847
.map(|item| {
826848
let (address, stake) = item.unwrap();
827849
(address.to_string(), stake)
828-
}).collect::<Vec<(String, u64)>>();
850+
})
851+
.collect::<Vec<(String, u64)>>();
829852
Ok(stakes)
830853
}
831854

832-
833855
#[cfg_attr(not(feature = "library"), entry_point)]
834856
pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Response, ContractError> {
835857
let storage_version: ContractVersion = get_contract_version(deps.storage)?;

0 commit comments

Comments
 (0)