use of org.xel.Account in project elastic-core-maven by OrdinaryDude.
the class ParameterParser method getAccounts.
public static List<Account> getAccounts(HttpServletRequest req) throws ParameterException {
String[] accountValues = req.getParameterValues("account");
if (accountValues == null || accountValues.length == 0) {
throw new ParameterException(MISSING_ACCOUNT);
}
List<Account> result = new ArrayList<>();
for (String accountValue : accountValues) {
if (accountValue == null || accountValue.equals("")) {
continue;
}
try {
Account account = Account.getAccount(Convert.parseAccountId(accountValue));
if (account == null) {
throw new ParameterException(UNKNOWN_ACCOUNT);
}
result.add(account);
} catch (RuntimeException e) {
throw new ParameterException(INCORRECT_ACCOUNT);
}
}
return result;
}
use of org.xel.Account in project elastic-core-maven by OrdinaryDude.
the class SearchAccounts method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws ParameterException {
String query = Convert.nullToEmpty(req.getParameter("query"));
if (query.isEmpty()) {
return JSONResponses.missing("query");
}
int firstIndex = ParameterParser.getFirstIndex(req);
int lastIndex = ParameterParser.getLastIndex(req);
JSONObject response = new JSONObject();
JSONArray accountsJSONArray = new JSONArray();
try (DbIterator<Account.AccountInfo> accounts = Account.searchAccounts(query, firstIndex, lastIndex)) {
for (Account.AccountInfo account : accounts) {
JSONObject accountJSON = new JSONObject();
JSONData.putAccount(accountJSON, "account", account.getAccountId());
if (account.getName() != null) {
accountJSON.put("name", account.getName());
}
if (account.getDescription() != null) {
accountJSON.put("description", account.getDescription());
}
accountsJSONArray.add(accountJSON);
}
}
response.put("accounts", accountsJSONArray);
return response;
}
use of org.xel.Account in project elastic-core-maven by OrdinaryDude.
the class SetAccountInfo method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
String name = Convert.nullToEmpty(req.getParameter("name")).trim();
String description = Convert.nullToEmpty(req.getParameter("description")).trim();
if (name.length() > Constants.MAX_ACCOUNT_NAME_LENGTH) {
return INCORRECT_ACCOUNT_NAME_LENGTH;
}
if (description.length() > Constants.MAX_ACCOUNT_DESCRIPTION_LENGTH) {
return INCORRECT_ACCOUNT_DESCRIPTION_LENGTH;
}
Account account = ParameterParser.getSenderAccount(req);
Attachment attachment = new Attachment.MessagingAccountInfo(name, description);
return createTransaction(req, account, attachment);
}
use of org.xel.Account in project elastic-core-maven by OrdinaryDude.
the class SetPhasingOnlyControl method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest request) throws NxtException {
Account account = ParameterParser.getSenderAccount(request);
PhasingParams phasingParams = parsePhasingParams(request, "control");
long maxFees = ParameterParser.getLong(request, "controlMaxFees", 0, Constants.MAX_BALANCE_NQT, false);
short minDuration = (short) ParameterParser.getInt(request, "controlMinDuration", 0, Constants.MAX_PHASING_DURATION - 1, false);
short maxDuration = (short) ParameterParser.getInt(request, "controlMaxDuration", 0, Constants.MAX_PHASING_DURATION - 1, false);
return createTransaction(request, account, new Attachment.SetPhasingOnly(phasingParams, maxFees, minDuration, maxDuration));
}
use of org.xel.Account in project elastic-core-maven by OrdinaryDude.
the class LeaseBalance method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
int period = ParameterParser.getInt(req, "period", Constants.LEASING_DELAY, 65535, true);
Account account = ParameterParser.getSenderAccount(req);
long recipient = ParameterParser.getAccountId(req, "recipient", true);
Account recipientAccount = Account.getAccount(recipient);
if (recipientAccount == null || Account.getPublicKey(recipientAccount.getId()) == null) {
JSONObject response = new JSONObject();
response.put("errorCode", 8);
response.put("errorDescription", "recipient account does not have public key");
return response;
}
Attachment attachment = new Attachment.AccountControlEffectiveBalanceLeasing(period);
return createTransaction(req, account, recipient, 0, attachment);
}
Aggregations