Search in sources :

Example 6 with Transaction

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;
}
Also used : Transaction(org.xel.Transaction) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray)

Example 7 with Transaction

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;
    }
}
Also used : Account(org.xel.Account) JSONObject(org.json.simple.JSONObject) Transaction(org.xel.Transaction)

Example 8 with 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;
}
Also used : JSONObject(org.json.simple.JSONObject) Transaction(org.xel.Transaction) JSONArray(org.json.simple.JSONArray)

Example 9 with Transaction

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;
}
Also used : JSONObject(org.json.simple.JSONObject) Transaction(org.xel.Transaction) JSONArray(org.json.simple.JSONArray)

Example 10 with Transaction

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;
}
Also used : Transaction(org.xel.Transaction) JSONObject(org.json.simple.JSONObject)

Aggregations

Transaction (org.xel.Transaction)27 JSONObject (org.json.simple.JSONObject)23 JSONArray (org.json.simple.JSONArray)12 Account (org.xel.Account)3 BufferedReader (java.io.BufferedReader)2 BufferedWriter (java.io.BufferedWriter)2 Console (java.io.Console)2 File (java.io.File)2 FileReader (java.io.FileReader)2 FileWriter (java.io.FileWriter)2 InputStreamReader (java.io.InputStreamReader)2 Appendix (org.xel.Appendix)2 Attachment (org.xel.Attachment)2 Block (org.xel.Block)2 FilteringIterator (org.xel.db.FilteringIterator)2 MessageDigest (java.security.MessageDigest)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1 Blockchain (org.xel.Blockchain)1 NxtException (org.xel.NxtException)1