Search in sources :

Example 1 with Blockchain

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

the class GetNextBlockGeneratorsTemp method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    JSONObject response = new JSONObject();
    int limit = Math.max(1, ParameterParser.getInt(req, "limit", 1, Integer.MAX_VALUE, false));
    Blockchain blockchain = Nxt.getBlockchain();
    blockchain.readLock();
    try {
        Block lastBlock = blockchain.getLastBlock();
        response.put("timestamp", lastBlock.getTimestamp());
        response.put("height", lastBlock.getHeight());
        response.put("lastBlock", Long.toUnsignedString(lastBlock.getId()));
        List<Generator.ActiveGenerator> activeGenerators = Generator.getNextGenerators();
        response.put("activeCount", activeGenerators.size());
        JSONArray generators = new JSONArray();
        for (Generator.ActiveGenerator generator : activeGenerators) {
            if (generator.getHitTime() > Integer.MAX_VALUE) {
                break;
            }
            JSONObject resp = new JSONObject();
            JSONData.putAccount(resp, "account", generator.getAccountId());
            resp.put("effectiveBalanceNXT", generator.getEffectiveBalance());
            resp.put("hitTime", generator.getHitTime());
            resp.put("deadline", (int) generator.getHitTime() - lastBlock.getTimestamp());
            generators.add(resp);
            if (generators.size() == limit) {
                break;
            }
        }
        response.put("generators", generators);
    } finally {
        blockchain.readUnlock();
    }
    return response;
}
Also used : JSONObject(org.json.simple.JSONObject) Blockchain(org.xel.Blockchain) JSONArray(org.json.simple.JSONArray) Block(org.xel.Block) Generator(org.xel.Generator)

Example 2 with Blockchain

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

the class GetTaggedDataExtendTransactions method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    long taggedDataId = ParameterParser.getUnsignedLong(req, "transaction", true);
    List<Long> extendTransactions = TaggedData.getExtendTransactionIds(taggedDataId);
    JSONObject response = new JSONObject();
    JSONArray jsonArray = new JSONArray();
    Blockchain blockchain = Nxt.getBlockchain();
    Filter<Appendix> filter = (appendix) -> !(appendix instanceof Attachment.TaggedDataExtend);
    extendTransactions.forEach(transactionId -> jsonArray.add(JSONData.transaction(blockchain.getTransaction(transactionId), filter)));
    response.put("extendTransactions", jsonArray);
    return response;
}
Also used : Filter(org.xel.util.Filter) Attachment(org.xel.Attachment) HttpServletRequest(javax.servlet.http.HttpServletRequest) List(java.util.List) NxtException(org.xel.NxtException) JSONObject(org.json.simple.JSONObject) Blockchain(org.xel.Blockchain) JSONStreamAware(org.json.simple.JSONStreamAware) Nxt(org.xel.Nxt) Appendix(org.xel.Appendix) TaggedData(org.xel.TaggedData) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) Blockchain(org.xel.Blockchain) JSONArray(org.json.simple.JSONArray) Appendix(org.xel.Appendix)

Example 3 with Blockchain

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

the class GetTransactions method processRequest.

@Override
JSONStreamAware processRequest(JSONObject request, Peer peer) {
    if (!Constants.INCLUDE_EXPIRED_PRUNABLE) {
        return PeerServlet.UNSUPPORTED_REQUEST_TYPE;
    }
    JSONObject response = new JSONObject();
    JSONArray transactionArray = new JSONArray();
    JSONArray transactionIds = (JSONArray) request.get("transactionIds");
    Blockchain blockchain = Nxt.getBlockchain();
    // 
    if (transactionIds != null) {
        transactionIds.forEach(transactionId -> {
            long id = Long.parseUnsignedLong((String) transactionId);
            Transaction transaction = blockchain.getTransaction(id);
            if (transaction != null) {
                transaction.getAppendages(true);
                JSONObject transactionJSON = transaction.getJSONObject();
                transactionArray.add(transactionJSON);
            }
        });
    }
    response.put("transactions", transactionArray);
    return response;
}
Also used : JSONObject(org.json.simple.JSONObject) Transaction(org.xel.Transaction) Blockchain(org.xel.Blockchain) JSONArray(org.json.simple.JSONArray)

Aggregations

JSONArray (org.json.simple.JSONArray)3 JSONObject (org.json.simple.JSONObject)3 Blockchain (org.xel.Blockchain)3 List (java.util.List)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 JSONStreamAware (org.json.simple.JSONStreamAware)1 Appendix (org.xel.Appendix)1 Attachment (org.xel.Attachment)1 Block (org.xel.Block)1 Generator (org.xel.Generator)1 Nxt (org.xel.Nxt)1 NxtException (org.xel.NxtException)1 TaggedData (org.xel.TaggedData)1 Transaction (org.xel.Transaction)1 Filter (org.xel.util.Filter)1