mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-22 14:22:45 +01:00
BaseMessage: remove field serializer
This commit is contained in:
parent
306ad03e6a
commit
e6125b49a2
2 changed files with 7 additions and 19 deletions
|
@ -36,24 +36,14 @@ import java.nio.ByteBuffer;
|
|||
public abstract class BaseMessage implements Message {
|
||||
private static final Logger log = LoggerFactory.getLogger(BaseMessage.class);
|
||||
|
||||
protected final MessageSerializer serializer;
|
||||
|
||||
protected BaseMessage() {
|
||||
this.serializer = DummySerializer.DEFAULT;
|
||||
}
|
||||
|
||||
protected BaseMessage(MessageSerializer serializer) {
|
||||
this.serializer = serializer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param payload Bitcoin protocol formatted byte array containing message content.
|
||||
* @param serializer the serializer to use for this message.
|
||||
* @throws ProtocolException
|
||||
*/
|
||||
protected BaseMessage(ByteBuffer payload, MessageSerializer serializer) throws ProtocolException {
|
||||
this.serializer = serializer;
|
||||
|
||||
protected BaseMessage(ByteBuffer payload) throws ProtocolException {
|
||||
try {
|
||||
parse(payload);
|
||||
} catch(BufferUnderflowException e) {
|
||||
|
@ -61,10 +51,6 @@ public abstract class BaseMessage implements Message {
|
|||
}
|
||||
}
|
||||
|
||||
protected BaseMessage(ByteBuffer payload) throws ProtocolException {
|
||||
this(payload, DummySerializer.DEFAULT);
|
||||
}
|
||||
|
||||
// These methods handle the serialization/deserialization using the custom Bitcoin protocol.
|
||||
|
||||
protected abstract void parse(ByteBuffer payload) throws BufferUnderflowException, ProtocolException;
|
||||
|
|
|
@ -156,6 +156,8 @@ public class Transaction extends BaseMessage {
|
|||
*/
|
||||
public static final Coin DEFAULT_TX_FEE = Coin.valueOf(100000); // 1 mBTC
|
||||
|
||||
private final int protocolVersion;
|
||||
|
||||
// These are bitcoin serialized.
|
||||
private long version;
|
||||
private ArrayList<TransactionInput> inputs;
|
||||
|
@ -309,11 +311,11 @@ public class Transaction extends BaseMessage {
|
|||
}
|
||||
|
||||
private Transaction(int protocolVersion) {
|
||||
super(new DummySerializer(protocolVersion));
|
||||
this.protocolVersion = protocolVersion;
|
||||
}
|
||||
|
||||
public Transaction() {
|
||||
super(new DummySerializer(ProtocolVersion.CURRENT.intValue()));
|
||||
this.protocolVersion = ProtocolVersion.CURRENT.intValue();
|
||||
version = 1;
|
||||
inputs = new ArrayList<>();
|
||||
outputs = new ArrayList<>();
|
||||
|
@ -1427,7 +1429,7 @@ public class Transaction extends BaseMessage {
|
|||
|
||||
@Override
|
||||
public int getMessageSize() {
|
||||
boolean useSegwit = hasWitnesses() && allowWitness(serializer.getProtocolVersion());
|
||||
boolean useSegwit = hasWitnesses() && allowWitness(protocolVersion);
|
||||
int size = 4; // version
|
||||
if (useSegwit)
|
||||
size += 2; // marker, flag
|
||||
|
@ -1446,7 +1448,7 @@ public class Transaction extends BaseMessage {
|
|||
|
||||
@Override
|
||||
protected void bitcoinSerializeToStream(OutputStream stream) throws IOException {
|
||||
boolean useSegwit = hasWitnesses() && allowWitness(serializer.getProtocolVersion());
|
||||
boolean useSegwit = hasWitnesses() && allowWitness(protocolVersion);
|
||||
bitcoinSerializeToStream(stream, useSegwit);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue