public LNEstablishCMessage (Transaction transaction) { this.anchorSigned = transaction.bitcoinSerialize(); }
public byte[] bitcoinSerialize() { checkState(!isTrimmed, "Cannot serialize a trimmed transaction"); return tx.bitcoinSerialize(); }
@Override public void serialize(Transaction value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException { gen.writeString(bytesToHexString(value.bitcoinSerialize())); }
public byte[] bitcoinSerialize() { checkState(!isTrimmed, "Cannot serialize a trimmed transaction"); return tx.bitcoinSerialize(); }
@Override public Bytestring serialize() { return new Bytestring(bitcoinj.bitcoinSerialize()); }
/** * Calculate the size of the transaction * * @param transaction The transaction to calculate the size of * * @return size of the transaction */ private int calculateSizeWithSignatures(Transaction transaction) throws IOException { ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream(); transaction.bitcoinSerialize(byteOutputStream); int unsignedSize = byteOutputStream.size(); // Add on size of signatures return unsignedSize + SIZE_OF_SIGNATURE * transaction.getInputs().size(); }
private void writeTransactions(OutputStream stream) throws IOException { // check for no transaction conditions first // must be a more efficient way to do this but I'm tired atm. if (transactions == null) { return; } // confirmed we must have transactions either cached or as objects. if (transactionBytesValid && payload != null && payload.length >= offset + length) { stream.write(payload, offset + HEADER_SIZE, length - HEADER_SIZE); return; } if (transactions != null) { stream.write(new VarInt(transactions.size()).encode()); for (Transaction tx : transactions) { tx.bitcoinSerialize(stream); } } }
private void writeTransactions(OutputStream stream) throws IOException { // check for no transaction conditions first // must be a more efficient way to do this but I'm tired atm. if (transactions == null) { return; } // confirmed we must have transactions either cached or as objects. if (transactionBytesValid && payload != null && payload.length >= offset + length) { stream.write(payload, offset + HEADER_SIZE, length - HEADER_SIZE); return; } if (transactions != null) { stream.write(new VarInt(transactions.size()).encode()); for (Transaction tx : transactions) { tx.bitcoinSerialize(stream); } } }
public LNEstablishAMessage (ECKey channelKeyServer, Transaction anchor, RevocationHash revocationHash, long clientAmount, long serverAmount, int minConfirmationAnchor, Address address, int feePerByte, long csvDelay) { this.channelKeyServer = channelKeyServer.getPubKey(); this.minConfirmationAnchor = minConfirmationAnchor; this.anchorTransaction = anchor.bitcoinSerialize(); this.revocationHash = revocationHash; this.amountClient = clientAmount; this.amountServer = serverAmount; this.addressBytes = address.getHash160(); this.feePerByte = feePerByte; this.csvDelay = csvDelay; }
private void writeTransactions(OutputStream stream) throws IOException { // check for no transaction conditions first // must be a more efficient way to do this but I'm tired atm. if (transactions == null) { return; } // confirmed we must have transactions either cached or as objects. if (transactionBytesValid && payload != null && payload.length >= offset + length) { stream.write(payload, offset + HEADER_SIZE, length - HEADER_SIZE); return; } if (transactions != null) { stream.write(new VarInt(transactions.size()).encode()); for (Transaction tx : transactions) { tx.bitcoinSerialize(stream); } } }
private void writeTransactions(OutputStream stream) throws IOException { // check for no transaction conditions first // must be a more efficient way to do this but I'm tired atm. if (transactions == null) { return; } // confirmed we must have transactions either cached or as objects. if (transactionBytesValid && payload != null && payload.length >= offset + length) { stream.write(payload, offset + HEADER_SIZE, length - HEADER_SIZE); return; } if (transactions != null) { stream.write(new VarInt(transactions.size()).encode()); for (Transaction tx : transactions) { tx.bitcoinSerialize(stream); } } //writeMasterNodeVotes(stream); } /**
public static synchronized Call<ResponseBody> publishTransaction(Transaction transaction, String apiCode) throws IOException { log.info("Publishing transaction"); PushTx pushTx = new PushTx(BlockchainFramework.getRetrofitExplorerInstance(), apiCode); return pushTx.pushTx(new String(Hex.encode(transaction.bitcoinSerialize()))); } }
private static void sendTransactionsToListener(StoredBlock block, NewBlockType blockType, TransactionReceivedInBlockListener listener, int relativityOffset, List<Transaction> transactions, boolean clone, Set<Sha256Hash> falsePositives) throws VerificationException { for (Transaction tx : transactions) { try { falsePositives.remove(tx.getHash()); if (clone) tx = tx.params.getDefaultSerializer().makeTransaction(tx.bitcoinSerialize()); listener.receiveFromBlock(tx, block, blockType, relativityOffset++); } catch (ScriptException e) { // We don't want scripts we don't understand to break the block chain so just note that this tx was // not scanned here and continue. log.warn("Failed to parse a script: " + e.toString()); } catch (ProtocolException e) { // Failed to duplicate tx, should never happen. throw new RuntimeException(e); } } }
private static void sendTransactionsToListener(StoredBlock block, NewBlockType blockType, TransactionReceivedInBlockListener listener, int relativityOffset, List<Transaction> transactions, boolean clone, Set<Sha256Hash> falsePositives) throws VerificationException { for (Transaction tx : transactions) { try { falsePositives.remove(tx.getHash()); if (clone) tx = tx.params.getDefaultSerializer().makeTransaction(tx.bitcoinSerialize()); listener.receiveFromBlock(tx, block, blockType, relativityOffset++); } catch (ScriptException e) { // We don't want scripts we don't understand to break the block chain so just note that this tx was // not scanned here and continue. log.warn("Failed to parse a script: " + e.toString()); } catch (ProtocolException e) { // Failed to duplicate tx, should never happen. throw new RuntimeException(e); } } }
private static void sendTransactionsToListener(StoredBlock block, NewBlockType blockType, TransactionReceivedInBlockListener listener, int relativityOffset, List<Transaction> transactions, boolean clone, Set<Sha256Hash> falsePositives) throws VerificationException { for (Transaction tx : transactions) { try { falsePositives.remove(tx.getHash()); if (clone) tx = tx.params.getDefaultSerializer().makeTransaction(tx.bitcoinSerialize()); listener.receiveFromBlock(tx, block, blockType, relativityOffset++); } catch (ScriptException e) { // We don't want scripts we don't understand to break the block chain so just note that this tx was // not scanned here and continue. log.warn("Failed to parse a script: " + e.toString()); } catch (ProtocolException e) { // Failed to duplicate tx, should never happen. throw new RuntimeException(e); } } }
@Override protected void bitcoinSerializeToStream(OutputStream stream) throws IOException { transaction.bitcoinSerialize(stream); stream.write(Utils.reverseBytes(hashBlock.getBytes())); coinbaseBranch.bitcoinSerialize(stream); chainMerkleBranch.bitcoinSerialize(stream); parentBlockHeader.bitcoinSerializeToStream(stream); }
public String sendOffline(String destinationAddress, long amountSatoshis) throws InsufficientMoneyException { Address addressj; try { addressj = new Address(params, destinationAddress); } catch (AddressFormatException e) { e.printStackTrace(); throw new RuntimeException(e); } Coin amount = Coin.valueOf(amountSatoshis); // create a SendRequest of amount to destinationAddress Wallet.SendRequest sendRequest = Wallet.SendRequest.to(addressj, amount); // set dynamic fee sendRequest.feePerKb = getRecommendedFee(); // complete & sign tx kit.wallet().completeTx(sendRequest); kit.wallet().signTransaction(sendRequest); // return tx bytes as hex encoded String return Hex.encodeHexString(sendRequest.tx.bitcoinSerialize()); }
@Test public void pinHandlers() throws Exception { Transaction tx = PARAMS.getDefaultSerializer().makeTransaction(tx1.bitcoinSerialize()); Sha256Hash hash = tx.getHash(); table.seen(hash, address1); assertEquals(1, tx.getConfidence().numBroadcastPeers()); final int[] seen = new int[1]; tx.getConfidence().addEventListener(Threading.SAME_THREAD, new TransactionConfidence.Listener() { @Override public void onConfidenceChanged(TransactionConfidence confidence, ChangeReason reason) { seen[0] = confidence.numBroadcastPeers(); } }); tx = null; System.gc(); table.seen(hash, address2); assertEquals(2, seen[0]); }
@Test public void balances() throws Exception { Coin nanos = COIN; Transaction tx1 = sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, nanos); assertEquals(nanos, tx1.getValueSentToMe(wallet)); assertTrue(tx1.getWalletOutputs(wallet).size() >= 1); // Send 0.10 to somebody else. Transaction send1 = wallet.createSend(OTHER_ADDRESS, valueOf(0, 10)); // Reserialize. Transaction send2 = PARAMS.getDefaultSerializer().makeTransaction(send1.bitcoinSerialize()); assertEquals(nanos, send2.getValueSentFromMe(wallet)); assertEquals(ZERO.subtract(valueOf(0, 10)), send2.getValue(wallet)); }
@Test public void isConsistent_duplicates() throws Exception { // This test ensures that isConsistent catches duplicate transactions, eg, because we submitted the same block // twice (this is not allowed). Transaction tx = createFakeTx(PARAMS, COIN, myAddress); TransactionOutput output = new TransactionOutput(PARAMS, tx, valueOf(0, 5), OTHER_ADDRESS); tx.addOutput(output); wallet.receiveFromBlock(tx, null, BlockChain.NewBlockType.BEST_CHAIN, 0); assertTrue(wallet.isConsistent()); Transaction txClone = PARAMS.getDefaultSerializer().makeTransaction(tx.bitcoinSerialize()); try { wallet.receiveFromBlock(txClone, null, BlockChain.NewBlockType.BEST_CHAIN, 0); fail("Illegal argument not thrown when it should have been."); } catch (IllegalStateException ex) { // expected } }