Search in sources :

Example 16 with Account

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

the class ParameterParser method getAccounts.

public static List<Account> getAccounts(HttpServletRequest req) throws ParameterException {
    String[] accountValues = req.getParameterValues("account");
    if (accountValues == null || accountValues.length == 0) {
        throw new ParameterException(MISSING_ACCOUNT);
    }
    List<Account> result = new ArrayList<>();
    for (String accountValue : accountValues) {
        if (accountValue == null || accountValue.equals("")) {
            continue;
        }
        try {
            Account account = Account.getAccount(Convert.parseAccountId(accountValue));
            if (account == null) {
                throw new ParameterException(UNKNOWN_ACCOUNT);
            }
            result.add(account);
        } catch (RuntimeException e) {
            throw new ParameterException(INCORRECT_ACCOUNT);
        }
    }
    return result;
}
Also used : Account(org.xel.Account)

Example 17 with Account

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

the class SearchAccounts method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws ParameterException {
    String query = Convert.nullToEmpty(req.getParameter("query"));
    if (query.isEmpty()) {
        return JSONResponses.missing("query");
    }
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);
    JSONObject response = new JSONObject();
    JSONArray accountsJSONArray = new JSONArray();
    try (DbIterator<Account.AccountInfo> accounts = Account.searchAccounts(query, firstIndex, lastIndex)) {
        for (Account.AccountInfo account : accounts) {
            JSONObject accountJSON = new JSONObject();
            JSONData.putAccount(accountJSON, "account", account.getAccountId());
            if (account.getName() != null) {
                accountJSON.put("name", account.getName());
            }
            if (account.getDescription() != null) {
                accountJSON.put("description", account.getDescription());
            }
            accountsJSONArray.add(accountJSON);
        }
    }
    response.put("accounts", accountsJSONArray);
    return response;
}
Also used : Account(org.xel.Account) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray)

Example 18 with Account

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

Example 19 with Account

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

the class SetPhasingOnlyControl method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest request) throws NxtException {
    Account account = ParameterParser.getSenderAccount(request);
    PhasingParams phasingParams = parsePhasingParams(request, "control");
    long maxFees = ParameterParser.getLong(request, "controlMaxFees", 0, Constants.MAX_BALANCE_NQT, false);
    short minDuration = (short) ParameterParser.getInt(request, "controlMinDuration", 0, Constants.MAX_PHASING_DURATION - 1, false);
    short maxDuration = (short) ParameterParser.getInt(request, "controlMaxDuration", 0, Constants.MAX_PHASING_DURATION - 1, false);
    return createTransaction(request, account, new Attachment.SetPhasingOnly(phasingParams, maxFees, minDuration, maxDuration));
}
Also used : Account(org.xel.Account) PhasingParams(org.xel.PhasingParams) Attachment(org.xel.Attachment)

Example 20 with Account

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

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