3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-07 14:54:15 +00:00

NetworkParameters: hide packet magic behind a getter.

Conflicts:
	tools/src/main/java/com/google/bitcoin/tools/BlockImporter.java
	core/src/main/java/com/google/bitcoin/utils/BlockFileLoader.java
	core/src/test/java/com/google/bitcoin/core/FullBlockTestGenerator.java
This commit is contained in:
Mike Hearn 2013-05-08 14:45:13 +02:00
parent 8043bc335b
commit 1f005d7b3d
4 changed files with 16 additions and 12 deletions

View File

@ -103,7 +103,7 @@ public class BitcoinSerializer {
}
byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 /* checksum */];
uint32ToByteArrayBE(params.packetMagic, header, 0);
uint32ToByteArrayBE(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.
@ -272,7 +272,7 @@ public class BitcoinSerializer {
}
// We're looking for a run of bytes that is the same as the packet magic but we want to ignore partial
// magics that aren't complete. So we keep track of where we're up to with magicCursor.
int expectedByte = 0xFF & (int) (params.packetMagic >>> (magicCursor * 8));
int expectedByte = 0xFF & (int) (params.getPacketMagic() >>> (magicCursor * 8));
if (b == expectedByte) {
magicCursor--;
if (magicCursor < 0) {

View File

@ -62,8 +62,7 @@ public class NetworkParameters implements Serializable {
/** What the easiest allowable proof of work should be. */
public /*final*/ BigInteger proofOfWorkLimit;
private final int port;
/** The header bytes that identify the start of a packet on this network. */
public final long packetMagic;
private final long packetMagic;
/**
* First byte of a base58 encoded address. See {@link Address}. This is the same as acceptableAddressCodes[0] and
* is the one used for "normal" addresses. Other types of address may be encountered with version codes found in
@ -397,4 +396,9 @@ public class NetworkParameters implements Serializable {
public int getPort() {
return port;
}
/** The header bytes that identify the start of a packet on this network. */
public long getPacketMagic() {
return packetMagic;
}
}

View File

@ -124,18 +124,18 @@ public class BlockFileLoader implements Iterable<Block>, Iterator<Block> {
try {
int nextChar = currentFileStream.read();
while (nextChar != -1) {
if (nextChar != ((params.packetMagic >>> 24) & 0xff)) {
if (nextChar != ((params.getPacketMagic() >>> 24) & 0xff)) {
nextChar = currentFileStream.read();
continue;
}
nextChar = currentFileStream.read();
if (nextChar != ((params.packetMagic >>> 16) & 0xff))
if (nextChar != ((params.getPacketMagic() >>> 16) & 0xff))
continue;
nextChar = currentFileStream.read();
if (nextChar != ((params.packetMagic >>> 8) & 0xff))
if (nextChar != ((params.getPacketMagic() >>> 8) & 0xff))
continue;
nextChar = currentFileStream.read();
if (nextChar == (params.packetMagic & 0xff))
if (nextChar == (params.getPacketMagic() & 0xff))
break;
}
byte[] bytes = new byte[4];

View File

@ -85,10 +85,10 @@ public class FullBlockTestGenerator {
public boolean add(BlockAndValidity element) {
if (outStream != null) {
try {
outStream.write((int) (params.packetMagic >>> 24));
outStream.write((int) (params.packetMagic >>> 16));
outStream.write((int) (params.packetMagic >>> 8));
outStream.write((int) (params.packetMagic >>> 0));
outStream.write((int) (params.getPacketMagic() >>> 24));
outStream.write((int) (params.getPacketMagic() >>> 16));
outStream.write((int) (params.getPacketMagic() >>> 8));
outStream.write((int) (params.getPacketMagic() >>> 0));
byte[] block = element.block.bitcoinSerialize();
byte[] length = new byte[4];
Utils.uint32ToByteArrayBE(block.length, length, 0);