Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🦀 Clippy linter changes #379

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added clippy.toml
Empty file.
6 changes: 3 additions & 3 deletions nodes/parachain/src/chain_spec/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ pub fn genesis_config(genesis_config_params: GenesisConfigParams) -> serde_json:
],
// (id, account_id, amount)
"accounts": vec![
(usdt_id, funding_assets_owner.clone(), 1000000000000u64),
(usdc_id, funding_assets_owner.clone(), 1000000000000u64),
(dot_id, funding_assets_owner.clone(), 1000000000000u64)
(usdt_id, funding_assets_owner.clone(), 1_000_000_000_000_u64),
(usdc_id, funding_assets_owner.clone(), 1_000_000_000_000_u64),
(dot_id, funding_assets_owner.clone(), 1_000_000_000_000_u64)
],
},
"parachainStaking": {
Expand Down
2 changes: 1 addition & 1 deletion nodes/parachain/src/chain_spec/polimec_paseo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use sc_service::ChainType;

use crate::chain_spec::{common::*, get_properties, Extensions, GenericChainSpec, DEFAULT_PARA_ID};
use crate::chain_spec::{common::{GenesisConfigParams, alice, bob, charlie, dave, eve, genesis_config}, get_properties, Extensions, GenericChainSpec, DEFAULT_PARA_ID};
use polimec_runtime::{AccountId, MinCandidateStk};

pub fn get_local_chain_spec() -> GenericChainSpec {
Expand Down
4 changes: 2 additions & 2 deletions nodes/parachain/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pub fn run() -> Result<()> {
&polkadot_cli,
config.tokio_handle.clone(),
)
.map_err(|err| format!("Relay chain argument error: {}", err))?;
.map_err(|err| format!("Relay chain argument error: {err}"))?;

cmd.run(config, polkadot_config)
})
Expand Down Expand Up @@ -280,7 +280,7 @@ pub fn run() -> Result<()> {
let tokio_handle = config.tokio_handle.clone();
let polkadot_config =
SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, tokio_handle)
.map_err(|err| format!("Relay chain argument error: {}", err))?;
.map_err(|err| format!("Relay chain argument error: {err}"))?;

info!("Parachain Account: {parachain_account}");
info!("Is collating: {}", if config.role.is_authority() { "yes" } else { "no" });
Expand Down
10 changes: 5 additions & 5 deletions nodes/parachain/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

//! Service and ServiceFactory implementation. Specialized wrapper over substrate service.
//! Service and `ServiceFactory` implementation. Specialized wrapper over substrate service.

// std
use std::{sync::Arc, time::Duration};
Expand Down Expand Up @@ -61,7 +61,7 @@ type ParachainBackend = TFullBackend<Block>;

type ParachainBlockImport = TParachainBlockImport<Block, Arc<ParachainClient>, ParachainBackend>;

/// Assembly of PartialComponents (enough to run chain ops subcommands)
/// Assembly of `PartialComponents` (enough to run chain ops subcommands)
pub type Service = PartialComponents<
ParachainClient,
ParachainBackend,
Expand Down Expand Up @@ -126,7 +126,7 @@ pub fn new_partial(config: &Configuration) -> Result<Service, sc_service::Error>
client.clone(),
block_import.clone(),
config,
telemetry.as_ref().map(|telemetry| telemetry.handle()),
telemetry.as_ref().map(sc_telemetry::Telemetry::handle),
&task_manager,
)?;

Expand Down Expand Up @@ -291,7 +291,7 @@ async fn start_node_impl(
backend.clone(),
block_import,
prometheus_registry.as_ref(),
telemetry.as_ref().map(|t| t.handle()),
telemetry.as_ref().map(sc_telemetry::Telemetry::handle),
&task_manager,
relay_chain_interface.clone(),
transaction_pool,
Expand Down Expand Up @@ -329,7 +329,7 @@ fn build_import_queue(
>(
client,
block_import,
move |_, _| async move {
move |_, ()| async move {
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
Ok(timestamp)
},
Expand Down
11 changes: 4 additions & 7 deletions pallets/democracy/src/conviction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ use sp_runtime::{
use sp_std::{prelude::*, result::Result};

/// A value denoting the strength of conviction of a vote.
#[derive(Encode, MaxEncodedLen, Decode, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, RuntimeDebug, TypeInfo)]
#[derive(
Encode, MaxEncodedLen, Decode, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, RuntimeDebug, TypeInfo, Default,
)]
pub enum Conviction {
/// 0.1x votes, unlocked.
#[default]
None,
/// 1x votes, locked for an enactment period following a successful vote.
Locked1x,
Expand All @@ -39,12 +42,6 @@ pub enum Conviction {
Locked6x,
}

impl Default for Conviction {
fn default() -> Self {
Conviction::None
}
}

impl From<Conviction> for u8 {
fn from(c: Conviction) -> u8 {
match c {
Expand Down
12 changes: 6 additions & 6 deletions pallets/democracy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,12 +813,12 @@ pub mod pallet {
return Err(Error::<T>::NoProposal.into());
}

let mut existing_vetoers = <Blacklist<T>>::get(&proposal_hash).map(|pair| pair.1).unwrap_or_default();
let mut existing_vetoers = <Blacklist<T>>::get(proposal_hash).map(|pair| pair.1).unwrap_or_default();
let insert_position = existing_vetoers.binary_search(&who).err().ok_or(Error::<T>::AlreadyVetoed)?;
existing_vetoers.try_insert(insert_position, who.clone()).map_err(|_| Error::<T>::TooMany)?;

let until = <frame_system::Pallet<T>>::block_number().saturating_add(T::CooloffPeriod::get());
<Blacklist<T>>::insert(&proposal_hash, (until, existing_vetoers));
<Blacklist<T>>::insert(proposal_hash, (until, existing_vetoers));

Self::deposit_event(Event::<T>::Vetoed { who, proposal_hash, until });
<NextExternal<T>>::kill();
Expand Down Expand Up @@ -1020,7 +1020,7 @@ pub mod pallet {

// Insert the proposal into the blacklist.
let permanent = (BlockNumberFor::<T>::max_value(), BoundedVec::<T::AccountId, _>::default());
Blacklist::<T>::insert(&proposal_hash, permanent);
Blacklist::<T>::insert(proposal_hash, permanent);

// Remove the queued proposal, if it's there.
PublicProps::<T>::mutate(|props| {
Expand Down Expand Up @@ -1229,7 +1229,7 @@ impl<T: Config> Pallet<T> {
/// Actually enact a vote, if legit.
fn try_vote(who: &T::AccountId, ref_index: ReferendumIndex, vote: AccountVote<BalanceOf<T>>) -> DispatchResult {
let mut status = Self::referendum_status(ref_index)?;
ensure!(vote.balance() <= T::Fungible::total_balance(&who), Error::<T>::InsufficientFunds);
ensure!(vote.balance() <= T::Fungible::total_balance(who), Error::<T>::InsufficientFunds);
VotingOf::<T>::try_mutate(who, |voting| -> DispatchResult {
if let Voting::Direct { ref mut votes, delegations, .. } = voting {
match votes.binary_search_by_key(&ref_index, |i| i.0) {
Expand Down Expand Up @@ -1479,7 +1479,7 @@ impl<T: Config> Pallet<T> {
Self::transfer_metadata(MetadataOwner::External, MetadataOwner::Referendum(ref_index));
Ok(())
} else {
return Err(Error::<T>::NoneWaiting.into());
Err(Error::<T>::NoneWaiting.into())
}
}

Expand Down Expand Up @@ -1509,7 +1509,7 @@ impl<T: Config> Pallet<T> {
}
Ok(())
} else {
return Err(Error::<T>::NoneWaiting.into());
Err(Error::<T>::NoneWaiting.into())
}
}

Expand Down
2 changes: 1 addition & 1 deletion pallets/democracy/src/tests/cancellation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn cancel_referendum_should_work() {
new_test_ext().execute_with(|| {
let r = Democracy::inject_referendum(2, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
assert_ok!(Democracy::cancel_referendum(RuntimeOrigin::root(), r.into()));
assert_ok!(Democracy::cancel_referendum(RuntimeOrigin::root(), r));
assert_eq!(Democracy::lowest_unbaked(), 0);

next_block();
Expand Down
4 changes: 2 additions & 2 deletions pallets/democracy/src/tests/decoders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn test_decode_compact_u32_at() {
migration::put_storage_value(b"test", b"", &[], v);
assert_eq!(decode_compact_u32_at(b"test"), None);

for v in vec![0, 10, u32::MAX] {
for v in [0, 10, u32::MAX] {
let compact_v = parity_scale_codec::Compact(v);
unhashed::put(b"test", &compact_v);
assert_eq!(decode_compact_u32_at(b"test"), Some(v));
Expand All @@ -38,7 +38,7 @@ fn test_decode_compact_u32_at() {
#[test]
fn len_of_deposit_of() {
new_test_ext().execute_with(|| {
for l in vec![0, 1, 200, 1000] {
for l in [0, 1, 200, 1000] {
let value: (BoundedVec<u64, _>, u64) =
((0..l).map(|_| Default::default()).collect::<Vec<_>>().try_into().unwrap(), 3u64);
DepositOf::<Test>::insert(2, value);
Expand Down
2 changes: 1 addition & 1 deletion pallets/democracy/src/tests/scheduling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn lowest_unbaked_should_be_sensible() {
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r1, aye(1)));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r2, aye(1)));
// r3 is canceled
assert_ok!(Democracy::cancel_referendum(RuntimeOrigin::root(), r3.into()));
assert_ok!(Democracy::cancel_referendum(RuntimeOrigin::root(), r3));
assert_eq!(Democracy::lowest_unbaked(), 0);

next_block();
Expand Down
6 changes: 2 additions & 4 deletions pallets/dispenser/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,8 @@ where
len: usize,
result: &DispatchResult,
) -> Result<(), TransactionValidityError> {
if let Some(pre) = pre {
if let Some(pre) = pre {
S::post_dispatch(Some(pre), info, post_info, len, result)?;
}
if let Some(Some(pre)) = pre {
S::post_dispatch(Some(pre), info, post_info, len, result)?;
}
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions pallets/dispenser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ pub mod pallet {
impl<T: Config> Pallet<T> {
#[pallet::feeless_if( | origin: &OriginFor<T>, jwt: &UntrustedToken | -> bool {
if let Ok((_, did, _, _)) = T::InvestorOrigin::ensure_origin(origin.clone(), jwt, T::VerifierPublicKey::get()) {
return Dispensed::<T>::get(did).is_none()
Dispensed::<T>::get(did).is_none()
} else {
return false
false
}
})]
#[pallet::call_index(0)]
Expand Down
25 changes: 12 additions & 13 deletions pallets/elections-phragmen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ use frame_support::{
},
weights::Weight,
};
use log;
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_npos_elections::{ElectionResult, ExtendedBalance};
Expand Down Expand Up @@ -572,7 +571,7 @@ pub mod pallet {
#[pallet::call_index(5)]
#[pallet::weight(T::WeightInfo::clean_defunct_voters(*num_voters, *num_defunct))]
pub fn clean_defunct_voters(origin: OriginFor<T>, num_voters: u32, num_defunct: u32) -> DispatchResult {
let _ = ensure_root(origin)?;
ensure_root(origin)?;

<Voting<T>>::iter()
.take(num_voters as usize)
Expand Down Expand Up @@ -729,7 +728,7 @@ pub mod pallet {
// once this genesis voter is removed, and for now it is okay because
// remove_lock is noop if lock is not there.
<Voting<T>>::insert(
&member,
member,
Voter { votes: vec![member.clone()], stake: *stake, lockup_till: T::VotingLockPeriod::get() },
);

Expand Down Expand Up @@ -1373,7 +1372,7 @@ mod tests {
self
}

pub fn build_and_execute(self, test: impl FnOnce() -> ()) {
pub fn build_and_execute(self, test: impl FnOnce()) {
sp_tracing::try_init_simple();
MEMBERS.with(|m| *m.borrow_mut() = self.genesis_members.iter().map(|(m, _)| *m).collect::<Vec<_>>());
let mut ext: sp_io::TestExternalities = RuntimeGenesisConfig {
Expand Down Expand Up @@ -2002,7 +2001,7 @@ mod tests {
assert_ok!(vote(RuntimeOrigin::signed(2), vec![5], 20));
assert_ok!(vote(RuntimeOrigin::signed(3), vec![5], 30));

assert_eq_uvec!(all_voters(), vec![2, 3]);
assert_eq_uvec!(all_voters(), [2, 3]);
assert_eq!(balances(&2), (20, 0));
assert_eq!(locked_stake_of(&2), 20);
assert_eq!(balances(&3), (30, 0));
Expand All @@ -2014,12 +2013,12 @@ mod tests {
System::set_block_number(3);
assert_ok!(Elections::remove_voter(RuntimeOrigin::signed(2)));

assert_eq_uvec!(all_voters(), vec![3]);
assert_eq_uvec!(all_voters(), [3]);
assert!(votes_of(&2).is_empty());
assert_eq!(locked_stake_of(&2), 0);

assert_eq!(balances(&2), (20, 0));
assert_eq!(Balances::locks(&2).len(), 0);
assert_eq!(Balances::locks(2).len(), 0);
});
}

Expand Down Expand Up @@ -2074,7 +2073,7 @@ mod tests {
assert_ok!(vote(RuntimeOrigin::signed(4), vec![4], 15));
assert_ok!(vote(RuntimeOrigin::signed(3), vec![3], 30));

assert_eq_uvec!(all_voters(), vec![2, 3, 4]);
assert_eq_uvec!(all_voters(), [2, 3, 4]);

assert_eq!(votes_of(&2), vec![5]);
assert_eq!(votes_of(&3), vec![3]);
Expand All @@ -2094,7 +2093,7 @@ mod tests {
assert_eq!(members_and_stake(), vec![(3, 30), (5, 20)]);
assert!(Elections::runners_up().is_empty());

assert_eq_uvec!(all_voters(), vec![2, 3, 4]);
assert_eq_uvec!(all_voters(), [2, 3, 4]);
assert!(candidate_ids().is_empty());
assert_eq!(<Candidates<Test>>::decode_len(), None);

Expand Down Expand Up @@ -2170,7 +2169,7 @@ mod tests {
// candidate 4 is affected by an old vote.
assert_eq!(members_and_stake(), vec![(4, 30), (5, 50)]);
assert_eq!(Elections::election_rounds(), 2);
assert_eq_uvec!(all_voters(), vec![3, 5]);
assert_eq_uvec!(all_voters(), [3, 5]);
});
}

Expand Down Expand Up @@ -2402,7 +2401,7 @@ mod tests {
// no new candidates but old members and runners-up are always added.
assert!(candidate_ids().is_empty());
assert_eq!(Elections::election_rounds(), b / 5);
assert_eq_uvec!(all_voters(), vec![2, 3, 4, 5]);
assert_eq_uvec!(all_voters(), [2, 3, 4, 5]);
};

// this state will always persist when no further input is given.
Expand Down Expand Up @@ -2533,7 +2532,7 @@ mod tests {
System::set_block_number(5);
Elections::on_initialize(System::block_number());

assert_eq_uvec!(members_ids(), vec![3, 4]);
assert_eq_uvec!(members_ids(), [3, 4]);
assert_eq!(Elections::election_rounds(), 1);
});
}
Expand Down Expand Up @@ -2941,7 +2940,7 @@ mod tests {
// wrong member to remove.
ExtBuilder::default().desired_runners_up(1).build_and_execute(|| {
setup();
assert!(matches!(Elections::remove_and_replace_member(&2, false), Err(_)));
assert!(Elections::remove_and_replace_member(&2, false).is_err());
});
}

Expand Down
6 changes: 2 additions & 4 deletions pallets/funding/src/functions/6_settlement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,8 @@ impl<T: Config> Pallet<T> {
pub fn do_settle_bid(bid: BidInfoOf<T>, project_id: ProjectId) -> DispatchResult {
let project_details = ProjectsDetails::<T>::get(project_id).ok_or(Error::<T>::ProjectDetailsNotFound)?;
let project_metadata = ProjectsMetadata::<T>::get(project_id).ok_or(Error::<T>::ProjectMetadataNotFound)?;
let funding_success = match project_details.status {
ProjectStatus::SettlementStarted(FundingOutcome::Success) => true,
_ => false,
};
let funding_success =
matches!(project_details.status, ProjectStatus::SettlementStarted(FundingOutcome::Success));
let wap = project_details.weighted_average_price.ok_or(Error::<T>::ImpossibleState)?;

ensure!(
Expand Down
4 changes: 2 additions & 2 deletions pallets/funding/src/functions/7_ct_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl<T: Config> Pallet<T> {
// TODO: set these constants with a proper value
const EXECUTION_DOT: MultiAsset = MultiAsset {
id: Concrete(MultiLocation { parents: 0, interior: Here }),
fun: Fungible(1_0_000_000_000u128),
fun: Fungible(10_000_000_000_u128),
};
const MAX_WEIGHT: Weight = Weight::from_parts(20_000_000_000, 1_000_000);

Expand Down Expand Up @@ -466,7 +466,7 @@ impl<T: Config> Pallet<T> {
Self::change_migration_status(project_id, participant.clone(), MigrationStatus::Sent(query_id))?;

// * Process Data *
let xcm = Self::construct_migration_xcm_message(migrations.into(), query_id, pallet_index);
let xcm = Self::construct_migration_xcm_message(migrations, query_id, pallet_index);

<pallet_xcm::Pallet<T>>::send_xcm(Here, project_multilocation, xcm).map_err(|_| Error::<T>::XcmFailed)?;
ActiveMigrationQueue::<T>::insert(query_id, (project_id, participant.clone()));
Expand Down
8 changes: 3 additions & 5 deletions pallets/funding/src/functions/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,9 @@ impl<T: Config> Pallet<T> {
ensure!(project_details.status == current_round, Error::<T>::IncorrectRound);
ensure!(project_details.round_duration.ended(now) || skip_end_check, Error::<T>::TooEarlyForRound);

let round_end = if let Some(round_duration) = maybe_round_duration {
Some(now.saturating_add(round_duration).saturating_sub(One::one()))
} else {
None
};
let round_end =
maybe_round_duration.map(|round_duration| now.saturating_add(round_duration).saturating_sub(One::one()));

project_details.round_duration = BlockNumberPair::new(Some(now), round_end);
project_details.status = next_round.clone();

Expand Down
Loading