Search in sources :

Example 1 with Transaction

use of org.xel.Transaction in project elastic-core-maven by OrdinaryDude.

the class CalculateFullHash method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws ParameterException {
    String unsignedBytesString = Convert.emptyToNull(req.getParameter("unsignedTransactionBytes"));
    String signatureHashString = Convert.emptyToNull(req.getParameter("signatureHash"));
    String unsignedTransactionJSONString = Convert.emptyToNull(req.getParameter("unsignedTransactionJSON"));
    if (signatureHashString == null) {
        return MISSING_SIGNATURE_HASH;
    }
    JSONObject response = new JSONObject();
    try {
        Transaction transaction = ParameterParser.parseTransaction(unsignedTransactionJSONString, unsignedBytesString, null).build();
        MessageDigest digest = Crypto.sha256();
        digest.update(transaction.getUnsignedBytes());
        byte[] fullHash = digest.digest(Convert.parseHexString(signatureHashString));
        response.put("fullHash", Convert.toHexString(fullHash));
    } catch (NxtException.NotValidException e) {
        JSONData.putException(response, e, "Incorrect unsigned transaction json or bytes");
    }
    return response;
}
Also used : JSONObject(org.json.simple.JSONObject) Transaction(org.xel.Transaction) NxtException(org.xel.NxtException) MessageDigest(java.security.MessageDigest)

Example 2 with Transaction

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

Example 3 with Transaction

use of org.xel.Transaction in project elastic-core-maven by OrdinaryDude.

the class ExtendTaggedData method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    Account account = ParameterParser.getSenderAccount(req);
    long transactionId = ParameterParser.getUnsignedLong(req, "transaction", true);
    TaggedData taggedData = TaggedData.getData(transactionId);
    if (taggedData == null) {
        Transaction transaction = Nxt.getBlockchain().getTransaction(transactionId);
        if (transaction == null || transaction.getType() != TransactionType.Data.TAGGED_DATA_UPLOAD) {
            return UNKNOWN_TRANSACTION;
        }
        Attachment.TaggedDataUpload taggedDataUpload = ParameterParser.getTaggedData(req);
        taggedData = new TaggedData(transaction, taggedDataUpload);
    }
    Attachment.TaggedDataExtend taggedDataExtend = new Attachment.TaggedDataExtend(taggedData);
    return createTransaction(req, account, taggedDataExtend);
}
Also used : Account(org.xel.Account) Transaction(org.xel.Transaction) Attachment(org.xel.Attachment) TaggedData(org.xel.TaggedData)

Example 4 with Transaction

use of org.xel.Transaction in project elastic-core-maven by OrdinaryDude.

the class GetReferencingTransactions method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    long transactionId = ParameterParser.getUnsignedLong(req, "transaction", true);
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);
    JSONArray transactions = new JSONArray();
    try (DbIterator<? extends Transaction> iterator = Nxt.getBlockchain().getReferencingTransactions(transactionId, 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 5 with Transaction

use of org.xel.Transaction in project elastic-core-maven by OrdinaryDude.

the class GetTransactionBytes method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) {
    String transactionValue = req.getParameter("transaction");
    if (transactionValue == null) {
        return MISSING_TRANSACTION;
    }
    long transactionId;
    Transaction transaction;
    try {
        transactionId = Convert.parseUnsignedLong(transactionValue);
    } catch (RuntimeException e) {
        return INCORRECT_TRANSACTION;
    }
    transaction = Nxt.getBlockchain().getTransaction(transactionId);
    JSONObject response = new JSONObject();
    if (transaction == null) {
        transaction = Nxt.getTransactionProcessor().getUnconfirmedTransaction(transactionId);
        if (transaction == null) {
            return UNKNOWN_TRANSACTION;
        }
    } else {
        response.put("confirmations", Nxt.getBlockchain().getHeight() - transaction.getHeight());
    }
    response.put("transactionBytes", Convert.toHexString(transaction.getBytes()));
    response.put("unsignedTransactionBytes", Convert.toHexString(transaction.getUnsignedBytes()));
    JSONData.putPrunableAttachment(response, transaction);
    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