@@ -60,7 +60,7 @@ impl StakingPrecompile {
6060 Self :: remove_stake ( handle, & method_input)
6161 }
6262 id if id == get_method_id ( "getStake(bytes32,bytes32)" ) => {
63- Self :: get_stake ( handle , & method_input)
63+ Self :: get_stake ( & method_input)
6464 }
6565 _ => Err ( PrecompileFailure :: Error {
6666 exit_status : ExitError :: InvalidRange ,
@@ -104,18 +104,37 @@ impl StakingPrecompile {
104104 Self :: dispatch ( handle, call)
105105 }
106106
107- fn get_stake ( handle : & mut impl PrecompileHandle , data : & [ u8 ] ) -> PrecompileResult {
108- let hotkey: AccountId32 = Self :: parse_hotkey ( data) ?. into ( ) ;
107+ fn get_stake ( data : & [ u8 ] ) -> PrecompileResult {
108+ let ( hotkey, coldkey ) = Self :: parse_hotkey_coldkey ( data) ?. into ( ) ;
109109
110- let data =
111- pallet_subtensor:: Pallet :: < Runtime > :: get_stake_for_coldkey_and_hotkey ( & hotkey, & hotkey) ;
110+ let stake = pallet_subtensor:: Pallet :: < Runtime > :: get_stake_for_coldkey_and_hotkey (
111+ & hotkey. into ( ) ,
112+ & coldkey. into ( ) ,
113+ ) ;
114+
115+ let stake_u256 = U256 :: from ( stake) ;
116+ let mut result = [ 0_u8 ; 32 ] ;
117+ U256 :: to_big_endian ( & stake_u256, & mut result) ;
112118
113119 Ok ( PrecompileOutput {
114120 exit_status : ExitSucceed :: Returned ,
115- output : data . to_le_bytes ( ) . to_vec ( ) ,
121+ output : result . into ( ) ,
116122 } )
117123 }
118124
125+ fn parse_hotkey_coldkey ( data : & [ u8 ] ) -> Result < ( [ u8 ; 32 ] , [ u8 ; 32 ] ) , PrecompileFailure > {
126+ if data. len ( ) < 64 {
127+ return Err ( PrecompileFailure :: Error {
128+ exit_status : ExitError :: InvalidRange ,
129+ } ) ;
130+ }
131+ let mut hotkey = [ 0u8 ; 32 ] ;
132+ hotkey. copy_from_slice ( get_slice ( data, 0 , 32 ) ?) ;
133+ let mut coldkey = [ 0u8 ; 32 ] ;
134+ coldkey. copy_from_slice ( get_slice ( data, 32 , 64 ) ?) ;
135+ Ok ( ( hotkey, coldkey) )
136+ }
137+
119138 fn parse_hotkey ( data : & [ u8 ] ) -> Result < [ u8 ; 32 ] , PrecompileFailure > {
120139 if data. len ( ) < 32 {
121140 return Err ( PrecompileFailure :: Error {
0 commit comments