@@ -66,16 +66,24 @@ impl StakingPrecompile {
66
66
}
67
67
68
68
fn add_stake ( handle : & mut impl PrecompileHandle , data : & [ u8 ] ) -> PrecompileResult {
69
+ log:: error!( "++++++ add_stake data as {:?}" , data) ;
69
70
let hotkey = Self :: parse_hotkey ( data) ?. into ( ) ;
70
71
let amount: U256 = handle. context ( ) . apparent_value ;
71
72
let amount_sub =
72
73
<Runtime as pallet_evm:: Config >:: BalanceConverter :: into_substrate_balance ( amount)
73
74
. ok_or ( ExitError :: OutOfFund ) ?;
74
75
75
- let netuid =
76
- Self :: parse_netuid ( data. get ( 56 ..64 ) . unwrap_or ( Err ( PrecompileFailure :: Error {
77
- exit_status : ExitError :: InvalidRange ,
78
- } ) ?) ) ?;
76
+ log:: error!( "++++++ amount_sub {:?}" , & amount_sub) ;
77
+
78
+ let netuid_vec = data. get ( 56 ..64 ) . ok_or ( PrecompileFailure :: Error {
79
+ exit_status : ExitError :: InvalidRange ,
80
+ } ) ?;
81
+
82
+ log:: error!( "++++++ netuid_vec is {:?}" , netuid_vec) ;
83
+
84
+ let netuid = Self :: parse_netuid ( netuid_vec) ?;
85
+
86
+ log:: error!( "++++++ netuid is {}" , netuid) ;
79
87
80
88
// Create the add_stake call
81
89
let call = RuntimeCall :: SubtensorModule ( pallet_subtensor:: Call :: < Runtime > :: add_stake {
@@ -87,6 +95,8 @@ impl StakingPrecompile {
87
95
Self :: dispatch ( handle, call)
88
96
}
89
97
fn remove_stake ( handle : & mut impl PrecompileHandle , data : & [ u8 ] ) -> PrecompileResult {
98
+ log:: error!( "------ add_stake data as {:?}" , data) ;
99
+
90
100
let hotkey = Self :: parse_hotkey ( data) ?. into ( ) ;
91
101
92
102
// We have to treat this as uint256 (because of Solidity ABI encoding rules, it pads uint64),
@@ -100,10 +110,21 @@ impl StakingPrecompile {
100
110
<Runtime as pallet_evm:: Config >:: BalanceConverter :: into_substrate_balance ( amount)
101
111
. ok_or ( ExitError :: OutOfFund ) ?;
102
112
103
- let netuid =
104
- Self :: parse_netuid ( data. get ( 64 ..72 ) . unwrap_or ( Err ( PrecompileFailure :: Error {
105
- exit_status : ExitError :: InvalidRange ,
106
- } ) ?) ) ?;
113
+ log:: error!( "------ add_stake amount as {:?}" , amount) ;
114
+
115
+ let netuid_vec = data. get ( 88 ..96 ) . ok_or ( PrecompileFailure :: Error {
116
+ exit_status : ExitError :: InvalidRange ,
117
+ } ) ?;
118
+
119
+ log:: error!( "------ netuid_vec is {:?}" , netuid_vec) ;
120
+
121
+ let netuid = Self :: parse_netuid ( netuid_vec) ?;
122
+ log:: error!( "------ add_stake netuid as {:?}" , netuid) ;
123
+
124
+ // let netuid =
125
+ // Self::parse_netuid(data.get(64..72).unwrap_or(Err(PrecompileFailure::Error {
126
+ // exit_status: ExitError::InvalidRange,
127
+ // })?))?;
107
128
108
129
let call = RuntimeCall :: SubtensorModule ( pallet_subtensor:: Call :: < Runtime > :: remove_stake {
109
130
hotkey,
@@ -125,19 +146,28 @@ impl StakingPrecompile {
125
146
}
126
147
127
148
fn parse_netuid ( data : & [ u8 ] ) -> Result < u16 , PrecompileFailure > {
149
+ log:: error!( "++++++ parse_netuid data is {:?}" , & data) ;
150
+
128
151
let netuid = data
129
152
. get ( 0 ..8 )
130
153
. map ( U256 :: from_big_endian)
131
154
. ok_or ( ExitError :: InvalidRange ) ?;
132
155
156
+ log:: error!( "++++++ parse_netuid is {:?}" , & netuid) ;
157
+
133
158
let u16_max_u256 = U256 :: from ( u16:: MAX ) ;
159
+
160
+ log:: error!( "++++++ parse_netuid u16_max_u256 {:?}" , & u16_max_u256) ;
161
+
134
162
if netuid > u16_max_u256 {
135
163
// if netuid.as_u128() > u16::MAX as u128 {
136
164
return Err ( PrecompileFailure :: Error {
137
165
exit_status : ExitError :: InvalidRange ,
138
166
} ) ;
139
167
}
140
168
169
+ log:: error!( "++++++ parse_netuid netuid.as_u32() {:?}" , & netuid. as_u32( ) ) ;
170
+
141
171
Ok ( netuid. as_u32 ( ) as u16 )
142
172
}
143
173
0 commit comments