use super::*; extern crate alloc; use codec::Compact; use frame_support::pallet_prelude::{Decode, Encode}; use substrate_fixed::types::I96F32; use subtensor_macros::freeze_struct; use subtensor_runtime_common::{AlphaBalance, NetUid, TaoBalance}; #[freeze_struct("cf677afa654c96a6")] #[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] pub struct DynamicInfo { netuid: Compact, owner_hotkey: AccountId, owner_coldkey: AccountId, subnet_name: Vec>, token_symbol: Vec>, tempo: Compact, last_step: Compact, blocks_since_last_step: Compact, emission: Compact, alpha_in: Compact, alpha_out: Compact, tao_in: Compact, alpha_out_emission: Compact, alpha_in_emission: Compact, tao_in_emission: Compact, pending_alpha_emission: Compact, pending_root_emission: Compact, subnet_volume: Compact, network_registered_at: Compact, subnet_identity: Option, moving_price: I96F32, } impl Pallet { pub fn get_dynamic_info(netuid: NetUid) -> Option> { if !Self::if_subnet_exist(netuid) { return None; } let last_step: u64 = LastMechansimStepBlock::::get(netuid); let current_block: u64 = Pallet::::get_current_block_as_u64(); let blocks_since_last_step: u64 = current_block.saturating_sub(last_step); Some(DynamicInfo { netuid: netuid.into(), owner_hotkey: SubnetOwnerHotkey::::get(netuid), owner_coldkey: SubnetOwner::::get(netuid), subnet_name: Self::get_name_for_subnet(netuid) .into_iter() .map(Compact) .collect(), token_symbol: TokenSymbol::::get(netuid) .into_iter() .map(Compact) .collect(), tempo: Tempo::::get(netuid).into(), last_step: last_step.into(), blocks_since_last_step: blocks_since_last_step.into(), emission: 0.into(), alpha_in: SubnetAlphaIn::::get(netuid).into(), alpha_out: SubnetAlphaOut::::get(netuid).into(), tao_in: SubnetTAO::::get(netuid).into(), alpha_out_emission: SubnetAlphaOutEmission::::get(netuid).into(), alpha_in_emission: SubnetAlphaInEmission::::get(netuid).into(), tao_in_emission: SubnetTaoInEmission::::get(netuid).into(), pending_alpha_emission: PendingValidatorEmission::::get(netuid) .saturating_add(PendingServerEmission::::get(netuid)) .into(), pending_root_emission: TaoBalance::ZERO.into(), subnet_volume: SubnetVolume::::get(netuid).into(), network_registered_at: NetworkRegisteredAt::::get(netuid).into(), subnet_identity: SubnetIdentitiesV3::::get(netuid), moving_price: SubnetMovingPrice::::get(netuid), }) } pub fn get_all_dynamic_info() -> Vec>> { let netuids = Self::get_all_subnet_netuids(); let mut dynamic_info = Vec::>>::new(); for netuid in netuids.clone().iter() { dynamic_info.push(Self::get_dynamic_info(*netuid)); } dynamic_info } }