Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
darkforest0202 committed Aug 4, 2023
1 parent 29bcffc commit 60e5147
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 47 deletions.
28 changes: 14 additions & 14 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,21 +311,21 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
ProxyType::Any => true,
ProxyType::NonTransfer => !matches!(
c,
RuntimeCall::Balances(..)
| RuntimeCall::Assets(..)
| RuntimeCall::Uniques(..)
| RuntimeCall::Nfts(..)
| RuntimeCall::Vesting(pallet_vesting::Call::vested_transfer { .. })
| RuntimeCall::Indices(pallet_indices::Call::transfer { .. })
RuntimeCall::Balances(..) |
RuntimeCall::Assets(..) |
RuntimeCall::Uniques(..) |
RuntimeCall::Nfts(..) |
RuntimeCall::Vesting(pallet_vesting::Call::vested_transfer { .. }) |
RuntimeCall::Indices(pallet_indices::Call::transfer { .. })
),
ProxyType::Governance => matches!(
c,
RuntimeCall::Democracy(..)
| RuntimeCall::Council(..)
| RuntimeCall::Society(..)
| RuntimeCall::TechnicalCommittee(..)
| RuntimeCall::Elections(..)
| RuntimeCall::Treasury(..)
RuntimeCall::Democracy(..) |
RuntimeCall::Council(..) |
RuntimeCall::Society(..) |
RuntimeCall::TechnicalCommittee(..) |
RuntimeCall::Elections(..) |
RuntimeCall::Treasury(..)
),
ProxyType::Staking => {
matches!(c, RuntimeCall::Staking(..) | RuntimeCall::FastUnstake(..))
Expand Down Expand Up @@ -693,8 +693,8 @@ impl Get<Option<BalancingConfig>> for OffchainRandomBalancing {
max => {
let seed = sp_io::offchain::random_seed();
let random = <u32>::decode(&mut TrailingZeroInput::new(&seed))
.expect("input is padded with zeroes; qed")
% max.saturating_add(1);
.expect("input is padded with zeroes; qed") %
max.saturating_add(1);
random as usize
},
};
Expand Down
4 changes: 3 additions & 1 deletion frame/asset-conversion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,9 @@ pub mod pallet {
()
);
} else {
let MultiAssetIdConversionResult::Converted(asset_id) = T::MultiAssetIdConverter::try_convert(asset) else {
let MultiAssetIdConversionResult::Converted(asset_id) =
T::MultiAssetIdConverter::try_convert(asset)
else {
return Err(())
};
let minimal = T::Assets::minimum_balance(asset_id);
Expand Down
6 changes: 5 additions & 1 deletion frame/asset-conversion/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ fn pool_assets() -> Vec<u32> {

fn create_tokens(owner: u128, tokens: Vec<NativeOrAssetId<u32>>) {
for token_id in tokens {
let MultiAssetIdConversionResult::Converted(asset_id) = NativeOrAssetIdConverter::try_convert(&token_id) else { unreachable!("invalid token") };
let MultiAssetIdConversionResult::Converted(asset_id) =
NativeOrAssetIdConverter::try_convert(&token_id)
else {
unreachable!("invalid token")
};
assert_ok!(Assets::force_create(RuntimeOrigin::root(), asset_id, owner, false, 1));
}
}
Expand Down
46 changes: 23 additions & 23 deletions frame/assets/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
// allow accidental usage of all consumer references which could cause grief.
if !frame_system::Pallet::<T>::can_inc_consumer(who) {
frame_system::Pallet::<T>::dec_consumers(who);
return Err(Error::<T, I>::UnavailableConsumer.into());
return Err(Error::<T, I>::UnavailableConsumer.into())
}
ExistenceReason::Consumer
};
Expand Down Expand Up @@ -134,25 +134,25 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
};

if increase_supply && details.supply.checked_add(&amount).is_none() {
return DepositConsequence::Overflow;
return DepositConsequence::Overflow
}

if let Some(account) = Account::<T, I>::get(id, who) {
if account.status.is_blocked() {
return DepositConsequence::Blocked;
return DepositConsequence::Blocked
}
if account.balance.checked_add(&amount).is_none() {
return DepositConsequence::Overflow;
return DepositConsequence::Overflow
}
} else {
if amount < details.min_balance {
return DepositConsequence::BelowMinimum;
return DepositConsequence::BelowMinimum
}
if !details.is_sufficient && !frame_system::Pallet::<T>::can_accrue_consumers(who, 2) {
return DepositConsequence::CannotCreate;
return DepositConsequence::CannotCreate
}
if details.is_sufficient && details.sufficients.checked_add(1).is_none() {
return DepositConsequence::Overflow;
return DepositConsequence::Overflow
}
}

Expand All @@ -172,20 +172,20 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
None => return UnknownAsset,
};
if details.supply.checked_sub(&amount).is_none() {
return Underflow;
return Underflow
}
if details.status == AssetStatus::Frozen {
return Frozen;
return Frozen
}
if amount.is_zero() {
return Success;
return Success
}
let account = match Account::<T, I>::get(&id, who) {
Some(a) => a,
None => return BalanceLow,
};
if account.status.is_frozen() {
return Frozen;
return Frozen
}
if let Some(rest) = account.balance.checked_sub(&amount) {
if let Some(frozen) = T::Freezer::frozen_balance(id.clone(), who) {
Expand Down Expand Up @@ -269,7 +269,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
Ok(dust) => actual.saturating_add(dust), //< guaranteed by reducible_balance
Err(e) => {
debug_assert!(false, "passed from reducible_balance; qed");
return Err(e);
return Err(e)
},
};

Expand Down Expand Up @@ -362,7 +362,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
debug_assert!(false, "refund did not result in dead account?!");
// deposit may have been refunded, need to update `Account`
Account::<T, I>::insert(id, &who, account);
return Ok(());
return Ok(())
}
Asset::<T, I>::insert(&id, details);
// Executing a hook here is safe, since it is not in a `mutate`.
Expand Down Expand Up @@ -393,12 +393,12 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
debug_assert!(false, "refund did not result in dead account?!");
// deposit may have been refunded, need to update `Account`
Account::<T, I>::insert(&id, &who, account);
return Ok(());
return Ok(())
}
Asset::<T, I>::insert(&id, details);
// Executing a hook here is safe, since it is not in a `mutate`.
T::Freezer::died(id, &who);
return Ok(());
return Ok(())
}

/// Increases the asset `id` balance of `beneficiary` by `amount`.
Expand Down Expand Up @@ -443,7 +443,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
) -> DispatchResult,
) -> DispatchResult {
if amount.is_zero() {
return Ok(());
return Ok(())
}

Self::can_increase(id.clone(), beneficiary, amount, true).into_result()?;
Expand Down Expand Up @@ -530,7 +530,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
) -> DispatchResult,
) -> Result<T::Balance, DispatchError> {
if amount.is_zero() {
return Ok(amount);
return Ok(amount)
}

let details = Asset::<T, I>::get(&id).ok_or(Error::<T, I>::Unknown)?;
Expand All @@ -553,7 +553,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
debug_assert!(account.balance.is_zero(), "checked in prep; qed");
target_died = Some(Self::dead_account(target, details, &account.reason, false));
if let Some(Remove) = target_died {
return Ok(());
return Ok(())
}
};
*maybe_account = Some(account);
Expand Down Expand Up @@ -606,7 +606,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
) -> Result<(T::Balance, Option<DeadConsequence>), DispatchError> {
// Early exit if no-op.
if amount.is_zero() {
return Ok((amount, None));
return Ok((amount, None))
}
let details = Asset::<T, I>::get(&id).ok_or(Error::<T, I>::Unknown)?;
ensure!(details.status == AssetStatus::Live, Error::<T, I>::AssetNotLive);
Expand All @@ -629,7 +629,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {

// Skip if source == dest
if source == dest {
return Ok(());
return Ok(())
}

// Burn any dust if needed.
Expand Down Expand Up @@ -674,7 +674,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
Some(Self::dead_account(source, details, &source_account.reason, false));
if let Some(Remove) = source_died {
Account::<T, I>::remove(&id, &source);
return Ok(());
return Ok(())
}
}
Account::<T, I>::insert(&id, &source, &source_account);
Expand Down Expand Up @@ -778,7 +778,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
defensive!("destroy did not result in dead account?!");
}
if i + 1 >= (max_items as usize) {
break;
break
}
}
remaining_accounts = details.accounts;
Expand Down Expand Up @@ -819,7 +819,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
removed_approvals = removed_approvals.saturating_add(1);
details.approvals = details.approvals.saturating_sub(1);
if removed_approvals >= max_items {
break;
break
}
}
Self::deposit_event(Event::ApprovalsDestroyed {
Expand Down
11 changes: 6 additions & 5 deletions frame/assets/src/impl_fungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ impl<T: Config<I>, I: 'static> fungibles::InspectHold<T::AccountId> for Pallet<T
let ed = Asset::<T, I>::get(asset).map(|x| x.min_balance).unwrap();

if free.saturating_sub(total_hold) < ed {
return total_hold.saturating_sub(ed);
return total_hold.saturating_sub(ed)
}
total_hold
}
Expand All @@ -348,15 +348,15 @@ impl<T: Config<I>, I: 'static> fungibles::InspectHold<T::AccountId> for Pallet<T
let asset_details = Asset::<T, I>::get(asset.clone()).unwrap();
let holds = Holds::<T, I>::get(who, asset);
if !holds.is_full() && asset_details.is_sufficient == true {
return true;
return true
}

if frame_system::Pallet::<T>::providers(who) == 0 {
return false;
return false
}

if holds.is_full() && !holds.iter().any(|x| &x.id == reason) {
return false;
return false
}
true
}
Expand Down Expand Up @@ -403,7 +403,8 @@ impl<T: Config<I>, I: 'static> fungibles::UnbalancedHold<T::AccountId> for Palle
Account::<T, I>::insert(&asset, &who, new_account);
}

// Here the balance pallet calls try_mutate_account that calculates then dust. We should do something similar.
// Here the balance pallet calls try_mutate_account that calculates then dust. We should do
// something similar.
Holds::<T, I>::insert(who, asset, holds);
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ pub mod pallet {
ensure!(details.status == AssetStatus::Live, Error::<T, I>::LiveAsset);
ensure!(origin == details.owner, Error::<T, I>::NoPermission);
if details.owner == owner {
return Ok(());
return Ok(())
}

let metadata_deposit = Metadata::<T, I>::get(&id).deposit;
Expand Down
4 changes: 2 additions & 2 deletions frame/assets/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ where
{
pub(crate) fn take_deposit(&mut self) -> Option<Balance> {
if !matches!(self, ExistenceReason::DepositHeld(_)) {
return None;
return None
}
if let ExistenceReason::DepositHeld(deposit) =
sp_std::mem::replace(self, ExistenceReason::DepositRefunded)
Expand All @@ -142,7 +142,7 @@ where

pub(crate) fn take_deposit_from(&mut self) -> Option<(AccountId, Balance)> {
if !matches!(self, ExistenceReason::DepositFrom(..)) {
return None;
return None
}
if let ExistenceReason::DepositFrom(depositor, deposit) =
sp_std::mem::replace(self, ExistenceReason::DepositRefunded)
Expand Down

0 comments on commit 60e5147

Please sign in to comment.