From 5e07a94a3c80d81a22232c8328102e94125b00ed Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Thu, 19 Jul 2018 17:17:13 +0200 Subject: [PATCH] Fix wrong values for vote and issuance --- .../main/dao/results/ResultsListItem.java | 18 +++++++++++++++++- .../desktop/main/dao/results/ResultsView.java | 2 +- .../combo/VotesPerProposalTableView.java | 1 + .../main/dao/results/model/ResultsOfCycle.java | 14 ++------------ 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/main/java/bisq/desktop/main/dao/results/ResultsListItem.java b/src/main/java/bisq/desktop/main/dao/results/ResultsListItem.java index 0d0e3e6220..c956369872 100644 --- a/src/main/java/bisq/desktop/main/dao/results/ResultsListItem.java +++ b/src/main/java/bisq/desktop/main/dao/results/ResultsListItem.java @@ -19,24 +19,31 @@ package bisq.desktop.main.dao.results; import bisq.desktop.main.dao.results.model.ResultsOfCycle; +import bisq.core.dao.state.BsqStateService; import bisq.core.dao.voting.proposal.compensation.CompensationProposal; +import bisq.core.dao.voting.voteresult.EvaluatedProposal; import bisq.core.locale.Res; import bisq.core.util.BsqFormatter; import org.bitcoinj.core.Coin; import java.util.Date; +import java.util.HashMap; +import java.util.Map; import lombok.Getter; public class ResultsListItem { + private final BsqStateService bsqStateService; private final BsqFormatter bsqFormatter; @Getter private ResultsOfCycle resultsOfCycle; public ResultsListItem(ResultsOfCycle resultsOfCycle, + BsqStateService bsqStateService, BsqFormatter bsqFormatter) { this.resultsOfCycle = resultsOfCycle; + this.bsqStateService = bsqStateService; this.bsqFormatter = bsqFormatter; } @@ -55,11 +62,20 @@ public class ResultsListItem { } public String getStake() { - return bsqFormatter.formatCoinWithCode(Coin.valueOf(resultsOfCycle.getTotalStake())); + //TODO move to domain + Map map = new HashMap<>(); + resultsOfCycle.getDecryptedVotesForCycle() + .forEach(decryptedVote -> { + decryptedVote.getBallotList().stream().forEach(ballot -> { + map.putIfAbsent(decryptedVote.getBlindVoteTxId(), decryptedVote.getStake() + decryptedVote.getMerit(bsqStateService)); + }); + }); + return bsqFormatter.formatCoinWithCode(Coin.valueOf(map.values().stream().mapToLong(e -> e).sum())); } public String getIssuance() { long totalIssuance = resultsOfCycle.getEvaluatedProposals().stream() + .filter(EvaluatedProposal::isAccepted) .filter(e -> e.getProposal() instanceof CompensationProposal) .map(e -> (CompensationProposal) e.getProposal()) .mapToLong(e -> e.getRequestedBsq().value) diff --git a/src/main/java/bisq/desktop/main/dao/results/ResultsView.java b/src/main/java/bisq/desktop/main/dao/results/ResultsView.java index 73197e3754..eb5ebaa37d 100644 --- a/src/main/java/bisq/desktop/main/dao/results/ResultsView.java +++ b/src/main/java/bisq/desktop/main/dao/results/ResultsView.java @@ -299,7 +299,7 @@ public class ResultsView extends ActivatableViewAndModel map = resultsOfCycle.getEvaluatedProposals().stream() .collect(Collectors.toMap(EvaluatedProposal::getProposalTxId, EvaluatedProposalWithDecryptedVote::new)); diff --git a/src/main/java/bisq/desktop/main/dao/results/model/ResultsOfCycle.java b/src/main/java/bisq/desktop/main/dao/results/model/ResultsOfCycle.java index 2530c7af75..b6d916ba4c 100644 --- a/src/main/java/bisq/desktop/main/dao/results/model/ResultsOfCycle.java +++ b/src/main/java/bisq/desktop/main/dao/results/model/ResultsOfCycle.java @@ -26,14 +26,14 @@ import bisq.core.util.BsqFormatter; import java.util.List; import lombok.Data; +import lombok.extern.slf4j.Slf4j; +@Slf4j @Data public class ResultsOfCycle { private final Cycle cycle; private final int cycleIndex; private final int numVotes, numAcceptedVotes, numRejectedVotes; - private final long stakeOfAcceptedVotes; - private final long stakeOfRejectedVotes; private BsqFormatter bsqFormatter; private long cycleStartTime; @@ -67,15 +67,5 @@ public class ResultsOfCycle { numRejectedVotes = evaluatedProposals.stream() .mapToInt(e -> e.getProposalVoteResult().getNumRejectedVotes()) .sum(); - stakeOfAcceptedVotes = evaluatedProposals.stream() - .mapToLong(e -> e.getProposalVoteResult().getStakeOfAcceptedVotes()) - .sum(); - stakeOfRejectedVotes = evaluatedProposals.stream() - .mapToLong(e -> e.getProposalVoteResult().getStakeOfRejectedVotes()) - .sum(); - } - - public long getTotalStake() { - return stakeOfAcceptedVotes + stakeOfRejectedVotes; } }