use of org.json.simple.JSONArray in project elastic-core-maven by OrdinaryDude.
the class GetAccount method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
Account account = ParameterParser.getAccount(req);
boolean includeLessors = "true".equalsIgnoreCase(req.getParameter("includeLessors"));
boolean includeEffectiveBalance = "true".equalsIgnoreCase(req.getParameter("includeEffectiveBalance"));
JSONObject response = JSONData.accountBalance(account, includeEffectiveBalance);
JSONData.putAccount(response, "account", account.getId());
byte[] publicKey = Account.getPublicKey(account.getId());
if (publicKey != null) {
response.put("publicKey", Convert.toHexString(publicKey));
}
Account.AccountInfo accountInfo = account.getAccountInfo();
if (accountInfo != null) {
response.put("name", Convert.nullToEmpty(accountInfo.getName()));
response.put("description", Convert.nullToEmpty(accountInfo.getDescription()));
}
Account.AccountLease accountLease = account.getAccountLease();
if (accountLease != null) {
JSONData.putAccount(response, "currentLessee", accountLease.getCurrentLesseeId());
response.put("currentLeasingHeightFrom", accountLease.getCurrentLeasingHeightFrom());
response.put("currentLeasingHeightTo", accountLease.getCurrentLeasingHeightTo());
if (accountLease.getNextLesseeId() != 0) {
JSONData.putAccount(response, "nextLessee", accountLease.getNextLesseeId());
response.put("nextLeasingHeightFrom", accountLease.getNextLeasingHeightFrom());
response.put("nextLeasingHeightTo", accountLease.getNextLeasingHeightTo());
}
}
if (!account.getControls().isEmpty()) {
JSONArray accountControlsJson = new JSONArray();
account.getControls().forEach(accountControl -> accountControlsJson.add(accountControl.toString()));
response.put("accountControls", accountControlsJson);
}
if (includeLessors) {
try (DbIterator<Account> lessors = account.getLessors()) {
if (lessors.hasNext()) {
JSONArray lessorIds = new JSONArray();
JSONArray lessorIdsRS = new JSONArray();
JSONArray lessorInfo = new JSONArray();
while (lessors.hasNext()) {
Account lessor = lessors.next();
lessorIds.add(Long.toUnsignedString(lessor.getId()));
lessorIdsRS.add(Convert.rsAccount(lessor.getId()));
lessorInfo.add(JSONData.lessor(lessor, includeEffectiveBalance));
}
response.put("lessors", lessorIds);
response.put("lessorsRS", lessorIdsRS);
response.put("lessorsInfo", lessorInfo);
}
}
}
return response;
}
use of org.json.simple.JSONArray in project elastic-core-maven by OrdinaryDude.
the class GetAccountProperties method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
long recipientId = ParameterParser.getAccountId(req, "recipient", false);
long setterId = ParameterParser.getAccountId(req, "setter", false);
if (recipientId == 0 && setterId == 0) {
return JSONResponses.missing("recipient", "setter");
}
String property = Convert.emptyToNull(req.getParameter("property"));
int firstIndex = ParameterParser.getFirstIndex(req);
int lastIndex = ParameterParser.getLastIndex(req);
JSONObject response = new JSONObject();
JSONArray propertiesJSON = new JSONArray();
response.put("properties", propertiesJSON);
if (recipientId != 0) {
JSONData.putAccount(response, "recipient", recipientId);
}
if (setterId != 0) {
JSONData.putAccount(response, "setter", setterId);
}
try (DbIterator<Account.AccountProperty> iterator = Account.getProperties(recipientId, setterId, property, firstIndex, lastIndex)) {
while (iterator.hasNext()) {
propertiesJSON.add(JSONData.accountProperty(iterator.next(), recipientId == 0, setterId == 0));
}
}
return response;
}
use of org.json.simple.JSONArray in project elastic-core-maven by OrdinaryDude.
the class GetAllPhasingOnlyControls method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws ParameterException {
int firstIndex = ParameterParser.getFirstIndex(req);
int lastIndex = ParameterParser.getLastIndex(req);
JSONObject response = new JSONObject();
JSONArray jsonArray = new JSONArray();
try (DbIterator<PhasingOnly> iterator = PhasingOnly.getAll(firstIndex, lastIndex)) {
for (PhasingOnly phasingOnly : iterator) {
jsonArray.add(JSONData.phasingOnly(phasingOnly));
}
}
response.put("phasingOnlyControls", jsonArray);
return response;
}
use of org.json.simple.JSONArray in project elastic-core-maven by OrdinaryDude.
the class GetBlockchainTransactions method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
long accountId = ParameterParser.getAccountId(req, true);
int timestamp = ParameterParser.getTimestamp(req);
int numberOfConfirmations = ParameterParser.getNumberOfConfirmations(req);
boolean withMessage = "true".equalsIgnoreCase(req.getParameter("withMessage"));
boolean phasedOnly = "true".equalsIgnoreCase(req.getParameter("phasedOnly"));
boolean nonPhasedOnly = "true".equalsIgnoreCase(req.getParameter("nonPhasedOnly"));
boolean includeExpiredPrunable = "true".equalsIgnoreCase(req.getParameter("includeExpiredPrunable"));
boolean includePhasingResult = "true".equalsIgnoreCase(req.getParameter("includePhasingResult"));
boolean executedOnly = "true".equalsIgnoreCase(req.getParameter("executedOnly"));
byte type;
byte subtype;
try {
type = Byte.parseByte(req.getParameter("type"));
} catch (NumberFormatException e) {
type = -1;
}
try {
subtype = Byte.parseByte(req.getParameter("subtype"));
} catch (NumberFormatException e) {
subtype = -1;
}
int firstIndex = ParameterParser.getFirstIndex(req);
int lastIndex = ParameterParser.getLastIndex(req);
JSONArray transactions = new JSONArray();
try (DbIterator<? extends Transaction> iterator = Nxt.getBlockchain().getTransactions(accountId, numberOfConfirmations, type, subtype, timestamp, withMessage, phasedOnly, nonPhasedOnly, firstIndex, lastIndex, includeExpiredPrunable, executedOnly)) {
while (iterator.hasNext()) {
Transaction transaction = iterator.next();
transactions.add(JSONData.transaction(transaction, includePhasingResult));
}
}
JSONObject response = new JSONObject();
response.put("transactions", transactions);
return response;
}
use of org.json.simple.JSONArray in project elastic-core-maven by OrdinaryDude.
the class GetChannelTaggedData method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
String channel = Convert.emptyToNull(req.getParameter("channel"));
if (channel == null) {
return JSONResponses.missing("channel");
}
long accountId = ParameterParser.getAccountId(req, "account", false);
int firstIndex = ParameterParser.getFirstIndex(req);
int lastIndex = ParameterParser.getLastIndex(req);
boolean includeData = "true".equalsIgnoreCase(req.getParameter("includeData"));
JSONObject response = new JSONObject();
JSONArray jsonArray = new JSONArray();
response.put("data", jsonArray);
try (DbIterator<TaggedData> data = TaggedData.getData(channel, accountId, firstIndex, lastIndex)) {
while (data.hasNext()) {
jsonArray.add(JSONData.taggedData(data.next(), includeData));
}
}
return response;
}
Aggregations