Skip to content

Commit

Permalink
chore: optimization cargo clippy check problem
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoguang1010 committed Dec 29, 2023
1 parent 5b11a85 commit fe378a6
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 17 deletions.
5 changes: 1 addition & 4 deletions token-core/tcx-common/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ pub type Hash160 = [u8; 20];
pub fn merkle_hash(data: &[u8]) -> Hash256 {
assert!(!data.is_empty(), "data should not be empty");

let mut hashes = data
.chunks(1024)
.map(|chunk| sha256d(chunk))
.collect::<Vec<Hash256>>();
let mut hashes = data.chunks(1024).map(sha256d).collect::<Vec<Hash256>>();

let mut len = hashes.len();
let mut data = [0u8; 64];
Expand Down
4 changes: 2 additions & 2 deletions token-core/tcx-constants/src/btc_fork_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ pub fn network_from_param(
.filter(|x| x.coin.eq(&chain_type.to_uppercase()))
.filter(|x| x.network.eq(&network.to_uppercase()))
.filter(|x| x.seg_wit.eq(&seg_wit.to_uppercase()))
.map(|x| x.clone())
.cloned()
.collect::<Vec<BtcForkNetwork>>();
ret.pop()
}
Expand All @@ -206,7 +206,7 @@ pub fn network_form_hrp(hrp: &str) -> Option<BtcForkNetwork> {
let mut ret: Vec<BtcForkNetwork> = networks
.iter()
.filter(|x| x.hrp.eq(hrp))
.map(|x| x.clone())
.cloned()
.collect::<Vec<BtcForkNetwork>>();
ret.pop()
}
Expand Down
2 changes: 1 addition & 1 deletion token-core/tcx-constants/src/coin_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ pub fn coin_info_from_param(
&& (x.seg_wit.as_str() == seg_wit || seg_wit.is_empty())
&& (x.curve.as_str() == curve || curve.is_empty())
})
.map(|x| x.clone())
.cloned()
.collect::<Vec<CoinInfo>>();

if coins.is_empty() {
Expand Down
4 changes: 2 additions & 2 deletions token-core/tcx-filecoin/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const TESTNET_PREFIX: &str = "t";
#[derive(Clone, Copy)]
pub enum Protocol {
Secp256k1 = 1,
BLS = 3,
Bls = 3,
}

#[derive(PartialEq, Eq, Clone)]
Expand Down Expand Up @@ -49,7 +49,7 @@ impl Address for FilecoinAddress {
checksum = Self::checksum(&[vec![protocol as u8], payload.to_vec()].concat());
}
TypedPublicKey::BLS(pk) => {
protocol = Protocol::BLS;
protocol = Protocol::Bls;
payload = pk.to_bytes();

checksum = Self::checksum(&[vec![protocol as u8], payload.to_vec()].concat());
Expand Down
10 changes: 5 additions & 5 deletions token-core/tcx-keystore/src/keystore/hd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use uuid::Uuid;

use super::{transform_mnemonic_error, Account, Address, Error, Metadata, Result, Store};

use std::collections::HashMap;
use std::collections::{hash_map::Entry, HashMap};

use tcx_common::ToHex;
use tcx_constants::{CoinInfo, CurveType};
Expand Down Expand Up @@ -37,12 +37,12 @@ impl Cache {
F: FnOnce() -> Result<TypedDeterministicPrivateKey>,
{
let cache_key = Cache::get_cache_key(key, curve);
if self.keys.contains_key(&cache_key) {
Ok(self.keys[&cache_key].clone())
} else {
if let Entry::Vacant(e) = self.keys.entry(cache_key.clone()) {
let k = f()?;
self.keys.insert(cache_key, k.clone());
e.insert(k.clone());
Ok(k)
} else {
Ok(self.keys[&cache_key].clone())
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions token-core/tcx-substrate/src/keystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,9 @@ fn gen_nonce() -> [u8; 24] {
let mut rng = rand::thread_rng();
let mut nonce = [0u8; 24];

for idx in 0..24 {
nonce[idx] = rng.gen::<u8>()
}
(0..nonce.len()).for_each(|idx| {
nonce[idx] = rng.gen::<u8>();
});
nonce
}

Expand Down

0 comments on commit fe378a6

Please sign in to comment.