@Override JSONStreamAware processRequest(HttpServletRequest req) { JSONObject response = new JSONObject(); long longId = Convert.fullHashToId(Convert.parseHexString(req.getParameter("fullHash"))); response.put("longId", String.valueOf(longId)); response.put("stringId", Long.toUnsignedString(longId)); return response; }
@Override JSONStreamAware processRequest(HttpServletRequest req) throws NxtException.ValidationException { String transactionBytes = Convert.emptyToNull(req.getParameter("unsignedTransactionBytes")); String transactionJSON = Convert.emptyToNull(req.getParameter("unsignedTransactionJSON")); if (transactionBytes == null && transactionJSON == null) { return MISSING_UNSIGNED_BYTES; } String secretPhrase = Convert.emptyToNull(req.getParameter("secretPhrase")); if (secretPhrase == null) { return MISSING_SECRET_PHRASE; } try { Transaction transaction; if (transactionBytes != null) { byte[] bytes = Convert.parseHexString(transactionBytes); transaction = Nxt.getTransactionProcessor().parseTransaction(bytes); } else { JSONObject json = (JSONObject) JSONValue.parse(transactionJSON); transaction = Nxt.getTransactionProcessor().parseTransaction(json); } transaction.validate(); if (transaction.getSignature() != null) { JSONObject response = new JSONObject(); response.put("errorCode", 4); response.put( "errorDescription", "Incorrect \"unsignedTransactionBytes\" - transaction is already signed"); return response; } transaction.sign(secretPhrase); JSONObject response = new JSONObject(); response.put("transaction", transaction.getStringId()); response.put("fullHash", transaction.getFullHash()); response.put("transactionBytes", Convert.toHexString(transaction.getBytes())); response.put( "signatureHash", Convert.toHexString(Crypto.sha256().digest(transaction.getSignature()))); response.put("verify", transaction.verifySignature()); return response; } catch (NxtException.ValidationException | RuntimeException e) { // Logger.logDebugMessage(e.getMessage(), e); return INCORRECT_UNSIGNED_BYTES; } }
public static Hallmark parseHallmark(String hallmarkString) { byte[] hallmarkBytes = Convert.parseHexString(hallmarkString); ByteBuffer buffer = ByteBuffer.wrap(hallmarkBytes); buffer.order(ByteOrder.LITTLE_ENDIAN); byte[] publicKey = new byte[32]; buffer.get(publicKey); int hostLength = buffer.getShort(); if (hostLength > 300) { throw new IllegalArgumentException("Invalid host length"); } byte[] hostBytes = new byte[hostLength]; buffer.get(hostBytes); String host = Convert.toString(hostBytes); int weight = buffer.getInt(); int date = buffer.getInt(); buffer.get(); byte[] signature = new byte[64]; buffer.get(signature); byte[] data = new byte[hallmarkBytes.length - 64]; System.arraycopy(hallmarkBytes, 0, data, 0, data.length); boolean isValid = host.length() < 100 && weight > 0 && weight <= Constants.MAX_BALANCE_NXT && Crypto.verify(signature, data, publicKey, true); try { return new Hallmark(hallmarkString, publicKey, signature, host, weight, date, isValid); } catch (URISyntaxException e) { throw new RuntimeException(e.toString(), e); } }
@Override public boolean hasTransactionByFullHash(String fullHash) { return TransactionDb.hasTransactionByFullHash(Convert.parseHexString(fullHash)); }
@Override public TransactionImpl getTransactionByFullHash(String fullHash) { return TransactionDb.findTransactionByFullHash(Convert.parseHexString(fullHash)); }
TransactionImpl parseTransaction(JSONObject transactionData) throws NxtException.ValidationException { try { byte type = ((Long) transactionData.get("type")).byteValue(); byte subtype = ((Long) transactionData.get("subtype")).byteValue(); int timestamp = ((Long) transactionData.get("timestamp")).intValue(); short deadline = ((Long) transactionData.get("deadline")).shortValue(); byte[] senderPublicKey = Convert.parseHexString((String) transactionData.get("senderPublicKey")); Long recipientId = Convert.parseUnsignedLong((String) transactionData.get("recipient")); if (recipientId == null) recipientId = 0L; // ugly long amountNQT; long feeNQT; if (transactionData.get("amountNQT") != null) { amountNQT = ((Long) transactionData.get("amountNQT")); feeNQT = ((Long) transactionData.get("feeNQT")); } else { amountNQT = Convert.safeMultiply(((Long) transactionData.get("amount")), Constants.ONE_NXT); feeNQT = Convert.safeMultiply(((Long) transactionData.get("fee")), Constants.ONE_NXT); } String referencedTransactionFullHash = (String) transactionData.get("referencedTransactionFullHash"); Long referencedTransactionId = Convert.parseUnsignedLong((String) transactionData.get("referencedTransaction")); byte[] signature = Convert.parseHexString((String) transactionData.get("signature")); TransactionType transactionType = TransactionType.findTransactionType(type, subtype); TransactionImpl transaction; if (referencedTransactionFullHash != null) { transaction = new TransactionImpl( transactionType, timestamp, deadline, senderPublicKey, recipientId, amountNQT, feeNQT, referencedTransactionFullHash, signature); } else { transaction = new TransactionImpl( transactionType, timestamp, deadline, senderPublicKey, recipientId, amountNQT, feeNQT, referencedTransactionId, signature); } JSONObject attachmentData = (JSONObject) transactionData.get("attachment"); transactionType.loadAttachment(transaction, attachmentData); return transaction; } catch (RuntimeException e) { Logger.logDebugMessage(e.toString(), e); throw new NxtException.ValidationException(e.toString()); } }