@@ -53,10 +53,10 @@ impl StakingPrecompile {
53
53
. map_or_else ( vec:: Vec :: new, |slice| slice. to_vec ( ) ) ; // Avoiding borrowing conflicts
54
54
55
55
match method_id {
56
- id if id == get_method_id ( "addStake(bytes32,uint16 )" ) => {
56
+ id if id == get_method_id ( "addStake(bytes32,uint256 )" ) => {
57
57
Self :: add_stake ( handle, & method_input)
58
58
}
59
- id if id == get_method_id ( "removeStake(bytes32,uint256,uint16 )" ) => {
59
+ id if id == get_method_id ( "removeStake(bytes32,uint256,uint256 )" ) => {
60
60
Self :: remove_stake ( handle, & method_input)
61
61
}
62
62
id if id == get_method_id ( "getStake(bytes32,bytes32,uint16)" ) => {
@@ -71,9 +71,7 @@ impl StakingPrecompile {
71
71
fn add_stake ( handle : & mut impl PrecompileHandle , data : & [ u8 ] ) -> PrecompileResult {
72
72
let hotkey = Self :: parse_hotkey ( data) ?. into ( ) ;
73
73
let amount: U256 = handle. context ( ) . apparent_value ;
74
-
75
- // TODO: Use netuid method parameter here
76
- let netuid: u16 = 0 ;
74
+ let netuid = Self :: parse_netuid ( data, 0x3E ) ?;
77
75
78
76
let amount_sub =
79
77
<Runtime as pallet_evm:: Config >:: BalanceConverter :: into_substrate_balance ( amount)
@@ -88,11 +86,10 @@ impl StakingPrecompile {
88
86
// Dispatch the add_stake call
89
87
Self :: dispatch ( handle, call)
90
88
}
89
+
91
90
fn remove_stake ( handle : & mut impl PrecompileHandle , data : & [ u8 ] ) -> PrecompileResult {
92
91
let hotkey = Self :: parse_hotkey ( data) ?. into ( ) ;
93
-
94
- // TODO: Use netuid method parameter here
95
- let netuid: u16 = 0 ;
92
+ let netuid = Self :: parse_netuid ( data, 0x5E ) ?;
96
93
97
94
// We have to treat this as uint256 (because of Solidity ABI encoding rules, it pads uint64),
98
95
// but this will never exceed 8 bytes, se we will ignore higher bytes and will only use lower
@@ -157,6 +154,20 @@ impl StakingPrecompile {
157
154
Ok ( hotkey)
158
155
}
159
156
157
+ fn parse_netuid ( data : & [ u8 ] , offset : usize ) -> Result < u16 , PrecompileFailure > {
158
+ if data. len ( ) < offset + 2 {
159
+ return Err ( PrecompileFailure :: Error {
160
+ exit_status : ExitError :: InvalidRange ,
161
+ } ) ;
162
+ }
163
+
164
+ let mut netuid_bytes = [ 0u8 ; 2 ] ;
165
+ netuid_bytes. copy_from_slice ( get_slice ( data, offset, offset + 2 ) ?) ;
166
+ let netuid: u16 = netuid_bytes[ 1 ] as u16 | ( ( netuid_bytes[ 0 ] as u16 ) << 8u16 ) ;
167
+
168
+ Ok ( netuid)
169
+ }
170
+
160
171
fn dispatch ( handle : & mut impl PrecompileHandle , call : RuntimeCall ) -> PrecompileResult {
161
172
let account_id =
162
173
<HashedAddressMapping < BlakeTwo256 > as AddressMapping < AccountId32 > >:: into_account_id (
@@ -181,9 +192,12 @@ impl StakingPrecompile {
181
192
exit_status : ExitSucceed :: Returned ,
182
193
output : vec ! [ ] ,
183
194
} ) ,
184
- Err ( _) => Err ( PrecompileFailure :: Error {
185
- exit_status : ExitError :: Other ( "Subtensor call failed" . into ( ) ) ,
186
- } ) ,
195
+ Err ( _) => {
196
+ log:: warn!( "Returning error PrecompileFailure::Error" ) ;
197
+ Err ( PrecompileFailure :: Error {
198
+ exit_status : ExitError :: Other ( "Subtensor call failed" . into ( ) ) ,
199
+ } )
200
+ }
187
201
}
188
202
}
189
203
0 commit comments