Search in sources :

Example 91 with JsonArray

use of org.json.simple.JsonArray 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 92 with JsonArray

use of org.json.simple.JsonArray in project elastic-core-maven by OrdinaryDude.

the class GetAccountProperties method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    long recipientId = ParameterParser.getAccountId(req, "recipient", false);
    long setterId = ParameterParser.getAccountId(req, "setter", false);
    if (recipientId == 0 && setterId == 0) {
        return JSONResponses.missing("recipient", "setter");
    }
    String property = Convert.emptyToNull(req.getParameter("property"));
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);
    JSONObject response = new JSONObject();
    JSONArray propertiesJSON = new JSONArray();
    response.put("properties", propertiesJSON);
    if (recipientId != 0) {
        JSONData.putAccount(response, "recipient", recipientId);
    }
    if (setterId != 0) {
        JSONData.putAccount(response, "setter", setterId);
    }
    try (DbIterator<Account.AccountProperty> iterator = Account.getProperties(recipientId, setterId, property, firstIndex, lastIndex)) {
        while (iterator.hasNext()) {
            propertiesJSON.add(JSONData.accountProperty(iterator.next(), recipientId == 0, setterId == 0));
        }
    }
    return response;
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray)

Example 93 with JsonArray

use of org.json.simple.JsonArray in project elastic-core-maven by OrdinaryDude.

the class GetAllPhasingOnlyControls method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws ParameterException {
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);
    JSONObject response = new JSONObject();
    JSONArray jsonArray = new JSONArray();
    try (DbIterator<PhasingOnly> iterator = PhasingOnly.getAll(firstIndex, lastIndex)) {
        for (PhasingOnly phasingOnly : iterator) {
            jsonArray.add(JSONData.phasingOnly(phasingOnly));
        }
    }
    response.put("phasingOnlyControls", jsonArray);
    return response;
}
Also used : PhasingOnly(org.xel.AccountRestrictions.PhasingOnly) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray)

Example 94 with JsonArray

use of org.json.simple.JsonArray in project elastic-core-maven by OrdinaryDude.

the class GetBlockchainTransactions method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    long accountId = ParameterParser.getAccountId(req, true);
    int timestamp = ParameterParser.getTimestamp(req);
    int numberOfConfirmations = ParameterParser.getNumberOfConfirmations(req);
    boolean withMessage = "true".equalsIgnoreCase(req.getParameter("withMessage"));
    boolean phasedOnly = "true".equalsIgnoreCase(req.getParameter("phasedOnly"));
    boolean nonPhasedOnly = "true".equalsIgnoreCase(req.getParameter("nonPhasedOnly"));
    boolean includeExpiredPrunable = "true".equalsIgnoreCase(req.getParameter("includeExpiredPrunable"));
    boolean includePhasingResult = "true".equalsIgnoreCase(req.getParameter("includePhasingResult"));
    boolean executedOnly = "true".equalsIgnoreCase(req.getParameter("executedOnly"));
    byte type;
    byte subtype;
    try {
        type = Byte.parseByte(req.getParameter("type"));
    } catch (NumberFormatException e) {
        type = -1;
    }
    try {
        subtype = Byte.parseByte(req.getParameter("subtype"));
    } catch (NumberFormatException e) {
        subtype = -1;
    }
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);
    JSONArray transactions = new JSONArray();
    try (DbIterator<? extends Transaction> iterator = Nxt.getBlockchain().getTransactions(accountId, numberOfConfirmations, type, subtype, timestamp, withMessage, phasedOnly, nonPhasedOnly, firstIndex, lastIndex, includeExpiredPrunable, executedOnly)) {
        while (iterator.hasNext()) {
            Transaction transaction = iterator.next();
            transactions.add(JSONData.transaction(transaction, includePhasingResult));
        }
    }
    JSONObject response = new JSONObject();
    response.put("transactions", transactions);
    return response;
}
Also used : Transaction(org.xel.Transaction) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray)

Example 95 with JsonArray

use of org.json.simple.JsonArray in project elastic-core-maven by OrdinaryDude.

the class GetChannelTaggedData method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    String channel = Convert.emptyToNull(req.getParameter("channel"));
    if (channel == null) {
        return JSONResponses.missing("channel");
    }
    long accountId = ParameterParser.getAccountId(req, "account", false);
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);
    boolean includeData = "true".equalsIgnoreCase(req.getParameter("includeData"));
    JSONObject response = new JSONObject();
    JSONArray jsonArray = new JSONArray();
    response.put("data", jsonArray);
    try (DbIterator<TaggedData> data = TaggedData.getData(channel, accountId, firstIndex, lastIndex)) {
        while (data.hasNext()) {
            jsonArray.add(JSONData.taggedData(data.next(), includeData));
        }
    }
    return response;
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) TaggedData(org.xel.TaggedData)

Aggregations

JSONArray (org.json.simple.JSONArray)267 JSONObject (org.json.simple.JSONObject)238 JSONParser (org.json.simple.parser.JSONParser)73 Test (org.junit.Test)40 ParseException (org.json.simple.parser.ParseException)23 ArrayList (java.util.ArrayList)21 HttpClient (org.apache.commons.httpclient.HttpClient)21 IOException (java.io.IOException)17 HashMap (java.util.HashMap)17 GetMethod (org.apache.commons.httpclient.methods.GetMethod)17 Transaction (org.xel.Transaction)12 File (java.io.File)11 List (java.util.List)10 HttpResponse (org.apache.http.HttpResponse)10 BlockchainTest (org.xel.BlockchainTest)10 APICall (org.xel.http.APICall)10 Block (org.xel.Block)9 MapLayer (au.org.emii.portal.menu.MapLayer)8 Map (java.util.Map)8 FileReader (java.io.FileReader)6