From 05376ebec8abb4ba486d8c8d4e7dc7d4cf52b36f Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Fri, 22 Sep 2023 15:58:30 +0200 Subject: [PATCH] Fix some clippy warnings --- cli/src/account.rs | 63 +++++++++++++------------- sdk/src/client/builder.rs | 2 +- sdk/src/client/node_api/core/routes.rs | 2 +- sdk/src/client/secret/mnemonic.rs | 2 +- sdk/src/client/secret/private_key.rs | 2 +- sdk/src/client/stronghold/secret.rs | 2 +- sdk/src/types/block/core/wrapper.rs | 2 +- sdk/src/types/block/rand/signature.rs | 2 +- sdk/src/types/block/slot/index.rs | 12 ++--- sdk/src/utils/serde.rs | 2 +- sdk/tests/types/block.rs | 4 +- 11 files changed, 47 insertions(+), 48 deletions(-) diff --git a/cli/src/account.rs b/cli/src/account.rs index b01e21142a..7a1c0e5a10 100644 --- a/cli/src/account.rs +++ b/cli/src/account.rs @@ -75,6 +75,7 @@ pub async fn account_prompt_internal( } let input = rl.readline(&prompt); + match input { Ok(command) => { match command.as_str() { @@ -103,16 +104,16 @@ pub async fn account_prompt_internal( } }; match account_cli.command { - AccountCommand::Addresses => addresses_command(&account).await, - AccountCommand::Balance { addresses } => balance_command(&account, addresses).await, + AccountCommand::Addresses => addresses_command(account).await, + AccountCommand::Balance { addresses } => balance_command(account, addresses).await, AccountCommand::BurnNativeToken { token_id, amount } => { - burn_native_token_command(&account, token_id, amount).await + burn_native_token_command(account, token_id, amount).await } - AccountCommand::BurnNft { nft_id } => burn_nft_command(&account, nft_id).await, - AccountCommand::Claim { output_id } => claim_command(&account, output_id).await, - AccountCommand::ClaimableOutputs => claimable_outputs_command(&account).await, - AccountCommand::Consolidate => consolidate_command(&account).await, - AccountCommand::CreateAccountOutput => create_account_output_command(&account).await, + AccountCommand::BurnNft { nft_id } => burn_nft_command(account, nft_id).await, + AccountCommand::Claim { output_id } => claim_command(account, output_id).await, + AccountCommand::ClaimableOutputs => claimable_outputs_command(account).await, + AccountCommand::Consolidate => consolidate_command(account).await, + AccountCommand::CreateAccountOutput => create_account_output_command(account).await, AccountCommand::CreateNativeToken { circulating_supply, maximum_supply, @@ -128,20 +129,20 @@ pub async fn account_prompt_internal( .await } AccountCommand::DestroyAccount { account_id } => { - destroy_account_command(&account, account_id).await + destroy_account_command(account, account_id).await } AccountCommand::DestroyFoundry { foundry_id } => { - destroy_foundry_command(&account, foundry_id).await + destroy_foundry_command(account, foundry_id).await } AccountCommand::Exit => { return Ok(AccountPromptResponse::Done); } - AccountCommand::Faucet { address, url } => faucet_command(&account, address, url).await, + AccountCommand::Faucet { address, url } => faucet_command(account, address, url).await, AccountCommand::MeltNativeToken { token_id, amount } => { - melt_native_token_command(&account, token_id, amount).await + melt_native_token_command(account, token_id, amount).await } AccountCommand::MintNativeToken { token_id, amount } => { - mint_native_token(&account, token_id, amount).await + mint_native_token(account, token_id, amount).await } AccountCommand::MintNft { address, @@ -164,10 +165,10 @@ pub async fn account_prompt_internal( ) .await } - AccountCommand::NewAddress => new_address_command(&account).await, - AccountCommand::NodeInfo => node_info_command(&account).await, - AccountCommand::Output { output_id } => output_command(&account, output_id).await, - AccountCommand::Outputs => outputs_command(&account).await, + AccountCommand::NewAddress => new_address_command(account).await, + AccountCommand::NodeInfo => node_info_command(account).await, + AccountCommand::Output { output_id } => output_command(account, output_id).await, + AccountCommand::Outputs => outputs_command(account).await, AccountCommand::Send { address, amount, @@ -187,35 +188,33 @@ pub async fn account_prompt_internal( token_id, amount, gift_storage_deposit, - } => send_native_token_command(&account, address, token_id, amount, gift_storage_deposit).await, - AccountCommand::SendNft { address, nft_id } => { - send_nft_command(&account, address, nft_id).await - } + } => send_native_token_command(account, address, token_id, amount, gift_storage_deposit).await, + AccountCommand::SendNft { address, nft_id } => send_nft_command(account, address, nft_id).await, AccountCommand::Switch { account_id } => { return Ok(AccountPromptResponse::Switch(wallet.get_account(account_id).await?)); } - AccountCommand::Sync => sync_command(&account).await, - AccountCommand::Transaction { selector } => transaction_command(&account, selector).await, + AccountCommand::Sync => sync_command(account).await, + AccountCommand::Transaction { selector } => transaction_command(account, selector).await, AccountCommand::Transactions { show_details } => { - transactions_command(&account, show_details).await + transactions_command(account, show_details).await } - AccountCommand::UnspentOutputs => unspent_outputs_command(&account).await, - AccountCommand::Vote { event_id, answers } => vote_command(&account, event_id, answers).await, + AccountCommand::UnspentOutputs => unspent_outputs_command(account).await, + AccountCommand::Vote { event_id, answers } => vote_command(account, event_id, answers).await, AccountCommand::StopParticipating { event_id } => { - stop_participating_command(&account, event_id).await + stop_participating_command(account, event_id).await } AccountCommand::ParticipationOverview { event_ids } => { let event_ids = (!event_ids.is_empty()).then_some(event_ids); - participation_overview_command(&account, event_ids).await + participation_overview_command(account, event_ids).await } - AccountCommand::VotingPower => voting_power_command(&account).await, + AccountCommand::VotingPower => voting_power_command(account).await, AccountCommand::IncreaseVotingPower { amount } => { - increase_voting_power_command(&account, amount).await + increase_voting_power_command(account, amount).await } AccountCommand::DecreaseVotingPower { amount } => { - decrease_voting_power_command(&account, amount).await + decrease_voting_power_command(account, amount).await } - AccountCommand::VotingOutput => voting_output_command(&account).await, + AccountCommand::VotingOutput => voting_output_command(account).await, } .unwrap_or_else(|err| { println_log_error!("{err}"); diff --git a/sdk/src/client/builder.rs b/sdk/src/client/builder.rs index 15f3cf95c0..68033eb21e 100644 --- a/sdk/src/client/builder.rs +++ b/sdk/src/client/builder.rs @@ -297,7 +297,7 @@ impl NetworkInfo { } pub fn with_tangle_time(mut self, tangle_time: u64) -> Self { - self.tangle_time = Some(tangle_time.into()); + self.tangle_time = Some(tangle_time); self } } diff --git a/sdk/src/client/node_api/core/routes.rs b/sdk/src/client/node_api/core/routes.rs index 6c8b33a97b..33cd2da771 100644 --- a/sdk/src/client/node_api/core/routes.rs +++ b/sdk/src/client/node_api/core/routes.rs @@ -112,7 +112,7 @@ impl ClientInner { /// Returns the information of committee members at the given epoch index. If epoch index is not provided, the /// current committee members are returned. /// GET /api/core/v3/committee/?epochIndex - pub async fn get_committee(&self, epoch_index: impl Into>) -> Result { + pub async fn get_committee(&self, epoch_index: impl Into> + Send) -> Result { const PATH: &str = "api/core/v3/committee"; let epoch_index = epoch_index.into().map(|i| format!("epochIndex={i}")); diff --git a/sdk/src/client/secret/mnemonic.rs b/sdk/src/client/secret/mnemonic.rs index f1f091dd56..69062278e0 100644 --- a/sdk/src/client/secret/mnemonic.rs +++ b/sdk/src/client/secret/mnemonic.rs @@ -103,7 +103,7 @@ impl SecretManage for MnemonicSecretManager { let public_key = private_key.public_key(); let signature = private_key.sign(msg); - Ok(Ed25519Signature::new(public_key.into(), signature)) + Ok(Ed25519Signature::new(public_key, signature)) } async fn sign_secp256k1_ecdsa( diff --git a/sdk/src/client/secret/private_key.rs b/sdk/src/client/secret/private_key.rs index fc6525c765..9622d16d40 100644 --- a/sdk/src/client/secret/private_key.rs +++ b/sdk/src/client/secret/private_key.rs @@ -69,7 +69,7 @@ impl SecretManage for PrivateKeySecretManager { let public_key = self.0.public_key(); let signature = self.0.sign(msg); - Ok(Ed25519Signature::new(public_key.into(), signature)) + Ok(Ed25519Signature::new(public_key, signature)) } async fn sign_secp256k1_ecdsa( diff --git a/sdk/src/client/stronghold/secret.rs b/sdk/src/client/stronghold/secret.rs index e52e91135d..9167d87f4c 100644 --- a/sdk/src/client/stronghold/secret.rs +++ b/sdk/src/client/stronghold/secret.rs @@ -226,7 +226,7 @@ impl SecretManage for StrongholdAdapter { .delete_secret(derive_location.record_path()) .map_err(Error::from)?; - Ok(Ed25519Signature::new(public_key.into(), signature)) + Ok(Ed25519Signature::new(public_key, signature)) } async fn sign_secp256k1_ecdsa( diff --git a/sdk/src/types/block/core/wrapper.rs b/sdk/src/types/block/core/wrapper.rs index cb72d4ebac..ecf61b5f38 100644 --- a/sdk/src/types/block/core/wrapper.rs +++ b/sdk/src/types/block/core/wrapper.rs @@ -352,7 +352,7 @@ pub(crate) mod dto { } } - Ok(BlockWrapper::new( + Ok(Self::new( dto.protocol_version, dto.network_id, dto.issuing_time, diff --git a/sdk/src/types/block/rand/signature.rs b/sdk/src/types/block/rand/signature.rs index 9fe679ebc4..7ffd5d5508 100644 --- a/sdk/src/types/block/rand/signature.rs +++ b/sdk/src/types/block/rand/signature.rs @@ -22,7 +22,7 @@ pub fn rand_ed25519_signature() -> Ed25519Signature { let public_key = private_key.public_key(); let signature = private_key.sign(&rand_bytes(64)); - Ed25519Signature::new(public_key.into(), signature) + Ed25519Signature::new(public_key, signature) } pub fn rand_signature() -> Signature { diff --git a/sdk/src/types/block/slot/index.rs b/sdk/src/types/block/slot/index.rs index f58472c225..93889fc129 100644 --- a/sdk/src/types/block/slot/index.rs +++ b/sdk/src/types/block/slot/index.rs @@ -60,9 +60,9 @@ impl SlotIndex { /// Gets the slot index of a unix timestamp. /// Slots are counted starting from `1` with `0` being reserved for times before the genesis. - pub fn from_timestamp(timestamp: u64, genesis_unix_timestamp: u64, slot_duration_in_seconds: u8) -> SlotIndex { + pub fn from_timestamp(timestamp: u64, genesis_unix_timestamp: u64, slot_duration_in_seconds: u8) -> Self { timestamp - .checked_sub(genesis_unix_timestamp as u64) + .checked_sub(genesis_unix_timestamp) .map(|elapsed| (elapsed / slot_duration_in_seconds as u64) + 1) .unwrap_or_default() .into() @@ -73,7 +73,7 @@ impl SlotIndex { pub fn to_timestamp(self, genesis_unix_timestamp: u64, slot_duration_in_seconds: u8) -> u64 { self.0 .checked_sub(1) - .map(|adjusted_slot| (adjusted_slot * slot_duration_in_seconds as u64) + genesis_unix_timestamp as u64) + .map(|adjusted_slot| (adjusted_slot * slot_duration_in_seconds as u64) + genesis_unix_timestamp) .unwrap_or_default() } } @@ -130,7 +130,7 @@ mod test { let protocol_params = ProtocolParameters::default(); // Timestamp before the genesis - let timestamp = protocol_params.genesis_unix_timestamp() as u64 - 100; + let timestamp = protocol_params.genesis_unix_timestamp() - 100; let slot_index = protocol_params.slot_index(timestamp); assert_eq!(*slot_index, 0); assert_eq!( @@ -142,7 +142,7 @@ mod test { ); // Genesis timestamp - let timestamp = protocol_params.genesis_unix_timestamp() as u64; + let timestamp = protocol_params.genesis_unix_timestamp(); let slot_index = protocol_params.slot_index(timestamp); assert_eq!(*slot_index, 1); assert_eq!( @@ -154,7 +154,7 @@ mod test { ); // Timestamp 5 seconds after slot 100 starts - let timestamp = protocol_params.genesis_unix_timestamp() as u64 + let timestamp = protocol_params.genesis_unix_timestamp() + (99 * protocol_params.slot_duration_in_seconds() as u64) // Add 99 because the slots are 1-indexed + 5; let slot_index = protocol_params.slot_index(timestamp); diff --git a/sdk/src/utils/serde.rs b/sdk/src/utils/serde.rs index cb7de80138..40a0d47c91 100644 --- a/sdk/src/utils/serde.rs +++ b/sdk/src/utils/serde.rs @@ -192,7 +192,7 @@ pub mod boxed_slice_prefix { T: Serialize, { let mut seq = serializer.serialize_seq(Some(value.len()))?; - for e in value.into_iter() { + for e in value.iter() { seq.serialize_element(e)?; } seq.end() diff --git a/sdk/tests/types/block.rs b/sdk/tests/types/block.rs index 803baaffdf..a9c9a187b2 100644 --- a/sdk/tests/types/block.rs +++ b/sdk/tests/types/block.rs @@ -126,7 +126,7 @@ fn dto_mismatch_version() { let protocol_parameters = ProtocolParameters::default(); let protocol_parameters_hash = protocol_parameters.hash(); let slot_index = 11_u64; - let issuing_time = protocol_parameters.genesis_unix_timestamp() as u64 + let issuing_time = protocol_parameters.genesis_unix_timestamp() + (slot_index - 1) * protocol_parameters.slot_duration_in_seconds() as u64; let network_id = protocol_parameters.network_id(); let protocol_version = 4; @@ -168,7 +168,7 @@ fn dto_mismatch_network_id() { let protocol_parameters = ProtocolParameters::default(); let protocol_parameters_hash = protocol_parameters.hash(); let slot_index = 11_u64; - let issuing_time = protocol_parameters.genesis_unix_timestamp() as u64 + let issuing_time = protocol_parameters.genesis_unix_timestamp() + (slot_index - 1) * protocol_parameters.slot_duration_in_seconds() as u64; let network_id = network_name_to_id("invalid-network"); let block_dto_json = serde_json::json!({