Skip to content

Commit 1398353

Browse files
committed
add get subnet register interface
1 parent 6b5d834 commit 1398353

File tree

3 files changed

+142
-0
lines changed

3 files changed

+142
-0
lines changed

runtime/src/precompiles/metagraph.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ impl MetagraphPrecompile {
2121

2222
match method_id {
2323
id if id == get_method_id("getUidCount(uint16)") => Self::get_uid_count(&method_input),
24+
id if id == get_method_id("getIsSubnetRegistered(uint16)") => {
25+
Self::get_is_subnet_registered(&method_input)
26+
}
2427
id if id == get_method_id("getStake(uint16,uint16)") => Self::get_stake(&method_input),
2528
id if id == get_method_id("getRank(uint16,uint16)") => Self::get_rank(&method_input),
2629
id if id == get_method_id("getTrust(uint16,uint16)") => Self::get_trust(&method_input),
@@ -76,6 +79,24 @@ impl MetagraphPrecompile {
7679
})
7780
}
7881

82+
fn get_is_subnet_registered(data: &[u8]) -> PrecompileResult {
83+
let netuid = Self::parse_netuid(data)?;
84+
let is_registered = pallet_subtensor::Pallet::<Runtime>::if_subnet_exist(netuid);
85+
86+
let result_u256 = if is_registered {
87+
U256::from(1)
88+
} else {
89+
U256::from(0)
90+
};
91+
let mut result = [0_u8; 32];
92+
U256::to_big_endian(&result_u256, &mut result);
93+
94+
Ok(PrecompileOutput {
95+
exit_status: ExitSucceed::Returned,
96+
output: result.into(),
97+
})
98+
}
99+
79100
fn get_stake(data: &[u8]) -> PrecompileResult {
80101
let netuid = Self::parse_netuid(data)?;
81102
let uid = Self::parse_uid(get_slice(data, 32, 64)?)?;

runtime/src/precompiles/solidity/metagraph.abi

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,25 @@
338338
"stateMutability": "view",
339339
"type": "function"
340340
},
341+
{
342+
"inputs": [
343+
{
344+
"internalType": "uint16",
345+
"name": "netuid",
346+
"type": "uint16"
347+
}
348+
],
349+
"name": "getIsSubnetRegistered",
350+
"outputs": [
351+
{
352+
"internalType": "bool",
353+
"name": "",
354+
"type": "bool"
355+
}
356+
],
357+
"stateMutability": "view",
358+
"type": "function"
359+
},
341360
{
342361
"inputs": [
343362
{

runtime/src/precompiles/solidity/metagraph.sol

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,123 @@ interface IMetagraph {
1919
* @return The count of UIDs associated with the specified netuid.
2020
*/
2121
function getUidCount(uint16 netuid) external view returns (uint16);
22+
23+
/**
24+
* @dev Checks if a subnet with the given network identifier (netuid) is registered.
25+
* @param netuid The network identifier of the subnet to check.
26+
* @return Returns true if the subnet is registered, false otherwise.
27+
*/
28+
function getIsSubnetRegistered(uint16 netuid) external view returns (bool);
2229

30+
/**
31+
* @dev Retrieves the stake amount associated with a given network identifier (netuid) and unique identifier (uid).
32+
* @param netuid The network identifier for which to retrieve the stake.
33+
* @param uid The unique identifier for which to retrieve the stake.
34+
* @return The stake amount associated with the specified netuid and uid.
35+
*/
2336
function getStake(uint16 netuid, uint16 uid) external view returns (uint64);
2437

38+
/**
39+
* @dev Retrieves the rank of a node with a given network identifier (netuid) and unique identifier (uid).
40+
* @param netuid The network identifier for which to retrieve the rank.
41+
* @param uid The unique identifier for which to retrieve the rank.
42+
* @return The rank of the node with the specified netuid and uid.
43+
*/
2544
function getRank(uint16 netuid, uint16 uid) external view returns (uint16);
2645

46+
/**
47+
* @dev Retrieves the trust value of a node with a given network identifier (netuid) and unique identifier (uid).
48+
* @param netuid The network identifier for which to retrieve the trust value.
49+
* @param uid The unique identifier for which to retrieve the trust value.
50+
* @return The trust value of the node with the specified netuid and uid.
51+
*/
2752
function getTrust(uint16 netuid, uint16 uid) external view returns (uint16);
53+
54+
/**
55+
* @dev Retrieves the consensus value of a node with a given network identifier (netuid) and unique identifier (uid).
56+
* @param netuid The network identifier for which to retrieve the consensus value.
57+
* @param uid The unique identifier for which to retrieve the consensus value.
58+
* @return The consensus value of the node with the specified netuid and uid.
59+
*/
2860
function getConsensus(uint16 netuid, uint16 uid) external view returns (uint16);
61+
62+
/**
63+
* @dev Retrieves the incentive value of a node with a given network identifier (netuid) and unique identifier (uid).
64+
* @param netuid The network identifier for which to retrieve the incentive value.
65+
* @param uid The unique identifier for which to retrieve the incentive value.
66+
* @return The incentive value of the node with the specified netuid and uid.
67+
*/
2968
function getIncentive(uint16 netuid, uint16 uid) external view returns (uint16);
69+
70+
/**
71+
* @dev Retrieves the dividend value of a node with a given network identifier (netuid) and unique identifier (uid).
72+
* @param netuid The network identifier for which to retrieve the dividend value.
73+
* @param uid The unique identifier for which to retrieve the dividend value.
74+
* @return The dividend value of the node with the specified netuid and uid.
75+
*/
3076
function getDividends(uint16 netuid, uint16 uid) external view returns (uint16);
77+
78+
/**
79+
* @dev Retrieves the emission value of a node with a given network identifier (netuid) and unique identifier (uid).
80+
* @param netuid The network identifier for which to retrieve the emission value.
81+
* @param uid The unique identifier for which to retrieve the emission value.
82+
* @return The emission value of the node with the specified netuid and uid.
83+
*/
3184
function getEmission(uint16 netuid, uint16 uid) external view returns (uint64);
85+
86+
/**
87+
* @dev Retrieves the v-trust value of a node with a given network identifier (netuid) and unique identifier (uid).
88+
* @param netuid The network identifier for which to retrieve the v-trust value.
89+
* @param uid The unique identifier for which to retrieve the v-trust value.
90+
* @return The v-trust value of the node with the specified netuid and uid.
91+
*/
3292
function getVtrust(uint16 netuid, uint16 uid) external view returns (uint16);
93+
94+
/**
95+
* @dev Checks the validator status of a node with a given network identifier (netuid) and unique identifier (uid).
96+
* @param netuid The network identifier for which to check the validator status.
97+
* @param uid The unique identifier for which to check the validator status.
98+
* @return Returns true if the node is a validator, false otherwise.
99+
*/
33100
function getValidatorStatus(uint16 netuid, uint16 uid) external view returns (bool);
101+
102+
/**
103+
* @dev Retrieves the last update timestamp of a node with a given network identifier (netuid) and unique identifier (uid).
104+
* @param netuid The network identifier for which to retrieve the last update timestamp.
105+
* @param uid The unique identifier for which to retrieve the last update timestamp.
106+
* @return The last update timestamp of the node with the specified netuid and uid.
107+
*/
34108
function getLastUpdate(uint16 netuid, uint16 uid) external view returns (uint64);
109+
110+
/**
111+
* @dev Checks if a node with a given network identifier (netuid) and unique identifier (uid) is active.
112+
* @param netuid The network identifier for which to check the node's activity.
113+
* @param uid The unique identifier for which to check the node's activity.
114+
* @return Returns true if the node is active, false otherwise.
115+
*/
35116
function getIsActive(uint16 netuid, uint16 uid) external view returns (bool);
117+
118+
/**
119+
* @dev Retrieves the axon information of a node with a given network identifier (netuid) and unique identifier (uid).
120+
* @param netuid The network identifier for which to retrieve the axon information.
121+
* @param uid The unique identifier for which to retrieve the axon information.
122+
* @return The axon information of the node with the specified netuid and uid.
123+
*/
36124
function getAxon(uint16 netuid, uint16 uid) external view returns (AxonInfo memory);
125+
126+
/**
127+
* @dev Retrieves the hotkey of a node with a given network identifier (netuid) and unique identifier (uid).
128+
* @param netuid The network identifier for which to retrieve the hotkey.
129+
* @param uid The unique identifier for which to retrieve the hotkey.
130+
* @return The hotkey of the node with the specified netuid and uid.
131+
*/
37132
function getHotkey(uint16 netuid, uint16 uid) external view returns (bytes32);
133+
134+
/**
135+
* @dev Retrieves the coldkey of a node with a given network identifier (netuid) and unique identifier (uid).
136+
* @param netuid The network identifier for which to retrieve the coldkey.
137+
* @param uid The unique identifier for which to retrieve the coldkey.
138+
* @return The coldkey of the node with the specified netuid and uid.
139+
*/
38140
function getColdkey(uint16 netuid, uint16 uid) external view returns (bytes32);
39141
}

0 commit comments

Comments
 (0)