Skip to content

Commit

Permalink
Added private vote tally certificate to explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsanchezq authored and Mikhail Zabaluev committed Oct 15, 2020
1 parent d315beb commit bbe80fa
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions jormungandr/src/explorer/mod.rs
Expand Up @@ -713,6 +713,63 @@ fn apply_block_to_vote_plans(
})
.unwrap()
}
Certificate::PrivateVoteTally(vote_tally) => {
use chain_impl_mockchain::vote::PayloadType;
vote_plans
.update(vote_tally.id(), |vote_plan| {
let proposals_from_state =
futures::executor::block_on(blockchain_tip.get_ref())
.active_vote_plans()
.into_iter()
.find_map(|vps| {
if vps.id != vote_plan.id {
return None;
}
Some(vps.proposals)
})
.unwrap();
let proposals = vote_plan
.proposals
.clone()
.into_iter()
.enumerate()
.map(|(index, mut proposal)| {
proposal.tally = Some(match vote_tally.tally_type() {
PayloadType::Public => ExplorerVoteTally::Public {
results: proposals_from_state[index]
.tally
.clone()
.unwrap()
.public()
.unwrap()
.results()
.to_vec(),
options: proposal.options.clone(),
},
PayloadType::Private => {
let tally = &proposals_from_state[index]
.tally
.clone()
.unwrap()
.private()
.cloned()
.unwrap();
ExplorerVoteTally::Private {
tally: tally.to_bytes(),
}
}
});
proposal
})
.collect();
let vote_plan = ExplorerVotePlan {
proposals,
..(**vote_plan).clone()
};
Ok::<_, std::convert::Infallible>(Some(Arc::new(vote_plan)))
})
.unwrap()
}
_ => vote_plans,
}
}
Expand Down

0 comments on commit bbe80fa

Please sign in to comment.