@Override public void bitcoinSerializeToStream(OutputStream stream) throws IOException { byte[] messageBytes = message.getBytes("UTF-8"); stream.write(new VarInt(messageBytes.length).encode()); stream.write(messageBytes); stream.write(code.code); byte[] reasonBytes = reason.getBytes("UTF-8"); stream.write(new VarInt(reasonBytes.length).encode()); stream.write(reasonBytes); if ("block".equals(message) || "tx".equals(message)) stream.write(messageHash.getReversedBytes()); }
@Override public void bitcoinSerializeToStream(OutputStream stream) throws IOException { byte[] messageBytes = message.getBytes("UTF-8"); stream.write(new VarInt(messageBytes.length).encode()); stream.write(messageBytes); stream.write(code.code); byte[] reasonBytes = reason.getBytes("UTF-8"); stream.write(new VarInt(reasonBytes.length).encode()); stream.write(reasonBytes); if ("block".equals(message) || "tx".equals(message)) stream.write(messageHash.getReversedBytes()); }
@Override protected void bitcoinSerializeToStream(OutputStream stream) throws IOException { stream.write(new byte[]{includeMempool ? (byte) 1 : 0}); // include mempool. stream.write(new VarInt(outPoints.size()).encode()); for (TransactionOutPoint outPoint : outPoints) { outPoint.bitcoinSerializeToStream(stream); } }
@Override protected void bitcoinSerializeToStream(OutputStream stream) throws IOException { checkNotNull(scriptBytes); Utils.int64ToByteStreamLE(value, stream); // TODO: Move script serialization into the Script class, where it belongs. stream.write(new VarInt(scriptBytes.length).encode()); stream.write(scriptBytes); }
@Override protected void bitcoinSerializeToStream(OutputStream stream) throws IOException { stream.write(new byte[]{includeMempool ? (byte) 1 : 0}); // include mempool. stream.write(new VarInt(outPoints.size()).encode()); for (TransactionOutPoint outPoint : outPoints) { outPoint.bitcoinSerializeToStream(stream); } }
@Override protected void bitcoinSerializeToStream(OutputStream stream) throws IOException { checkNotNull(scriptBytes); Utils.int64ToByteStreamLE(value, stream); // TODO: Move script serialization into the Script class, where it belongs. stream.write(new VarInt(scriptBytes.length).encode()); stream.write(scriptBytes); }
@Override public void bitcoinSerializeToStream(OutputStream stream) throws IOException { uint32ToByteStreamLE(transactionCount, stream); stream.write(new VarInt(hashes.size()).encode()); for (Sha256Hash hash : hashes) stream.write(hash.getReversedBytes()); stream.write(new VarInt(matchedChildBits.length).encode()); stream.write(matchedChildBits); }
@Override public void bitcoinSerializeToStream(OutputStream stream) throws IOException { uint32ToByteStreamLE(transactionCount, stream); stream.write(new VarInt(hashes.size()).encode()); for (Sha256Hash hash : hashes) stream.write(hash.getReversedBytes()); stream.write(new VarInt(matchedChildBits.length).encode()); stream.write(matchedChildBits); }
@Override protected void bitcoinSerializeToStream(OutputStream stream) throws IOException { if (addresses == null) return; stream.write(new VarInt(addresses.size()).encode()); for (PeerAddress addr : addresses) { addr.bitcoinSerialize(stream); } }
@Override protected void bitcoinSerializeToStream(OutputStream stream) throws IOException { if (addresses == null) return; stream.write(new VarInt(addresses.size()).encode()); for (PeerAddress addr : addresses) { addr.bitcoinSerialize(stream); } }
/** * Serializes this message to the provided stream. If you just want the raw bytes use bitcoinSerialize(). */ @Override protected void bitcoinSerializeToStream(OutputStream stream) throws IOException { stream.write(new VarInt(data.length).encode()); stream.write(data); Utils.uint32ToByteStreamLE(hashFuncs, stream); Utils.uint32ToByteStreamLE(nTweak, stream); stream.write(nFlags); }
@Override public void bitcoinSerializeToStream(OutputStream stream) throws IOException { stream.write(new VarInt(blockHeaders.size()).encode()); for (Block header : blockHeaders) { header.cloneAsHeader().bitcoinSerializeToStream(stream); stream.write(0); } }
@Override public void bitcoinSerializeToStream(OutputStream stream) throws IOException { stream.write(new VarInt(blockHeaders.size()).encode()); for (Block header : blockHeaders) { header.cloneAsHeader().bitcoinSerializeToStream(stream); stream.write(0); } }
protected long readVarInt(int offset) throws ProtocolException { try { VarInt varint = new VarInt(payload, cursor + offset); cursor += offset + varint.getOriginalSizeInBytes(); return varint.value; } catch (ArrayIndexOutOfBoundsException e) { throw new ProtocolException(e); } }
@Override protected void bitcoinSerializeToStream(OutputStream stream) throws IOException { outpoint.bitcoinSerialize(stream); stream.write(new VarInt(scriptBytes.length).encode()); stream.write(scriptBytes); Utils.uint32ToByteStreamLE(sequence, stream); }
protected long readVarInt(int offset) throws ProtocolException { try { VarInt varint = new VarInt(payload, cursor + offset); cursor += offset + varint.getOriginalSizeInBytes(); return varint.value; } catch (ArrayIndexOutOfBoundsException e) { throw new ProtocolException(e); } }
@Override protected void bitcoinSerializeToStream(OutputStream stream) throws IOException { uint32ToByteStreamLE(version, stream); stream.write(new VarInt(inputs.size()).encode()); for (TransactionInput in : inputs) in.bitcoinSerialize(stream); stream.write(new VarInt(outputs.size()).encode()); for (TransactionOutput out : outputs) out.bitcoinSerialize(stream); uint32ToByteStreamLE(lockTime, stream); }
@Override protected void bitcoinSerializeToStream(OutputStream stream) throws IOException { outpoint.bitcoinSerialize(stream); stream.write(new VarInt(scriptBytes.length).encode()); stream.write(scriptBytes); Utils.uint32ToByteStreamLE(sequence, stream); }
@Override public void bitcoinSerializeToStream(OutputStream stream) throws IOException { stream.write(new VarInt(items.size()).encode()); for (InventoryItem i : items) { // Write out the type code. Utils.uint32ToByteStreamLE(i.type.code(), stream); // And now the hash. stream.write(i.hash.getReversedBytes()); } }
@Override public void bitcoinSerializeToStream(OutputStream stream) throws IOException { stream.write(new VarInt(items.size()).encode()); for (InventoryItem i : items) { // Write out the type code. Utils.uint32ToByteStreamLE(i.type.ordinal(), stream); // And now the hash. stream.write(i.hash.getReversedBytes()); } }