use of org.xel.Vote in project elastic-core-maven by OrdinaryDude.
the class GetPollVotes method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
int firstIndex = ParameterParser.getFirstIndex(req);
int lastIndex = ParameterParser.getLastIndex(req);
boolean includeWeights = "true".equalsIgnoreCase(req.getParameter("includeWeights"));
Poll poll = ParameterParser.getPoll(req);
int countHeight;
JSONData.VoteWeighter weighter = null;
if (includeWeights && (countHeight = Math.min(poll.getFinishHeight(), Nxt.getBlockchain().getHeight())) >= Nxt.getBlockchainProcessor().getMinRollbackHeight()) {
VoteWeighting voteWeighting = poll.getVoteWeighting();
VoteWeighting.VotingModel votingModel = voteWeighting.getVotingModel();
weighter = voterId -> votingModel.calcWeight(voteWeighting, voterId, countHeight);
}
JSONArray votesJson = new JSONArray();
try (DbIterator<Vote> votes = Vote.getVotes(poll.getId(), firstIndex, lastIndex)) {
for (Vote vote : votes) {
votesJson.add(JSONData.vote(vote, weighter));
}
}
JSONObject response = new JSONObject();
response.put("votes", votesJson);
return response;
}
use of org.xel.Vote in project elastic-core-maven by OrdinaryDude.
the class GetPollVote method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
Poll poll = ParameterParser.getPoll(req);
long accountId = ParameterParser.getAccountId(req, true);
boolean includeWeights = "true".equalsIgnoreCase(req.getParameter("includeWeights"));
Vote vote = Vote.getVote(poll.getId(), accountId);
if (vote != null) {
int countHeight;
JSONData.VoteWeighter weighter = null;
if (includeWeights && (countHeight = Math.min(poll.getFinishHeight(), Nxt.getBlockchain().getHeight())) >= Nxt.getBlockchainProcessor().getMinRollbackHeight()) {
VoteWeighting voteWeighting = poll.getVoteWeighting();
VoteWeighting.VotingModel votingModel = voteWeighting.getVotingModel();
weighter = voterId -> votingModel.calcWeight(voteWeighting, voterId, countHeight);
}
return JSONData.vote(vote, weighter);
}
return JSON.emptyJSON;
}
Aggregations