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