mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2024-11-19 18:00:39 +01:00
Message: from within the hierarchy, construct child messages directly
There is no point in taking the `MessageSerializer` route.
This commit is contained in:
parent
b2c54e8bf4
commit
795f64b43d
@ -298,7 +298,7 @@ public class BitcoinSerializer extends MessageSerializer {
|
||||
*/
|
||||
@Override
|
||||
public Block makeBlock(ByteBuffer payload) throws ProtocolException {
|
||||
return new Block(params, payload, this);
|
||||
return new Block(params, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -146,12 +146,11 @@ public class Block extends Message {
|
||||
* Construct a block object from the Bitcoin wire format.
|
||||
* @param params NetworkParameters object.
|
||||
* @param payload the payload to extract the block from.
|
||||
* @param serializer the serializer to use for this message.
|
||||
* @throws ProtocolException
|
||||
*/
|
||||
public Block(NetworkParameters params, ByteBuffer payload, MessageSerializer serializer)
|
||||
public Block(NetworkParameters params, ByteBuffer payload)
|
||||
throws ProtocolException {
|
||||
super(params, payload, serializer);
|
||||
super(params, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,7 +69,7 @@ public class FilteredBlock extends Message {
|
||||
@Override
|
||||
protected void parse() throws BufferUnderflowException, ProtocolException {
|
||||
byte[] headerBytes = Buffers.readBytes(payload, Block.HEADER_SIZE);
|
||||
header = params.getDefaultSerializer().makeBlock(ByteBuffer.wrap(headerBytes));
|
||||
header = new Block(params, ByteBuffer.wrap(headerBytes));
|
||||
merkleTree = new PartialMerkleTree(params, payload);
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ public class HeadersMessage extends Message {
|
||||
final BitcoinSerializer serializer = this.params.getSerializer();
|
||||
|
||||
for (int i = 0; i < numHeaders; ++i) {
|
||||
final Block newBlockHeader = serializer.makeBlock(payload);
|
||||
final Block newBlockHeader = new Block(params, payload);
|
||||
if (newBlockHeader.hasTransactions()) {
|
||||
throw new ProtocolException("Block header does not end with a null byte");
|
||||
}
|
||||
|
@ -1279,7 +1279,7 @@ public class Transaction extends ChildMessage {
|
||||
try {
|
||||
// Create a copy of this transaction to operate upon because we need make changes to the inputs and outputs.
|
||||
// It would not be thread-safe to change the attributes of the transaction object itself.
|
||||
Transaction tx = this.params.getDefaultSerializer().makeTransaction(ByteBuffer.wrap(bitcoinSerialize()));
|
||||
Transaction tx = new Transaction(params, ByteBuffer.wrap(bitcoinSerialize()));
|
||||
|
||||
// Clear input scripts in preparation for signing. If we're signing a fresh
|
||||
// transaction that step isn't very helpful, but it doesn't add much cost relative to the actual
|
||||
|
Loading…
Reference in New Issue
Block a user