Skip to content

Commit

Permalink
fix clippy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjiao committed Dec 16, 2022
1 parent b154f13 commit 941c546
Show file tree
Hide file tree
Showing 20 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/components/abciapp/src/abci/staking/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn check_block_rewards_rate() -> Result<()> {

{
let rate = ledger.staking_get_block_rewards_rate();
let rate = [rate[0] as u128, rate[1] as u128];
let rate = [rate[0], rate[1]];
// max value: 105%
assert!(rate[0] * 100 <= rate[1] * 105);
// min value: 2%
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ pub async fn query_validators(
})
.collect();
return Ok(web::Json(ValidatorList::new(
staking.cur_height() as u64,
staking.cur_height(),
validators_list,
)));
};
Expand Down
6 changes: 3 additions & 3 deletions src/components/contracts/modules/evm/tests/utils/solidity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl ContractConstructor {
{
let bin_file = format!("{}.bin", contract_name);
let abi_file = format!("{}.abi", contract_name);
let hex_path = artifacts_base_path.as_ref().join(&bin_file);
let hex_path = artifacts_base_path.as_ref().join(bin_file);
let hex_rep = match std::fs::read_to_string(&hex_path) {
Ok(hex) => hex,
Err(_) => {
Expand All @@ -40,8 +40,8 @@ impl ContractConstructor {
std::fs::read_to_string(hex_path).unwrap()
}
};
let code = hex::decode(&hex_rep).unwrap();
let abi_path = artifacts_base_path.as_ref().join(&abi_file);
let code = hex::decode(hex_rep).unwrap();
let abi_path = artifacts_base_path.as_ref().join(abi_file);
let reader = std::fs::File::open(abi_path).unwrap();
let abi = ethabi::Contract::load(reader).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion src/components/contracts/primitives/mocks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub struct KeyPair {
}

pub fn generate_address(seed: u8) -> KeyPair {
let private_key = H256::from_slice(&[(seed + 1) as u8; 32]);
let private_key = H256::from_slice(&[seed + 1; 32]);
let secret_key = libsecp256k1::SecretKey::parse_slice(&private_key[..]).unwrap();
let public_key =
&libsecp256k1::PublicKey::from_secret_key(&secret_key).serialize()[1..65];
Expand Down
2 changes: 1 addition & 1 deletion src/components/contracts/primitives/types/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ pub fn secp256k1_ecdsa_recover(sig: &[u8; 65], msg: &[u8; 32]) -> ruc::Result<[u
.map_err(|_| eg!("Ecdsa signature verify error: bad RS"))?;
let v =
libsecp256k1::RecoveryId::parse(
if sig[64] > 26 { sig[64] - 27 } else { sig[64] } as u8,
if sig[64] > 26 { sig[64] - 27 } else { sig[64] }
)
.map_err(|_| eg!("Ecdsa signature verify error: bad V"))?;
let pubkey = libsecp256k1::recover(&libsecp256k1::Message::parse(msg), &rs, &v)
Expand Down
4 changes: 2 additions & 2 deletions src/components/contracts/primitives/utils/src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl<'de> Deserialize<'de> for Public {
D: Deserializer<'de>,
{
let pk =
base64::decode_config(&String::deserialize(deserializer)?, base64::URL_SAFE)
base64::decode_config(String::deserialize(deserializer)?, base64::URL_SAFE)
.map_err(|e| de::Error::custom(format!("{:?}", e)))?;
Public::try_from(pk.as_slice())
.map_err(|e| de::Error::custom(format!("{:?}", e)))
Expand Down Expand Up @@ -173,7 +173,7 @@ impl<'de> Deserialize<'de> for Signature {
where
D: Deserializer<'de>,
{
let signature_hex = hex::decode(&String::deserialize(deserializer)?)
let signature_hex = hex::decode(String::deserialize(deserializer)?)
.map_err(|e| de::Error::custom(format!("{:?}", e)))?;
Signature::try_from(signature_hex.as_ref())
.map_err(|e| de::Error::custom(format!("{:?}", e)))
Expand Down
2 changes: 1 addition & 1 deletion src/components/contracts/primitives/utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use primitive_types::H160;
pub fn timestamp_converter(timestamp: protobuf::well_known_types::Timestamp) -> u64 {
let unix_time =
core::time::Duration::new(timestamp.seconds as u64, timestamp.nanos as u32);
unix_time.as_secs() as u64
unix_time.as_secs()
}

pub fn proposer_converter(address: Vec<u8>) -> Option<H160> {
Expand Down
8 changes: 4 additions & 4 deletions src/components/contracts/primitives/wasm/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn recover_signer(transaction: &Transaction) -> Option<H160> {

#[wasm_bindgen]
pub fn recover_tx_signer(raw_tx: String) -> Result<String, JsValue> {
let tx_bytes = base64::decode_config(&raw_tx, base64::URL_SAFE)
let tx_bytes = base64::decode_config(raw_tx, base64::URL_SAFE)
.c(d!())
.map_err(error_to_jsvalue)?;
let raw_tx = EvmRawTxWrapper::unwrap(&tx_bytes)
Expand All @@ -55,7 +55,7 @@ pub fn recover_tx_signer(raw_tx: String) -> Result<String, JsValue> {

#[wasm_bindgen]
pub fn evm_tx_hash(raw_tx: String) -> Result<String, JsValue> {
let tx_bytes = base64::decode_config(&raw_tx, base64::URL_SAFE)
let tx_bytes = base64::decode_config(raw_tx, base64::URL_SAFE)
.c(d!())
.map_err(error_to_jsvalue)?;
let raw_tx = EvmRawTxWrapper::unwrap(&tx_bytes)
Expand All @@ -82,7 +82,7 @@ mod test {
#[test]
fn recover_signer_works() {
let raw_tx = String::from("ZXZtOnsic2lnbmF0dXJlIjpudWxsLCJmdW5jdGlvbiI6eyJFdGhlcmV1bSI6eyJUcmFuc2FjdCI6eyJub25jZSI6IjB4MSIsImdhc19wcmljZSI6IjB4MTc0ODc2ZTgwMCIsImdhc19saW1pdCI6IjB4NTIwOCIsImFjdGlvbiI6eyJDYWxsIjoiMHgyYWQzMjg0NmM2ZGQyZmZkM2VkYWRiZTUxY2Q1YWUwNGFhNWU1NzVlIn0sInZhbHVlIjoiMHg1NmJjNzVlMmQ2MzEwMDAwMCIsImlucHV0IjpbXSwic2lnbmF0dXJlIjp7InYiOjEwODIsInIiOiIweGY4YWVmN2Y4MDUzZDg5ZmVlMzk1MGM0ZDcwMjA4MGJmM2E4MDcyYmVkNWQ4NGEzYWYxOWEzNjAwODFiNjM2YTIiLCJzIjoiMHgyOTYyOTlhOGYyNDMwYjg2ZmQzZWI5NzZlYWJjNzMwYWMxY2ZiYmJlMzZlYjY5ZWFlMzM4Y2ZmMzNjNGE5OGMxIn19fX19");
let tx_bytes = base64::decode_config(&raw_tx, base64::URL_SAFE).unwrap();
let tx_bytes = base64::decode_config(raw_tx, base64::URL_SAFE).unwrap();
let evm_tx = EvmRawTxWrapper::unwrap(&tx_bytes).unwrap();
let unchecked_tx: UncheckedTransaction<()> =
serde_json::from_slice(evm_tx).unwrap();
Expand All @@ -100,7 +100,7 @@ mod test {
#[test]
fn evm_tx_hash_works() {
let raw_tx = String::from("eyJzaWduYXR1cmUiOm51bGwsImZ1bmN0aW9uIjp7IkV0aGVyZXVtIjp7IlRyYW5zYWN0Ijp7Im5vbmNlIjoiMHg5IiwiZ2FzX3ByaWNlIjoiMHhlOGQ0YTUxMDAwIiwiZ2FzX2xpbWl0IjoiMHg1MjA4IiwiYWN0aW9uIjp7IkNhbGwiOiIweGE1MjI1Y2JlZTUwNTIxMDBlYzJkMmQ5NGFhNmQyNTg1NTgwNzM3NTcifSwidmFsdWUiOiIweDk4YTdkOWI4MzE0YzAwMDAiLCJpbnB1dCI6W10sInNpZ25hdHVyZSI6eyJ2IjoxMDgyLCJyIjoiMHg4MDBjZjQ5ZTAzMmJhYzY4MjY3MzdhZGJhZDEzN2Y0MTk5OTRjNjgxZWE1ZDUyYjliMGJhZDJmNDAyYjMwMTI0IiwicyI6IjB4Mjk1Mjc3ZWY2NTYzNDAwY2VkNjFiODhkM2ZiNGM3YjMyY2NkNTcwYThiOWJiOGNiYmUyNTkyMTRhYjdkZTI1YSJ9fX19fQ==");
let tx_bytes = base64::decode_config(&raw_tx, base64::URL_SAFE).unwrap();
let tx_bytes = base64::decode_config(raw_tx, base64::URL_SAFE).unwrap();
let unchecked_tx: UncheckedTransaction<()> =
serde_json::from_slice(tx_bytes.as_slice()).unwrap();
if let Action::Ethereum(EthAction::Transact(tx)) = unchecked_tx.function {
Expand Down
2 changes: 1 addition & 1 deletion src/components/contracts/rpc/src/eth_pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl SubscriptionResult {
let transaction_hash: Option<H256> = if !receipt.logs.is_empty() {
Some(H256::from_slice(
Keccak256::digest(&rlp::encode(
&block.transactions[receipt_index as usize],
&block.transactions[receipt_index],
))
.as_slice(),
))
Expand Down
2 changes: 1 addition & 1 deletion src/components/finutils/src/bins/stt/init/i_testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ struct TmValidator {

fn get_26657_validators(sa: &str) -> Result<TmValidatorsBody> {
let url = format!("{}:26657/validators", sa);
attohttpc::get(&url)
attohttpc::get(url)
.send()
.c(d!())?
.error_for_status()
Expand Down
18 changes: 9 additions & 9 deletions src/components/finutils/src/common/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn new_tx_builder() -> Result<TransactionBuilder> {
#[allow(missing_docs)]
pub fn send_tx(tx: &Transaction) -> Result<()> {
let url = format!("{}:8669/submit_transaction", get_serv_addr().c(d!())?);
attohttpc::post(&url)
attohttpc::post(url)
.header(attohttpc::header::CONTENT_TYPE, "application/json")
.bytes(&serde_json::to_vec(tx).c(d!())?)
.send()
Expand Down Expand Up @@ -372,7 +372,7 @@ struct TmStatus {
fn get_network_status(addr: &str) -> Result<TmStatus> {
let url = format!("{}:26657/status", addr);

attohttpc::get(&url)
attohttpc::get(url)
.send()
.c(d!())?
.error_for_status()
Expand Down Expand Up @@ -403,7 +403,7 @@ pub fn get_local_block_height() -> u64 {
pub fn get_asset_type(code: &str) -> Result<AssetType> {
let url = format!("{}:8668/asset_token/{}", get_serv_addr().c(d!())?, code);

attohttpc::get(&url)
attohttpc::get(url)
.send()
.c(d!())?
.error_for_status()
Expand All @@ -421,7 +421,7 @@ pub fn get_created_assets(addr: &XfrPublicKey) -> Result<Vec<DefineAsset>> {
wallet::public_key_to_base64(addr)
);

attohttpc::get(&url)
attohttpc::get(url)
.send()
.c(d!())?
.error_for_status()
Expand Down Expand Up @@ -474,7 +474,7 @@ fn get_owned_utxos_x(
wallet::public_key_to_base64(addr)
);

attohttpc::get(&url)
attohttpc::get(url)
.send()
.c(d!())?
.error_for_status()
Expand All @@ -497,7 +497,7 @@ fn get_seq_id() -> Result<u64> {

let url = format!("{}:8668/global_state", get_serv_addr().c(d!())?);

attohttpc::get(&url)
attohttpc::get(url)
.send()
.c(d!())?
.error_for_status()
Expand All @@ -522,7 +522,7 @@ pub fn get_owner_memo_batch(ids: &[TxoSID]) -> Result<Vec<Option<OwnerMemo>>> {
ids
);

attohttpc::get(&url)
attohttpc::get(url)
.send()
.c(d!())?
.error_for_status()
Expand All @@ -540,7 +540,7 @@ pub fn get_delegation_info(pk: &XfrPublicKey) -> Result<DelegationInfo> {
wallet::public_key_to_base64(pk)
);

attohttpc::get(&url)
attohttpc::get(url)
.send()
.c(d!())?
.error_for_status()
Expand All @@ -558,7 +558,7 @@ pub fn get_validator_detail(td_addr: TendermintAddrRef) -> Result<ValidatorDetai
td_addr
);

attohttpc::get(&url)
attohttpc::get(url)
.send()
.c(d!())?
.error_for_status()
Expand Down
2 changes: 1 addition & 1 deletion src/ledger/src/data_model/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ fn gen_sample_tx() -> Transaction {
let issuance_operation = Operation::IssueAsset(asset_issuance.clone());

// Instantiate an DefineAsset operation
let mut asset = Box::new(Asset::default());
let mut asset = Box::<Asset>::default();
asset.code = AssetTypeCode::gen_random();

let asset_creation = DefineAsset::new(
Expand Down
4 changes: 2 additions & 2 deletions src/ledger/src/staking/cosig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ pub struct CoSigRule {
impl CoSigRule {
#[allow(missing_docs)]
pub fn new(threshold: [u64; 2]) -> Result<Self> {
if threshold[0] > threshold[1] || threshold[1] > MAX_TOTAL_POWER as u64 {
if threshold[0] > threshold[1] || threshold[1] > MAX_TOTAL_POWER {
return Err(eg!("invalid threshold"));
}

Expand Down Expand Up @@ -263,7 +263,7 @@ mod test {
vd.cosig_rule = pnk!(CoSigRule::new([75, 100]));

assert!(CoSigRule::new([200, 100]).is_err());
assert!(CoSigRule::new([200, 1 + MAX_TOTAL_POWER as u64]).is_err());
assert!(CoSigRule::new([200, 1 + MAX_TOTAL_POWER]).is_err());

let mut data = CoSigOp::create(Data::default(), no_replay_token());
pnk!(data.batch_sign(&kps.iter().skip(10).collect::<Vec<_>>()));
Expand Down
2 changes: 1 addition & 1 deletion src/ledger/src/staking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ impl Staking {
) -> Result<Vec<Validator>> {
self.validator_info
.remove(&h)
.map(|v| v.body.into_iter().map(|(_, v)| v).collect())
.map(|v| v.body.into_values().collect())
.c(d!("not exists"))
}

Expand Down
2 changes: 1 addition & 1 deletion src/ledger/src/store/api_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ pub fn check_lost_data(ledger: &mut LedgerState) -> Result<()> {
.as_mut()
.unwrap()
.last_sid
.insert("last_txo_sid".to_string(), index as u64);
.insert("last_txo_sid".to_string(), index);
}
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/ledger/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ impl LedgerStatus {
);
if seq_id > self.block_commit_count {
return Err(eg!(("Transaction seq_id ahead of block_count")));
} else if seq_id + (TRANSACTION_WINDOW_WIDTH as u64) < self.block_commit_count {
} else if seq_id + TRANSACTION_WINDOW_WIDTH < self.block_commit_count {
return Err(eg!(("Transaction seq_id too far behind block_count")));
} else {
// Check to see that this nrpt has not been seen before
Expand Down
4 changes: 2 additions & 2 deletions src/libs/bitmap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ fn count_byte(mask: usize) -> u8 {
let mut result = 0;

for i in 0..8 {
result += if mask & (1 << i) == 0 { 0 } else { 1 };
result += u8::from(mask & (1 << i) != 0);
}

result
Expand Down Expand Up @@ -1098,7 +1098,7 @@ impl BitMap {
// Append a list of the set bits to the serialization
// results.
fn append_set(&self, index: usize, result: &mut Vec<u8>) {
let set_bits = self.set_bits[index] as u32;
let set_bits = self.set_bits[index];

// Append the header to the serialization.
self.append_header(index, BIT_DESC_SET, set_bits, result);
Expand Down
2 changes: 1 addition & 1 deletion src/libs/globutils/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ fn check_lang(lang: &str) -> Result<Language> {
/// Convert a XfrPublicKey to base64 human-readable address
#[inline(always)]
pub fn public_key_to_base64(key: &XfrPublicKey) -> String {
base64::encode_config(&ZeiFromToBytes::zei_to_bytes(key), base64::URL_SAFE)
base64::encode_config(ZeiFromToBytes::zei_to_bytes(key), base64::URL_SAFE)
}

/// Restore a XfrPublicKey from base64 human-readable address
Expand Down
4 changes: 2 additions & 2 deletions src/libs/merkle_tree/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1952,7 +1952,7 @@ impl AppendOnlyMerkle {
self.check_lower(block, lower_list, lower_index).c(d!())?;
}

leaf_count += block.valid_leaves() as u64;
leaf_count += block.valid_leaves();
}

if leaf_count != leaves_at_this_level {
Expand Down Expand Up @@ -2875,7 +2875,7 @@ mod tests {
};

for i in 0..transactions {
test_append(&mut tree, i as u64, false);
test_append(&mut tree, i, false);

if i == 1
|| i == 2
Expand Down
2 changes: 1 addition & 1 deletion src/libs/sliding_set/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl<T> SlidingSet<T> {
/// Create a new sliding window start with 0
#[inline(always)]
pub fn new(width: usize) -> Self {
let mut map = Vec::with_capacity(width as usize);
let mut map = Vec::with_capacity(width);
for _ in 0..width {
map.push(Vec::new());
}
Expand Down

0 comments on commit 941c546

Please sign in to comment.