diff --git a/core/src/main/java/com/google/bitcoin/core/BitcoinSerializer.java b/core/src/main/java/com/google/bitcoin/core/BitcoinSerializer.java index ee3df9d99..c397a9e8b 100644 --- a/core/src/main/java/com/google/bitcoin/core/BitcoinSerializer.java +++ b/core/src/main/java/com/google/bitcoin/core/BitcoinSerializer.java @@ -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) { diff --git a/core/src/main/java/com/google/bitcoin/core/NetworkParameters.java b/core/src/main/java/com/google/bitcoin/core/NetworkParameters.java index 02f2e9362..e1020db10 100644 --- a/core/src/main/java/com/google/bitcoin/core/NetworkParameters.java +++ b/core/src/main/java/com/google/bitcoin/core/NetworkParameters.java @@ -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; + } } diff --git a/core/src/main/java/com/google/bitcoin/utils/BlockFileLoader.java b/core/src/main/java/com/google/bitcoin/utils/BlockFileLoader.java index 07f58062c..95b7e2410 100644 --- a/core/src/main/java/com/google/bitcoin/utils/BlockFileLoader.java +++ b/core/src/main/java/com/google/bitcoin/utils/BlockFileLoader.java @@ -124,18 +124,18 @@ public class BlockFileLoader implements Iterable, Iterator { 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]; diff --git a/core/src/test/java/com/google/bitcoin/core/FullBlockTestGenerator.java b/core/src/test/java/com/google/bitcoin/core/FullBlockTestGenerator.java index dea737769..8e7f2a14e 100644 --- a/core/src/test/java/com/google/bitcoin/core/FullBlockTestGenerator.java +++ b/core/src/test/java/com/google/bitcoin/core/FullBlockTestGenerator.java @@ -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);