BaseMessage: remove method parse()

This commit is contained in:
Andreas Schildbach 2023-04-14 23:46:29 +02:00
parent e6125b49a2
commit 917a1097c3
17 changed files with 1 additions and 99 deletions

View file

@ -49,11 +49,6 @@ public class AddressV1Message extends AddressMessage {
super(addresses);
}
@Override
protected void parse(ByteBuffer payload) throws BufferUnderflowException, ProtocolException {
throw new UnsupportedOperationException();
}
public void addAddress(PeerAddress address) {
addresses.add(address);
}

View file

@ -50,11 +50,6 @@ public class AddressV2Message extends AddressMessage {
super(addresses);
}
@Override
protected void parse(ByteBuffer payload) throws BufferUnderflowException, ProtocolException {
throw new UnsupportedOperationException();
}
public void addAddress(PeerAddress address) {
addresses.add(address);
}

View file

@ -23,8 +23,6 @@ import org.slf4j.LoggerFactory;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
/**
* A Message is a data structure that can be serialized/deserialized using the Bitcoin serialization format.
@ -36,25 +34,8 @@ import java.nio.ByteBuffer;
public abstract class BaseMessage implements Message {
private static final Logger log = LoggerFactory.getLogger(BaseMessage.class);
protected BaseMessage() {
}
/**
* @param payload Bitcoin protocol formatted byte array containing message content.
* @throws ProtocolException
*/
protected BaseMessage(ByteBuffer payload) throws ProtocolException {
try {
parse(payload);
} catch(BufferUnderflowException e) {
throw new ProtocolException(e);
}
}
// These methods handle the serialization/deserialization using the custom Bitcoin protocol.
protected abstract void parse(ByteBuffer payload) throws BufferUnderflowException, ProtocolException;
/**
* <p>Serialize this message to a byte array that conforms to the bitcoin wire protocol.</p>
*

View file

@ -231,11 +231,6 @@ public class Block extends BaseMessage {
transactions);
}
@Override
protected void parse(ByteBuffer payload) throws BufferUnderflowException, ProtocolException {
throw new UnsupportedOperationException();
}
public static Block createGenesis() {
Block genesisBlock = new Block(BLOCK_VERSION_GENESIS);
Transaction tx = Transaction.coinbase(genesisTxInputScriptBytes);

View file

@ -167,11 +167,6 @@ public class BloomFilter extends BaseMessage {
return helper.toString();
}
@Override
protected void parse(ByteBuffer payload) throws BufferUnderflowException, ProtocolException {
throw new UnsupportedOperationException();
}
/**
* Serializes this message to the provided stream. If you just want the raw bytes use bitcoinSerialize().
*/

View file

@ -19,8 +19,6 @@ package org.bitcoinj.core;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
/**
* <p>Parent class for header only messages that don't have a payload.
@ -42,8 +40,4 @@ public abstract class EmptyMessage extends BaseMessage {
@Override
protected final void bitcoinSerializeToStream(OutputStream stream) throws IOException {
}
@Override
protected void parse(ByteBuffer payload) throws BufferUnderflowException, ProtocolException {
}
}

View file

@ -60,11 +60,6 @@ public class FeeFilterMessage extends BaseMessage {
ByteUtils.writeInt64LE(feeRate.value, stream);
}
@Override
protected void parse(ByteBuffer payload) throws BufferUnderflowException, ProtocolException {
throw new UnsupportedOperationException();
}
public Coin getFeeRate() {
return feeRate;
}

View file

@ -76,11 +76,6 @@ public class FilteredBlock extends BaseMessage {
stream.write(merkleTree.serialize());
}
@Override
protected void parse(ByteBuffer payload) throws BufferUnderflowException, ProtocolException {
throw new UnsupportedOperationException();
}
/**
* Gets a list of leaf hashes which are contained in the partial merkle tree in this filtered block
*

View file

@ -68,11 +68,6 @@ public class GetBlocksMessage extends BaseMessage {
this.stopHash = stopHash;
}
@Override
protected void parse(ByteBuffer payload) throws BufferUnderflowException, ProtocolException {
throw new UnsupportedOperationException();
}
public BlockLocator getLocator() {
return locator;
}

View file

@ -97,11 +97,6 @@ public class HeadersMessage extends BaseMessage {
}
}
@Override
protected void parse(ByteBuffer payload) throws BufferUnderflowException, ProtocolException {
throw new UnsupportedOperationException();
}
public List<Block> getBlockHeaders() {
return blockHeaders;
}

View file

@ -89,11 +89,6 @@ public abstract class ListMessage extends BaseMessage {
items.remove(index);
}
@Override
protected void parse(ByteBuffer payload) throws BufferUnderflowException, ProtocolException {
throw new UnsupportedOperationException();
}
@Override
public void bitcoinSerializeToStream(OutputStream stream) throws IOException {
stream.write(VarInt.of(items.size()).serialize());

View file

@ -63,11 +63,6 @@ public class Ping extends BaseMessage {
ByteUtils.writeInt64LE(nonce, stream);
}
@Override
protected void parse(ByteBuffer payload) throws BufferUnderflowException, ProtocolException {
throw new UnsupportedOperationException();
}
/** @deprecated returns true */
@Deprecated
public boolean hasNonce() {

View file

@ -50,12 +50,7 @@ public class Pong extends BaseMessage {
public Pong(long nonce) {
this.nonce = nonce;
}
@Override
protected void parse(ByteBuffer payload) throws BufferUnderflowException, ProtocolException {
throw new UnsupportedOperationException();
}
@Override
public void bitcoinSerializeToStream(OutputStream stream) throws IOException {
ByteUtils.writeInt64LE(nonce, stream);

View file

@ -107,11 +107,6 @@ public class RejectMessage extends BaseMessage {
this.reason = reason;
}
@Override
protected void parse(ByteBuffer payload) throws BufferUnderflowException, ProtocolException {
throw new UnsupportedOperationException();
}
@Override
public void bitcoinSerializeToStream(OutputStream stream) throws IOException {
byte[] messageBytes = message.getBytes(StandardCharsets.UTF_8);

View file

@ -634,11 +634,6 @@ public class Transaction extends BaseMessage {
*/
public static final byte SIGHASH_ANYONECANPAY_VALUE = (byte) 0x80;
@Override
protected void parse(ByteBuffer payload) throws BufferUnderflowException, ProtocolException {
throw new UnsupportedOperationException();
}
private void readInputs(ByteBuffer payload) throws BufferUnderflowException, ProtocolException {
VarInt numInputsVarInt = VarInt.read(payload);
check(numInputsVarInt.fitsInt(), BufferUnderflowException::new);

View file

@ -175,11 +175,6 @@ public class VersionMessage extends BaseMessage {
return localServices;
}
@Override
protected void parse(ByteBuffer payload) throws BufferUnderflowException, ProtocolException {
throw new UnsupportedOperationException();
}
@Override
public void bitcoinSerializeToStream(OutputStream buf) throws IOException {
ByteUtils.writeInt32LE(clientVersion, buf);

View file

@ -234,9 +234,6 @@ public class BitcoinSerializerTest {
MessageSerializer serializer = MAINNET.getDefaultSerializer();
Message unknownMessage = new BaseMessage() {
@Override
protected void parse(ByteBuffer payload) throws BufferUnderflowException, ProtocolException {
}
};
ByteArrayOutputStream bos = new ByteArrayOutputStream(ADDRESS_MESSAGE_BYTES.length);
serializer.serialize(unknownMessage, bos);