mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-01-18 21:32:35 +01:00
AddressMessage: remove params
and serializer
from constructors in hierarchy
This commit is contained in:
parent
8576602180
commit
8c6e584e02
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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());
|
||||
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user