@Override public void onResponse(Response response) throws IOException { try { if (!response.isSuccessful()) { log.info("Unable to fetch txs."); log.info("[Error code] = " + response.code()); } JSONObject reply = parseReply(response); //String txId = reply.getString("transaction"); //Integer confirmations = reply.getInt("confirmations"); //getTransactionBytes(txId, listener, confirmations); NxtTransaction tx = new NxtTransaction(type, TransactionImpl.parseTransaction(reply)); //log.info("Transaction fetched"); listener.onTransactionUpdate(tx); } catch (IOException e) { log.info("IOException: " + e.getMessage()); } catch (JSONException e) { log.info("Could not parse JSON: " + e.getMessage()); }catch (NxtException.NotValidException e) { log.info("Not valid transaction: " + e.getMessage()); } } });
@Override public void onResponse(Response response) throws IOException { try { if (!response.isSuccessful()) { log.info("Unable to fetch txs."); log.info("[Error code] = " + response.code()); } JSONObject reply = parseReply(response); String txBytes = reply.getString("transactionBytes"); TransactionImpl rawTx = TransactionImpl.parseTransaction(Convert.parseHexString(txBytes)); rawTx.setConfirmations(confirmations); NxtTransaction tx = new NxtTransaction(type, rawTx); log.info("Fetching tx bytes"); listener.onTransactionUpdate(tx); } catch (IOException e) { log.info("IOException: " + e.getMessage()); } catch (JSONException e) { log.info("Could not parse JSON: " + e.getMessage()); } catch (NxtException.ValidationException e) { log.info("Transaction is invalid"); e.printStackTrace(); } } });
byte[] txBytes = transaction.getBytes(); Transaction parsedTx = TransactionImpl.parseTransaction(txBytes);
byte[] txBytes = transaction.getBytes(); Transaction parsedTx = TransactionImpl.parseTransaction(txBytes); assertEquals(Attachment.ORDINARY_PAYMENT, parsedTx.getAttachment()); assertEquals(deadline, parsedTx.getDeadline());
@Test public void testNxtTransaction() throws WalletAccount.WalletAccountException, NxtException.ValidationException { NxtAddress destination = (NxtAddress) otherAccount.getReceiveAddress(); Value amount = NXT.value("1"); NxtSendRequest req = nxtAccount.sendCoinsOffline(destination, amount); nxtAccount.completeAndSignTx(req); Transaction nxtTx = req.nxtTxBuilder.build(); // nxtTx.sign(nxtSecret); byte[] txBytes = req.nxtTxBuilder.build().getBytes(); req.tx = new NxtTransaction(NXT, req.nxtTxBuilder.build()); Transaction parsedTx = TransactionImpl.parseTransaction(txBytes); assertEquals(Attachment.ORDINARY_PAYMENT, parsedTx.getAttachment()); assertEquals(NxtFamily.DEFAULT_DEADLINE, parsedTx.getDeadline()); assertEquals((req.tx.getRawTransaction()).getTimestamp(), parsedTx.getTimestamp()); assertEquals(nxtAccountId, parsedTx.getSenderId()); assertArrayEquals(nxtPublicKey, parsedTx.getSenderPublicKey()); assertEquals(amount.value, parsedTx.getAmountNQT()); assertEquals(req.fee.value, parsedTx.getFeeNQT()); assertEquals(destination.getAccountId(), parsedTx.getRecipientId()); // System.out.println(Convert.toHexString(nxtTx.getBytes())); // TODO check signature }