File tree Expand file tree Collapse file tree 3 files changed +53
-2
lines changed
Expand file tree Collapse file tree 3 files changed +53
-2
lines changed Original file line number Diff line number Diff line change 1717 "stateMutability": "payable",
1818 "type": "function"
1919 },
20+ {
21+ "inputs": [
22+ {
23+ "internalType": "bytes32",
24+ "name": "hotkey",
25+ "type": "bytes32"
26+ },
27+ {
28+ "internalType": "bytes32",
29+ "name": "coldkey",
30+ "type": "bytes32"
31+ }
32+ ],
33+ "name": "getStake",
34+ "outputs": [
35+ {
36+ "internalType": "uint64",
37+ "name": "",
38+ "type": "uint64"
39+ }
40+ ],
41+ "stateMutability": "view",
42+ "type": "function"
43+ },
2044 {
2145 "inputs": [
2246 {
3761 ],
3862 "name": "removeStake",
3963 "outputs": [],
40- "stateMutability": "payable ",
64+ "stateMutability": "nonpayable ",
4165 "type": "function"
4266 }
43- ]
67+ ]
Original file line number Diff line number Diff line change @@ -42,4 +42,16 @@ interface IStaking {
4242 * - The existing stake amount must be not lower than specified amount
4343 */
4444 function removeStake (bytes32 hotkey , uint256 amount , uint16 netuid ) external ;
45+
46+ /**
47+ * @dev Returns the stake amount associated with the specified `hotkey` and `coldkey`.
48+ *
49+ * This function retrieves the current stake amount linked to a specific hotkey and coldkey pair.
50+ * It is a view function, meaning it does not modify the state of the contract and is free to call.
51+ *
52+ * @param hotkey The hotkey public key (32 bytes).
53+ * @param coldkey The coldkey public key (32 bytes).
54+ * @return The current stake amount in uint64 format.
55+ */
56+ function getStake (bytes32 hotkey , bytes32 coldkey ) external view returns (uint64 );
4557}
Original file line number Diff line number Diff line change @@ -59,6 +59,9 @@ impl StakingPrecompile {
5959 id if id == get_method_id ( "removeStake(bytes32,uint256,uint16)" ) => {
6060 Self :: remove_stake ( handle, & method_input)
6161 }
62+ id if id == get_method_id ( "getStake(bytes32,bytes32)" ) => {
63+ Self :: get_stake ( handle, & method_input)
64+ }
6265 _ => Err ( PrecompileFailure :: Error {
6366 exit_status : ExitError :: InvalidRange ,
6467 } ) ,
@@ -101,6 +104,18 @@ impl StakingPrecompile {
101104 Self :: dispatch ( handle, call)
102105 }
103106
107+ fn get_stake ( handle : & mut impl PrecompileHandle , data : & [ u8 ] ) -> PrecompileResult {
108+ let hotkey: AccountId32 = Self :: parse_hotkey ( data) ?. into ( ) ;
109+
110+ let data =
111+ pallet_subtensor:: Pallet :: < Runtime > :: get_stake_for_coldkey_and_hotkey ( & hotkey, & hotkey) ;
112+
113+ Ok ( PrecompileOutput {
114+ exit_status : ExitSucceed :: Returned ,
115+ output : data. to_le_bytes ( ) . to_vec ( ) ,
116+ } )
117+ }
118+
104119 fn parse_hotkey ( data : & [ u8 ] ) -> Result < [ u8 ; 32 ] , PrecompileFailure > {
105120 if data. len ( ) < 32 {
106121 return Err ( PrecompileFailure :: Error {
You can’t perform that action at this time.
0 commit comments