/** * Returns the transaction hash that owns this output. */ @Nullable public Sha256Hash getParentTransactionHash() { return parent == null ? null : parent.getHash(); }
@Override protected void adjustLength(int newArraySize, int adjustment) { super.adjustLength(newArraySize, adjustment); if (parent != null) parent.adjustLength(newArraySize, adjustment); }
private void selfCheck(byte[] payload, int offset) { if (!(this instanceof VersionMessage)) { byte[] payloadBytes = new byte[cursor - offset]; System.arraycopy(payload, offset, payloadBytes, 0, cursor - offset); byte[] reserialized = bitcoinSerialize(); if (!Arrays.equals(reserialized, payloadBytes)) throw new RuntimeException("Serialization is wrong: \n" + Utils.HEX.encode(reserialized) + " vs \n" + Utils.HEX.encode(payloadBytes)); } }
protected byte[] readByteArray() throws ProtocolException { long len = readVarInt(); return readBytes((int)len); }
protected Sha256Hash readHash() throws ProtocolException { // We have to flip it around, as it's been read off the wire in little endian. // Not the most efficient way to do this but the clearest. return Sha256Hash.wrapReversed(readBytes(32)); }
/** * Serialize this message to the provided OutputStream using the bitcoin wire format. * * @param stream * @throws IOException */ public final void bitcoinSerialize(OutputStream stream) throws IOException { // 1st check for cached bytes. if (payload != null && length != UNKNOWN_LENGTH) { stream.write(payload, offset, length); return; } bitcoinSerializeToStream(stream); }
/** * Returns a copy of the array returned by {@link Message#unsafeBitcoinSerialize()}, which is safe to mutate. * If you need extra performance and can guarantee you won't write to the array, you can use the unsafe version. * * @return a freshly allocated serialized byte array */ public byte[] bitcoinSerialize() { byte[] bytes = unsafeBitcoinSerialize(); byte[] copy = new byte[bytes.length]; System.arraycopy(bytes, 0, copy, 0, bytes.length); return copy; }
protected long readVarInt() throws ProtocolException { return readVarInt(0); }
/** * * @param params NetworkParameters object. * @param payload Bitcoin protocol formatted byte array containing message content. * @param offset The location of the first payload byte within the array. * @param protocolVersion Bitcoin protocol version. * @param serializer the serializer to use for this message. * @param length The length of message payload if known. Usually this is provided when deserializing of the wire * as the length will be provided as part of the header. If unknown then set to Message.UNKNOWN_LENGTH * @throws ProtocolException */ protected Message(NetworkParameters params, byte[] payload, int offset, int protocolVersion, MessageSerializer serializer, int length) throws ProtocolException { this.serializer = serializer; this.protocolVersion = protocolVersion; this.params = params; this.payload = payload; this.cursor = this.offset = offset; this.length = length; parse(); if (this.length == UNKNOWN_LENGTH) checkState(false, "Length field has not been set in constructor for %s after parse.", getClass().getSimpleName()); if (SELF_CHECK) { selfCheck(payload, offset); } if (!serializer.isParseRetainMode()) this.payload = null; }
protected byte[] readByteArray() throws ProtocolException { long len = readVarInt(); return readBytes((int)len); }
protected Sha256Hash readHash() throws ProtocolException { // We have to flip it around, as it's been read off the wire in little endian. // Not the most efficient way to do this but the clearest. return Sha256Hash.wrapReversed(readBytes(32)); }
/** * Serialize this message to the provided OutputStream using the bitcoin wire format. * * @param stream * @throws IOException */ public final void bitcoinSerialize(OutputStream stream) throws IOException { // 1st check for cached bytes. if (payload != null && length != UNKNOWN_LENGTH) { stream.write(payload, offset, length); return; } bitcoinSerializeToStream(stream); }
/** * Returns a copy of the array returned by {@link Message#unsafeBitcoinSerialize()}, which is safe to mutate. * If you need extra performance and can guarantee you won't write to the array, you can use the unsafe version. * * @return a freshly allocated serialized byte array */ public byte[] bitcoinSerialize() { byte[] bytes = unsafeBitcoinSerialize(); byte[] copy = new byte[bytes.length]; System.arraycopy(bytes, 0, copy, 0, bytes.length); return copy; }
protected long readVarInt() throws ProtocolException { return readVarInt(0); }
/** * * @param params NetworkParameters object. * @param payload Bitcoin protocol formatted byte array containing message content. * @param offset The location of the first payload byte within the array. * @param protocolVersion Bitcoin protocol version. * @param serializer the serializer to use for this message. * @param length The length of message payload if known. Usually this is provided when deserializing of the wire * as the length will be provided as part of the header. If unknown then set to Message.UNKNOWN_LENGTH * @throws ProtocolException */ protected Message(NetworkParameters params, byte[] payload, int offset, int protocolVersion, MessageSerializer serializer, int length) throws ProtocolException { this.serializer = serializer; this.protocolVersion = protocolVersion; this.params = params; this.payload = payload; this.cursor = this.offset = offset; this.length = length; parse(); if (this.length == UNKNOWN_LENGTH) checkState(false, "Length field has not been set in constructor for %s after parse.", getClass().getSimpleName()); if (SELF_CHECK) { selfCheck(payload, offset); } if (!serializer.isParseRetainMode()) this.payload = null; }
protected byte[] readByteArray() throws ProtocolException { long len = readVarInt(); return readBytes((int)len); }
/** * Returns the transaction hash that owns this output. */ @Nullable public Sha256Hash getParentTransactionHash() { return parent == null ? null : parent.getHash(); }
private void selfCheck(byte[] payload, int offset) { if (!(this instanceof VersionMessage)) { byte[] payloadBytes = new byte[cursor - offset]; System.arraycopy(payload, offset, payloadBytes, 0, cursor - offset); byte[] reserialized = bitcoinSerialize(); if (!Arrays.equals(reserialized, payloadBytes)) throw new RuntimeException("Serialization is wrong: \n" + Utils.HEX.encode(reserialized) + " vs \n" + Utils.HEX.encode(payloadBytes)); } }