From 76d75a95e52a388eedd9b017d935767ba95a6d26 Mon Sep 17 00:00:00 2001 From: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com> Date: Fri, 9 May 2025 22:15:55 +0200 Subject: [PATCH] chore: remove useless clone --- Cargo.toml | 3 +- pallets/dispenser/src/extensions.rs | 2 +- .../funding/src/functions/1_application.rs | 6 ++-- pallets/funding/src/functions/3_auction.rs | 2 +- pallets/funding/src/functions/5_settlement.rs | 4 +-- pallets/funding/src/functions/misc.rs | 2 +- .../funding/src/instantiator/calculations.rs | 6 ++-- .../src/instantiator/chain_interactions.rs | 33 ++++++++----------- pallets/funding/src/instantiator/mod.rs | 2 +- pallets/funding/src/instantiator/types.rs | 20 +++++------ pallets/funding/src/types.rs | 12 +++---- pallets/linear-release/src/lib.rs | 2 +- pallets/on-slash-vesting/src/lib.rs | 10 +++--- pallets/proxy-bonding/src/functions.rs | 11 ++----- polimec-common/common/src/lib.rs | 2 +- runtimes/polimec/src/xcm_config.rs | 4 +-- 16 files changed, 55 insertions(+), 66 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3e20b3c0f..1b56e5da5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,8 @@ missing_errors_doc = "allow" must_use_candidate = "allow" identity_op = "allow" tabs_in_doc_comments = "allow" -redundant_clone = "warn" +redundant_clone = "deny" +missing-const-for-fn = "warn" [workspace.lints.rust] unreachable_patterns = "deny" diff --git a/pallets/dispenser/src/extensions.rs b/pallets/dispenser/src/extensions.rs index a36f56f01..cd21765a6 100644 --- a/pallets/dispenser/src/extensions.rs +++ b/pallets/dispenser/src/extensions.rs @@ -43,7 +43,7 @@ pub struct CheckNonce(#[codec(compact)] pub T::Nonce); impl CheckNonce { /// utility constructor. Used only in client/factory code. - pub fn from(nonce: T::Nonce) -> Self { + pub const fn from(nonce: T::Nonce) -> Self { Self(nonce) } } diff --git a/pallets/funding/src/functions/1_application.rs b/pallets/funding/src/functions/1_application.rs index d50745876..1c4e9fd8e 100644 --- a/pallets/funding/src/functions/1_application.rs +++ b/pallets/funding/src/functions/1_application.rs @@ -31,8 +31,8 @@ impl Pallet { project_metadata.minimum_price.checked_mul_int(total_allocation_size).ok_or(Error::::BadMath)?; let project_details = ProjectDetails { - issuer_account: issuer.clone(), - issuer_did: did.clone(), + issuer_account: issuer, + issuer_did: did, is_frozen: false, fundraising_target_usd: fundraising_target, status: ProjectStatus::Application, @@ -110,7 +110,7 @@ impl Pallet { // * Calculate new variables * let (project_details, bucket) = - Self::project_validation(&new_project_metadata, issuer.clone(), project_details.issuer_did.clone())?; + Self::project_validation(&new_project_metadata, issuer.clone(), project_details.issuer_did)?; // * Update storage * ProjectsMetadata::::insert(project_id, new_project_metadata.clone()); diff --git a/pallets/funding/src/functions/3_auction.rs b/pallets/funding/src/functions/3_auction.rs index 8dc3178e5..38fb6f08a 100644 --- a/pallets/funding/src/functions/3_auction.rs +++ b/pallets/funding/src/functions/3_auction.rs @@ -187,7 +187,7 @@ impl Pallet { Self::deposit_event(Event::Bid { project_id, - bidder: bidder.clone(), + bidder, id: bid_id, ct_amount, ct_price: ct_usd_price, diff --git a/pallets/funding/src/functions/5_settlement.rs b/pallets/funding/src/functions/5_settlement.rs index 428c931f1..3613be824 100644 --- a/pallets/funding/src/functions/5_settlement.rs +++ b/pallets/funding/src/functions/5_settlement.rs @@ -50,7 +50,7 @@ impl Pallet { T::ContributionTokenCurrency::create(project_id, escrow_account.clone(), false, 1_u32.into())?; T::ContributionTokenCurrency::set( project_id, - &escrow_account.clone(), + &escrow_account, token_information.name.into(), token_information.symbol.into(), token_information.decimals, @@ -390,7 +390,7 @@ impl Pallet { Fortitude::Force, )?; - T::OnSlash::on_slash(&evaluation.evaluator, slashed_amount); + T::OnSlash::on_slash(&evaluation.evaluator, &slashed_amount); Ok(evaluation.current_plmc_bond.saturating_sub(slashed_amount)) } diff --git a/pallets/funding/src/functions/misc.rs b/pallets/funding/src/functions/misc.rs index 80064f6c1..8c1729c77 100644 --- a/pallets/funding/src/functions/misc.rs +++ b/pallets/funding/src/functions/misc.rs @@ -330,7 +330,7 @@ impl Pallet { polimec_account: AccountIdOf, project_id: ProjectId, ) -> bool { - let message_to_sign = Self::get_substrate_message_to_sign(polimec_account.clone(), project_id).unwrap(); + let message_to_sign = Self::get_substrate_message_to_sign(polimec_account, project_id).unwrap(); let message_bytes = message_to_sign.into_bytes(); let signature = SrSignature::from_slice(&signature_bytes[..64]).unwrap(); let public = SrPublic::from_slice(&expected_substrate_account).unwrap(); diff --git a/pallets/funding/src/instantiator/calculations.rs b/pallets/funding/src/instantiator/calculations.rs index 5e95cb1f2..e14904b4e 100644 --- a/pallets/funding/src/instantiator/calculations.rs +++ b/pallets/funding/src/instantiator/calculations.rs @@ -119,7 +119,7 @@ impl< ) -> Vec> { let mut output = Vec::new(); let charged_bids = self.get_actual_price_charged_for_bucketed_bids(bids, project_metadata.clone(), None); - let grouped_by_price_bids = charged_bids.clone().into_iter().group_by(|&(_, price)| price); + let grouped_by_price_bids = charged_bids.into_iter().group_by(|&(_, price)| price); let mut grouped_by_price_bids: Vec<(PriceOf, Vec>)> = grouped_by_price_bids .into_iter() .map(|(key, group)| (key, group.map(|(bid, _price_)| bid).collect())) @@ -208,7 +208,7 @@ impl< ) -> Vec> { let mut output = Vec::new(); let charged_bids = self.get_actual_price_charged_for_bucketed_bids(bids, project_metadata.clone(), None); - let grouped_by_price_bids = charged_bids.clone().into_iter().group_by(|&(_, price)| price); + let grouped_by_price_bids = charged_bids.into_iter().group_by(|&(_, price)| price); let mut grouped_by_price_bids: Vec<(PriceOf, Vec>)> = grouped_by_price_bids .into_iter() .map(|(key, group)| (key, group.map(|(bid, _price)| bid).collect())) @@ -499,7 +499,7 @@ impl< bucket.update(ct_min_ticket); } - self.generate_bids_from_bucket(project_metadata.clone(), bucket, AcceptedFundingAsset::USDT) + self.generate_bids_from_bucket(project_metadata, bucket, AcceptedFundingAsset::USDT) } pub fn generate_bids_from_total_ct_percent( diff --git a/pallets/funding/src/instantiator/chain_interactions.rs b/pallets/funding/src/instantiator/chain_interactions.rs index af562e83e..0a43e0cc3 100644 --- a/pallets/funding/src/instantiator/chain_interactions.rs +++ b/pallets/funding/src/instantiator/chain_interactions.rs @@ -12,7 +12,7 @@ impl< RuntimeEvent: From> + TryInto> + Parameter + Member + IsType<::RuntimeEvent>, > Instantiator { - pub fn new(ext: OptionalExternalities) -> Self { + pub const fn new(ext: OptionalExternalities) -> Self { Self { ext, nonce: RefCell::new(0u64), _marker: PhantomData } } @@ -447,7 +447,7 @@ impl< } pub fn mint_necessary_tokens_for_evaluations(&mut self, evaluations: Vec>) { - let plmc_required = self.calculate_evaluation_plmc_spent(evaluations.clone()); + let plmc_required = self.calculate_evaluation_plmc_spent(evaluations); self.mint_plmc_ed_if_required(plmc_required.accounts()); self.mint_plmc_to(plmc_required); } @@ -684,7 +684,7 @@ impl< issuer: AccountIdOf, maybe_did: Option, ) -> ProjectId { - let project_id = self.create_new_project(project_metadata, issuer.clone(), maybe_did); + let project_id = self.create_new_project(project_metadata, issuer, maybe_did); assert_eq!(self.go_to_next_state(project_id), ProjectStatus::EvaluationRound); project_id @@ -697,15 +697,14 @@ impl< maybe_did: Option, evaluations: Vec>, ) -> ProjectId { - let project_id = self.create_evaluating_project(project_metadata, issuer.clone(), maybe_did); + let project_id = self.create_evaluating_project(project_metadata, issuer, maybe_did); let evaluators = evaluations.accounts(); self.mint_plmc_ed_if_required(evaluators.clone()); let prev_supply = self.get_plmc_total_supply(); let prev_free_plmc_balances = self.get_free_plmc_balances_for(evaluators.clone()); - let prev_held_plmc_balances = - self.get_reserved_plmc_balances_for(evaluators.clone(), HoldReason::Evaluation.into()); + let prev_held_plmc_balances = self.get_reserved_plmc_balances_for(evaluators, HoldReason::Evaluation.into()); let plmc_evaluation_deposits: Vec> = self.calculate_evaluation_plmc_spent(evaluations.clone()); @@ -716,11 +715,10 @@ impl< let expected_free_plmc_balances = prev_free_plmc_balances; let expected_held_plmc_balances = self.generic_map_operation( - vec![prev_held_plmc_balances.clone(), plmc_evaluation_deposits.clone()], + vec![prev_held_plmc_balances, plmc_evaluation_deposits.clone()], MergeOperation::Add, ); - let expected_total_plmc_supply = - prev_supply + self.sum_balance_mappings(vec![plmc_evaluation_deposits.clone()]); + let expected_total_plmc_supply = prev_supply + self.sum_balance_mappings(vec![plmc_evaluation_deposits]); self.evaluation_assertions( project_id, @@ -757,7 +755,7 @@ impl< let plmc_evaluation_deposits: Vec> = self.calculate_evaluation_plmc_spent(evaluations); let plmc_bid_deposits: Vec> = self .calculate_auction_plmc_charged_from_all_bids_made_or_with_bucket(&bids, project_metadata.clone(), None); - let reducible_evaluator_balances = self.slash_evaluator_balances(plmc_evaluation_deposits.clone()); + let reducible_evaluator_balances = self.slash_evaluator_balances(plmc_evaluation_deposits); let necessary_plmc_mints = self.generic_map_operation( vec![plmc_bid_deposits.clone(), reducible_evaluator_balances], @@ -765,7 +763,7 @@ impl< ); let funding_asset_deposits = self.calculate_auction_funding_asset_charged_from_all_bids_made_or_with_bucket( &bids, - project_metadata.clone(), + project_metadata, None, ); @@ -774,8 +772,8 @@ impl< self.generic_map_operation(vec![prev_held_plmc_balances, plmc_bid_deposits], MergeOperation::Add); let expected_plmc_supply = prev_plmc_supply + necessary_plmc_mints.total(); - self.mint_plmc_to(necessary_plmc_mints.clone()); - self.mint_funding_asset_to(funding_asset_deposits.clone()); + self.mint_plmc_to(necessary_plmc_mints); + self.mint_funding_asset_to(funding_asset_deposits); self.bid_for_users(project_id, bids.clone()).unwrap(); @@ -805,13 +803,8 @@ impl< bids: Vec>, mark_as_settled: bool, ) -> ProjectId { - let project_id = self.create_finished_project( - project_metadata.clone(), - issuer.clone(), - maybe_did, - evaluations.clone(), - bids.clone(), - ); + let project_id = + self.create_finished_project(project_metadata.clone(), issuer, maybe_did, evaluations, bids.clone()); assert!(matches!(self.go_to_next_state(project_id), ProjectStatus::SettlementStarted(_))); self.test_ct_created_for(project_id); diff --git a/pallets/funding/src/instantiator/mod.rs b/pallets/funding/src/instantiator/mod.rs index c985cb411..2bb9efc6d 100644 --- a/pallets/funding/src/instantiator/mod.rs +++ b/pallets/funding/src/instantiator/mod.rs @@ -13,7 +13,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#[allow(clippy::wildcard_imports)] + extern crate alloc; use crate::{traits::*, *}; diff --git a/pallets/funding/src/instantiator/types.rs b/pallets/funding/src/instantiator/types.rs index 3040ca126..e81e4826c 100644 --- a/pallets/funding/src/instantiator/types.rs +++ b/pallets/funding/src/instantiator/types.rs @@ -43,7 +43,7 @@ pub struct UserToPLMCBalance { pub plmc_amount: Balance, } impl UserToPLMCBalance { - pub fn new(account: AccountIdOf, plmc_amount: Balance) -> Self { + pub const fn new(account: AccountIdOf, plmc_amount: Balance) -> Self { Self { account, plmc_amount } } } @@ -101,7 +101,7 @@ pub struct EvaluationParams { pub receiving_account: Junction, } impl EvaluationParams { - pub fn new(account: AccountIdOf, usd_amount: Balance, receiving_account: Junction) -> Self { + pub const fn new(account: AccountIdOf, usd_amount: Balance, receiving_account: Junction) -> Self { EvaluationParams:: { account, usd_amount, receiving_account } } } @@ -137,7 +137,7 @@ pub struct UserToUSDAmount { pub usd_amount: Balance, } impl UserToUSDAmount { - pub fn new(account: AccountIdOf, usd_amount: Balance) -> Self { + pub const fn new(account: AccountIdOf, usd_amount: Balance) -> Self { Self { account, usd_amount } } } @@ -195,7 +195,7 @@ pub struct UserToFundingAsset { pub asset_id: AssetIdOf, } impl UserToFundingAsset { - pub fn new(account: AccountIdOf, asset_amount: Balance, asset_id: AssetIdOf) -> Self { + pub const fn new(account: AccountIdOf, asset_amount: Balance, asset_id: AssetIdOf) -> Self { Self { account, asset_amount, asset_id } } } @@ -298,7 +298,7 @@ pub struct BidParams { pub receiving_account: Junction, } impl BidParams { - pub fn new( + pub const fn new( bidder: AccountIdOf, investor_type: InvestorType, amount: Balance, @@ -319,7 +319,7 @@ impl From<(AccountIdOf, Balance)> for BidParams { asset: AcceptedFundingAsset::USDT, receiving_account: Junction::AccountId32 { network: Some(NetworkId::Polkadot), - id: T::AccountId32Conversion::convert(bidder.clone()), + id: T::AccountId32Conversion::convert(bidder), }, } } @@ -334,7 +334,7 @@ impl From<(AccountIdOf, InvestorType, Balance)> for BidParams { asset: AcceptedFundingAsset::USDT, receiving_account: Junction::AccountId32 { network: Some(NetworkId::Polkadot), - id: T::AccountId32Conversion::convert(bidder.clone()), + id: T::AccountId32Conversion::convert(bidder), }, } } @@ -349,7 +349,7 @@ impl From<(AccountIdOf, InvestorType, Balance, ParticipationMode)> asset: AcceptedFundingAsset::USDT, receiving_account: Junction::AccountId32 { network: Some(NetworkId::Polkadot), - id: T::AccountId32Conversion::convert(bidder.clone()), + id: T::AccountId32Conversion::convert(bidder), }, } } @@ -366,7 +366,7 @@ impl From<(AccountIdOf, InvestorType, Balance, AcceptedFundingAsse asset, receiving_account: Junction::AccountId32 { network: Some(NetworkId::Polkadot), - id: T::AccountId32Conversion::convert(bidder.clone()), + id: T::AccountId32Conversion::convert(bidder), }, } } @@ -391,7 +391,7 @@ impl From<(AccountIdOf, InvestorType, Balance, ParticipationMode, asset, receiving_account: Junction::AccountId32 { network: Some(NetworkId::Polkadot), - id: T::AccountId32Conversion::convert(bidder.clone()), + id: T::AccountId32Conversion::convert(bidder), }, } } diff --git a/pallets/funding/src/types.rs b/pallets/funding/src/types.rs index aa71c7d4e..0f71c3a22 100644 --- a/pallets/funding/src/types.rs +++ b/pallets/funding/src/types.rs @@ -525,22 +525,22 @@ pub mod inner { pub usd_maximum_per_did: Option, } impl TicketSize { - pub fn new(usd_minimum_per_participation: Balance, usd_maximum_per_did: Option) -> Self { + pub const fn new(usd_minimum_per_participation: Balance, usd_maximum_per_did: Option) -> Self { Self { usd_minimum_per_participation, usd_maximum_per_did } } - pub fn usd_ticket_above_minimum_per_participation(&self, usd_amount: Balance) -> bool { + pub const fn usd_ticket_above_minimum_per_participation(&self, usd_amount: Balance) -> bool { usd_amount >= self.usd_minimum_per_participation } - pub fn usd_ticket_below_maximum_per_did(&self, usd_amount: Balance) -> bool { + pub const fn usd_ticket_below_maximum_per_did(&self, usd_amount: Balance) -> bool { match self.usd_maximum_per_did { Some(max) => usd_amount <= max, None => true, } } - pub fn check_valid(&self, bound: Bound) -> bool { + pub const fn check_valid(&self, bound: Bound) -> bool { if let (min, Some(max)) = (self.usd_minimum_per_participation, self.usd_maximum_per_did) { if min > max { return false @@ -766,7 +766,7 @@ pub mod inner { Classic(u8), } impl ParticipationMode { - pub fn multiplier(&self) -> u8 { + pub const fn multiplier(&self) -> u8 { match self { // OTM multiplier is fixed at 5 ParticipationMode::OTM => 5u8, @@ -794,7 +794,7 @@ pub mod inner { Ethereum, } impl ParticipantsAccountType { - pub fn junction_is_supported(&self, junction: &Junction) -> bool { + pub const fn junction_is_supported(&self, junction: &Junction) -> bool { match self { // This project expects users to submit a 32 byte account, and sign it with SR25519 crypto ParticipantsAccountType::Polkadot => matches!(junction, Junction::AccountId32 { .. }), diff --git a/pallets/linear-release/src/lib.rs b/pallets/linear-release/src/lib.rs index 51b6229dc..f47513b63 100644 --- a/pallets/linear-release/src/lib.rs +++ b/pallets/linear-release/src/lib.rs @@ -162,7 +162,7 @@ pub mod pallet { #[pallet::extra_constants] impl Pallet { #[pallet::constant_name(MaxVestingSchedules)] - fn max_vesting_schedules() -> u32 { + const fn max_vesting_schedules() -> u32 { T::MAX_VESTING_SCHEDULES } } diff --git a/pallets/on-slash-vesting/src/lib.rs b/pallets/on-slash-vesting/src/lib.rs index 571f986a2..b705c0271 100644 --- a/pallets/on-slash-vesting/src/lib.rs +++ b/pallets/on-slash-vesting/src/lib.rs @@ -14,13 +14,13 @@ use pallet_vesting::Vesting; use sp_runtime::{traits::BlockNumberProvider, BoundedVec}; pub trait OnSlash { - fn on_slash(account: &AccountId, amount: Balance); + fn on_slash(account: &AccountId, amount: &Balance); } #[impl_trait_for_tuples::impl_for_tuples(30)] impl OnSlash for Tuple { - fn on_slash(account: &AccountId, amount: Balance) { - for_tuples!( #( Tuple::on_slash(account, amount.clone()); )* ); + fn on_slash(account: &AccountId, amount: &Balance) { + for_tuples!( #( Tuple::on_slash(account, amount); )* ); } } @@ -30,12 +30,12 @@ where T: pallet_vesting::Config, T::Currency: Currency, Balance = u128>, { - fn on_slash(account: &AccountIdOf, slashed_amount: u128) { + fn on_slash(account: &AccountIdOf, slashed_amount: &u128) { if let Some(vesting_schedules) = >::get(account) { let mut new_vesting_schedules = BoundedVec::with_bounded_capacity(vesting_schedules.len()); let now = T::BlockNumberProvider::current_block_number(); for schedule in vesting_schedules { - let total_locked = schedule.locked_at::(now).saturating_sub(slashed_amount); + let total_locked = schedule.locked_at::(now).saturating_sub(*slashed_amount); let start_block = T::BlockNumberToBalance::convert(now); let end_block = schedule.ending_block_as_balance::(); let duration = end_block.saturating_sub(start_block); diff --git a/pallets/proxy-bonding/src/functions.rs b/pallets/proxy-bonding/src/functions.rs index 5344f5501..791795477 100644 --- a/pallets/proxy-bonding/src/functions.rs +++ b/pallets/proxy-bonding/src/functions.rs @@ -60,18 +60,13 @@ impl Pallet { // Ensure the sub-account has an ED by the treasury. This will be refunded after all the tokens are unlocked if T::BondingToken::balance(&bonding_account) < existential_deposit { - T::BondingToken::transfer( - &treasury.clone(), - &bonding_account, - existential_deposit, - Preservation::Preserve, - )?; + T::BondingToken::transfer(&treasury, &bonding_account, existential_deposit, Preservation::Preserve)?; } // Bond the PLMC on behalf of the user T::BondingToken::transfer_and_hold( &hold_reason.into(), - &treasury.clone(), - &bonding_account.clone(), + &treasury, + &bonding_account, bond_amount, Precision::Exact, Preservation::Preserve, diff --git a/polimec-common/common/src/lib.rs b/polimec-common/common/src/lib.rs index 68f9afd75..6eedc6ba7 100644 --- a/polimec-common/common/src/lib.rs +++ b/polimec-common/common/src/lib.rs @@ -214,7 +214,7 @@ pub mod migration_types { self.0.push(migration) } - pub fn from(migrations: Vec) -> Self { + pub const fn from(migrations: Vec) -> Self { Self(migrations) } diff --git a/runtimes/polimec/src/xcm_config.rs b/runtimes/polimec/src/xcm_config.rs index 9090fdf33..f2f02304f 100644 --- a/runtimes/polimec/src/xcm_config.rs +++ b/runtimes/polimec/src/xcm_config.rs @@ -129,7 +129,7 @@ pub struct SupportedAssets; impl frame_support::traits::Contains for SupportedAssets { fn contains(l: &Location) -> bool { let funding_assets = AcceptedFundingAsset::all_ids(); - l.clone().try_into().ok().map_or(false, |v4_location| funding_assets.contains(&v4_location)) + l.clone().try_into().ok().is_some_and(|v4_location| funding_assets.contains(&v4_location)) } } @@ -483,7 +483,7 @@ impl WeightTrader for AssetTrader { } if asset_amount > 0 { - Some((asset_id.clone(), asset_amount).into()) + Some((asset_id, asset_amount).into()) } else { None }