Search in sources :

Example 1 with PhasingPoll

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;
}
Also used : PhasingPoll(org.xel.PhasingPoll)

Example 2 with PhasingPoll

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;
}
Also used : PhasingPoll(org.xel.PhasingPoll) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray)

Example 3 with PhasingPoll

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);
}
Also used : PhasingPoll(org.xel.PhasingPoll) Account(org.xel.Account) ArrayList(java.util.ArrayList) Attachment(org.xel.Attachment)

Example 4 with PhasingPoll

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;
}
Also used : PhasingPoll(org.xel.PhasingPoll) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) PhasingVote(org.xel.PhasingVote)

Aggregations

PhasingPoll (org.xel.PhasingPoll)4 JSONArray (org.json.simple.JSONArray)2 JSONObject (org.json.simple.JSONObject)2 ArrayList (java.util.ArrayList)1 Account (org.xel.Account)1 Attachment (org.xel.Attachment)1 PhasingVote (org.xel.PhasingVote)1