@@ -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
_ => Err ( PrecompileFailure :: Error {
@@ -68,9 +68,7 @@ impl StakingPrecompile {
68
68
fn add_stake ( handle : & mut impl PrecompileHandle , data : & [ u8 ] ) -> PrecompileResult {
69
69
let hotkey = Self :: parse_hotkey ( data) ?. into ( ) ;
70
70
let amount: U256 = handle. context ( ) . apparent_value ;
71
-
72
- // TODO: Use netuid method parameter here
73
- let netuid: u16 = 0 ;
71
+ let netuid = Self :: parse_netuid ( data, 0x3E ) ?;
74
72
75
73
let amount_sub =
76
74
<Runtime as pallet_evm:: Config >:: BalanceConverter :: into_substrate_balance ( amount)
@@ -85,11 +83,10 @@ impl StakingPrecompile {
85
83
// Dispatch the add_stake call
86
84
Self :: dispatch ( handle, call)
87
85
}
86
+
88
87
fn remove_stake ( handle : & mut impl PrecompileHandle , data : & [ u8 ] ) -> PrecompileResult {
89
88
let hotkey = Self :: parse_hotkey ( data) ?. into ( ) ;
90
-
91
- // TODO: Use netuid method parameter here
92
- let netuid: u16 = 0 ;
89
+ let netuid = Self :: parse_netuid ( data, 0x5E ) ?;
93
90
94
91
// We have to treat this as uint256 (because of Solidity ABI encoding rules, it pads uint64),
95
92
// but this will never exceed 8 bytes, se we will ignore higher bytes and will only use lower
@@ -121,6 +118,20 @@ impl StakingPrecompile {
121
118
Ok ( hotkey)
122
119
}
123
120
121
+ fn parse_netuid ( data : & [ u8 ] , offset : usize ) -> Result < u16 , PrecompileFailure > {
122
+ if data. len ( ) < offset + 2 {
123
+ return Err ( PrecompileFailure :: Error {
124
+ exit_status : ExitError :: InvalidRange ,
125
+ } ) ;
126
+ }
127
+
128
+ let mut netuid_bytes = [ 0u8 ; 2 ] ;
129
+ netuid_bytes. copy_from_slice ( get_slice ( data, offset, offset + 2 ) ?) ;
130
+ let netuid: u16 = netuid_bytes[ 1 ] as u16 | ( ( netuid_bytes[ 0 ] as u16 ) << 8u16 ) ;
131
+
132
+ Ok ( netuid)
133
+ }
134
+
124
135
fn dispatch ( handle : & mut impl PrecompileHandle , call : RuntimeCall ) -> PrecompileResult {
125
136
let account_id =
126
137
<HashedAddressMapping < BlakeTwo256 > as AddressMapping < AccountId32 > >:: into_account_id (
@@ -145,9 +156,12 @@ impl StakingPrecompile {
145
156
exit_status : ExitSucceed :: Returned ,
146
157
output : vec ! [ ] ,
147
158
} ) ,
148
- Err ( _) => Err ( PrecompileFailure :: Error {
149
- exit_status : ExitError :: Other ( "Subtensor call failed" . into ( ) ) ,
150
- } ) ,
159
+ Err ( _) => {
160
+ log:: warn!( "Returning error PrecompileFailure::Error" ) ;
161
+ Err ( PrecompileFailure :: Error {
162
+ exit_status : ExitError :: Other ( "Subtensor call failed" . into ( ) ) ,
163
+ } )
164
+ }
151
165
}
152
166
}
153
167
0 commit comments