Fix wrong values for vote and issuance

This commit is contained in:
Manfred Karrer 2018-07-19 17:17:13 +02:00
parent e1f23be46e
commit 5e07a94a3c
No known key found for this signature in database
GPG Key ID: 401250966A6B2C46
4 changed files with 21 additions and 14 deletions

View File

@ -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<String, Long> 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)

View File

@ -299,7 +299,7 @@ public class ResultsView extends ActivatableViewAndModel<AnchorPane, Activatable
proposalsForCycle,
evaluatedProposalsForCycle,
decryptedVotesForCycle);
ResultsListItem resultsListItem = new ResultsListItem(resultsOfCycle, bsqFormatter);
ResultsListItem resultsListItem = new ResultsListItem(resultsOfCycle, bsqStateService, bsqFormatter);
itemList.add(resultsListItem);
}

View File

@ -77,6 +77,7 @@ public class VotesPerProposalTableView extends BaseResultsTableView<VotesPerProp
@Override
protected void fillList() {
//TODO move to domain
Map<String, EvaluatedProposalWithDecryptedVote> map = resultsOfCycle.getEvaluatedProposals().stream()
.collect(Collectors.toMap(EvaluatedProposal::getProposalTxId,
EvaluatedProposalWithDecryptedVote::new));

View File

@ -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;
}
}