Skip to content

Commit

Permalink
chore: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ipapandinas committed Mar 29, 2024
1 parent 7bb3bc7 commit 3c2bde3
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 83 deletions.
7 changes: 4 additions & 3 deletions client/consensus/manual-seal/src/consensus/babe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ where
authorities: Vec<(AuthorityId, BabeAuthorityWeight)>,
) -> Result<Self, Error> {
if authorities.is_empty() {
return Err(Error::StringError("Cannot supply empty authority set!".into()))
return Err(Error::StringError("Cannot supply empty authority set!".into()));
}

let config = sc_consensus_babe::configuration(&*client)?;
Expand Down Expand Up @@ -277,14 +277,15 @@ where

// manually hard code epoch descriptor
epoch_descriptor = match epoch_descriptor {
ViableEpochDescriptor::Signaled(identifier, _header) =>
ViableEpochDescriptor::Signaled(identifier, _header) => {
ViableEpochDescriptor::Signaled(
identifier,
EpochHeader {
start_slot: slot,
end_slot: (*slot * self.config.epoch_length).into(),
},
),
)
},
_ => unreachable!(
"we're not in the authorities, so this isn't the genesis epoch; qed"
),
Expand Down
4 changes: 2 additions & 2 deletions client/consensus/manual-seal/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ where
if height <= best_number {
return Err(JsonRpseeError::Custom(
"Target height is lower than current best height".into(),
))
));
}

let diff = height - best_number;
Expand Down Expand Up @@ -200,7 +200,7 @@ where
if height >= best_number {
return Err(JsonRpseeError::Custom(
"Target height is higher than current best height".into(),
))
));
}

let diff = best_number - height;
Expand Down
14 changes: 8 additions & 6 deletions client/consensus/manual-seal/src/seal_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,16 @@ pub async fn seal_block<B, BI, SC, C, E, TP, CIDP, P>(
{
let future = async {
if pool.status().ready == 0 && !create_empty {
return Err(Error::EmptyTransactionPool)
return Err(Error::EmptyTransactionPool);
}

// get the header to build this new block on.
// use the parent_hash supplied via `EngineCommand`
// or fetch the best_block.
let parent = match parent_hash {
Some(hash) =>
client.header(hash)?.ok_or_else(|| Error::BlockNotFound(format!("{}", hash)))?,
Some(hash) => {
client.header(hash)?.ok_or_else(|| Error::BlockNotFound(format!("{}", hash)))?
},
None => select_chain.best_chain().await?,
};

Expand Down Expand Up @@ -113,7 +114,7 @@ pub async fn seal_block<B, BI, SC, C, E, TP, CIDP, P>(
.await?;

if proposal.block.extrinsics().len() == inherents_len && !create_empty {
return Err(Error::EmptyTransactionPool)
return Err(Error::EmptyTransactionPool);
}

let (header, body) = proposal.block.deconstruct();
Expand All @@ -136,8 +137,9 @@ pub async fn seal_block<B, BI, SC, C, E, TP, CIDP, P>(
post_header.digest_mut().logs.extend(params.post_digests.iter().cloned());

match block_import.import_block(params).await? {
ImportResult::Imported(aux) =>
Ok(CreatedBlock { hash: <B as BlockT>::Header::hash(&post_header), aux }),
ImportResult::Imported(aux) => {
Ok(CreatedBlock { hash: <B as BlockT>::Header::hash(&post_header), aux })
},
other => Err(other.into()),
}
};
Expand Down
5 changes: 3 additions & 2 deletions frame/balances/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ mod benchmarks {
// and reap this user.
let recipient: T::AccountId = account("recipient", 0, SEED);
let recipient_lookup = T::Lookup::unlookup(recipient.clone());
let transfer_amount =
existential_deposit.saturating_mul((ED_MULTIPLIER - 1).into()).saturating_add(1u32.into());
let transfer_amount = existential_deposit
.saturating_mul((ED_MULTIPLIER - 1).into())
.saturating_add(1u32.into());

#[extrinsic_call]
_(RawOrigin::Root, source_lookup, recipient_lookup, transfer_amount);
Expand Down
57 changes: 29 additions & 28 deletions frame/balances/src/impl_currency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ where
// Check if `value` amount of free balance can be slashed from `who`.
fn can_slash(who: &T::AccountId, value: Self::Balance) -> bool {
if value.is_zero() {
return true
return true;
}
Self::free_balance(who) >= value
}
Expand Down Expand Up @@ -244,7 +244,7 @@ where
// Is a no-op if amount to be burned is zero.
fn burn(mut amount: Self::Balance) -> Self::PositiveImbalance {
if amount.is_zero() {
return PositiveImbalance::zero()
return PositiveImbalance::zero();
}
<TotalIssuance<T, I>>::mutate(|issued| {
*issued = issued.checked_sub(&amount).unwrap_or_else(|| {
Expand All @@ -260,7 +260,7 @@ where
// Is a no-op if amount to be issued it zero.
fn issue(mut amount: Self::Balance) -> Self::NegativeImbalance {
if amount.is_zero() {
return NegativeImbalance::zero()
return NegativeImbalance::zero();
}
<TotalIssuance<T, I>>::mutate(|issued| {
*issued = issued.checked_add(&amount).unwrap_or_else(|| {
Expand All @@ -285,7 +285,7 @@ where
new_balance: T::Balance,
) -> DispatchResult {
if amount.is_zero() {
return Ok(())
return Ok(());
}
ensure!(new_balance >= Self::account(who).frozen, Error::<T, I>::LiquidityRestrictions);
Ok(())
Expand All @@ -300,7 +300,7 @@ where
existence_requirement: ExistenceRequirement,
) -> DispatchResult {
if value.is_zero() || transactor == dest {
return Ok(())
return Ok(());
}
let keep_alive = match existence_requirement {
ExistenceRequirement::KeepAlive => Preserve,
Expand All @@ -321,10 +321,10 @@ where
/// inconsistent or `can_slash` wasn't used appropriately.
fn slash(who: &T::AccountId, value: Self::Balance) -> (Self::NegativeImbalance, Self::Balance) {
if value.is_zero() {
return (NegativeImbalance::zero(), Zero::zero())
return (NegativeImbalance::zero(), Zero::zero());
}
if Self::total_balance(who).is_zero() {
return (NegativeImbalance::zero(), value)
return (NegativeImbalance::zero(), value);
}

let result = match Self::try_mutate_account_handling_dust(
Expand Down Expand Up @@ -361,7 +361,7 @@ where
value: Self::Balance,
) -> Result<Self::PositiveImbalance, DispatchError> {
if value.is_zero() {
return Ok(PositiveImbalance::zero())
return Ok(PositiveImbalance::zero());
}

Self::try_mutate_account_handling_dust(
Expand All @@ -386,7 +386,7 @@ where
/// - `value` is so large it would cause the balance of `who` to overflow.
fn deposit_creating(who: &T::AccountId, value: Self::Balance) -> Self::PositiveImbalance {
if value.is_zero() {
return Self::PositiveImbalance::zero()
return Self::PositiveImbalance::zero();
}

Self::try_mutate_account_handling_dust(
Expand Down Expand Up @@ -419,7 +419,7 @@ where
liveness: ExistenceRequirement,
) -> result::Result<Self::NegativeImbalance, DispatchError> {
if value.is_zero() {
return Ok(NegativeImbalance::zero())
return Ok(NegativeImbalance::zero());
}

Self::try_mutate_account_handling_dust(
Expand Down Expand Up @@ -487,11 +487,11 @@ where
/// Always `true` if value to be reserved is zero.
fn can_reserve(who: &T::AccountId, value: Self::Balance) -> bool {
if value.is_zero() {
return true
return true;
}
Self::account(who).free.checked_sub(&value).map_or(false, |new_balance| {
new_balance >= T::ExistentialDeposit::get() &&
Self::ensure_can_withdraw(who, value, WithdrawReasons::RESERVE, new_balance)
new_balance >= T::ExistentialDeposit::get()
&& Self::ensure_can_withdraw(who, value, WithdrawReasons::RESERVE, new_balance)
.is_ok()
})
}
Expand All @@ -505,7 +505,7 @@ where
/// Is a no-op if value to be reserved is zero.
fn reserve(who: &T::AccountId, value: Self::Balance) -> DispatchResult {
if value.is_zero() {
return Ok(())
return Ok(());
}

Self::try_mutate_account_handling_dust(who, |account, _| -> DispatchResult {
Expand All @@ -527,10 +527,10 @@ where
/// NOTE: returns amount value which wasn't successfully unreserved.
fn unreserve(who: &T::AccountId, value: Self::Balance) -> Self::Balance {
if value.is_zero() {
return Zero::zero()
return Zero::zero();
}
if Self::total_balance(who).is_zero() {
return value
return value;
}

let actual = match Self::mutate_account_handling_dust(who, |account| {
Expand All @@ -546,7 +546,7 @@ where
// This should never happen since we don't alter the total amount in the account.
// If it ever does, then we should fail gracefully though, indicating that nothing
// could be done.
return value
return value;
},
};

Expand All @@ -563,10 +563,10 @@ where
value: Self::Balance,
) -> (Self::NegativeImbalance, Self::Balance) {
if value.is_zero() {
return (NegativeImbalance::zero(), Zero::zero())
return (NegativeImbalance::zero(), Zero::zero());
}
if Self::total_balance(who).is_zero() {
return (NegativeImbalance::zero(), value)
return (NegativeImbalance::zero(), value);
}

// NOTE: `mutate_account` may fail if it attempts to reduce the balance to the point that an
Expand Down Expand Up @@ -634,7 +634,7 @@ where
value: Self::Balance,
) -> DispatchResult {
if value.is_zero() {
return Ok(())
return Ok(());
}

Reserves::<T, I>::try_mutate(who, |reserves| -> DispatchResult {
Expand Down Expand Up @@ -663,7 +663,7 @@ where
value: Self::Balance,
) -> Self::Balance {
if value.is_zero() {
return Zero::zero()
return Zero::zero();
}

Reserves::<T, I>::mutate_exists(who, |maybe_reserves| -> Self::Balance {
Expand Down Expand Up @@ -710,7 +710,7 @@ where
value: Self::Balance,
) -> (Self::NegativeImbalance, Self::Balance) {
if value.is_zero() {
return (NegativeImbalance::zero(), Zero::zero())
return (NegativeImbalance::zero(), Zero::zero());
}

Reserves::<T, I>::mutate(who, |reserves| -> (Self::NegativeImbalance, Self::Balance) {
Expand Down Expand Up @@ -749,15 +749,16 @@ where
status: Status,
) -> Result<Self::Balance, DispatchError> {
if value.is_zero() {
return Ok(Zero::zero())
return Ok(Zero::zero());
}

if slashed == beneficiary {
return match status {
Status::Free => Ok(Self::unreserve_named(id, slashed, value)),
Status::Reserved =>
Ok(value.saturating_sub(Self::reserved_balance_named(id, slashed))),
}
Status::Reserved => {
Ok(value.saturating_sub(Self::reserved_balance_named(id, slashed)))
},
};
}

Reserves::<T, I>::try_mutate(slashed, |reserves| -> Result<Self::Balance, DispatchError> {
Expand Down Expand Up @@ -855,7 +856,7 @@ where
) {
if reasons.is_empty() || amount.is_zero() {
Self::remove_lock(id, who);
return
return;
}

let mut new_lock = Some(BalanceLock { id, amount, reasons: reasons.into() });
Expand All @@ -878,7 +879,7 @@ where
reasons: WithdrawReasons,
) {
if amount.is_zero() || reasons.is_empty() {
return
return;
}
let mut new_lock = Some(BalanceLock { id, amount, reasons: reasons.into() });
let mut locks = Self::locks(who)
Expand Down
22 changes: 11 additions & 11 deletions frame/balances/src/impl_fungible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ impl<T: Config<I>, I: 'static> fungible::Inspect<T::AccountId> for Pallet<T, I>
provenance: Provenance,
) -> DepositConsequence {
if amount.is_zero() {
return DepositConsequence::Success
return DepositConsequence::Success;
}

if provenance == Minted && TotalIssuance::<T, I>::get().checked_add(&amount).is_none() {
return DepositConsequence::Overflow
return DepositConsequence::Overflow;
}

let account = Self::account(who);
Expand All @@ -103,11 +103,11 @@ impl<T: Config<I>, I: 'static> fungible::Inspect<T::AccountId> for Pallet<T, I>
amount: Self::Balance,
) -> WithdrawConsequence<Self::Balance> {
if amount.is_zero() {
return WithdrawConsequence::Success
return WithdrawConsequence::Success;
}

if TotalIssuance::<T, I>::get().checked_sub(&amount).is_none() {
return WithdrawConsequence::Underflow
return WithdrawConsequence::Underflow;
}

let account = Self::account(who);
Expand All @@ -118,7 +118,7 @@ impl<T: Config<I>, I: 'static> fungible::Inspect<T::AccountId> for Pallet<T, I>

let liquid = Self::reducible_balance(who, Expendable, Polite);
if amount > liquid {
return WithdrawConsequence::Frozen
return WithdrawConsequence::Frozen;
}

// Provider restriction - total account balance cannot be reduced to zero if it cannot
Expand All @@ -130,7 +130,7 @@ impl<T: Config<I>, I: 'static> fungible::Inspect<T::AccountId> for Pallet<T, I>
if frame_system::Pallet::<T>::can_dec_provider(who) {
WithdrawConsequence::ReducedToZero(new_free_balance)
} else {
return WithdrawConsequence::WouldDie
return WithdrawConsequence::WouldDie;
}
} else {
WithdrawConsequence::Success
Expand All @@ -140,7 +140,7 @@ impl<T: Config<I>, I: 'static> fungible::Inspect<T::AccountId> for Pallet<T, I>

// Eventual free funds must be no less than the frozen balance.
if new_total_balance < account.frozen {
return WithdrawConsequence::Frozen
return WithdrawConsequence::Frozen;
}

success
Expand Down Expand Up @@ -232,11 +232,11 @@ impl<T: Config<I>, I: 'static> fungible::InspectHold<T::AccountId> for Pallet<T,
}
fn hold_available(reason: &Self::Reason, who: &T::AccountId) -> bool {
if frame_system::Pallet::<T>::providers(who) == 0 {
return false
return false;
}
let holds = Holds::<T, I>::get(who);
if holds.is_full() && !holds.iter().any(|x| &x.id == reason) {
return false
return false;
}
true
}
Expand Down Expand Up @@ -302,7 +302,7 @@ impl<T: Config<I>, I: 'static> fungible::InspectFreeze<T::AccountId> for Pallet<
impl<T: Config<I>, I: 'static> fungible::MutateFreeze<T::AccountId> for Pallet<T, I> {
fn set_freeze(id: &Self::Id, who: &T::AccountId, amount: Self::Balance) -> DispatchResult {
if amount.is_zero() {
return Self::thaw(id, who)
return Self::thaw(id, who);
}
let mut locks = Freezes::<T, I>::get(who);
if let Some(i) = locks.iter_mut().find(|x| &x.id == id) {
Expand All @@ -317,7 +317,7 @@ impl<T: Config<I>, I: 'static> fungible::MutateFreeze<T::AccountId> for Pallet<T

fn extend_freeze(id: &Self::Id, who: &T::AccountId, amount: Self::Balance) -> DispatchResult {
if amount.is_zero() {
return Ok(())
return Ok(());
}
let mut locks = Freezes::<T, I>::get(who);
if let Some(i) = locks.iter_mut().find(|x| &x.id == id) {
Expand Down
Loading

0 comments on commit 3c2bde3

Please sign in to comment.