Search in sources :

Example 26 with Transaction

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

the class GetUnconfirmedTransactions method processRequest.

@Override
JSONStreamAware processRequest(JSONObject request, Peer peer) {
    List<String> exclude = (List<String>) request.get("exclude");
    if (exclude == null) {
        return JSON.emptyJSON;
    }
    SortedSet<? extends Transaction> transactionSet = Nxt.getTransactionProcessor().getCachedUnconfirmedTransactions(exclude);
    JSONArray transactionsData = new JSONArray();
    for (Transaction transaction : transactionSet) {
        if (transactionsData.size() >= 100) {
            break;
        }
        transactionsData.add(transaction.getJSONObject());
    }
    JSONObject response = new JSONObject();
    response.put("unconfirmedTransactions", transactionsData);
    return response;
}
Also used : Transaction(org.xel.Transaction) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) List(java.util.List)

Example 27 with Transaction

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

the class GetUnconfirmedTransactions method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws ParameterException {
    Set<Long> accountIds = Convert.toSet(ParameterParser.getAccountIds(req, false));
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);
    JSONArray transactions = new JSONArray();
    if (accountIds.isEmpty()) {
        try (DbIterator<? extends Transaction> transactionsIterator = Nxt.getTransactionProcessor().getAllUnconfirmedTransactions(firstIndex, lastIndex)) {
            while (transactionsIterator.hasNext()) {
                Transaction transaction = transactionsIterator.next();
                transactions.add(JSONData.unconfirmedTransaction(transaction));
            }
        }
    } else {
        try (FilteringIterator<? extends Transaction> transactionsIterator = new FilteringIterator<>(Nxt.getTransactionProcessor().getAllUnconfirmedTransactions(0, -1), transaction -> accountIds.contains(transaction.getSenderId()) || accountIds.contains(transaction.getRecipientId()), firstIndex, lastIndex)) {
            while (transactionsIterator.hasNext()) {
                Transaction transaction = transactionsIterator.next();
                transactions.add(JSONData.unconfirmedTransaction(transaction));
            }
        }
    }
    JSONObject response = new JSONObject();
    response.put("unconfirmedTransactions", transactions);
    return response;
}
Also used : Transaction(org.xel.Transaction) JSONObject(org.json.simple.JSONObject) FilteringIterator(org.xel.db.FilteringIterator) JSONArray(org.json.simple.JSONArray)

Aggregations

Transaction (org.xel.Transaction)27 JSONObject (org.json.simple.JSONObject)23 JSONArray (org.json.simple.JSONArray)12 Account (org.xel.Account)3 BufferedReader (java.io.BufferedReader)2 BufferedWriter (java.io.BufferedWriter)2 Console (java.io.Console)2 File (java.io.File)2 FileReader (java.io.FileReader)2 FileWriter (java.io.FileWriter)2 InputStreamReader (java.io.InputStreamReader)2 Appendix (org.xel.Appendix)2 Attachment (org.xel.Attachment)2 Block (org.xel.Block)2 FilteringIterator (org.xel.db.FilteringIterator)2 MessageDigest (java.security.MessageDigest)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1 Blockchain (org.xel.Blockchain)1 NxtException (org.xel.NxtException)1