use config::*; pub mod prelude; pub use prelude::*; pub fn mine( method: Method, voters: Vec<( Config::AccountId, VoteWeight, BoundedVec, )>, targets: Vec, round: u32, desired_targets: u32, ) -> Result>, anyhow::Error> where Config: MinerConfig, { let (solution, score, _solution_or_snapshot_size, _trimming_status) = match method { Method::SeqPhragmen => Miner::::mine_solution_with_snapshot::< SeqSolver, >(voters, targets, desired_targets) .expect("seq miner failed"), Method::PhragMMS => Miner::::mine_solution_with_snapshot::< MmsSolver, >(voters, targets, desired_targets) .expect("mms miner failed"), }; // TODO: Miner::::feasibility_check(); -> ready_solution Ok(RawSolution { solution, score, round, }) } pub struct Solutions { pub raw_solution: Vec, pub ready_solution: Vec, } pub fn solve( chain: &str, method: &str, snapshot_bytes: &[u8], round: u32, desired_targets: u32, iterations: usize, tolerance: u128, ) -> Result { BalanceIterations::set(iterations); Tolerance::set(tolerance); let method = method.parse::()?; let chain = chain.parse::()?; let mut snapshot_bytes = snapshot_bytes; with_chain!(chain, { type Snapshot = RoundSnapshot< AccountId, Voter::MaxVotesPerVoter>, >; let snapshot: Snapshot = Decode::decode(&mut snapshot_bytes)?; let raw_solution: RawSolution> = mine::( method, snapshot.voters.clone(), snapshot.targets.clone(), round, desired_targets, )?; let ready_solution: ReadySolution< ::AccountId, ::MaxWinners, > = Miner::::feasibility_check( raw_solution.clone(), ElectionCompute::Signed, desired_targets, snapshot, round, Some(ElectionScore::default()), ) .map_err(|e| anyhow::anyhow!("feasibility check failed: {:?}", e))?; Ok(Solutions { raw_solution: raw_solution.encode(), ready_solution: ready_solution.encode(), }) }) // with_chain!() }