public boolean broadcastNxtTxSync(NxtTransaction tx) throws TransactionBroadcastException { if (isConnected()) { if (log.isInfoEnabled()) { log.info("Broadcasting tx {}", Utils.HEX.encode(tx.getRawTransaction().getBytes())); } boolean success = blockchainConnection.broadcastTxSync(tx); if (success) { onTransactionBroadcast(tx); } else { onTransactionBroadcastError(tx); } return success; } else { throw new TransactionBroadcastException("No connection available"); } }
@Override public boolean broadcastTxSync(final NxtTransaction tx) { RequestBody formBody = new FormEncodingBuilder().add("requestType","broadcastTransaction") .add("transactionBytes", Convert.toHexString(tx.getRawTransaction().getBytes())).build(); Request request = new Request.Builder().url(getBaseUrl()).post(formBody).build(); // FIXME this is not a sync call getHttpClient().newCall(request).enqueue(new Callback() { @Override public void onFailure(Request request, IOException e) { log.info("Failed to communicate with server: " + request.toString()); } @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); log.info("Transaction broadcasted {0}", reply.toString()); } catch (IOException e) { log.info("IOException: " + e.getMessage()); } catch (JSONException e) { log.info("Could not parse JSON: " + e.getMessage()); } } }); return true; }
Transaction transaction = builder.recipientId(recipientLong).build(); transaction.sign(nxtPrivateKey); byte[] txBytes = transaction.getBytes();
byte[] txBytes = transaction.getBytes();