mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-22 14:22:45 +01:00
BaseMessage: remove method parse()
This commit is contained in:
parent
e6125b49a2
commit
917a1097c3
17 changed files with 1 additions and 99 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
*
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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().
|
||||
*/
|
||||
|
|
|
@ -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 {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue