Skip to content

Commit

Permalink
fix count vote
Browse files Browse the repository at this point in the history
  • Loading branch information
nanfengpo committed Jun 20, 2018
1 parent 40ce84f commit e02ed09
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions src/main/java/org/tron/core/witness/WitnessController.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,30 +259,27 @@ private Map<ByteString, Long> countVote(VotesStore votesStore) {
// .getVoteRewardRate());
//account.setBalance(account.getBalance() + reward);
//accountStore.put(account.createDbKey(), account);
Optional<Long> sum = votes.getNewVotes().stream().map(vote -> vote.getVoteCount())
.reduce((a, b) -> a + b);
if (sum.isPresent()) { //todo: will be removed in next deployment
votes.getOldVotes().forEach(vote -> {
//TODO validate witness //active_witness
ByteString voteAddress = vote.getVoteAddress();
long voteCount = vote.getVoteCount();
if (countWitness.containsKey(voteAddress)) {
countWitness.put(voteAddress, countWitness.get(voteAddress) - voteCount);
} else {
countWitness.put(voteAddress, -voteCount);
}
});
votes.getNewVotes().forEach(vote -> {
//TODO validate witness //active_witness
ByteString voteAddress = vote.getVoteAddress();
long voteCount = vote.getVoteCount();
if (countWitness.containsKey(voteAddress)) {
countWitness.put(voteAddress, countWitness.get(voteAddress) + voteCount);
} else {
countWitness.put(voteAddress, voteCount);
}
});
}

votes.getOldVotes().forEach(vote -> {
//TODO validate witness //active_witness
ByteString voteAddress = vote.getVoteAddress();
long voteCount = vote.getVoteCount();
if (countWitness.containsKey(voteAddress)) {
countWitness.put(voteAddress, countWitness.get(voteAddress) - voteCount);
} else {
countWitness.put(voteAddress, -voteCount);
}
});
votes.getNewVotes().forEach(vote -> {
//TODO validate witness //active_witness
ByteString voteAddress = vote.getVoteAddress();
long voteCount = vote.getVoteCount();
if (countWitness.containsKey(voteAddress)) {
countWitness.put(voteAddress, countWitness.get(voteAddress) + voteCount);
} else {
countWitness.put(voteAddress, voteCount);
}
});


sizeCount++;
Expand Down

0 comments on commit e02ed09

Please sign in to comment.