Search in sources :

Example 1 with FilteringIterator

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

the class GetUnconfirmedTransactionIds 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 transactionIds = new JSONArray();
    if (accountIds.isEmpty()) {
        try (DbIterator<? extends Transaction> transactionsIterator = Nxt.getTransactionProcessor().getAllUnconfirmedTransactions(firstIndex, lastIndex)) {
            while (transactionsIterator.hasNext()) {
                Transaction transaction = transactionsIterator.next();
                transactionIds.add(transaction.getStringId());
            }
        }
    } 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();
                transactionIds.add(transaction.getStringId());
            }
        }
    }
    JSONObject response = new JSONObject();
    response.put("unconfirmedTransactionIds", transactionIds);
    return response;
}
Also used : Transaction(org.xel.Transaction) JSONObject(org.json.simple.JSONObject) FilteringIterator(org.xel.db.FilteringIterator) JSONArray(org.json.simple.JSONArray)

Example 2 with FilteringIterator

use of org.xel.db.FilteringIterator 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

JSONArray (org.json.simple.JSONArray)2 JSONObject (org.json.simple.JSONObject)2 Transaction (org.xel.Transaction)2 FilteringIterator (org.xel.db.FilteringIterator)2