Search in sources :

Example 1 with VoteWithProposalTxId

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);
}
Also used : VoteWithProposalTxId(bisq.core.dao.governance.blindvote.VoteWithProposalTxId) Arrays(java.util.Arrays) Utilities(bisq.common.util.Utilities) Vote(bisq.core.dao.governance.ballot.vote.Vote) P2PDataStorage(bisq.network.p2p.storage.P2PDataStorage) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) BlindVoteListService(bisq.core.dao.governance.blindvote.BlindVoteListService) Map(java.util.Map) VoteRevealConsensus(bisq.core.dao.governance.votereveal.VoteRevealConsensus) ChangeParamProposal(bisq.core.dao.governance.proposal.param.ChangeParamProposal) BlindVote(bisq.core.dao.governance.blindvote.BlindVote) CompensationProposal(bisq.core.dao.governance.proposal.compensation.CompensationProposal) VoteRevealService(bisq.core.dao.governance.votereveal.VoteRevealService) BondedRolesService(bisq.core.dao.governance.role.BondedRolesService) BallotListService(bisq.core.dao.governance.ballot.BallotListService) Proposal(bisq.core.dao.governance.proposal.Proposal) PeriodService(bisq.core.dao.state.period.PeriodService) Set(java.util.Set) ConfiscateBond(bisq.core.dao.state.governance.ConfiscateBond) Collectors(java.util.stream.Collectors) ProposalListPresentation(bisq.core.dao.governance.proposal.ProposalListPresentation) Objects(java.util.Objects) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) IssuanceService(bisq.core.dao.governance.voteresult.issuance.IssuanceService) Optional(java.util.Optional) BallotList(bisq.core.dao.governance.ballot.BallotList) ObservableList(javafx.collections.ObservableList) SecretKey(javax.crypto.SecretKey) Getter(lombok.Getter) BondedRoleProposal(bisq.core.dao.governance.proposal.role.BondedRoleProposal) TxOutput(bisq.core.dao.state.blockchain.TxOutput) MeritConsensus(bisq.core.dao.governance.merit.MeritConsensus) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) Block(bisq.core.dao.state.blockchain.Block) ArrayList(java.util.ArrayList) Value(lombok.Value) Inject(javax.inject.Inject) HashSet(java.util.HashSet) ParamChange(bisq.core.dao.state.governance.ParamChange) BondedRole(bisq.core.dao.governance.role.BondedRole) Nullable(javax.annotation.Nullable) MeritList(bisq.core.dao.governance.merit.MeritList) ConfiscateBondProposal(bisq.core.dao.governance.proposal.confiscatebond.ConfiscateBondProposal) Ballot(bisq.core.dao.governance.ballot.Ballot) Tx(bisq.core.dao.state.blockchain.Tx) BsqStateService(bisq.core.dao.state.BsqStateService) DaoSetupService(bisq.core.dao.DaoSetupService) BlindVoteConsensus(bisq.core.dao.governance.blindvote.BlindVoteConsensus) VoteWithProposalTxIdList(bisq.core.dao.governance.blindvote.VoteWithProposalTxIdList) BsqStateListener(bisq.core.dao.state.BsqStateListener) Comparator(java.util.Comparator) DaoPhase(bisq.core.dao.state.period.DaoPhase) Vote(bisq.core.dao.governance.ballot.vote.Vote) BlindVote(bisq.core.dao.governance.blindvote.BlindVote) ArrayList(java.util.ArrayList) Ballot(bisq.core.dao.governance.ballot.Ballot) BallotList(bisq.core.dao.governance.ballot.BallotList)

Aggregations

Utilities (bisq.common.util.Utilities)1 DaoSetupService (bisq.core.dao.DaoSetupService)1 Ballot (bisq.core.dao.governance.ballot.Ballot)1 BallotList (bisq.core.dao.governance.ballot.BallotList)1 BallotListService (bisq.core.dao.governance.ballot.BallotListService)1 Vote (bisq.core.dao.governance.ballot.vote.Vote)1 BlindVote (bisq.core.dao.governance.blindvote.BlindVote)1 BlindVoteConsensus (bisq.core.dao.governance.blindvote.BlindVoteConsensus)1 BlindVoteListService (bisq.core.dao.governance.blindvote.BlindVoteListService)1 VoteWithProposalTxId (bisq.core.dao.governance.blindvote.VoteWithProposalTxId)1 VoteWithProposalTxIdList (bisq.core.dao.governance.blindvote.VoteWithProposalTxIdList)1 MeritConsensus (bisq.core.dao.governance.merit.MeritConsensus)1 MeritList (bisq.core.dao.governance.merit.MeritList)1 Proposal (bisq.core.dao.governance.proposal.Proposal)1 ProposalListPresentation (bisq.core.dao.governance.proposal.ProposalListPresentation)1 CompensationProposal (bisq.core.dao.governance.proposal.compensation.CompensationProposal)1 ConfiscateBondProposal (bisq.core.dao.governance.proposal.confiscatebond.ConfiscateBondProposal)1 ChangeParamProposal (bisq.core.dao.governance.proposal.param.ChangeParamProposal)1 BondedRoleProposal (bisq.core.dao.governance.proposal.role.BondedRoleProposal)1 BondedRole (bisq.core.dao.governance.role.BondedRole)1