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;
}
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;
}
Aggregations