Search in sources :

Example 1 with Attachment

use of org.xel.Attachment 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 2 with Attachment

use of org.xel.Attachment in project elastic-core-maven by OrdinaryDude.

the class CastVote method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    Poll poll = ParameterParser.getPoll(req);
    if (poll.isFinished()) {
        return POLL_FINISHED;
    }
    int numberOfOptions = poll.getOptions().length;
    byte[] vote = new byte[numberOfOptions];
    try {
        for (int i = 0; i < numberOfOptions; i++) {
            String voteValue = Convert.emptyToNull(req.getParameter("vote" + (i < 10 ? "0" + i : i)));
            if (voteValue != null) {
                vote[i] = Byte.parseByte(voteValue);
                if (vote[i] != Constants.NO_VOTE_VALUE && (vote[i] < poll.getMinRangeValue() || vote[i] > poll.getMaxRangeValue())) {
                    return INCORRECT_VOTE;
                }
            } else {
                vote[i] = Constants.NO_VOTE_VALUE;
            }
        }
    } catch (NumberFormatException e) {
        return INCORRECT_VOTE;
    }
    Account account = ParameterParser.getSenderAccount(req);
    Attachment attachment = new Attachment.MessagingVoteCasting(poll.getId(), vote);
    return createTransaction(req, account, attachment);
}
Also used : Account(org.xel.Account) Poll(org.xel.Poll) Attachment(org.xel.Attachment)

Example 3 with Attachment

use of org.xel.Attachment in project elastic-core-maven by OrdinaryDude.

the class CreatePoll method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    String nameValue = Convert.emptyToNull(req.getParameter("name"));
    String descriptionValue = req.getParameter("description");
    if (nameValue == null || nameValue.trim().isEmpty()) {
        return MISSING_NAME;
    } else if (descriptionValue == null) {
        return MISSING_DESCRIPTION;
    }
    if (nameValue.length() > Constants.MAX_POLL_NAME_LENGTH) {
        return INCORRECT_POLL_NAME_LENGTH;
    }
    if (descriptionValue.length() > Constants.MAX_POLL_DESCRIPTION_LENGTH) {
        return INCORRECT_POLL_DESCRIPTION_LENGTH;
    }
    List<String> options = new ArrayList<>();
    while (options.size() < Constants.MAX_POLL_OPTION_COUNT) {
        int i = options.size();
        String optionValue = Convert.emptyToNull(req.getParameter("option" + (i < 10 ? "0" + i : i)));
        if (optionValue == null) {
            break;
        }
        if (optionValue.length() > Constants.MAX_POLL_OPTION_LENGTH || (optionValue = optionValue.trim()).isEmpty()) {
            return INCORRECT_POLL_OPTION_LENGTH;
        }
        options.add(optionValue);
    }
    byte optionsSize = (byte) options.size();
    if (options.size() == 0) {
        return INCORRECT_ZEROOPTIONS;
    }
    int currentHeight = Nxt.getBlockchain().getHeight();
    int finishHeight = ParameterParser.getInt(req, "finishHeight", currentHeight + 2, currentHeight + Constants.MAX_POLL_DURATION + 1, true);
    byte votingModel = ParameterParser.getByte(req, "votingModel", (byte) 0, (byte) 3, true);
    byte minNumberOfOptions = ParameterParser.getByte(req, "minNumberOfOptions", (byte) 1, optionsSize, true);
    byte maxNumberOfOptions = ParameterParser.getByte(req, "maxNumberOfOptions", minNumberOfOptions, optionsSize, true);
    byte minRangeValue = ParameterParser.getByte(req, "minRangeValue", Constants.MIN_VOTE_VALUE, Constants.MAX_VOTE_VALUE, true);
    byte maxRangeValue = ParameterParser.getByte(req, "maxRangeValue", minRangeValue, Constants.MAX_VOTE_VALUE, true);
    PollBuilder builder = new PollBuilder(nameValue.trim(), descriptionValue.trim(), options.toArray(new String[options.size()]), finishHeight, votingModel, minNumberOfOptions, maxNumberOfOptions, minRangeValue, maxRangeValue);
    long minBalance = ParameterParser.getLong(req, "minBalance", 0, Long.MAX_VALUE, false);
    if (minBalance != 0) {
        byte minBalanceModel = ParameterParser.getByte(req, "minBalanceModel", (byte) 0, (byte) 1, true);
        builder.minBalance(minBalanceModel, minBalance);
    }
    long holdingId = ParameterParser.getUnsignedLong(req, "holding", false);
    if (holdingId != 0) {
        builder.holdingId(holdingId);
    }
    Account account = ParameterParser.getSenderAccount(req);
    Attachment attachment = builder.build();
    return createTransaction(req, account, attachment);
}
Also used : Account(org.xel.Account) PollBuilder(org.xel.Attachment.MessagingPollCreation.PollBuilder) ArrayList(java.util.ArrayList) Attachment(org.xel.Attachment)

Example 4 with Attachment

use of org.xel.Attachment in project elastic-core-maven by OrdinaryDude.

the class LeaseBalance method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    int period = ParameterParser.getInt(req, "period", Constants.LEASING_DELAY, 65535, true);
    Account account = ParameterParser.getSenderAccount(req);
    long recipient = ParameterParser.getAccountId(req, "recipient", true);
    Account recipientAccount = Account.getAccount(recipient);
    if (recipientAccount == null || Account.getPublicKey(recipientAccount.getId()) == null) {
        JSONObject response = new JSONObject();
        response.put("errorCode", 8);
        response.put("errorDescription", "recipient account does not have public key");
        return response;
    }
    Attachment attachment = new Attachment.AccountControlEffectiveBalanceLeasing(period);
    return createTransaction(req, account, recipient, 0, attachment);
}
Also used : Account(org.xel.Account) JSONObject(org.json.simple.JSONObject) Attachment(org.xel.Attachment)

Example 5 with Attachment

use of org.xel.Attachment in project elastic-core-maven by OrdinaryDude.

the class SetAccountInfo method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    String name = Convert.nullToEmpty(req.getParameter("name")).trim();
    String description = Convert.nullToEmpty(req.getParameter("description")).trim();
    if (name.length() > Constants.MAX_ACCOUNT_NAME_LENGTH) {
        return INCORRECT_ACCOUNT_NAME_LENGTH;
    }
    if (description.length() > Constants.MAX_ACCOUNT_DESCRIPTION_LENGTH) {
        return INCORRECT_ACCOUNT_DESCRIPTION_LENGTH;
    }
    Account account = ParameterParser.getSenderAccount(req);
    Attachment attachment = new Attachment.MessagingAccountInfo(name, description);
    return createTransaction(req, account, attachment);
}
Also used : Account(org.xel.Account) Attachment(org.xel.Attachment)

Aggregations

Attachment (org.xel.Attachment)7 Account (org.xel.Account)5 ArrayList (java.util.ArrayList)2 JSONObject (org.json.simple.JSONObject)2 DumpedPrivateKey (org.bitcoinj.core.DumpedPrivateKey)1 ECKey (org.bitcoinj.core.ECKey)1 NetworkParameters (org.bitcoinj.core.NetworkParameters)1 PollBuilder (org.xel.Attachment.MessagingPollCreation.PollBuilder)1 PhasingPoll (org.xel.PhasingPoll)1 Poll (org.xel.Poll)1 Transaction (org.xel.Transaction)1