From fc2dd61f1418437af6b1c8a453679a63c566a648 Mon Sep 17 00:00:00 2001 From: Alex Pozhylenkov <alex_pozhilenkov@adoriasoft.com> Date: Fri, 23 Jul 2021 14:06:18 +0300 Subject: [PATCH] Staking refactor. Change *_or() to *_or_else() (#9400) * update * update * update * fix fmt --- substrate/frame/staking/src/lib.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/substrate/frame/staking/src/lib.rs b/substrate/frame/staking/src/lib.rs index 4cf0596ddc1..eb0817c2e5d 100644 --- a/substrate/frame/staking/src/lib.rs +++ b/substrate/frame/staking/src/lib.rs @@ -2346,10 +2346,10 @@ impl<T: Config> Pallet<T> { era: EraIndex, ) -> DispatchResultWithPostInfo { // Validate input data - let current_era = CurrentEra::<T>::get().ok_or( + let current_era = CurrentEra::<T>::get().ok_or_else(|| { Error::<T>::InvalidEraToReward - .with_weight(T::WeightInfo::payout_stakers_alive_staked(0)), - )?; + .with_weight(T::WeightInfo::payout_stakers_alive_staked(0)) + })?; let history_depth = Self::history_depth(); ensure!( era <= current_era && era >= current_era.saturating_sub(history_depth), @@ -2364,10 +2364,11 @@ impl<T: Config> Pallet<T> { .with_weight(T::WeightInfo::payout_stakers_alive_staked(0)) })?; - let controller = Self::bonded(&validator_stash).ok_or( - Error::<T>::NotStash.with_weight(T::WeightInfo::payout_stakers_alive_staked(0)), - )?; - let mut ledger = <Ledger<T>>::get(&controller).ok_or_else(|| Error::<T>::NotController)?; + let controller = Self::bonded(&validator_stash).ok_or_else(|| { + Error::<T>::NotStash + .with_weight(T::WeightInfo::payout_stakers_alive_staked(0)) + })?; + let mut ledger = <Ledger<T>>::get(&controller).ok_or(Error::<T>::NotController)?; ledger .claimed_rewards @@ -3127,7 +3128,7 @@ impl<T: Config> frame_election_provider_support::ElectionDataProvider<T::Account targets.into_iter().for_each(|v| { let stake: BalanceOf<T> = target_stake .and_then(|w| <BalanceOf<T>>::try_from(w).ok()) - .unwrap_or(MinNominatorBond::<T>::get() * 100u32.into()); + .unwrap_or_else(|| MinNominatorBond::<T>::get() * 100u32.into()); <Bonded<T>>::insert(v.clone(), v.clone()); <Ledger<T>>::insert( v.clone(), -- GitLab