mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 16:11:05 +00:00
Attempt to remove the where bounds in arithmetic. (#7933)
* Attempt to remove the where bounds. * Fix further and further. * Format better. * Update primitives/npos-elections/src/lib.rs * fix build * remove unused
This commit is contained in:
@@ -17,11 +17,8 @@
|
||||
|
||||
//! Helper methods for npos-elections.
|
||||
|
||||
use crate::{
|
||||
Assignment, Error, ExtendedBalance, IdentifierT, PerThing128, StakedAssignment, VoteWeight,
|
||||
WithApprovalOf,
|
||||
};
|
||||
use sp_arithmetic::{InnerOf, PerThing};
|
||||
use crate::{Assignment, Error, IdentifierT, PerThing128, StakedAssignment, VoteWeight, WithApprovalOf};
|
||||
use sp_arithmetic::PerThing;
|
||||
use sp_std::prelude::*;
|
||||
|
||||
/// Converts a vector of ratio assignments into ones with absolute budget value.
|
||||
@@ -33,7 +30,6 @@ pub fn assignment_ratio_to_staked<A: IdentifierT, P: PerThing128, FS>(
|
||||
) -> Vec<StakedAssignment<A>>
|
||||
where
|
||||
for<'r> FS: Fn(&'r A) -> VoteWeight,
|
||||
ExtendedBalance: From<InnerOf<P>>,
|
||||
{
|
||||
ratios
|
||||
.into_iter()
|
||||
@@ -51,7 +47,6 @@ pub fn assignment_ratio_to_staked_normalized<A: IdentifierT, P: PerThing128, FS>
|
||||
) -> Result<Vec<StakedAssignment<A>>, Error>
|
||||
where
|
||||
for<'r> FS: Fn(&'r A) -> VoteWeight,
|
||||
ExtendedBalance: From<InnerOf<P>>,
|
||||
{
|
||||
let mut staked = assignment_ratio_to_staked(ratio, &stake_of);
|
||||
staked
|
||||
@@ -68,24 +63,19 @@ where
|
||||
/// Note that this will NOT attempt at normalizing the result.
|
||||
pub fn assignment_staked_to_ratio<A: IdentifierT, P: PerThing>(
|
||||
staked: Vec<StakedAssignment<A>>,
|
||||
) -> Vec<Assignment<A, P>>
|
||||
where
|
||||
ExtendedBalance: From<InnerOf<P>>,
|
||||
{
|
||||
) -> Vec<Assignment<A, P>> {
|
||||
staked.into_iter().map(|a| a.into_assignment()).collect()
|
||||
}
|
||||
|
||||
/// Same as [`assignment_staked_to_ratio`] and try and do normalization.
|
||||
pub fn assignment_staked_to_ratio_normalized<A: IdentifierT, P: PerThing128>(
|
||||
staked: Vec<StakedAssignment<A>>,
|
||||
) -> Result<Vec<Assignment<A, P>>, Error>
|
||||
where
|
||||
ExtendedBalance: From<InnerOf<P>>,
|
||||
{
|
||||
) -> Result<Vec<Assignment<A, P>>, Error> {
|
||||
let mut ratio = staked.into_iter().map(|a| a.into_assignment()).collect::<Vec<_>>();
|
||||
ratio.iter_mut().map(|a|
|
||||
a.try_normalize().map_err(|err| Error::ArithmeticError(err))
|
||||
).collect::<Result<_, _>>()?;
|
||||
ratio
|
||||
.iter_mut()
|
||||
.map(|a| a.try_normalize().map_err(|err| Error::ArithmeticError(err)))
|
||||
.collect::<Result<_, _>>()?;
|
||||
Ok(ratio)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user