mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 05:51:02 +00:00
Small syntax changes for staking and elections code (#9688)
* Simplify stake map creation in `OnChainSequentialPhragmen::elect` * Use or_else * More or_else * trivial; * revert
This commit is contained in:
@@ -73,11 +73,10 @@ impl<T: Config> ElectionProvider<T::AccountId, T::BlockNumber> for OnChainSequen
|
|||||||
let targets = Self::DataProvider::targets(None).map_err(Error::DataProvider)?;
|
let targets = Self::DataProvider::targets(None).map_err(Error::DataProvider)?;
|
||||||
let desired_targets = Self::DataProvider::desired_targets().map_err(Error::DataProvider)?;
|
let desired_targets = Self::DataProvider::desired_targets().map_err(Error::DataProvider)?;
|
||||||
|
|
||||||
let mut stake_map: BTreeMap<T::AccountId, VoteWeight> = BTreeMap::new();
|
let stake_map: BTreeMap<T::AccountId, VoteWeight> = voters
|
||||||
|
.iter()
|
||||||
voters.iter().for_each(|(v, s, _)| {
|
.map(|(validator, vote_weight, _)| (validator.clone(), *vote_weight))
|
||||||
stake_map.insert(v.clone(), *s);
|
.collect();
|
||||||
});
|
|
||||||
|
|
||||||
let stake_of =
|
let stake_of =
|
||||||
|w: &T::AccountId| -> VoteWeight { stake_map.get(w).cloned().unwrap_or_default() };
|
|w: &T::AccountId| -> VoteWeight { stake_map.get(w).cloned().unwrap_or_default() };
|
||||||
|
|||||||
@@ -78,10 +78,10 @@ impl<T: Config> Pallet<T> {
|
|||||||
era: EraIndex,
|
era: EraIndex,
|
||||||
) -> DispatchResultWithPostInfo {
|
) -> DispatchResultWithPostInfo {
|
||||||
// Validate input data
|
// Validate input data
|
||||||
let current_era = CurrentEra::<T>::get().ok_or(
|
let current_era = CurrentEra::<T>::get().ok_or_else(|| {
|
||||||
Error::<T>::InvalidEraToReward
|
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();
|
let history_depth = Self::history_depth();
|
||||||
ensure!(
|
ensure!(
|
||||||
era <= current_era && era >= current_era.saturating_sub(history_depth),
|
era <= current_era && era >= current_era.saturating_sub(history_depth),
|
||||||
@@ -96,10 +96,10 @@ impl<T: Config> Pallet<T> {
|
|||||||
.with_weight(T::WeightInfo::payout_stakers_alive_staked(0))
|
.with_weight(T::WeightInfo::payout_stakers_alive_staked(0))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let controller = Self::bonded(&validator_stash).ok_or(
|
let controller = Self::bonded(&validator_stash).ok_or_else(|| {
|
||||||
Error::<T>::NotStash.with_weight(T::WeightInfo::payout_stakers_alive_staked(0)),
|
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 mut ledger = <Ledger<T>>::get(&controller).ok_or(Error::<T>::NotController)?;
|
||||||
|
|
||||||
ledger
|
ledger
|
||||||
.claimed_rewards
|
.claimed_rewards
|
||||||
@@ -891,7 +891,7 @@ impl<T: Config> frame_election_provider_support::ElectionDataProvider<T::Account
|
|||||||
targets.into_iter().for_each(|v| {
|
targets.into_iter().for_each(|v| {
|
||||||
let stake: BalanceOf<T> = target_stake
|
let stake: BalanceOf<T> = target_stake
|
||||||
.and_then(|w| <BalanceOf<T>>::try_from(w).ok())
|
.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());
|
<Bonded<T>>::insert(v.clone(), v.clone());
|
||||||
<Ledger<T>>::insert(
|
<Ledger<T>>::insert(
|
||||||
v.clone(),
|
v.clone(),
|
||||||
|
|||||||
Reference in New Issue
Block a user