Skip to content

Commit c3d85bd

Browse files
authored
Merge pull request #1463 from opentensor/selective-metagraph
Selective metagraph interface
2 parents 1a371e3 + 2d023f7 commit c3d85bd

File tree

4 files changed

+1207
-2
lines changed

4 files changed

+1207
-2
lines changed

pallets/subtensor/rpc/src/lib.rs

+26
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ pub trait SubtensorCustomApi<BlockHash> {
6464
fn get_subnet_state(&self, netuid: u16, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
6565
#[method(name = "subnetInfo_getLockCost")]
6666
fn get_network_lock_cost(&self, at: Option<BlockHash>) -> RpcResult<u64>;
67+
#[method(name = "subnetInfo_getSelectiveMetagraph")]
68+
fn get_selective_metagraph(
69+
&self,
70+
netuid: u16,
71+
metagraph_index: Vec<u16>,
72+
at: Option<BlockHash>,
73+
) -> RpcResult<Vec<u8>>;
6774
}
6875

6976
pub struct SubtensorCustom<C, P> {
@@ -390,4 +397,23 @@ where
390397
Error::RuntimeError(format!("Unable to get subnet lock cost: {:?}", e)).into()
391398
})
392399
}
400+
401+
fn get_selective_metagraph(
402+
&self,
403+
netuid: u16,
404+
metagraph_index: Vec<u16>,
405+
at: Option<<Block as BlockT>::Hash>,
406+
) -> RpcResult<Vec<u8>> {
407+
let api = self.client.runtime_api();
408+
let at = at.unwrap_or_else(|| self.client.info().best_hash);
409+
410+
match api.get_selective_metagraph(at, netuid, metagraph_index) {
411+
Ok(result) => Ok(result.encode()),
412+
Err(e) => Err(Error::RuntimeError(format!(
413+
"Unable to get selective metagraph: {:?}",
414+
e
415+
))
416+
.into()),
417+
}
418+
}
393419
}

pallets/subtensor/runtime-api/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use codec::Compact;
55
use pallet_subtensor::rpc_info::{
66
delegate_info::DelegateInfo,
77
dynamic_info::DynamicInfo,
8-
metagraph::Metagraph,
8+
metagraph::{Metagraph, SelectiveMetagraph},
99
neuron_info::{NeuronInfo, NeuronInfoLite},
1010
show_subnet::SubnetState,
1111
stake_info::StakeInfo,
@@ -40,6 +40,7 @@ sp_api::decl_runtime_apis! {
4040
fn get_metagraph(netuid: u16) -> Option<Metagraph<AccountId32>>;
4141
fn get_dynamic_info(netuid: u16) -> Option<DynamicInfo<AccountId32>>;
4242
fn get_subnet_state(netuid: u16) -> Option<SubnetState<AccountId32>>;
43+
fn get_selective_metagraph(netuid: u16, metagraph_indexes: Vec<u16>) -> Option<SelectiveMetagraph<AccountId32>>;
4344
}
4445

4546
pub trait StakeInfoRuntimeApi {

0 commit comments

Comments
 (0)