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;
}
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;
}
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);
}
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;
}
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;
}
Aggregations