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