AddressMessage: remove params and serializer from constructors in hierarchy

This commit is contained in:
Andreas Schildbach 2023-03-30 16:13:54 +02:00
parent 8576602180
commit 8c6e584e02
6 changed files with 10 additions and 30 deletions

View File

@ -29,8 +29,8 @@ public abstract class AddressMessage extends Message {
protected static final long MAX_ADDRESSES = 1000;
protected List<PeerAddress> addresses;
AddressMessage(NetworkParameters params, ByteBuffer payload, MessageSerializer serializer) throws ProtocolException {
super(params, payload, serializer);
AddressMessage(ByteBuffer payload) throws ProtocolException {
super(payload);
}
@Override

View File

@ -35,16 +35,10 @@ public class AddressV1Message extends AddressMessage {
/**
* Construct a new 'addr' message.
* @param params NetworkParameters object.
* @param serializer the serializer to use for this block.
* @throws ProtocolException
*/
AddressV1Message(NetworkParameters params, ByteBuffer payload, MessageSerializer serializer) throws ProtocolException {
super(params, payload, serializer);
}
AddressV1Message(NetworkParameters params, ByteBuffer payload) throws ProtocolException {
super(params, payload, params.getDefaultSerializer());
AddressV1Message(ByteBuffer payload) throws ProtocolException {
super(payload);
}
@Override
@ -63,10 +57,6 @@ public class AddressV1Message extends AddressMessage {
}
public void addAddress(PeerAddress address) {
int protocolVersion = address.serializer.getProtocolVersion();
if (protocolVersion != 1)
throw new IllegalStateException("invalid protocolVersion: " + protocolVersion);
addresses.add(address);
}

View File

@ -35,16 +35,10 @@ import java.util.ArrayList;
public class AddressV2Message extends AddressMessage {
/**
* Construct a new 'addrv2' message.
* @param params NetworkParameters object.
* @param serializer the serializer to use for this block.
* @throws ProtocolException
*/
AddressV2Message(NetworkParameters params, ByteBuffer payload, MessageSerializer serializer) throws ProtocolException {
super(params, payload, serializer);
}
AddressV2Message(NetworkParameters params, ByteBuffer payload) throws ProtocolException {
super(params, payload, params.getDefaultSerializer());
AddressV2Message(ByteBuffer payload) throws ProtocolException {
super(payload);
}
@Override
@ -63,10 +57,6 @@ public class AddressV2Message extends AddressMessage {
}
public void addAddress(PeerAddress address) {
int protocolVersion = address.serializer.getProtocolVersion();
if (protocolVersion != 2)
throw new IllegalStateException("invalid protocolVersion: " + protocolVersion);
addresses.add(address);
}

View File

@ -280,7 +280,7 @@ public class BitcoinSerializer extends MessageSerializer {
*/
@Override
public AddressV1Message makeAddressV1Message(ByteBuffer payload) throws ProtocolException {
return new AddressV1Message(params, payload, this);
return new AddressV1Message(payload);
}
/**
@ -289,7 +289,7 @@ public class BitcoinSerializer extends MessageSerializer {
*/
@Override
public AddressV2Message makeAddressV2Message(ByteBuffer payload) throws ProtocolException {
return new AddressV2Message(params, payload, this);
return new AddressV2Message(payload);
}
/**

View File

@ -60,7 +60,7 @@ public class AddressV1MessageTest {
@Test
public void roundtrip() {
AddressMessage message = new AddressV1Message(TESTNET, ByteBuffer.wrap(ByteUtils.parseHex(MESSAGE_HEX)));
AddressMessage message = new AddressV1Message(ByteBuffer.wrap(ByteUtils.parseHex(MESSAGE_HEX)));
List<PeerAddress> addresses = message.getAddresses();
assertEquals(4, addresses.size());

View File

@ -75,7 +75,7 @@ public class AddressV2MessageTest {
@Test
public void roundtrip() {
AddressMessage message = new AddressV2Message(TESTNET, ByteBuffer.wrap(ByteUtils.parseHex(MESSAGE_HEX)));
AddressMessage message = new AddressV2Message(ByteBuffer.wrap(ByteUtils.parseHex(MESSAGE_HEX)));
List<PeerAddress> addresses = message.getAddresses();
assertEquals(5, addresses.size());