File tree Expand file tree Collapse file tree 3 files changed +50
-0
lines changed Expand file tree Collapse file tree 3 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 39
39
"outputs": [],
40
40
"stateMutability": "payable",
41
41
"type": "function"
42
+ },
43
+ {
44
+ "inputs": [
45
+ {
46
+ "internalType": "bytes32",
47
+ "name": "coldkey",
48
+ "type": "bytes32"
49
+ }
50
+ ],
51
+ "name": "getStakeColdkey",
52
+ "outputs": [
53
+ {
54
+ "internalType": "uint256",
55
+ "name": "",
56
+ "type": "uint256"
57
+ }
58
+ ],
59
+ "stateMutability": "view",
60
+ "type": "function"
42
61
}
43
62
]
Original file line number Diff line number Diff line change @@ -42,4 +42,16 @@ interface IStaking {
42
42
* - The existing stake amount must be not lower than specified amount
43
43
*/
44
44
function removeStake (bytes32 hotkey , uint256 amount , uint16 netuid ) external ;
45
+
46
+ /**
47
+ * @dev Returns the amount of RAO staked by the coldkey associated with the hotkey.
48
+ *
49
+ * This function allows external accounts and contracts to query the amount of RAO staked by the coldkey
50
+ * associated with the coldkey, which effectively calls `get_coldkey_stake` on the subtensor pallet with
51
+ * specified coldkey as a parameter.
52
+ *
53
+ * @param coldkey The coldkey public key (32 bytes).
54
+ * @return The amount of RAO staked by the coldkey associated with the hotkey.
55
+ */
56
+ function getStakeColdkey (bytes32 coldkey ) external view returns (uint256 );
45
57
}
Original file line number Diff line number Diff line change @@ -59,6 +59,9 @@ impl StakingPrecompile {
59
59
id if id == get_method_id ( "removeStake(bytes32,uint256,uint16)" ) => {
60
60
Self :: remove_stake ( handle, & method_input)
61
61
}
62
+ id if id == get_method_id ( "getStakeColdkey(bytes32)" ) => {
63
+ Self :: get_stake_coldkey ( & method_input)
64
+ }
62
65
_ => Err ( PrecompileFailure :: Error {
63
66
exit_status : ExitError :: InvalidRange ,
64
67
} ) ,
@@ -110,6 +113,22 @@ impl StakingPrecompile {
110
113
Self :: dispatch ( handle, call)
111
114
}
112
115
116
+ fn get_stake_coldkey ( data : & [ u8 ] ) -> PrecompileResult {
117
+ // TODO: rename parse_hotkey to parse_key or something?
118
+ let coldkey: AccountId32 = Self :: parse_hotkey ( data) ?. into ( ) ;
119
+
120
+ // get total stake of coldkey
121
+ let total_stake = pallet_subtensor:: TotalColdkeyStake :: < Runtime > :: get ( coldkey) ;
122
+ let result_u256 = U256 :: from ( total_stake) ;
123
+ let mut result = [ 0_u8 ; 32 ] ;
124
+ U256 :: to_big_endian ( & result_u256, & mut result) ;
125
+
126
+ Ok ( PrecompileOutput {
127
+ exit_status : ExitSucceed :: Returned ,
128
+ output : result. into ( ) ,
129
+ } )
130
+ }
131
+
113
132
fn parse_hotkey ( data : & [ u8 ] ) -> Result < [ u8 ; 32 ] , PrecompileFailure > {
114
133
if data. len ( ) < 32 {
115
134
return Err ( PrecompileFailure :: Error {
You can’t perform that action at this time.
0 commit comments