diff --git a/cli/src/wallet_cli/mod.rs b/cli/src/wallet_cli/mod.rs index 05c14320d3..a0b0d34413 100644 --- a/cli/src/wallet_cli/mod.rs +++ b/cli/src/wallet_cli/mod.rs @@ -1035,7 +1035,7 @@ pub async fn prompt_internal( let prompt = if let Some(alias) = wallet.alias().await { format!("Wallet \"{alias}\": ") } else { - format!("Wallet: ") + String::from("Wallet: ") }; if let Some(helper) = rl.helper_mut() { diff --git a/sdk/src/client/api/high_level.rs b/sdk/src/client/api/high_level.rs index f606cfac23..d715558687 100644 --- a/sdk/src/client/api/high_level.rs +++ b/sdk/src/client/api/high_level.rs @@ -89,11 +89,10 @@ impl Client { let mut total_already_spent = 0; let mut selected_inputs = Vec::new(); - for (_offset, output_wrapper) in basic_outputs + for output_wrapper in basic_outputs .into_iter() // Max inputs is 128 .take(INPUT_COUNT_MAX.into()) - .enumerate() { // Break if we have enough funds and don't create dust for the remainder if total_already_spent == amount || total_already_spent >= amount { diff --git a/sdk/src/client/api/types.rs b/sdk/src/client/api/types.rs index 0cbb745dd2..6df3cb6b2d 100644 --- a/sdk/src/client/api/types.rs +++ b/sdk/src/client/api/types.rs @@ -71,7 +71,7 @@ impl TryFromDto for PreparedTransactionData { inputs_data: dto .inputs_data .into_iter() - .map(|i| InputSigningData::try_from(i)) + .map(InputSigningData::try_from) .collect::>>() .map_err(|_| Error::InvalidField("input_data"))?, remainder: match dto.remainder { @@ -125,7 +125,7 @@ impl TryFromDto for SignedTransactionData { inputs_data: dto .inputs_data .into_iter() - .map(|i| InputSigningData::try_from(i)) + .map(InputSigningData::try_from) .collect::>>() .map_err(|_| Error::InvalidField("inputs_data"))?, }) diff --git a/sdk/src/client/secret/mnemonic.rs b/sdk/src/client/secret/mnemonic.rs index 2c7b3af261..d955309c1e 100644 --- a/sdk/src/client/secret/mnemonic.rs +++ b/sdk/src/client/secret/mnemonic.rs @@ -63,9 +63,7 @@ impl SecretManage for MnemonicSecretManager { .to_bytes(); // Hash the public key to get the address - let result = Blake2b256::digest(public_key).try_into().map_err(|_e| { - crate::client::Error::Blake2b256("hashing the public key while generating the address failed.") - })?; + let result = Blake2b256::digest(public_key).into(); crate::client::Result::Ok(Ed25519Address::new(result)) }) diff --git a/sdk/src/client/secret/private_key.rs b/sdk/src/client/secret/private_key.rs index 3f4b9fe7b1..f1b23862b6 100644 --- a/sdk/src/client/secret/private_key.rs +++ b/sdk/src/client/secret/private_key.rs @@ -48,9 +48,7 @@ impl SecretManage for PrivateKeySecretManager { let public_key = self.0.public_key().to_bytes(); // Hash the public key to get the address - let result = Blake2b256::digest(public_key).try_into().map_err(|_e| { - crate::client::Error::Blake2b256("hashing the public key while generating the address failed.") - })?; + let result = Blake2b256::digest(public_key).into(); crate::client::Result::Ok(vec![Ed25519Address::new(result)]) } diff --git a/sdk/src/client/utils.rs b/sdk/src/client/utils.rs index b8bdae8696..00805b66bb 100644 --- a/sdk/src/client/utils.rs +++ b/sdk/src/client/utils.rs @@ -41,18 +41,16 @@ pub fn bech32_to_hex(bech32: impl ConvertTo) -> Result { /// Transforms a hex encoded address to a bech32 encoded address pub fn hex_to_bech32(hex: &str, bech32_hrp: impl ConvertTo) -> Result { - let address: Ed25519Address = hex.parse::()?; + let address = hex.parse::()?; + Ok(Address::Ed25519(address).try_to_bech32(bech32_hrp)?) } /// Transforms a prefix hex encoded public key to a bech32 encoded address pub fn hex_public_key_to_bech32_address(hex: &str, bech32_hrp: impl ConvertTo) -> Result { let public_key: [u8; Ed25519Address::LENGTH] = prefix_hex::decode(hex)?; + let address = Ed25519Address::new(Blake2b256::digest(public_key).into()); - let address = Blake2b256::digest(public_key) - .try_into() - .map_err(|_e| Error::Blake2b256("hashing the public key failed."))?; - let address: Ed25519Address = Ed25519Address::new(address); Ok(Address::Ed25519(address).try_to_bech32(bech32_hrp)?) } diff --git a/sdk/src/types/block/address/ed25519.rs b/sdk/src/types/block/address/ed25519.rs index 4d44b1e5e9..964ecac162 100644 --- a/sdk/src/types/block/address/ed25519.rs +++ b/sdk/src/types/block/address/ed25519.rs @@ -34,8 +34,8 @@ impl Ed25519Address { } /// Creates a new [`Ed25519Address`] from the bytes of a [`PublicKey`]. - pub fn from_public_key_bytes(public_key_bytes: [u8; PublicKey::LENGTH]) -> Result { - Ok(Self::new(Blake2b256::digest(public_key_bytes).try_into()?)) + pub fn from_public_key_bytes(public_key_bytes: [u8; PublicKey::LENGTH]) -> Self { + Self::new(Blake2b256::digest(public_key_bytes).into()) } } diff --git a/sdk/src/types/block/address/multi.rs b/sdk/src/types/block/address/multi.rs index 73eed8753d..3138a7fd89 100644 --- a/sdk/src/types/block/address/multi.rs +++ b/sdk/src/types/block/address/multi.rs @@ -48,20 +48,21 @@ impl WeightedAddress { } fn verify_address(address: &Address) -> Result<(), Error> { - if VERIFY { - if !matches!( + if VERIFY + && !matches!( address, Address::Ed25519(_) | Address::Account(_) | Address::Nft(_) | Address::Anchor(_) - ) { - return Err(Error::InvalidAddressKind(address.kind())); - } + ) + { + Err(Error::InvalidAddressKind(address.kind())) + } else { + Ok(()) } - Ok(()) } fn verify_weight(weight: &u8) -> Result<(), Error> { if VERIFY && *weight == 0 { - return Err(Error::InvalidAddressWeight(*weight)); + Err(Error::InvalidAddressWeight(*weight)) } else { Ok(()) } @@ -123,7 +124,7 @@ impl MultiAddress { fn verify_addresses(addresses: &[WeightedAddress]) -> Result<(), Error> { if VERIFY && !is_unique_sorted(addresses.iter().map(WeightedAddress::address)) { - return Err(Error::WeightedAddressesNotUniqueSorted); + Err(Error::WeightedAddressesNotUniqueSorted) } else { Ok(()) } @@ -131,7 +132,7 @@ fn verify_addresses(addresses: &[WeightedAddress]) -> Result fn verify_threshold(threshold: &u16) -> Result<(), Error> { if VERIFY && *threshold == 0 { - return Err(Error::InvalidMultiAddressThreshold(*threshold)); + Err(Error::InvalidMultiAddressThreshold(*threshold)) } else { Ok(()) } diff --git a/sdk/src/types/block/mana/parameters.rs b/sdk/src/types/block/mana/parameters.rs index ec299b2d8e..228760fcfb 100644 --- a/sdk/src/types/block/mana/parameters.rs +++ b/sdk/src/types/block/mana/parameters.rs @@ -253,7 +253,7 @@ mod test { }; params }); - &*PARAMS + &PARAMS } #[test] diff --git a/sdk/src/types/block/output/account.rs b/sdk/src/types/block/output/account.rs index e6b8e8faa0..a1f27ab433 100644 --- a/sdk/src/types/block/output/account.rs +++ b/sdk/src/types/block/output/account.rs @@ -690,7 +690,7 @@ pub(crate) mod dto { impl AccountOutput { #[allow(clippy::too_many_arguments)] - pub fn try_from_dtos<'a>( + pub fn try_from_dtos( amount: OutputBuilderAmount, mana: u64, native_tokens: Option>, diff --git a/sdk/src/types/block/output/anchor.rs b/sdk/src/types/block/output/anchor.rs index c21c77b149..b5ec4780a5 100644 --- a/sdk/src/types/block/output/anchor.rs +++ b/sdk/src/types/block/output/anchor.rs @@ -773,7 +773,7 @@ pub(crate) mod dto { impl AnchorOutput { #[allow(clippy::too_many_arguments)] - pub fn try_from_dtos<'a>( + pub fn try_from_dtos( amount: OutputBuilderAmount, mana: u64, native_tokens: Option>, @@ -851,7 +851,7 @@ mod tests { output.mana(), Some(output.native_tokens().to_vec()), output.anchor_id(), - output.state_index().into(), + output.state_index(), output.state_metadata().to_owned().into(), output.unlock_conditions().iter().map(Into::into).collect(), Some(output.features().to_vec()), diff --git a/sdk/src/types/block/output/basic.rs b/sdk/src/types/block/output/basic.rs index ecc803410f..5cf17ea955 100644 --- a/sdk/src/types/block/output/basic.rs +++ b/sdk/src/types/block/output/basic.rs @@ -474,7 +474,7 @@ pub(crate) mod dto { } impl BasicOutput { - pub fn try_from_dtos<'a>( + pub fn try_from_dtos( amount: OutputBuilderAmount, mana: u64, native_tokens: Option>, diff --git a/sdk/src/types/block/output/delegation.rs b/sdk/src/types/block/output/delegation.rs index b1b3049cb3..ed5974df31 100644 --- a/sdk/src/types/block/output/delegation.rs +++ b/sdk/src/types/block/output/delegation.rs @@ -495,7 +495,7 @@ pub(crate) mod dto { impl DelegationOutput { #[allow(clippy::too_many_arguments)] - pub fn try_from_dtos<'a>( + pub fn try_from_dtos( amount: OutputBuilderAmount, delegated_amount: u64, delegation_id: &DelegationId, diff --git a/sdk/src/types/block/output/foundry.rs b/sdk/src/types/block/output/foundry.rs index 8cafce7ace..7978462879 100644 --- a/sdk/src/types/block/output/foundry.rs +++ b/sdk/src/types/block/output/foundry.rs @@ -740,7 +740,7 @@ pub(crate) mod dto { impl FoundryOutput { #[allow(clippy::too_many_arguments)] - pub fn try_from_dtos<'a>( + pub fn try_from_dtos( amount: OutputBuilderAmount, native_tokens: Option>, serial_number: u32, diff --git a/sdk/src/types/block/output/nft.rs b/sdk/src/types/block/output/nft.rs index 4f6bd4f0af..8c00c17128 100644 --- a/sdk/src/types/block/output/nft.rs +++ b/sdk/src/types/block/output/nft.rs @@ -650,7 +650,7 @@ pub(crate) mod dto { impl NftOutput { #[allow(clippy::too_many_arguments)] - pub fn try_from_dtos<'a>( + pub fn try_from_dtos( amount: OutputBuilderAmount, mana: u64, native_tokens: Option>, diff --git a/sdk/src/types/block/unlock/multi.rs b/sdk/src/types/block/unlock/multi.rs index 58e41a24fb..7cf6dd66f1 100644 --- a/sdk/src/types/block/unlock/multi.rs +++ b/sdk/src/types/block/unlock/multi.rs @@ -40,7 +40,7 @@ impl MultiUnlock { fn verify_unlocks(unlocks: &[Unlock]) -> Result<(), Error> { if VERIFY && unlocks.iter().any(Unlock::is_multi) { - return Err(Error::MultiUnlockRecursion); + Err(Error::MultiUnlockRecursion) } else { Ok(()) } diff --git a/sdk/src/wallet/core/builder.rs b/sdk/src/wallet/core/builder.rs index 06a24ebb16..b84b936b8d 100644 --- a/sdk/src/wallet/core/builder.rs +++ b/sdk/src/wallet/core/builder.rs @@ -137,10 +137,8 @@ where // Check if the db exists and if not, return an error if one parameter is missing, because otherwise the db // would be created with an empty parameter which just leads to errors later #[cfg(feature = "storage")] - if !storage_options.path.is_dir() { - if self.client_options.is_none() { - return Err(crate::wallet::Error::MissingParameter("client_options")); - } + if !storage_options.path.is_dir() && self.client_options.is_none() { + return Err(crate::wallet::Error::MissingParameter("client_options")); } #[cfg(all(feature = "rocksdb", feature = "storage"))] diff --git a/sdk/src/wallet/core/mod.rs b/sdk/src/wallet/core/mod.rs index 3cb0a9900b..5db7a7f0bc 100644 --- a/sdk/src/wallet/core/mod.rs +++ b/sdk/src/wallet/core/mod.rs @@ -263,7 +263,7 @@ where if let Address::Ed25519(address) = bech32_address.inner() { Ok(Bech32Address::new( *bech32_address.hrp(), - ImplicitAccountCreationAddress::from(address.clone()), + ImplicitAccountCreationAddress::from(*address), )) } else { Err(Error::NonEd25519Address) diff --git a/sdk/src/wallet/core/operations/stronghold_backup/mod.rs b/sdk/src/wallet/core/operations/stronghold_backup/mod.rs index ee8bb3fca9..81a3181bc5 100644 --- a/sdk/src/wallet/core/operations/stronghold_backup/mod.rs +++ b/sdk/src/wallet/core/operations/stronghold_backup/mod.rs @@ -110,7 +110,7 @@ impl Wallet { }); if !ignore_backup_values { - (*wallet_data).bip_path = read_bip_path; + wallet_data.bip_path = read_bip_path; } if let Some(mut read_secret_manager) = read_secret_manager { @@ -267,7 +267,7 @@ impl Wallet { }); if !ignore_backup_values { - (*wallet_data).bip_path = read_bip_path; + wallet_data.bip_path = read_bip_path; } if let Some(mut read_secret_manager) = read_secret_manager { diff --git a/sdk/src/wallet/core/operations/stronghold_backup/stronghold_snapshot.rs b/sdk/src/wallet/core/operations/stronghold_backup/stronghold_snapshot.rs index 68c3eac448..264962396b 100644 --- a/sdk/src/wallet/core/operations/stronghold_backup/stronghold_snapshot.rs +++ b/sdk/src/wallet/core/operations/stronghold_backup/stronghold_snapshot.rs @@ -66,7 +66,7 @@ pub(crate) async fn read_wallet_data_from_stronghold_snapshot(WALLET_DATA_KEY) .await? - .map(|dto| WalletData::try_from_dto(dto)) + .map(WalletData::try_from_dto) .transpose()?; Ok((client_options, restored_secret_manager, restored_wallet_data)) diff --git a/sdk/src/wallet/operations/syncing/mod.rs b/sdk/src/wallet/operations/syncing/mod.rs index abbbbb4d4e..b5fccd6a82 100644 --- a/sdk/src/wallet/operations/syncing/mod.rs +++ b/sdk/src/wallet/operations/syncing/mod.rs @@ -216,7 +216,7 @@ where let new_outputs_data_inner = self.get_outputs(output_ids).await?; let outputs_data_inner = self - .output_response_to_output_data(new_outputs_data_inner, &address_with_unspent_outputs) + .output_response_to_output_data(new_outputs_data_inner, address_with_unspent_outputs) .await?; outputs_data.extend(outputs_data_inner.clone()); diff --git a/sdk/src/wallet/operations/syncing/outputs.rs b/sdk/src/wallet/operations/syncing/outputs.rs index 85461ce33d..dfa73891c5 100644 --- a/sdk/src/wallet/operations/syncing/outputs.rs +++ b/sdk/src/wallet/operations/syncing/outputs.rs @@ -48,14 +48,12 @@ where .get(output_with_meta.metadata().transaction_id()) .map_or(false, |tx| !tx.incoming); - let chain = wallet_data.bip_path.map_or(None, |bip_path| { + let chain = wallet_data.bip_path.map(|bip_path| { // BIP 44 (HD wallets) and 4218 is the registered index for IOTA https://github.com/satoshilabs/slips/blob/master/slip-0044.md - Some( - Bip44::new(bip_path.coin_type) - .with_account(bip_path.account) - .with_change(associated_address.internal as _) - .with_address_index(associated_address.key_index), - ) + Bip44::new(bip_path.coin_type) + .with_account(bip_path.account) + .with_change(associated_address.internal as _) + .with_address_index(associated_address.key_index) }); OutputData { diff --git a/sdk/tests/types/output/account.rs b/sdk/tests/types/output/account.rs index c7c3b9bf9e..554e5f9a8f 100644 --- a/sdk/tests/types/output/account.rs +++ b/sdk/tests/types/output/account.rs @@ -3,7 +3,7 @@ use iota_sdk::types::block::{ address::AccountAddress, - output::{AccountOutput, Feature, FoundryId, MinimumOutputAmount, NativeToken, Output, SimpleTokenScheme, TokenId}, + output::{AccountOutput, Feature, FoundryId, MinimumOutputAmount, NativeToken, SimpleTokenScheme, TokenId}, protocol::protocol_parameters, rand::output::{ feature::{rand_issuer_feature, rand_metadata_feature, rand_sender_feature}, diff --git a/sdk/tests/types/output/basic.rs b/sdk/tests/types/output/basic.rs index 59967e4c01..9c675541e4 100644 --- a/sdk/tests/types/output/basic.rs +++ b/sdk/tests/types/output/basic.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 use iota_sdk::types::block::{ - output::{BasicOutput, Feature, FoundryId, MinimumOutputAmount, NativeToken, Output, SimpleTokenScheme, TokenId}, + output::{BasicOutput, Feature, FoundryId, MinimumOutputAmount, NativeToken, SimpleTokenScheme, TokenId}, protocol::protocol_parameters, rand::{ address::rand_account_address, diff --git a/sdk/tests/types/output/foundry.rs b/sdk/tests/types/output/foundry.rs index 68b1a23ff2..00ba0bd331 100644 --- a/sdk/tests/types/output/foundry.rs +++ b/sdk/tests/types/output/foundry.rs @@ -4,7 +4,7 @@ use iota_sdk::types::block::{ output::{ unlock_condition::ImmutableAccountAddressUnlockCondition, FoundryId, FoundryOutput, MinimumOutputAmount, - NativeToken, Output, SimpleTokenScheme, TokenId, + NativeToken, SimpleTokenScheme, TokenId, }, protocol::protocol_parameters, rand::{ diff --git a/sdk/tests/types/output/nft.rs b/sdk/tests/types/output/nft.rs index edf526aee2..3bdeac1bb2 100644 --- a/sdk/tests/types/output/nft.rs +++ b/sdk/tests/types/output/nft.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 use iota_sdk::types::block::{ - output::{FoundryId, MinimumOutputAmount, NativeToken, NftId, NftOutput, Output, SimpleTokenScheme, TokenId}, + output::{FoundryId, MinimumOutputAmount, NativeToken, NftId, NftOutput, SimpleTokenScheme, TokenId}, protocol::protocol_parameters, rand::{ address::rand_account_address,