Skip to content

Commit

Permalink
spec
Browse files Browse the repository at this point in the history
  • Loading branch information
unconst committed Jan 6, 2025
1 parent 79cdfe1 commit bae7cb1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pallets/subtensor/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ pub trait SubtensorCustomApi<BlockHash> {
fn get_subnet_hyperparams(&self, netuid: u16, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
#[method(name = "subnetInfo_getAllDynamicInfo")]
fn get_all_dynamic_info(&self, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
#[method(name = "subnetInfo_getDynamicInfo")]
fn get_dynamic_info(&self, netuid: u16, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
#[method(name = "subnetInfo_getLockCost")]
fn get_network_lock_cost(&self, at: Option<BlockHash>) -> RpcResult<u64>;
}
Expand Down Expand Up @@ -218,6 +220,13 @@ where
.map_err(|e| Error::RuntimeError(format!("Unable to get dynamic subnets info: {:?}", e)).into())
}

fn get_dynamic_info(&self, netuid: u16, at: Option<<Block as BlockT>::Hash>) -> RpcResult<Vec<u8>> {
let api = self.client.runtime_api();
let at = at.unwrap_or_else(|| self.client.info().best_hash);
api.get_dynamic_info(at, netuid)
.map_err(|e| Error::RuntimeError(format!("Unable to get dynamic subnets info: {:?}", e)).into())
}

fn get_subnets_info(&self, at: Option<<Block as BlockT>::Hash>) -> RpcResult<Vec<u8>> {
let api = self.client.runtime_api();
let at = at.unwrap_or_else(|| self.client.info().best_hash);
Expand Down
1 change: 1 addition & 0 deletions pallets/subtensor/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ sp_api::decl_runtime_apis! {
fn get_subnets_info_v2() -> Vec<u8>;
fn get_subnet_hyperparams(netuid: u16) -> Vec<u8>;
fn get_all_dynamic_info() -> Vec<u8>;
fn get_dynamic_info(netuid: u16) -> Vec<u8>;
}

pub trait StakeInfoRuntimeApi {
Expand Down
10 changes: 10 additions & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2082,6 +2082,16 @@ impl_runtime_apis! {
}
}

fn get_dynamic_info(netuid: u16) -> Vec<u8> {
let _result = SubtensorModule::get_dynamic_info(netuid);
if _result.is_some() {
let result = _result.expect("Could not get DynamicInfo.");
result.encode()
} else {
vec![]
}
}

fn get_all_dynamic_info() -> Vec<u8> {
let result = SubtensorModule::get_all_dynamic_info();
result.encode()
Expand Down

0 comments on commit bae7cb1

Please sign in to comment.