@@ -50,6 +50,7 @@ public class BitcoinSerializer extends MessageSerializer {
50
50
private static final int COMMAND_LEN = 12 ;
51
51
52
52
private final NetworkParameters params ;
53
+ private final int packetMagic ;
53
54
private final int protocolVersion ;
54
55
55
56
private static final Map <Class <? extends Message >, String > names = new HashMap <>();
@@ -96,6 +97,7 @@ public BitcoinSerializer(NetworkParameters params) {
96
97
*/
97
98
public BitcoinSerializer (NetworkParameters params , int protocolVersion ) {
98
99
this .params = params ;
100
+ this .packetMagic = params .getPacketMagic ();
99
101
this .protocolVersion = protocolVersion ;
100
102
}
101
103
@@ -116,7 +118,7 @@ public int getProtocolVersion() {
116
118
@ Override
117
119
public void serialize (String name , byte [] message , OutputStream out ) throws IOException {
118
120
byte [] header = new byte [4 + COMMAND_LEN + 4 + 4 /* checksum */ ];
119
- ByteUtils .writeInt32BE (params . getPacketMagic () , header , 0 );
121
+ ByteUtils .writeInt32BE (packetMagic , header , 0 );
120
122
121
123
// The header array is initialized to zero by Java so we don't have to worry about
122
124
// NULL terminating the string here.
@@ -344,7 +346,7 @@ public void seekPastMagicBytes(ByteBuffer in) throws BufferUnderflowException {
344
346
byte b = in .get ();
345
347
// We're looking for a run of bytes that is the same as the packet magic but we want to ignore partial
346
348
// magics that aren't complete. So we keep track of where we're up to with magicCursor.
347
- byte expectedByte = (byte )(0xFF & params . getPacketMagic () >>> (magicCursor * 8 ));
349
+ byte expectedByte = (byte )(0xFF & packetMagic >>> (magicCursor * 8 ));
348
350
if (b == expectedByte ) {
349
351
magicCursor --;
350
352
if (magicCursor < 0 ) {
0 commit comments