use of bisq.core.dao.governance.blindvote.VoteWithProposalTxId in project bisq-core by bisq-network.
the class VoteResultService method createBallotList.
private BallotList createBallotList(VoteWithProposalTxIdList voteWithProposalTxIdList) throws MissingBallotException {
// We convert the list to a map with proposalTxId as key and the vote as value
Map<String, Vote> voteByTxIdMap = voteWithProposalTxIdList.stream().filter(voteWithProposalTxId -> voteWithProposalTxId.getVote() != null).collect(Collectors.toMap(VoteWithProposalTxId::getProposalTxId, VoteWithProposalTxId::getVote));
// We make a map with proposalTxId as key and the ballot as value out of our stored ballot list
Map<String, Ballot> ballotByTxIdMap = ballotListService.getBallotList().stream().collect(Collectors.toMap(Ballot::getTxId, ballot -> ballot));
List<String> missingBallots = new ArrayList<>();
List<Ballot> ballots = voteByTxIdMap.entrySet().stream().map(entry -> {
String txId = entry.getKey();
if (ballotByTxIdMap.containsKey(txId)) {
// why not use proposalList?
Ballot ballot = ballotByTxIdMap.get(txId);
// We create a new Ballot with the proposal from the ballot list and the vote from our decrypted votes
Vote vote = entry.getValue();
// received from the network?
return new Ballot(ballot.getProposal(), vote);
} else {
// We got a vote but we don't have the ballot (which includes the proposal)
// We add it to the missing list to handle it as exception later. We want all missing data so we
// do not throw here.
missingBallots.add(txId);
return null;
}
}).filter(Objects::nonNull).collect(Collectors.toList());
if (!missingBallots.isEmpty())
throw new MissingBallotException(ballots, missingBallots);
// Let's keep the data more deterministic by sorting it by txId. Though we are not using the sorting.
ballots.sort(Comparator.comparing(Ballot::getTxId));
return new BallotList(ballots);
}
Aggregations