use of org.xel.PhasingPoll in project elastic-core-maven by OrdinaryDude.
the class GetPhasingPoll method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
long transactionId = ParameterParser.getUnsignedLong(req, "transaction", true);
boolean countVotes = "true".equalsIgnoreCase(req.getParameter("countVotes"));
PhasingPoll phasingPoll = PhasingPoll.getPoll(transactionId);
if (phasingPoll != null) {
return JSONData.phasingPoll(phasingPoll, countVotes);
}
PhasingPoll.PhasingPollResult pollResult = PhasingPoll.getResult(transactionId);
if (pollResult != null) {
return JSONData.phasingPollResult(pollResult);
}
return JSONResponses.UNKNOWN_TRANSACTION;
}
use of org.xel.PhasingPoll in project elastic-core-maven by OrdinaryDude.
the class GetPhasingPolls method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws ParameterException {
long[] transactionIds = ParameterParser.getUnsignedLongs(req, "transaction");
boolean countVotes = "true".equalsIgnoreCase(req.getParameter("countVotes"));
JSONObject response = new JSONObject();
JSONArray jsonArray = new JSONArray();
response.put("polls", jsonArray);
for (long transactionId : transactionIds) {
PhasingPoll poll = PhasingPoll.getPoll(transactionId);
if (poll != null) {
jsonArray.add(JSONData.phasingPoll(poll, countVotes));
} else {
PhasingPoll.PhasingPollResult pollResult = PhasingPoll.getResult(transactionId);
if (pollResult != null) {
jsonArray.add(JSONData.phasingPollResult(pollResult));
}
}
}
return response;
}
use of org.xel.PhasingPoll in project elastic-core-maven by OrdinaryDude.
the class ApproveTransaction method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
String[] phasedTransactionValues = req.getParameterValues("transactionFullHash");
if (phasedTransactionValues == null || phasedTransactionValues.length == 0) {
return MISSING_TRANSACTION_FULL_HASH;
}
if (phasedTransactionValues.length > Constants.MAX_PHASING_VOTE_TRANSACTIONS) {
return TOO_MANY_PHASING_VOTES;
}
List<byte[]> phasedTransactionFullHashes = new ArrayList<>(phasedTransactionValues.length);
for (String phasedTransactionValue : phasedTransactionValues) {
byte[] hash = Convert.parseHexString(phasedTransactionValue);
PhasingPoll phasingPoll = PhasingPoll.getPoll(Convert.fullHashToId(hash));
if (phasingPoll == null) {
return UNKNOWN_TRANSACTION_FULL_HASH;
}
phasedTransactionFullHashes.add(hash);
}
byte[] secret;
String secretValue = Convert.emptyToNull(req.getParameter("revealedSecret"));
if (secretValue != null) {
boolean isText = "true".equalsIgnoreCase(req.getParameter("revealedSecretIsText"));
secret = isText ? Convert.toBytes(secretValue) : Convert.parseHexString(secretValue);
} else {
String secretText = Convert.emptyToNull(req.getParameter("revealedSecretText"));
if (secretText != null) {
secret = Convert.toBytes(secretText);
} else {
secret = Convert.EMPTY_BYTE;
}
}
Account account = ParameterParser.getSenderAccount(req);
Attachment attachment = new Attachment.MessagingPhasingVoteCasting(phasedTransactionFullHashes, secret);
return createTransaction(req, account, attachment);
}
use of org.xel.PhasingPoll in project elastic-core-maven by OrdinaryDude.
the class GetPhasingPollVotes method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
long transactionId = ParameterParser.getUnsignedLong(req, "transaction", true);
int firstIndex = ParameterParser.getFirstIndex(req);
int lastIndex = ParameterParser.getLastIndex(req);
PhasingPoll phasingPoll = PhasingPoll.getPoll(transactionId);
if (phasingPoll != null) {
JSONObject response = new JSONObject();
JSONArray votesJSON = new JSONArray();
try (DbIterator<PhasingVote> votes = PhasingVote.getVotes(transactionId, firstIndex, lastIndex)) {
for (PhasingVote vote : votes) {
votesJSON.add(JSONData.phasingPollVote(vote));
}
}
response.put("votes", votesJSON);
return response;
}
return JSONResponses.UNKNOWN_TRANSACTION;
}
Aggregations