Message: from within the hierarchy, construct child messages directly

There is no point in taking the `MessageSerializer` route.
This commit is contained in:
Andreas Schildbach 2023-03-29 22:32:04 +02:00
parent b2c54e8bf4
commit 795f64b43d
5 changed files with 6 additions and 7 deletions

View File

@ -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);
}
/**

View File

@ -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);
}
/**

View File

@ -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);
}

View File

@ -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");
}

View File

@ -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