Skip to content

Commit 95764b6

Browse files
committed
fix clippy
1 parent 2d76d84 commit 95764b6

File tree

1 file changed

+18
-33
lines changed

1 file changed

+18
-33
lines changed

runtime/src/precompiles/metagraph.rs

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
11
extern crate alloc;
2-
3-
use alloc::vec::Vec;
4-
52
use crate::precompiles::{get_method_id, get_slice};
6-
use crate::{Runtime, RuntimeCall};
7-
use ed25519_dalek::{Signature, Verifier, VerifyingKey};
3+
use crate::Runtime;
84
use fp_evm::{
9-
ExitError, ExitSucceed, LinearCostPrecompile, PrecompileFailure, PrecompileHandle,
10-
PrecompileOutput, PrecompileResult,
5+
ExitError, ExitSucceed, PrecompileFailure, PrecompileHandle, PrecompileOutput, PrecompileResult,
116
};
127
use sp_core::{ByteArray, U256};
138
use sp_std::vec;
149
pub const METAGRAPH_PRECOMPILE_INDEX: u64 = 2050;
15-
use sp_runtime::AccountId32;
1610
pub struct MetagraphPrecompile;
1711

1812
const NO_HOTKEY: &str = "no hotkey";
1913

2014
impl MetagraphPrecompile {
2115
pub fn execute(handle: &mut impl PrecompileHandle) -> PrecompileResult {
22-
log::error!("++++++ execute metagraph");
2316
let txdata = handle.input();
2417
let method_id = get_slice(txdata, 0, 4)?;
2518
let method_input = txdata
@@ -70,12 +63,7 @@ impl MetagraphPrecompile {
7063
}
7164

7265
fn get_uid_count(data: &[u8]) -> PrecompileResult {
73-
log::error!("++++++ data len is {:?}", data.len());
74-
7566
let netuid = Self::parse_netuid(data)?;
76-
77-
log::error!("++++++ netuid is {:?}", netuid);
78-
7967
let uid_count = pallet_subtensor::SubnetworkN::<Runtime>::get(netuid);
8068

8169
let uid_count_u256 = U256::from(uid_count);
@@ -90,29 +78,26 @@ impl MetagraphPrecompile {
9078

9179
fn get_stake(data: &[u8]) -> PrecompileResult {
9280
let netuid = Self::parse_netuid(data)?;
93-
let uid = Self::parse_uid(&data[32..])?;
94-
81+
let uid = Self::parse_uid(get_slice(data, 32, 64)?)?;
9582
let hotkey = pallet_subtensor::Pallet::<Runtime>::get_hotkey_for_net_and_uid(netuid, uid)
9683
.map_err(|_| PrecompileFailure::Error {
9784
exit_status: ExitError::InvalidRange,
9885
})?;
9986

10087
let stake = pallet_subtensor::TotalHotkeyStake::<Runtime>::get(&hotkey);
101-
10288
let result_u256 = U256::from(stake);
10389
let mut result = [0_u8; 32];
10490
U256::to_big_endian(&result_u256, &mut result);
10591

10692
Ok(PrecompileOutput {
10793
exit_status: ExitSucceed::Returned,
108-
output: [].into(),
94+
output: result.into(),
10995
})
11096
}
11197

11298
fn get_rank(data: &[u8]) -> PrecompileResult {
11399
let netuid = Self::parse_netuid(data)?;
114-
let uid = Self::parse_uid(&data[32..])?;
115-
100+
let uid = Self::parse_uid(get_slice(data, 32, 64)?)?;
116101
let rank = pallet_subtensor::Pallet::<Runtime>::get_rank_for_uid(netuid, uid);
117102

118103
let result_u256 = U256::from(rank);
@@ -127,7 +112,7 @@ impl MetagraphPrecompile {
127112

128113
fn get_trust(data: &[u8]) -> PrecompileResult {
129114
let netuid = Self::parse_netuid(data)?;
130-
let uid = Self::parse_uid(&data[32..])?;
115+
let uid = Self::parse_uid(get_slice(data, 32, 64)?)?;
131116

132117
let trust = pallet_subtensor::Pallet::<Runtime>::get_trust_for_uid(netuid, uid);
133118

@@ -143,7 +128,7 @@ impl MetagraphPrecompile {
143128

144129
fn get_consensus(data: &[u8]) -> PrecompileResult {
145130
let netuid = Self::parse_netuid(data)?;
146-
let uid = Self::parse_uid(&data[32..])?;
131+
let uid = Self::parse_uid(get_slice(data, 32, 64)?)?;
147132

148133
let consensus = pallet_subtensor::Pallet::<Runtime>::get_consensus_for_uid(netuid, uid);
149134

@@ -159,7 +144,7 @@ impl MetagraphPrecompile {
159144

160145
fn get_incentive(data: &[u8]) -> PrecompileResult {
161146
let netuid = Self::parse_netuid(data)?;
162-
let uid = Self::parse_uid(&data[32..])?;
147+
let uid = Self::parse_uid(get_slice(data, 32, 64)?)?;
163148

164149
let incentive = pallet_subtensor::Pallet::<Runtime>::get_incentive_for_uid(netuid, uid);
165150

@@ -175,7 +160,7 @@ impl MetagraphPrecompile {
175160

176161
fn get_dividends(data: &[u8]) -> PrecompileResult {
177162
let netuid = Self::parse_netuid(data)?;
178-
let uid = Self::parse_uid(&data[32..])?;
163+
let uid = Self::parse_uid(get_slice(data, 32, 64)?)?;
179164

180165
let dividends = pallet_subtensor::Pallet::<Runtime>::get_dividends_for_uid(netuid, uid);
181166

@@ -191,7 +176,7 @@ impl MetagraphPrecompile {
191176

192177
fn get_emission(data: &[u8]) -> PrecompileResult {
193178
let netuid = Self::parse_netuid(data)?;
194-
let uid = Self::parse_uid(&data[32..])?;
179+
let uid = Self::parse_uid(get_slice(data, 32, 64)?)?;
195180

196181
let emission = pallet_subtensor::Pallet::<Runtime>::get_emission_for_uid(netuid, uid);
197182

@@ -207,7 +192,7 @@ impl MetagraphPrecompile {
207192

208193
fn get_vtrust(data: &[u8]) -> PrecompileResult {
209194
let netuid = Self::parse_netuid(data)?;
210-
let uid = Self::parse_uid(&data[32..])?;
195+
let uid = Self::parse_uid(get_slice(data, 32, 64)?)?;
211196

212197
let vtrust = pallet_subtensor::Pallet::<Runtime>::get_validator_trust_for_uid(netuid, uid);
213198

@@ -223,7 +208,7 @@ impl MetagraphPrecompile {
223208

224209
fn get_validator_status(data: &[u8]) -> PrecompileResult {
225210
let netuid = Self::parse_netuid(data)?;
226-
let uid = Self::parse_uid(&data[32..])?;
211+
let uid = Self::parse_uid(get_slice(data, 32, 64)?)?;
227212

228213
let validator_permit =
229214
pallet_subtensor::Pallet::<Runtime>::get_validator_permit_for_uid(netuid, uid);
@@ -238,13 +223,13 @@ impl MetagraphPrecompile {
238223

239224
Ok(PrecompileOutput {
240225
exit_status: ExitSucceed::Returned,
241-
output: [].into(),
226+
output: result.into(),
242227
})
243228
}
244229

245230
fn get_last_update(data: &[u8]) -> PrecompileResult {
246231
let netuid = Self::parse_netuid(data)?;
247-
let uid = Self::parse_uid(&data[32..])?;
232+
let uid = Self::parse_uid(get_slice(data, 32, 64)?)?;
248233

249234
let last_update = pallet_subtensor::Pallet::<Runtime>::get_last_update_for_uid(netuid, uid);
250235

@@ -260,7 +245,7 @@ impl MetagraphPrecompile {
260245

261246
fn get_is_active(data: &[u8]) -> PrecompileResult {
262247
let netuid = Self::parse_netuid(data)?;
263-
let uid = Self::parse_uid(&data[32..])?;
248+
let uid = Self::parse_uid(get_slice(data, 32, 64)?)?;
264249

265250
let active = pallet_subtensor::Pallet::<Runtime>::get_active_for_uid(netuid, uid);
266251

@@ -276,7 +261,7 @@ impl MetagraphPrecompile {
276261

277262
fn get_axon(data: &[u8]) -> PrecompileResult {
278263
let netuid = Self::parse_netuid(data)?;
279-
let uid = Self::parse_uid(&data[32..])?;
264+
let uid = Self::parse_uid(get_slice(data, 32, 64)?)?;
280265

281266
let hotkey = pallet_subtensor::Pallet::<Runtime>::get_hotkey_for_net_and_uid(netuid, uid)
282267
.map_err(|_| PrecompileFailure::Error {
@@ -319,7 +304,7 @@ impl MetagraphPrecompile {
319304

320305
fn get_hotkey(data: &[u8]) -> PrecompileResult {
321306
let netuid = Self::parse_netuid(data)?;
322-
let uid = Self::parse_uid(&data[32..])?;
307+
let uid = Self::parse_uid(get_slice(data, 32, 64)?)?;
323308

324309
let hotkey = pallet_subtensor::Pallet::<Runtime>::get_hotkey_for_net_and_uid(netuid, uid)
325310
.map_err(|_| PrecompileFailure::Error {
@@ -334,7 +319,7 @@ impl MetagraphPrecompile {
334319

335320
fn get_coldkey(data: &[u8]) -> PrecompileResult {
336321
let netuid = Self::parse_netuid(data)?;
337-
let uid = Self::parse_uid(&data[32..])?;
322+
let uid = Self::parse_uid(get_slice(data, 32, 64)?)?;
338323

339324
let hotkey = pallet_subtensor::Pallet::<Runtime>::get_hotkey_for_net_and_uid(netuid, uid)
340325
.map_err(|_| PrecompileFailure::Error {

0 commit comments

Comments
 (0)