Decouple Stkaing and Election - Part1: Support traits (#7908)

* Base features and traits.

* Fix the build

* Remove unused boxing

* Self review cleanup

* Fix build
This commit is contained in:
Kian Paimani
2021-01-18 10:24:12 +00:00
committed by GitHub
parent c58a2d9a74
commit ced107b355
23 changed files with 925 additions and 341 deletions
@@ -19,10 +19,13 @@
#![cfg(test)]
use crate::{seq_phragmen, ElectionResult, Assignment, VoteWeight, ExtendedBalance};
use sp_arithmetic::{PerThing, InnerOf, traits::{SaturatedConversion, Zero, One}};
use sp_std::collections::btree_map::BTreeMap;
use crate::*;
use sp_arithmetic::{
traits::{One, SaturatedConversion, Zero},
InnerOf, PerThing,
};
use sp_runtime::assert_eq_error_rate;
use sp_std::collections::btree_map::BTreeMap;
#[derive(Default, Debug)]
pub(crate) struct _Candidate<A> {
@@ -313,14 +316,13 @@ pub fn check_assignments_sum<T: PerThing>(assignments: Vec<Assignment<AccountId,
}
}
pub(crate) fn run_and_compare<Output: PerThing>(
pub(crate) fn run_and_compare<Output: PerThing128>(
candidates: Vec<AccountId>,
voters: Vec<(AccountId, Vec<AccountId>)>,
stake_of: &Box<dyn Fn(&AccountId) -> VoteWeight>,
to_elect: usize,
) where
ExtendedBalance: From<InnerOf<Output>>,
Output: sp_std::ops::Mul<ExtendedBalance, Output = ExtendedBalance>,
{
// run fixed point code.
let ElectionResult { winners, assignments } = seq_phragmen::<_, Output>(