use of org.xel.Transaction in project elastic-core-maven by OrdinaryDude.
the class GetVoterPhasedTransactions method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
long accountId = ParameterParser.getAccountId(req, true);
int firstIndex = ParameterParser.getFirstIndex(req);
int lastIndex = ParameterParser.getLastIndex(req);
JSONArray transactions = new JSONArray();
try (DbIterator<? extends Transaction> iterator = PhasingPoll.getVoterPhasedTransactions(accountId, firstIndex, lastIndex)) {
while (iterator.hasNext()) {
Transaction transaction = iterator.next();
transactions.add(JSONData.transaction(transaction));
}
}
JSONObject response = new JSONObject();
response.put("transactions", transactions);
return response;
}
use of org.xel.Transaction in project elastic-core-maven by OrdinaryDude.
the class SendMoney method processRequest.
@Override
JSONStreamAware processRequest(HttpServletRequest req, User user) throws NxtException.ValidationException, IOException {
if (user.getSecretPhrase() == null) {
return null;
}
String recipientValue = req.getParameter("recipient");
String amountValue = req.getParameter("amountNXT");
String feeValue = req.getParameter("feeNXT");
String deadlineValue = req.getParameter("deadline");
String secretPhrase = req.getParameter("secretPhrase");
long recipient;
long amountNQT = 0;
long feeNQT = 0;
short deadline = 0;
try {
recipient = Convert.parseUnsignedLong(recipientValue);
if (recipient == 0)
throw new IllegalArgumentException("invalid recipient");
amountNQT = Convert.parseNXT(amountValue.trim());
feeNQT = Convert.parseNXT(feeValue.trim());
deadline = (short) (Double.parseDouble(deadlineValue) * 60);
} catch (RuntimeException e) {
JSONObject response = new JSONObject();
response.put("response", "notifyOfIncorrectTransaction");
response.put("message", "One of the fields is filled incorrectly!");
response.put("recipient", recipientValue);
response.put("amountNXT", amountValue);
response.put("feeNXT", feeValue);
response.put("deadline", deadlineValue);
return response;
}
if (!user.getSecretPhrase().equals(secretPhrase)) {
JSONObject response = new JSONObject();
response.put("response", "notifyOfIncorrectTransaction");
response.put("message", "Wrong secret phrase!");
response.put("recipient", recipientValue);
response.put("amountNXT", amountValue);
response.put("feeNXT", feeValue);
response.put("deadline", deadlineValue);
return response;
} else if (amountNQT <= 0 || amountNQT > Constants.MAX_BALANCE_NQT) {
JSONObject response = new JSONObject();
response.put("response", "notifyOfIncorrectTransaction");
response.put("message", "\"Amount\" must be greater than 0!");
response.put("recipient", recipientValue);
response.put("amountNXT", amountValue);
response.put("feeNXT", feeValue);
response.put("deadline", deadlineValue);
return response;
} else if (feeNQT < Constants.ONE_NXT || feeNQT > Constants.MAX_BALANCE_NQT) {
JSONObject response = new JSONObject();
response.put("response", "notifyOfIncorrectTransaction");
response.put("message", "\"Fee\" must be at least 1 XEL!");
response.put("recipient", recipientValue);
response.put("amountNXT", amountValue);
response.put("feeNXT", feeValue);
response.put("deadline", deadlineValue);
return response;
} else if (deadline < 1 || deadline > 1440) {
JSONObject response = new JSONObject();
response.put("response", "notifyOfIncorrectTransaction");
response.put("message", "\"Deadline\" must be greater or equal to 1 minute and less than 24 hours!");
response.put("recipient", recipientValue);
response.put("amountNXT", amountValue);
response.put("feeNXT", feeValue);
response.put("deadline", deadlineValue);
return response;
}
Account account = Account.getAccount(user.getPublicKey());
if (account == null || Math.addExact(amountNQT, feeNQT) > account.getUnconfirmedBalanceNQT()) {
JSONObject response = new JSONObject();
response.put("response", "notifyOfIncorrectTransaction");
response.put("message", "Not enough funds!");
response.put("recipient", recipientValue);
response.put("amountNXT", amountValue);
response.put("feeNXT", feeValue);
response.put("deadline", deadlineValue);
return response;
} else {
final Transaction transaction = Nxt.newTransactionBuilder(user.getPublicKey(), amountNQT, feeNQT, deadline, Attachment.ORDINARY_PAYMENT).recipientId(recipient).build(secretPhrase);
Nxt.getTransactionProcessor().broadcast(transaction);
return NOTIFY_OF_ACCEPTED_TRANSACTION;
}
}
use of org.xel.Transaction in project elastic-core-maven by OrdinaryDude.
the class GetAllBroadcastedTransactions method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) {
JSONObject response = new JSONObject();
JSONArray jsonArray = new JSONArray();
response.put("transactions", jsonArray);
Transaction[] transactions = Nxt.getTransactionProcessor().getAllBroadcastedTransactions();
for (Transaction transaction : transactions) {
jsonArray.add(JSONData.unconfirmedTransaction(transaction));
}
return response;
}
use of org.xel.Transaction in project elastic-core-maven by OrdinaryDude.
the class GetAllWaitingTransactions method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) {
JSONObject response = new JSONObject();
JSONArray jsonArray = new JSONArray();
response.put("transactions", jsonArray);
Transaction[] transactions = Nxt.getTransactionProcessor().getAllWaitingTransactions();
for (Transaction transaction : transactions) {
jsonArray.add(JSONData.unconfirmedTransaction(transaction));
}
return response;
}
use of org.xel.Transaction in project elastic-core-maven by OrdinaryDude.
the class ParseTransaction method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
String transactionBytes = Convert.emptyToNull(req.getParameter("transactionBytes"));
String transactionJSON = Convert.emptyToNull(req.getParameter("transactionJSON"));
String prunableAttachmentJSON = Convert.emptyToNull(req.getParameter("prunableAttachmentJSON"));
Transaction transaction = ParameterParser.parseTransaction(transactionJSON, transactionBytes, prunableAttachmentJSON).build();
JSONObject response = JSONData.unconfirmedTransaction(transaction);
try {
transaction.validate();
} catch (NxtException.ValidationException | RuntimeException e) {
Logger.logDebugMessage(e.getMessage(), e);
response.put("validate", false);
JSONData.putException(response, e, "Invalid transaction");
}
response.put("verify", transaction.verifySignature());
return response;
}
Aggregations