use of org.xel.Block 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.Block in project elastic-core-maven by OrdinaryDude.
the class GetAccountBlocks method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
long accountId = ParameterParser.getAccountId(req, true);
int timestamp = ParameterParser.getTimestamp(req);
int firstIndex = ParameterParser.getFirstIndex(req);
int lastIndex = ParameterParser.getLastIndex(req);
boolean includeTransactions = "true".equalsIgnoreCase(req.getParameter("includeTransactions"));
JSONArray blocks = new JSONArray();
try (DbIterator<? extends Block> iterator = Nxt.getBlockchain().getBlocks(accountId, timestamp, firstIndex, lastIndex)) {
while (iterator.hasNext()) {
Block block = iterator.next();
blocks.add(JSONData.block(block, includeTransactions, false));
}
}
JSONObject response = new JSONObject();
response.put("blocks", blocks);
return response;
}
use of org.xel.Block in project elastic-core-maven by OrdinaryDude.
the class GetBlock method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) {
Block blockData;
String blockValue = Convert.emptyToNull(req.getParameter("block"));
String heightValue = Convert.emptyToNull(req.getParameter("height"));
String timestampValue = Convert.emptyToNull(req.getParameter("timestamp"));
if (blockValue != null) {
try {
blockData = Nxt.getBlockchain().getBlock(Convert.parseUnsignedLong(blockValue));
} catch (RuntimeException e) {
return INCORRECT_BLOCK;
}
} else if (heightValue != null) {
try {
int height = Integer.parseInt(heightValue);
if (height < 0 || height > Nxt.getBlockchain().getHeight()) {
return INCORRECT_HEIGHT;
}
blockData = Nxt.getBlockchain().getBlockAtHeight(height);
} catch (RuntimeException e) {
return INCORRECT_HEIGHT;
}
} else if (timestampValue != null) {
try {
int timestamp = Integer.parseInt(timestampValue);
if (timestamp < 0) {
return INCORRECT_TIMESTAMP;
}
blockData = Nxt.getBlockchain().getLastBlock(timestamp);
} catch (RuntimeException e) {
return INCORRECT_TIMESTAMP;
}
} else {
blockData = Nxt.getBlockchain().getLastBlock();
}
if (blockData == null) {
return UNKNOWN_BLOCK;
}
boolean includeTransactions = "true".equalsIgnoreCase(req.getParameter("includeTransactions"));
boolean includeExecutedPhased = "true".equalsIgnoreCase(req.getParameter("includeExecutedPhased"));
return JSONData.block(blockData, includeTransactions, includeExecutedPhased);
}
use of org.xel.Block in project elastic-core-maven by OrdinaryDude.
the class GetBlockchainStatus method processRequest.
@Override
protected JSONObject processRequest(HttpServletRequest req) {
JSONObject response = new JSONObject();
response.put("application", Nxt.APPLICATION);
response.put("version", Nxt.VERSION);
response.put("time", Nxt.getEpochTime());
Block lastBlock = Nxt.getBlockchain().getLastBlock();
response.put("lastBlock", lastBlock.getStringId());
response.put("cumulativeDifficulty", lastBlock.getCumulativeDifficulty().toString());
response.put("numberOfBlocks", lastBlock.getHeight() + 1);
BlockchainProcessor blockchainProcessor = Nxt.getBlockchainProcessor();
Peer lastBlockchainFeeder = blockchainProcessor.getLastBlockchainFeeder();
response.put("lastBlockchainFeeder", lastBlockchainFeeder == null ? null : lastBlockchainFeeder.getAnnouncedAddress());
response.put("lastBlockchainFeederHeight", blockchainProcessor.getLastBlockchainFeederHeight());
response.put("isScanning", blockchainProcessor.isScanning());
response.put("isDownloading", blockchainProcessor.isDownloading());
response.put("maxRollback", Constants.MAX_ROLLBACK);
response.put("currentMinRollbackHeight", Nxt.getBlockchainProcessor().getMinRollbackHeight());
response.put("isTestnet", Constants.isTestnet);
response.put("maxPrunableLifetime", Constants.MAX_PRUNABLE_LIFETIME);
response.put("includeExpiredPrunable", Constants.INCLUDE_EXPIRED_PRUNABLE);
response.put("correctInvalidFees", Constants.correctInvalidFees);
response.put("ledgerTrimKeep", AccountLedger.trimKeep);
JSONArray servicesArray = new JSONArray();
Peers.getServices().forEach(service -> servicesArray.add(service.name()));
response.put("services", servicesArray);
if (APIProxy.isActivated()) {
String servingPeer = APIProxy.getInstance().getMainPeerAnnouncedAddress();
response.put("apiProxy", true);
response.put("apiProxyPeer", servingPeer);
} else {
response.put("apiProxy", false);
}
response.put("isLightClient", Constants.isLightClient);
response.put("maxAPIRecords", API.maxRecords);
response.put("blockchainState", Peers.getMyBlockchainState());
return response;
}
use of org.xel.Block in project elastic-core-maven by OrdinaryDude.
the class GetBlocks method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
int firstIndex = ParameterParser.getFirstIndex(req);
int lastIndex = ParameterParser.getLastIndex(req);
final int timestamp = ParameterParser.getTimestamp(req);
boolean includeTransactions = "true".equalsIgnoreCase(req.getParameter("includeTransactions"));
boolean includeExecutedPhased = "true".equalsIgnoreCase(req.getParameter("includeExecutedPhased"));
JSONArray blocks = new JSONArray();
try (DbIterator<? extends Block> iterator = Nxt.getBlockchain().getBlocks(firstIndex, lastIndex)) {
while (iterator.hasNext()) {
Block block = iterator.next();
if (block.getTimestamp() < timestamp) {
break;
}
blocks.add(JSONData.block(block, includeTransactions, includeExecutedPhased));
}
}
JSONObject response = new JSONObject();
response.put("blocks", blocks);
return response;
}
Aggregations