use of org.xel.Transaction in project elastic-core-maven by OrdinaryDude.
the class GetUnconfirmedTransactionIds method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws ParameterException {
Set<Long> accountIds = Convert.toSet(ParameterParser.getAccountIds(req, false));
int firstIndex = ParameterParser.getFirstIndex(req);
int lastIndex = ParameterParser.getLastIndex(req);
JSONArray transactionIds = new JSONArray();
if (accountIds.isEmpty()) {
try (DbIterator<? extends Transaction> transactionsIterator = Nxt.getTransactionProcessor().getAllUnconfirmedTransactions(firstIndex, lastIndex)) {
while (transactionsIterator.hasNext()) {
Transaction transaction = transactionsIterator.next();
transactionIds.add(transaction.getStringId());
}
}
} else {
try (FilteringIterator<? extends Transaction> transactionsIterator = new FilteringIterator<>(Nxt.getTransactionProcessor().getAllUnconfirmedTransactions(0, -1), transaction -> accountIds.contains(transaction.getSenderId()) || accountIds.contains(transaction.getRecipientId()), firstIndex, lastIndex)) {
while (transactionsIterator.hasNext()) {
Transaction transaction = transactionsIterator.next();
transactionIds.add(transaction.getStringId());
}
}
}
JSONObject response = new JSONObject();
response.put("unconfirmedTransactionIds", transactionIds);
return response;
}
use of org.xel.Transaction in project elastic-core-maven by OrdinaryDude.
the class SignTransaction method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws ParameterException {
String transactionJSON = Convert.emptyToNull(req.getParameter("unsignedTransactionJSON"));
String transactionBytes = Convert.emptyToNull(req.getParameter("unsignedTransactionBytes"));
String prunableAttachmentJSON = Convert.emptyToNull(req.getParameter("prunableAttachmentJSON"));
Transaction.Builder builder = ParameterParser.parseTransaction(transactionJSON, transactionBytes, prunableAttachmentJSON);
String secretPhrase = ParameterParser.getSecretPhrase(req, true);
boolean validate = !"false".equalsIgnoreCase(req.getParameter("validate"));
JSONObject response = new JSONObject();
try {
Transaction transaction = builder.build(secretPhrase);
JSONObject signedTransactionJSON = JSONData.unconfirmedTransaction(transaction);
if (validate) {
transaction.validate();
response.put("verify", transaction.verifySignature());
}
response.put("transactionJSON", signedTransactionJSON);
response.put("fullHash", signedTransactionJSON.get("fullHash"));
response.put("signatureHash", signedTransactionJSON.get("signatureHash"));
response.put("transaction", transaction.getStringId());
response.put("transactionBytes", Convert.toHexString(transaction.getBytes()));
JSONData.putPrunableAttachment(response, transaction);
} catch (NxtException.ValidationException | RuntimeException 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 VerifyPrunableMessage method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
long transactionId = ParameterParser.getUnsignedLong(req, "transaction", true);
Transaction transaction = Nxt.getBlockchain().getTransaction(transactionId);
if (transaction == null) {
return UNKNOWN_TRANSACTION;
}
Appendix.PrunablePlainMessage plainMessage = (Appendix.PrunablePlainMessage) ParameterParser.getPlainMessage(req, true);
Appendix.PrunableEncryptedMessage encryptedMessage = (Appendix.PrunableEncryptedMessage) ParameterParser.getEncryptedMessage(req, null, true);
if (plainMessage == null && encryptedMessage == null) {
return MISSING_MESSAGE_ENCRYPTED_MESSAGE;
}
if (plainMessage != null && encryptedMessage != null) {
return EITHER_MESSAGE_ENCRYPTED_MESSAGE;
}
if (plainMessage != null) {
Appendix.PrunablePlainMessage myPlainMessage = transaction.getPrunablePlainMessage();
if (myPlainMessage == null) {
return NO_SUCH_PLAIN_MESSAGE;
}
if (!Arrays.equals(myPlainMessage.getHash(), plainMessage.getHash())) {
return JSONResponses.HASHES_MISMATCH;
}
JSONObject response = myPlainMessage.getJSONObject();
response.put("verify", true);
return response;
} else if (encryptedMessage != null) {
Appendix.PrunableEncryptedMessage myEncryptedMessage = transaction.getPrunableEncryptedMessage();
if (myEncryptedMessage == null) {
return NO_SUCH_ENCRYPTED_MESSAGE;
}
if (!Arrays.equals(myEncryptedMessage.getHash(), encryptedMessage.getHash())) {
return JSONResponses.HASHES_MISMATCH;
}
JSONObject response = myEncryptedMessage.getJSONObject();
response.put("verify", true);
return response;
}
return JSON.emptyJSON;
}
use of org.xel.Transaction in project elastic-core-maven by OrdinaryDude.
the class SendTransaction method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws ParameterException {
String transactionJSON = Convert.emptyToNull(req.getParameter("transactionJSON"));
String transactionBytes = Convert.emptyToNull(req.getParameter("transactionBytes"));
String prunableAttachmentJSON = Convert.emptyToNull(req.getParameter("prunableAttachmentJSON"));
JSONObject response = new JSONObject();
try {
Transaction.Builder builder = ParameterParser.parseTransaction(transactionJSON, transactionBytes, prunableAttachmentJSON);
Transaction transaction = builder.build();
Peers.sendToSomePeers(Collections.singletonList(transaction));
response.put("transaction", transaction.getStringId());
response.put("fullHash", transaction.getFullHash());
} catch (NxtException.ValidationException | RuntimeException e) {
JSONData.putException(response, e, "Failed to broadcast transaction");
}
return response;
}
use of org.xel.Transaction in project elastic-core-maven by OrdinaryDude.
the class VerifyTaggedData method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
long transactionId = ParameterParser.getUnsignedLong(req, "transaction", true);
Transaction transaction = Nxt.getBlockchain().getTransaction(transactionId);
if (transaction == null) {
return UNKNOWN_TRANSACTION;
}
Attachment.TaggedDataUpload taggedData = ParameterParser.getTaggedData(req);
Attachment attachment = transaction.getAttachment();
if (!(attachment instanceof Attachment.TaggedDataUpload)) {
return INCORRECT_TRANSACTION;
}
Attachment.TaggedDataUpload myTaggedData = (Attachment.TaggedDataUpload) attachment;
if (!Arrays.equals(myTaggedData.getHash(), taggedData.getHash())) {
return HASHES_MISMATCH;
}
JSONObject response = myTaggedData.getJSONObject();
response.put("verify", true);
return response;
}
Aggregations