mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2024-11-19 01:40:26 +01:00
ByteUtils: rename all writeUInt*()
helpers to writeInt*()
This creates overloads in some cases.
This commit is contained in:
parent
f3c4b5fcf4
commit
47a5d73035
@ -174,11 +174,11 @@ public class VarInt {
|
||||
break;
|
||||
case 3:
|
||||
buf.put((byte) 253);
|
||||
ByteUtils.writeUint16LE((int) value, buf);
|
||||
ByteUtils.writeInt16LE((int) value, buf);
|
||||
break;
|
||||
case 5:
|
||||
buf.put((byte) 254);
|
||||
ByteUtils.writeUint32LE(value, buf);
|
||||
ByteUtils.writeInt32LE(value, buf);
|
||||
break;
|
||||
default:
|
||||
buf.put((byte) 255);
|
||||
|
@ -110,7 +110,7 @@ public class ByteUtils {
|
||||
* @return the buffer
|
||||
* @throws BufferOverflowException if the value doesn't fit the remaining buffer
|
||||
*/
|
||||
public static ByteBuffer writeUint16LE(int val, ByteBuffer buf) throws BufferOverflowException {
|
||||
public static ByteBuffer writeInt16LE(int val, ByteBuffer buf) throws BufferOverflowException {
|
||||
return buf.order(ByteOrder.LITTLE_ENDIAN).putShort((short) val);
|
||||
}
|
||||
|
||||
@ -122,10 +122,10 @@ public class ByteUtils {
|
||||
* @throws ArrayIndexOutOfBoundsException if offset points outside of the buffer, or
|
||||
* if the value doesn't fit the remaining buffer
|
||||
*/
|
||||
public static void writeUint16LE(int val, byte[] out, int offset) throws ArrayIndexOutOfBoundsException {
|
||||
public static void writeInt16LE(int val, byte[] out, int offset) throws ArrayIndexOutOfBoundsException {
|
||||
check(offset >= 0 && offset <= out.length - 2, () ->
|
||||
new ArrayIndexOutOfBoundsException(offset));
|
||||
writeUint16LE(val, ByteBuffer.wrap(out, offset, out.length - offset));
|
||||
writeInt16LE(val, ByteBuffer.wrap(out, offset, out.length - offset));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -135,7 +135,7 @@ public class ByteUtils {
|
||||
* @return the buffer
|
||||
* @throws BufferOverflowException if the value doesn't fit the remaining buffer
|
||||
*/
|
||||
public static ByteBuffer writeUint16BE(int val, ByteBuffer buf) throws BufferOverflowException {
|
||||
public static ByteBuffer writeInt16BE(int val, ByteBuffer buf) throws BufferOverflowException {
|
||||
return buf.order(ByteOrder.BIG_ENDIAN).putShort((short) val);
|
||||
}
|
||||
|
||||
@ -147,10 +147,10 @@ public class ByteUtils {
|
||||
* @throws ArrayIndexOutOfBoundsException if offset points outside of the buffer, or
|
||||
* if the value doesn't fit the remaining buffer
|
||||
*/
|
||||
public static void writeUint16BE(int val, byte[] out, int offset) throws ArrayIndexOutOfBoundsException {
|
||||
public static void writeInt16BE(int val, byte[] out, int offset) throws ArrayIndexOutOfBoundsException {
|
||||
check(offset >= 0 && offset <= out.length - 2, () ->
|
||||
new ArrayIndexOutOfBoundsException(offset));
|
||||
writeUint16BE(val, ByteBuffer.wrap(out, offset, out.length - offset));
|
||||
writeInt16BE(val, ByteBuffer.wrap(out, offset, out.length - offset));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -171,7 +171,7 @@ public class ByteUtils {
|
||||
* @return the buffer
|
||||
* @throws BufferOverflowException if the value doesn't fit the remaining buffer
|
||||
*/
|
||||
public static ByteBuffer writeUint32LE(long val, ByteBuffer buf) throws BufferOverflowException {
|
||||
public static ByteBuffer writeInt32LE(long val, ByteBuffer buf) throws BufferOverflowException {
|
||||
return buf.order(ByteOrder.LITTLE_ENDIAN).putInt((int) val);
|
||||
}
|
||||
|
||||
@ -183,10 +183,10 @@ public class ByteUtils {
|
||||
* @throws ArrayIndexOutOfBoundsException if offset points outside of the buffer, or
|
||||
* if the value doesn't fit the remaining buffer
|
||||
*/
|
||||
public static void writeUint32LE(long val, byte[] out, int offset) throws ArrayIndexOutOfBoundsException {
|
||||
public static void writeInt32LE(long val, byte[] out, int offset) throws ArrayIndexOutOfBoundsException {
|
||||
check(offset >= 0 && offset <= out.length - 4, () ->
|
||||
new ArrayIndexOutOfBoundsException(offset));
|
||||
writeUint32LE(val, ByteBuffer.wrap(out, offset, out.length - offset));
|
||||
writeInt32LE(val, ByteBuffer.wrap(out, offset, out.length - offset));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -196,7 +196,7 @@ public class ByteUtils {
|
||||
* @return the buffer
|
||||
* @throws BufferOverflowException if the value doesn't fit the remaining buffer
|
||||
*/
|
||||
public static ByteBuffer writeUint32BE(long val, ByteBuffer buf) throws BufferOverflowException {
|
||||
public static ByteBuffer writeInt32BE(long val, ByteBuffer buf) throws BufferOverflowException {
|
||||
return buf.order(ByteOrder.BIG_ENDIAN).putInt((int) val);
|
||||
}
|
||||
|
||||
@ -208,10 +208,10 @@ public class ByteUtils {
|
||||
* @throws ArrayIndexOutOfBoundsException if offset points outside of the buffer, or
|
||||
* if the value doesn't fit the remaining buffer
|
||||
*/
|
||||
public static void writeUint32BE(long val, byte[] out, int offset) throws ArrayIndexOutOfBoundsException {
|
||||
public static void writeInt32BE(long val, byte[] out, int offset) throws ArrayIndexOutOfBoundsException {
|
||||
check(offset >= 0 && offset <= out.length - 4, () ->
|
||||
new ArrayIndexOutOfBoundsException(offset));
|
||||
writeUint32BE(val, ByteBuffer.wrap(out, offset, out.length - offset));
|
||||
writeInt32BE(val, ByteBuffer.wrap(out, offset, out.length - offset));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -245,9 +245,9 @@ public class ByteUtils {
|
||||
* @param stream strean to be written into
|
||||
* @throws IOException if an I/O error occurs
|
||||
*/
|
||||
public static void writeUint16LE(int val, OutputStream stream) throws IOException {
|
||||
public static void writeInt16LE(int val, OutputStream stream) throws IOException {
|
||||
byte[] buf = new byte[2];
|
||||
writeUint16LE(val, ByteBuffer.wrap(buf));
|
||||
writeInt16LE(val, ByteBuffer.wrap(buf));
|
||||
stream.write(buf);
|
||||
}
|
||||
|
||||
@ -257,9 +257,9 @@ public class ByteUtils {
|
||||
* @param stream strean to be written into
|
||||
* @throws IOException if an I/O error occurs
|
||||
*/
|
||||
public static void writeUint16BE(int val, OutputStream stream) throws IOException {
|
||||
public static void writeInt16BE(int val, OutputStream stream) throws IOException {
|
||||
byte[] buf = new byte[2];
|
||||
writeUint16BE(val, ByteBuffer.wrap(buf));
|
||||
writeInt16BE(val, ByteBuffer.wrap(buf));
|
||||
stream.write(buf);
|
||||
}
|
||||
|
||||
@ -281,9 +281,9 @@ public class ByteUtils {
|
||||
* @param stream strean to be written into
|
||||
* @throws IOException if an I/O error occurs
|
||||
*/
|
||||
public static void writeUint32LE(long val, OutputStream stream) throws IOException {
|
||||
public static void writeInt32LE(long val, OutputStream stream) throws IOException {
|
||||
byte[] buf = new byte[4];
|
||||
writeUint32LE(val, ByteBuffer.wrap(buf));
|
||||
writeInt32LE(val, ByteBuffer.wrap(buf));
|
||||
stream.write(buf);
|
||||
}
|
||||
|
||||
@ -293,9 +293,9 @@ public class ByteUtils {
|
||||
* @param stream strean to be written into
|
||||
* @throws IOException if an I/O error occurs
|
||||
*/
|
||||
public static void writeUint32BE(long val, OutputStream stream) throws IOException {
|
||||
public static void writeInt32BE(long val, OutputStream stream) throws IOException {
|
||||
byte[] buf = new byte[4];
|
||||
writeUint32BE(val, ByteBuffer.wrap(buf));
|
||||
writeInt32BE(val, ByteBuffer.wrap(buf));
|
||||
stream.write(buf);
|
||||
}
|
||||
|
||||
@ -317,7 +317,7 @@ public class ByteUtils {
|
||||
* @param stream strean to be written into
|
||||
* @throws IOException if an I/O error occurs
|
||||
*/
|
||||
public static void writeUint64LE(BigInteger val, OutputStream stream) throws IOException {
|
||||
public static void writeInt64LE(BigInteger val, OutputStream stream) throws IOException {
|
||||
byte[] bytes = val.toByteArray();
|
||||
if (bytes.length > 8) {
|
||||
throw new RuntimeException("Input too large to encode into a uint64");
|
||||
@ -536,7 +536,7 @@ public class ByteUtils {
|
||||
if (includeLength) {
|
||||
byte[] result = new byte[length + 4];
|
||||
System.arraycopy(array, 0, result, length - array.length + 3, array.length);
|
||||
writeUint32BE(length, result, 0);
|
||||
writeInt32BE(length, result, 0);
|
||||
if (isNegative)
|
||||
result[4] |= 0x80;
|
||||
return result;
|
||||
|
@ -32,7 +32,6 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.bitcoinj.base.internal.ByteUtils.readUint32;
|
||||
import static org.bitcoinj.base.internal.ByteUtils.writeUint32BE;
|
||||
|
||||
/**
|
||||
* <p>Methods to serialize and de-serialize messages to the Bitcoin network format as defined in
|
||||
@ -117,7 +116,7 @@ public class BitcoinSerializer extends MessageSerializer {
|
||||
@Override
|
||||
public void serialize(String name, byte[] message, OutputStream out) throws IOException {
|
||||
byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 /* checksum */];
|
||||
writeUint32BE(params.getPacketMagic(), header, 0);
|
||||
ByteUtils.writeInt32BE(params.getPacketMagic(), header, 0);
|
||||
|
||||
// The header array is initialized to zero by Java so we don't have to worry about
|
||||
// NULL terminating the string here.
|
||||
@ -125,7 +124,7 @@ public class BitcoinSerializer extends MessageSerializer {
|
||||
header[4 + i] = (byte) (name.codePointAt(i) & 0xFF);
|
||||
}
|
||||
|
||||
ByteUtils.writeUint32LE(message.length, header, 4 + COMMAND_LEN);
|
||||
ByteUtils.writeInt32LE(message.length, header, 4 + COMMAND_LEN);
|
||||
|
||||
byte[] hash = Sha256Hash.hashTwice(message);
|
||||
System.arraycopy(hash, 0, header, 4 + COMMAND_LEN + 4, 4);
|
||||
|
@ -299,12 +299,12 @@ public class Block extends Message {
|
||||
|
||||
// default for testing
|
||||
void writeHeader(OutputStream stream) throws IOException {
|
||||
ByteUtils.writeUint32LE(version, stream);
|
||||
ByteUtils.writeInt32LE(version, stream);
|
||||
stream.write(prevBlockHash.getReversedBytes());
|
||||
stream.write(getMerkleRoot().getReversedBytes());
|
||||
ByteUtils.writeUint32LE(time.getEpochSecond(), stream);
|
||||
ByteUtils.writeUint32LE(difficultyTarget, stream);
|
||||
ByteUtils.writeUint32LE(nonce, stream);
|
||||
ByteUtils.writeInt32LE(time.getEpochSecond(), stream);
|
||||
ByteUtils.writeInt32LE(difficultyTarget, stream);
|
||||
ByteUtils.writeInt32LE(nonce, stream);
|
||||
}
|
||||
|
||||
private void writeTransactions(OutputStream stream) throws IOException {
|
||||
|
@ -166,7 +166,7 @@ public class BloomFilter extends Message {
|
||||
protected void bitcoinSerializeToStream(OutputStream stream) throws IOException {
|
||||
stream.write(VarInt.of(data.length).encode());
|
||||
stream.write(data);
|
||||
ByteUtils.writeUint32LE(hashFuncs, stream);
|
||||
ByteUtils.writeInt32LE(hashFuncs, stream);
|
||||
ByteUtils.writeInt32LE(nTweak, stream);
|
||||
stream.write(nFlags);
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ public class GetBlocksMessage extends Message {
|
||||
@Override
|
||||
protected void bitcoinSerializeToStream(OutputStream stream) throws IOException {
|
||||
// Version, for some reason.
|
||||
ByteUtils.writeUint32LE(serializer.getProtocolVersion(), stream);
|
||||
ByteUtils.writeInt32LE(serializer.getProtocolVersion(), stream);
|
||||
// Then a vector of block hashes. This is actually a "block locator", a set of block
|
||||
// identifiers that spans the entire chain with exponentially increasing gaps between
|
||||
// them, until we end up at the genesis block. See CBlockLocator::Set()
|
||||
|
@ -95,7 +95,7 @@ public abstract class ListMessage extends Message {
|
||||
stream.write(VarInt.of(items.size()).encode());
|
||||
for (InventoryItem i : items) {
|
||||
// Write out the type code.
|
||||
ByteUtils.writeUint32LE(i.type.code, stream);
|
||||
ByteUtils.writeInt32LE(i.type.code, stream);
|
||||
// And now the hash.
|
||||
stream.write(i.hash.getReversedBytes());
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ import java.util.Objects;
|
||||
|
||||
import static org.bitcoinj.base.internal.ByteUtils.checkBitLE;
|
||||
import static org.bitcoinj.base.internal.ByteUtils.reverseBytes;
|
||||
import static org.bitcoinj.base.internal.ByteUtils.writeUint32LE;
|
||||
import static org.bitcoinj.base.internal.ByteUtils.writeInt32LE;
|
||||
|
||||
/**
|
||||
* <p>A data structure that contains proofs of block inclusion for one or more transactions, in an efficient manner.</p>
|
||||
@ -111,7 +111,7 @@ public class PartialMerkleTree extends Message {
|
||||
|
||||
@Override
|
||||
public void bitcoinSerializeToStream(OutputStream stream) throws IOException {
|
||||
writeUint32LE(transactionCount, stream);
|
||||
writeInt32LE(transactionCount, stream);
|
||||
|
||||
stream.write(VarInt.of(hashes.size()).encode());
|
||||
for (Sha256Hash hash : hashes)
|
||||
|
@ -156,7 +156,7 @@ public class PeerAddress extends ChildMessage {
|
||||
throw new IllegalStateException("invalid protocolVersion: " + protocolVersion);
|
||||
|
||||
if (protocolVersion >= 1) {
|
||||
ByteUtils.writeUint32LE(time.get().getEpochSecond(), stream);
|
||||
ByteUtils.writeInt32LE(time.get().getEpochSecond(), stream);
|
||||
}
|
||||
if (protocolVersion == 2) {
|
||||
stream.write(VarInt.of(services.longValue()).encode());
|
||||
@ -198,7 +198,7 @@ public class PeerAddress extends ChildMessage {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
} else {
|
||||
ByteUtils.writeUint64LE(services, stream); // nServices.
|
||||
ByteUtils.writeInt64LE(services, stream); // nServices.
|
||||
if (addr != null) {
|
||||
// Java does not provide any utility to map an IPv4 address into IPv6 space, so we have to do it by
|
||||
// hand.
|
||||
@ -225,7 +225,7 @@ public class PeerAddress extends ChildMessage {
|
||||
}
|
||||
}
|
||||
// And write out the port. Unlike the rest of the protocol, address and port is in big endian byte order.
|
||||
ByteUtils.writeUint16BE(port, stream);
|
||||
ByteUtils.writeInt16BE(port, stream);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -71,8 +71,8 @@ import java.util.TreeMap;
|
||||
import static org.bitcoinj.base.internal.Preconditions.checkArgument;
|
||||
import static org.bitcoinj.base.internal.Preconditions.checkState;
|
||||
import static org.bitcoinj.core.NetworkParameters.ProtocolVersion.WITNESS_VERSION;
|
||||
import static org.bitcoinj.base.internal.ByteUtils.writeUint32LE;
|
||||
import static org.bitcoinj.base.internal.ByteUtils.writeUint64LE;
|
||||
import static org.bitcoinj.base.internal.ByteUtils.writeInt32LE;
|
||||
import static org.bitcoinj.base.internal.ByteUtils.writeInt64LE;
|
||||
|
||||
/**
|
||||
* <p>A transaction represents the movement of coins from some addresses to some other addresses. It can also represent
|
||||
@ -1340,7 +1340,7 @@ public class Transaction extends ChildMessage {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(255); // just a guess at an average tx length
|
||||
tx.bitcoinSerializeToStream(bos, false);
|
||||
// We also have to write a hash type (sigHashType is actually an unsigned char)
|
||||
writeUint32LE(0x000000ff & sigHashType, bos);
|
||||
writeInt32LE(0x000000ff & sigHashType, bos);
|
||||
// Note that this is NOT reversed to ensure it will be signed correctly. If it were to be printed out
|
||||
// however then we would expect that it is IS reversed.
|
||||
Sha256Hash hash = Sha256Hash.twiceOf(bos.toByteArray());
|
||||
@ -1448,7 +1448,7 @@ public class Transaction extends ChildMessage {
|
||||
ByteArrayOutputStream bosHashPrevouts = new ByteArrayOutputStream(256);
|
||||
for (TransactionInput input : this.inputs) {
|
||||
bosHashPrevouts.write(input.getOutpoint().getHash().getReversedBytes());
|
||||
writeUint32LE(input.getOutpoint().getIndex(), bosHashPrevouts);
|
||||
writeInt32LE(input.getOutpoint().getIndex(), bosHashPrevouts);
|
||||
}
|
||||
hashPrevouts = Sha256Hash.hashTwice(bosHashPrevouts.toByteArray());
|
||||
}
|
||||
@ -1456,7 +1456,7 @@ public class Transaction extends ChildMessage {
|
||||
if (!anyoneCanPay && signAll) {
|
||||
ByteArrayOutputStream bosSequence = new ByteArrayOutputStream(256);
|
||||
for (TransactionInput input : this.inputs) {
|
||||
writeUint32LE(input.getSequenceNumber(), bosSequence);
|
||||
writeInt32LE(input.getSequenceNumber(), bosSequence);
|
||||
}
|
||||
hashSequence = Sha256Hash.hashTwice(bosSequence.toByteArray());
|
||||
}
|
||||
@ -1464,7 +1464,7 @@ public class Transaction extends ChildMessage {
|
||||
if (signAll) {
|
||||
ByteArrayOutputStream bosHashOutputs = new ByteArrayOutputStream(256);
|
||||
for (TransactionOutput output : this.outputs) {
|
||||
writeUint64LE(
|
||||
writeInt64LE(
|
||||
BigInteger.valueOf(output.getValue().getValue()),
|
||||
bosHashOutputs
|
||||
);
|
||||
@ -1474,7 +1474,7 @@ public class Transaction extends ChildMessage {
|
||||
hashOutputs = Sha256Hash.hashTwice(bosHashOutputs.toByteArray());
|
||||
} else if (basicSigHashType == SigHash.SINGLE.value && inputIndex < outputs.size()) {
|
||||
ByteArrayOutputStream bosHashOutputs = new ByteArrayOutputStream(256);
|
||||
writeUint64LE(
|
||||
writeInt64LE(
|
||||
BigInteger.valueOf(this.outputs.get(inputIndex).getValue().getValue()),
|
||||
bosHashOutputs
|
||||
);
|
||||
@ -1482,18 +1482,18 @@ public class Transaction extends ChildMessage {
|
||||
bosHashOutputs.write(this.outputs.get(inputIndex).getScriptBytes());
|
||||
hashOutputs = Sha256Hash.hashTwice(bosHashOutputs.toByteArray());
|
||||
}
|
||||
writeUint32LE(version, bos);
|
||||
writeInt32LE(version, bos);
|
||||
bos.write(hashPrevouts);
|
||||
bos.write(hashSequence);
|
||||
bos.write(inputs.get(inputIndex).getOutpoint().getHash().getReversedBytes());
|
||||
writeUint32LE(inputs.get(inputIndex).getOutpoint().getIndex(), bos);
|
||||
writeInt32LE(inputs.get(inputIndex).getOutpoint().getIndex(), bos);
|
||||
bos.write(VarInt.of(scriptCode.length).encode());
|
||||
bos.write(scriptCode);
|
||||
writeUint64LE(BigInteger.valueOf(prevValue.getValue()), bos);
|
||||
writeUint32LE(inputs.get(inputIndex).getSequenceNumber(), bos);
|
||||
writeInt64LE(BigInteger.valueOf(prevValue.getValue()), bos);
|
||||
writeInt32LE(inputs.get(inputIndex).getSequenceNumber(), bos);
|
||||
bos.write(hashOutputs);
|
||||
writeUint32LE(this.vLockTime.rawValue(), bos);
|
||||
writeUint32LE(0x000000ff & sigHashType, bos);
|
||||
writeInt32LE(this.vLockTime.rawValue(), bos);
|
||||
writeInt32LE(0x000000ff & sigHashType, bos);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e); // Cannot happen.
|
||||
}
|
||||
@ -1533,7 +1533,7 @@ public class Transaction extends ChildMessage {
|
||||
*/
|
||||
protected void bitcoinSerializeToStream(OutputStream stream, boolean useSegwit) throws IOException {
|
||||
// version
|
||||
writeUint32LE(version, stream);
|
||||
writeInt32LE(version, stream);
|
||||
// marker, flag
|
||||
if (useSegwit) {
|
||||
stream.write(0);
|
||||
@ -1554,7 +1554,7 @@ public class Transaction extends ChildMessage {
|
||||
}
|
||||
}
|
||||
// lock_time
|
||||
writeUint32LE(vLockTime.rawValue(), stream);
|
||||
writeInt32LE(vLockTime.rawValue(), stream);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -180,7 +180,7 @@ public class TransactionInput extends ChildMessage {
|
||||
outpoint.bitcoinSerializeToStream(stream);
|
||||
stream.write(VarInt.of(scriptBytes.length).encode());
|
||||
stream.write(scriptBytes);
|
||||
ByteUtils.writeUint32LE(sequence, stream);
|
||||
ByteUtils.writeInt32LE(sequence, stream);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,7 +117,7 @@ public class TransactionOutPoint extends ChildMessage {
|
||||
@Override
|
||||
protected void bitcoinSerializeToStream(OutputStream stream) throws IOException {
|
||||
stream.write(hash.getReversedBytes());
|
||||
ByteUtils.writeUint32LE(index, stream);
|
||||
ByteUtils.writeInt32LE(index, stream);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -160,23 +160,23 @@ public class VersionMessage extends Message {
|
||||
|
||||
@Override
|
||||
public void bitcoinSerializeToStream(OutputStream buf) throws IOException {
|
||||
ByteUtils.writeUint32LE(clientVersion, buf);
|
||||
ByteUtils.writeUint32LE(localServices, buf);
|
||||
ByteUtils.writeUint32LE(localServices >> 32, buf);
|
||||
ByteUtils.writeInt32LE(clientVersion, buf);
|
||||
ByteUtils.writeInt32LE(localServices, buf);
|
||||
ByteUtils.writeInt32LE(localServices >> 32, buf);
|
||||
ByteUtils.writeInt64LE(time.getEpochSecond(), buf);
|
||||
receivingAddr.bitcoinSerializeToStream(buf);
|
||||
fromAddr.bitcoinSerializeToStream(buf);
|
||||
// Next up is the "local host nonce", this is to detect the case of connecting
|
||||
// back to yourself. We don't care about this as we won't be accepting inbound
|
||||
// connections.
|
||||
ByteUtils.writeUint32LE(0, buf);
|
||||
ByteUtils.writeUint32LE(0, buf);
|
||||
ByteUtils.writeInt32LE(0, buf);
|
||||
ByteUtils.writeInt32LE(0, buf);
|
||||
// Now comes subVer.
|
||||
byte[] subVerBytes = subVer.getBytes(StandardCharsets.UTF_8);
|
||||
buf.write(VarInt.of(subVerBytes.length).encode());
|
||||
buf.write(subVerBytes);
|
||||
// Size of known block chain.
|
||||
ByteUtils.writeUint32LE(bestHeight, buf);
|
||||
ByteUtils.writeInt32LE(bestHeight, buf);
|
||||
if (clientVersion >= params.getProtocolVersionNum(NetworkParameters.ProtocolVersion.BLOOM_FILTER)) {
|
||||
buf.write(relayTxesBeforeFilter ? 1 : 0);
|
||||
}
|
||||
|
@ -457,7 +457,7 @@ public class Script {
|
||||
os.write(buf);
|
||||
} else if (buf.length < 65536) {
|
||||
os.write(OP_PUSHDATA2);
|
||||
ByteUtils.writeUint16LE(buf.length, os);
|
||||
ByteUtils.writeInt16LE(buf.length, os);
|
||||
os.write(buf);
|
||||
} else {
|
||||
throw new RuntimeException("Unimplemented");
|
||||
|
@ -120,11 +120,11 @@ public class ScriptChunk {
|
||||
} else if (opcode == OP_PUSHDATA2) {
|
||||
checkState(data.length <= 0xFFFF);
|
||||
stream.write(OP_PUSHDATA2);
|
||||
ByteUtils.writeUint16LE(data.length, stream);
|
||||
ByteUtils.writeInt16LE(data.length, stream);
|
||||
} else if (opcode == OP_PUSHDATA4) {
|
||||
checkState(data.length <= Script.MAX_SCRIPT_ELEMENT_SIZE);
|
||||
stream.write(OP_PUSHDATA4);
|
||||
ByteUtils.writeUint32LE(data.length, stream);
|
||||
ByteUtils.writeInt32LE(data.length, stream);
|
||||
} else {
|
||||
throw new RuntimeException("Unimplemented");
|
||||
}
|
||||
|
@ -314,12 +314,12 @@ public class BlockTest {
|
||||
Block block = new Block(TESTNET, 1, Sha256Hash.ZERO_HASH, Sha256Hash.ZERO_HASH, 1, 1, 1, new ArrayList<Transaction>()) {
|
||||
@Override
|
||||
protected void bitcoinSerializeToStream(OutputStream stream) throws IOException {
|
||||
ByteUtils.writeUint32LE(getVersion(), stream);
|
||||
ByteUtils.writeInt32LE(getVersion(), stream);
|
||||
stream.write(getPrevBlockHash().getReversedBytes());
|
||||
stream.write(getMerkleRoot().getReversedBytes());
|
||||
ByteUtils.writeUint32LE(getTimeSeconds(), stream);
|
||||
ByteUtils.writeUint32LE(getDifficultyTarget(), stream);
|
||||
ByteUtils.writeUint32LE(getNonce(), stream);
|
||||
ByteUtils.writeInt32LE(getTimeSeconds(), stream);
|
||||
ByteUtils.writeInt32LE(getDifficultyTarget(), stream);
|
||||
ByteUtils.writeInt32LE(getNonce(), stream);
|
||||
|
||||
stream.write(VarInt.of(Integer.MAX_VALUE).encode());
|
||||
}
|
||||
|
@ -192,10 +192,10 @@ public class FullBlockTestGenerator {
|
||||
public boolean add(Rule element) {
|
||||
if (outStream != null && element instanceof BlockAndValidity) {
|
||||
try {
|
||||
ByteUtils.writeUint32BE(params.getPacketMagic(), outStream);
|
||||
ByteUtils.writeInt32BE(params.getPacketMagic(), outStream);
|
||||
byte[] block = ((BlockAndValidity) element).block.bitcoinSerialize();
|
||||
byte[] length = new byte[4];
|
||||
ByteUtils.writeUint32BE(block.length, length, 0);
|
||||
ByteUtils.writeInt32BE(block.length, length, 0);
|
||||
outStream.write(ByteUtils.reverseBytes(length));
|
||||
outStream.write(block);
|
||||
((BlockAndValidity)element).block = null;
|
||||
@ -1222,8 +1222,8 @@ public class FullBlockTestGenerator {
|
||||
|
||||
byte[] varIntBytes = new byte[9];
|
||||
varIntBytes[0] = (byte) 255;
|
||||
ByteUtils.writeUint32LE((long)b64Original.block.getTransactions().size(), varIntBytes, 1);
|
||||
ByteUtils.writeUint32LE(((long)b64Original.block.getTransactions().size()) >>> 32, varIntBytes, 5);
|
||||
ByteUtils.writeInt32LE((long)b64Original.block.getTransactions().size(), varIntBytes, 1);
|
||||
ByteUtils.writeInt32LE(((long)b64Original.block.getTransactions().size()) >>> 32, varIntBytes, 5);
|
||||
stream.write(varIntBytes);
|
||||
checkState(VarInt.ofBytes(varIntBytes, 0).intValue() == b64Original.block.getTransactions().size());
|
||||
|
||||
@ -1383,7 +1383,7 @@ public class FullBlockTestGenerator {
|
||||
Arrays.fill(outputScript, (byte) OP_CHECKSIG);
|
||||
// If we push an element that is too large, the CHECKSIGs after that push are still counted
|
||||
outputScript[Block.MAX_BLOCK_SIGOPS - sigOps] = OP_PUSHDATA4;
|
||||
ByteUtils.writeUint32LE(Script.MAX_SCRIPT_ELEMENT_SIZE + 1, outputScript, Block.MAX_BLOCK_SIGOPS - sigOps + 1);
|
||||
ByteUtils.writeInt32LE(Script.MAX_SCRIPT_ELEMENT_SIZE + 1, outputScript, Block.MAX_BLOCK_SIGOPS - sigOps + 1);
|
||||
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, outputScript));
|
||||
addOnlyInputToTransaction(tx, b73);
|
||||
b73.addTransaction(tx);
|
||||
@ -1449,7 +1449,7 @@ public class FullBlockTestGenerator {
|
||||
Arrays.fill(outputScript, (byte) OP_CHECKSIG);
|
||||
// If we push an element that is filled with CHECKSIGs, they (obviously) arent counted
|
||||
outputScript[Block.MAX_BLOCK_SIGOPS - sigOps] = OP_PUSHDATA4;
|
||||
ByteUtils.writeUint32LE(Block.MAX_BLOCK_SIGOPS, outputScript, Block.MAX_BLOCK_SIGOPS - sigOps + 1);
|
||||
ByteUtils.writeInt32LE(Block.MAX_BLOCK_SIGOPS, outputScript, Block.MAX_BLOCK_SIGOPS - sigOps + 1);
|
||||
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, outputScript));
|
||||
addOnlyInputToTransaction(tx, b76);
|
||||
b76.addTransaction(tx);
|
||||
|
@ -57,7 +57,7 @@ import java.util.function.IntFunction;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.bitcoinj.base.internal.ByteUtils;
|
||||
import static org.bitcoinj.base.internal.ByteUtils.writeUint32LE;
|
||||
import static org.bitcoinj.base.internal.ByteUtils.writeInt32LE;
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@ -711,7 +711,7 @@ public class TransactionTest {
|
||||
@Override
|
||||
protected void bitcoinSerializeToStream(OutputStream stream, boolean useSegwit) throws IOException {
|
||||
// version
|
||||
writeUint32LE(getVersion(), stream);
|
||||
writeInt32LE(getVersion(), stream);
|
||||
// marker, flag
|
||||
if (useSegwit) {
|
||||
stream.write(0);
|
||||
@ -743,7 +743,7 @@ public class TransactionTest {
|
||||
}
|
||||
}
|
||||
// lock_time
|
||||
writeUint32LE(lockTime().rawValue(), stream);
|
||||
writeInt32LE(lockTime().rawValue(), stream);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.bitcoinj.base.internal.ByteUtils.writeUint32LE;
|
||||
import static org.bitcoinj.base.internal.ByteUtils.writeInt32LE;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@ -236,7 +236,7 @@ public class FilteredBlockAndPartialMerkleTreeTest extends TestWithPeerGroup {
|
||||
hashes.add(Sha256Hash.wrap("0000000000000000000000000000000000000000000000000000000000000003"));
|
||||
PartialMerkleTree pmt = new PartialMerkleTree(TESTNET, bits, hashes, 3) {
|
||||
public void bitcoinSerializeToStream(OutputStream stream) throws IOException {
|
||||
writeUint32LE(getTransactionCount(), stream);
|
||||
writeInt32LE(getTransactionCount(), stream);
|
||||
// Add Integer.MAX_VALUE instead of hashes.size()
|
||||
stream.write(VarInt.of(Integer.MAX_VALUE).encode());
|
||||
//stream.write(VarInt.of(hashes.size()).encode());
|
||||
|
Loading…
Reference in New Issue
Block a user