Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
blckngm committed Oct 11, 2023
1 parent 5be3544 commit 6aefb49
Show file tree
Hide file tree
Showing 51 changed files with 162 additions and 178 deletions.
8 changes: 5 additions & 3 deletions crates/block-producer/src/cleaner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,11 @@ impl Cleaner {
let rpc_client = &self.rpc_client;
for (idx, tx_hash) in consumed_txs {
let consumed = match tx_hash {
Some(tx_hash) => {
!matches!(rpc_client.ckb.get_transaction_status(tx_hash).await?, None)
}
Some(tx_hash) => rpc_client
.ckb
.get_transaction_status(tx_hash)
.await?
.is_some(),
None => false,
};
if consumed {
Expand Down
2 changes: 1 addition & 1 deletion crates/block-producer/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ impl BaseInitComponents {
.ok_or_else(|| anyhow!("Eth: No allowed EoA type hashes in the rollup config"))?;
account_lock_manage.register_lock_algorithm(
eth_lock_script_type_hash.hash().unpack(),
Arc::new(Secp256k1Eth::default()),
Arc::new(Secp256k1Eth),
);
let mut gen = Generator::new(
backend_manage,
Expand Down
14 changes: 7 additions & 7 deletions crates/block-producer/src/withdrawal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ mod test {
let sudt_script = Script::new_builder()
.code_hash(H256::from_u32(2).pack())
.hash_type(ScriptHashType::Type.into())
.args(vec![3u8; 32].pack())
.args([3u8; 32][..].pack())
.build();

let finalized_custodians = CollectedCustodianCells {
Expand All @@ -358,7 +358,7 @@ mod test {

let owner_lock = Script::new_builder()
.code_hash(H256::from_u32(4).pack())
.args(vec![5; 32].pack())
.args([5; 32][..].pack())
.build();

let withdrawal = {
Expand All @@ -374,7 +374,7 @@ mod test {
.build();
WithdrawalRequest::new_builder()
.raw(raw)
.signature(vec![6u8; 65].pack())
.signature([6u8; 65][..].pack())
.build()
};

Expand Down Expand Up @@ -460,7 +460,7 @@ mod test {
let sudt_script = Script::new_builder()
.code_hash(H256::from_u32(3).pack())
.hash_type(ScriptHashType::Type.into())
.args(vec![4u8; 32].pack())
.args([4u8; 32][..].pack())
.build();

let rollup_context = RollupContext {
Expand Down Expand Up @@ -497,7 +497,7 @@ mod test {
let owner_lock = Script::new_builder()
.code_hash(H256::from_u32(8).pack())
.hash_type(ScriptHashType::Type.into())
.args(vec![9u8; 32].pack())
.args([9u8; 32][..].pack())
.build();

let withdrawal_without_owner_lock = {
Expand Down Expand Up @@ -722,7 +722,7 @@ mod test {
let sudt_script = Script::new_builder()
.code_hash(H256::from_u32(3).pack())
.hash_type(ScriptHashType::Type.into())
.args(vec![4u8; 32].pack())
.args([4u8; 32][..].pack())
.build();
let rollup_config = RollupConfig::new_builder()
.l1_sudt_script_type_hash(sudt_script.code_hash())
Expand Down Expand Up @@ -793,7 +793,7 @@ mod test {
let owner_lock_script = Script::new_builder()
.code_hash(H256::from_u32(8).pack())
.hash_type(ScriptHashType::Type.into())
.args(vec![9u8; 32].pack())
.args([9u8; 32][..].pack())
.build();
let withdrawal_lock_args = WithdrawalLockArgs::new_builder()
.owner_lock_hash(owner_lock_script.hash().pack())
Expand Down
2 changes: 1 addition & 1 deletion crates/generator/src/account_lock_manage/always_success.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct AlwaysSuccess;
/// Usage
/// register AlwaysSuccess to AccountLockManage
///
/// manage.register_lock_algorithm(code_hash, Box::new(AlwaysSuccess::default()));
/// manage.register_lock_algorithm(code_hash, Box::new(AlwaysSuccess));
impl LockAlgorithm for AlwaysSuccess {
fn recover(&self, _message: H256, _signature: &[u8]) -> Result<Bytes, LockAlgorithmError> {
Ok(Default::default())
Expand Down
12 changes: 3 additions & 9 deletions crates/generator/src/account_lock_manage/eip712/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,7 @@ mod tests {
buf[64] = v;
buf
};
let pubkey_hash = Secp256k1Eth::default()
.recover(message, &signature)
.unwrap();
let pubkey_hash = Secp256k1Eth.recover(message, &signature).unwrap();
assert_eq!(hex::encode(mail.from.wallet), hex::encode(pubkey_hash));
}

Expand Down Expand Up @@ -517,9 +515,7 @@ mod tests {
};
let message = withdrawal.eip712_message(domain_seperator.hash_struct());
let signature: [u8; 65] = hex::decode("22cae59f1bfaf58f423d1a414cbcaefd45a89dd54c9142fccbb2473c74f4741b45f77f1f3680b8c0b6362957c8d79f96a683a859ccbf22a6cfc1ebc311b936d301").unwrap().try_into().unwrap();
let pubkey_hash = Secp256k1Eth::default()
.recover(message, &signature)
.unwrap();
let pubkey_hash = Secp256k1Eth.recover(message, &signature).unwrap();
assert_eq!(
"cc3e7fb0176a0e22a7f675306ceeb61d26eb0dc4".to_string(),
hex::encode(pubkey_hash)
Expand Down Expand Up @@ -555,9 +551,7 @@ mod tests {
};
let message = tx.eip712_message(domain_seperator.hash_struct());
let signature: [u8; 65] = hex::decode("64b164f5303000c283119974d7ba8f050cc7429984af904134d5cda6d3ce045934cc6b6f513ec939c2ae4cfb9cbee249ba8ae86f6274e4035c150f9c8e634a3a1b").unwrap().try_into().unwrap();
let pubkey_hash = Secp256k1Eth::default()
.recover(message, &signature)
.unwrap();
let pubkey_hash = Secp256k1Eth.recover(message, &signature).unwrap();
assert_eq!(
"e8ae579256c3b84efb76bbb69cb6bcbef1375f00".to_string(),
hex::encode(pubkey_hash)
Expand Down
16 changes: 8 additions & 8 deletions crates/generator/src/account_lock_manage/secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl Secp256k1Eth {
/// Usage
/// register AlwaysSuccess to AccountLockManage
///
/// manage.register_lock_algorithm(code_hash, Box::new(AlwaysSuccess::default()));
/// manage.register_lock_algorithm(code_hash, Box::new(AlwaysSuccess));
impl LockAlgorithm for Secp256k1Eth {
fn recover(&self, message: H256, signature: &[u8]) -> Result<Bytes, LockAlgorithmError> {
// extract rec_id
Expand Down Expand Up @@ -319,7 +319,7 @@ mod tests {
.raw(raw_tx)
.signature(signature.to_vec().pack())
.build();
let eth = Secp256k1Eth::default();
let eth = Secp256k1Eth;

let rollup_type_hash = vec![0u8; 32];

Expand Down Expand Up @@ -354,7 +354,7 @@ mod tests {
#[test]
fn test_secp256k1_eth_polyjuice_native_token_transfer() {
let chain_id = 42;
let mut polyjuice_args = vec![0u8; 72];
let mut polyjuice_args = [0u8; 72];
polyjuice_args[0..7].copy_from_slice(b"\xFF\xFF\xFFPOLY");
polyjuice_args[7] = 0;
let gas_limit: u64 = 21000;
Expand Down Expand Up @@ -410,7 +410,7 @@ mod tests {
.build(),
..Default::default()
};
let eth = Secp256k1Eth::default();
let eth = Secp256k1Eth;
eth.verify_tx(&ctx, sender_reg_addr, sender_script, receive_script, tx)
.expect("verify signature");
}
Expand Down Expand Up @@ -442,7 +442,7 @@ mod tests {
.raw(raw_tx)
.signature(signature.to_vec().pack())
.build();
let eth = Secp256k1Eth::default();
let eth = Secp256k1Eth;

// This rollup type hash is used, so the receiver script hash is:
// 00002b003de527c1d67f2a2a348683ecc9598647c30884c89c5dcf6da1afbddd,
Expand Down Expand Up @@ -510,7 +510,7 @@ mod tests {
.raw(raw_tx)
.signature(signature.to_vec().pack())
.build();
let eth = Secp256k1Eth::default();
let eth = Secp256k1Eth;

let rollup_type_hash = vec![0u8; 32];

Expand Down Expand Up @@ -555,7 +555,7 @@ mod tests {
.raw(raw_tx)
.signature(signature.to_vec().pack())
.build();
let eth = Secp256k1Eth::default();
let eth = Secp256k1Eth;

let rollup_type_hash = vec![0u8; 32];

Expand Down Expand Up @@ -644,7 +644,7 @@ mod tests {
rollup_config: RollupConfig::new_builder().chain_id(0.pack()).build(),
..Default::default()
};
let eth = Secp256k1Eth::default();
let eth = Secp256k1Eth;
eth.verify_tx(&ctx, sender_address, sender_script, receiver_script, tx)
.expect("verify signature");
}
Expand Down
8 changes: 4 additions & 4 deletions crates/generator/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ mod test {
};
let sudt_script = Script::new_builder()
.code_hash(H256::from_u32(1).pack())
.args(vec![3; 32].pack())
.args([3; 32][..].pack())
.build();
let owner_lock = Script::new_builder()
.code_hash(H256::from_u32(4).pack())
.args(vec![5; 32].pack())
.args([5; 32][..].pack())
.build();

// ## Fulfill withdrawal request
Expand All @@ -187,7 +187,7 @@ mod test {
.build();
WithdrawalRequest::new_builder()
.raw(raw)
.signature(vec![6u8; 65].pack())
.signature([6u8; 65][..].pack())
.build()
};
let withdrawal = WithdrawalRequestExtra::new_builder()
Expand Down Expand Up @@ -291,7 +291,7 @@ mod test {
let err_owner_lock = Script::new_builder()
.code_hash([100u8; 32].pack())
.hash_type(ScriptHashType::Data.into())
.args(vec![99u8; 32].pack())
.args([99u8; 32][..].pack())
.build();
let err = build_withdrawal_cell_output(
&rollup_context,
Expand Down
2 changes: 1 addition & 1 deletion crates/mem-pool/src/block_sync_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl BlockSyncServerState {
.transaction(tx)
.build();
let msg = BlockSync::new_builder().set(msg).build();
if let Some((_, messages)) = self.buffer.iter_mut().rev().next() {
if let Some((_, messages)) = self.buffer.iter_mut().next_back() {
// The first message is either a LocalBlock or a NextMemBlock. We
// only need to buffer it for NextMemBlock.
if matches!(
Expand Down
4 changes: 2 additions & 2 deletions crates/mem-pool/src/restore_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@ mod tests {

// Should able to restore from deprecated compact mem block
let deprecated = DeprecatedCompactMemBlock::new_builder()
.txs(vec![[1u8; 32]].pack())
.txs([[1u8; 32]][..].pack())
.build();
let expected = CompactMemBlock::new_builder()
.txs(vec![[1u8; 32]].pack())
.txs([[1u8; 32]][..].pack())
.build();

let latest_timestamp = SystemTime::now()
Expand Down
8 changes: 4 additions & 4 deletions crates/mem-pool/src/withdrawal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ mod test {

let sudt_script = Script::new_builder()
.code_hash(H256::from_u32(2).pack())
.args(vec![3u8; 32].pack())
.args([3u8; 32][..].pack())
.build();

let available_custodians = FinalizedCustodianCapacity {
Expand All @@ -353,7 +353,7 @@ mod test {

let owner_lock = Script::new_builder()
.code_hash(H256::from_u32(4).pack())
.args(vec![5; 32].pack())
.args([5; 32][..].pack())
.build();

let req = {
Expand All @@ -369,7 +369,7 @@ mod test {
.build();
WithdrawalRequest::new_builder()
.raw(raw)
.signature(vec![6u8; 65].pack())
.signature([6u8; 65][..].pack())
.build()
};

Expand Down Expand Up @@ -415,7 +415,7 @@ mod test {
let err_req_extra = {
let err_owner_lock = Script::new_builder()
.code_hash([100u8; 32].pack())
.args(vec![99u8; 32].pack())
.args([99u8; 32][..].pack())
.build();
req_extra
.clone()
Expand Down
2 changes: 1 addition & 1 deletion crates/polyjuice-sender-recover/src/recover/eth_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fn recover_registry_address(

let message = Secp256k1Eth::polyjuice_tx_signing_message(ctx.chain_id, raw_tx, &to_script)
.map_err(PolyjuiceTxSenderRecoverError::InvalidSignature)?;
let eth_address = Secp256k1Eth::default()
let eth_address = Secp256k1Eth
.recover(message, signature)
.map_err(|err| PolyjuiceTxSenderRecoverError::InvalidSignature(err.into()))?;
let registry_address = RegistryAddress::new(ETH_REGISTRY_ACCOUNT_ID, eth_address.to_vec());
Expand Down
2 changes: 1 addition & 1 deletion crates/replay-chain/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub async fn setup(args: SetupArgs) -> Result<Context> {
.ok_or_else(|| anyhow!("Eth: No allowed EoA type hashes in the rollup config"))?;
account_lock_manage.register_lock_algorithm(
eth_lock_script_type_hash.hash().unpack(),
Arc::new(Secp256k1Eth::default()),
Arc::new(Secp256k1Eth),
);
Arc::new(Generator::new(
backend_manage,
Expand Down
8 changes: 4 additions & 4 deletions crates/rpc-client/src/withdrawal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ mod test {
let owner_lock = Script::new_builder()
.code_hash(H256::from_u32(1).pack())
.hash_type(ScriptHashType::Type.into())
.args(vec![2u8; 32].pack())
.args([2u8; 32][..].pack())
.build();

let rollup_type_hash = [3u8; 32];
Expand Down Expand Up @@ -186,7 +186,7 @@ mod test {
// # owner lock not match
let err_owner_lock = Script::new_builder()
.code_hash(H256::from_u32(5).pack())
.args(vec![7u8; 32].pack())
.args([7u8; 32][..].pack())
.build();
let mut args = rollup_type_hash.to_vec();
args.extend_from_slice(&lock_args.as_bytes());
Expand All @@ -209,13 +209,13 @@ mod test {
let owner_lock = Script::new_builder()
.code_hash(H256::from_u32(1).pack())
.hash_type(ScriptHashType::Type.into())
.args(vec![2u8; 32].pack())
.args([2u8; 32][..].pack())
.build();

let l1_sudt = Script::new_builder()
.code_hash(H256::from_u32(3).pack())
.hash_type(ScriptHashType::Type.into())
.args(vec![4u8; 32].pack())
.args([4u8; 32][..].pack())
.build();

let last_finalized_timepoint = Timepoint::from_block_number(100);
Expand Down
2 changes: 1 addition & 1 deletion crates/store/src/state/overlay/mem_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<S: HistoryStateStore> HistoryStateStore for MemStore<S> {
.collect(),
None => HashSet::new(),
};
list.extend(self.inner.iter_block_state_record(block_number).into_iter());
list.extend(self.inner.iter_block_state_record(block_number));
list
}

Expand Down
14 changes: 5 additions & 9 deletions crates/tests/src/script_tests/l2_scripts/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ fn test_example_sum() {
}])
.unwrap();
let mut account_lock_manage = AccountLockManage::default();
account_lock_manage
.register_lock_algorithm(H256::zero(), Arc::new(AlwaysSuccess::default()));
account_lock_manage.register_lock_algorithm(H256::zero(), Arc::new(AlwaysSuccess));
let rollup_context = RollupContext {
rollup_config: Default::default(),
rollup_script_hash: [42u8; 32],
Expand Down Expand Up @@ -238,7 +237,7 @@ fn test_example_account_operation() {
}])
.unwrap();
let mut account_lock_manage = AccountLockManage::default();
account_lock_manage.register_lock_algorithm(H256::zero(), Arc::new(AlwaysSuccess::default()));
account_lock_manage.register_lock_algorithm(H256::zero(), Arc::new(AlwaysSuccess));
let rollup_context = RollupContext {
rollup_config: RollupConfig::new_builder()
.allowed_contract_type_hashes(
Expand Down Expand Up @@ -478,8 +477,7 @@ fn test_example_recover_account() {
.unwrap();
let mut account_lock_manage = AccountLockManage::default();
let secp256k1_code_hash = H256::from_u32(11);
account_lock_manage
.register_lock_algorithm(secp256k1_code_hash, Arc::new(Secp256k1Eth::default()));
account_lock_manage.register_lock_algorithm(secp256k1_code_hash, Arc::new(Secp256k1Eth));
let rollup_script_hash: H256 = [42u8; 32];
let rollup_context = RollupContext {
rollup_config: RollupConfig::new_builder()
Expand Down Expand Up @@ -661,10 +659,8 @@ fn test_sudt_total_supply() {
}])
.unwrap();
let mut account_lock_manage = AccountLockManage::default();
account_lock_manage.register_lock_algorithm(
*ALWAYS_SUCCESS_CODE_HASH,
Arc::new(AlwaysSuccess::default()),
);
account_lock_manage
.register_lock_algorithm(*ALWAYS_SUCCESS_CODE_HASH, Arc::new(AlwaysSuccess));
let rollup_context = RollupContext {
rollup_config,
rollup_script_hash: [42u8; 32],
Expand Down
Loading

0 comments on commit 6aefb49

Please sign in to comment.