Search in sources :

Example 1 with Account

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

the class GetAccount method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    Account account = ParameterParser.getAccount(req);
    boolean includeLessors = "true".equalsIgnoreCase(req.getParameter("includeLessors"));
    boolean includeEffectiveBalance = "true".equalsIgnoreCase(req.getParameter("includeEffectiveBalance"));
    JSONObject response = JSONData.accountBalance(account, includeEffectiveBalance);
    JSONData.putAccount(response, "account", account.getId());
    byte[] publicKey = Account.getPublicKey(account.getId());
    if (publicKey != null) {
        response.put("publicKey", Convert.toHexString(publicKey));
    }
    Account.AccountInfo accountInfo = account.getAccountInfo();
    if (accountInfo != null) {
        response.put("name", Convert.nullToEmpty(accountInfo.getName()));
        response.put("description", Convert.nullToEmpty(accountInfo.getDescription()));
    }
    Account.AccountLease accountLease = account.getAccountLease();
    if (accountLease != null) {
        JSONData.putAccount(response, "currentLessee", accountLease.getCurrentLesseeId());
        response.put("currentLeasingHeightFrom", accountLease.getCurrentLeasingHeightFrom());
        response.put("currentLeasingHeightTo", accountLease.getCurrentLeasingHeightTo());
        if (accountLease.getNextLesseeId() != 0) {
            JSONData.putAccount(response, "nextLessee", accountLease.getNextLesseeId());
            response.put("nextLeasingHeightFrom", accountLease.getNextLeasingHeightFrom());
            response.put("nextLeasingHeightTo", accountLease.getNextLeasingHeightTo());
        }
    }
    if (!account.getControls().isEmpty()) {
        JSONArray accountControlsJson = new JSONArray();
        account.getControls().forEach(accountControl -> accountControlsJson.add(accountControl.toString()));
        response.put("accountControls", accountControlsJson);
    }
    if (includeLessors) {
        try (DbIterator<Account> lessors = account.getLessors()) {
            if (lessors.hasNext()) {
                JSONArray lessorIds = new JSONArray();
                JSONArray lessorIdsRS = new JSONArray();
                JSONArray lessorInfo = new JSONArray();
                while (lessors.hasNext()) {
                    Account lessor = lessors.next();
                    lessorIds.add(Long.toUnsignedString(lessor.getId()));
                    lessorIdsRS.add(Convert.rsAccount(lessor.getId()));
                    lessorInfo.add(JSONData.lessor(lessor, includeEffectiveBalance));
                }
                response.put("lessors", lessorIds);
                response.put("lessorsRS", lessorIdsRS);
                response.put("lessorsInfo", lessorInfo);
            }
        }
    }
    return response;
}
Also used : Account(org.xel.Account) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray)

Example 2 with Account

use of org.xel.Account 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 3 with Account

use of org.xel.Account 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 4 with Account

use of org.xel.Account 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 5 with Account

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

the class GetBalance method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    boolean includeEffectiveBalance = "true".equalsIgnoreCase(req.getParameter("includeEffectiveBalance"));
    long accountId = ParameterParser.getAccountId(req, true);
    int height = ParameterParser.getHeight(req);
    if (height < 0) {
        height = Nxt.getBlockchain().getHeight();
    }
    Account account = Account.getAccount(accountId, height);
    return JSONData.accountBalance(account, includeEffectiveBalance, height);
}
Also used : Account(org.xel.Account)

Aggregations

Account (org.xel.Account)22 JSONObject (org.json.simple.JSONObject)8 Attachment (org.xel.Attachment)8 JSONArray (org.json.simple.JSONArray)5 Transaction (org.xel.Transaction)3 ArrayList (java.util.ArrayList)2 TreeSet (java.util.TreeSet)1 PollBuilder (org.xel.Attachment.MessagingPollCreation.PollBuilder)1 Block (org.xel.Block)1 Generator (org.xel.Generator)1 PhasingParams (org.xel.PhasingParams)1 PhasingPoll (org.xel.PhasingPoll)1 Poll (org.xel.Poll)1 TaggedData (org.xel.TaggedData)1