mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-11-03 05:57:21 +00:00
Replace magic numbers for header sizes with constants
This commit is contained in:
committed by
Andreas Schildbach
parent
a4c9ad6894
commit
4375f66d20
@@ -108,7 +108,7 @@ public class Block extends Message {
|
||||
time = System.currentTimeMillis() / 1000;
|
||||
prevBlockHash = Sha256Hash.ZERO_HASH;
|
||||
|
||||
length = 80;
|
||||
length = HEADER_SIZE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -70,7 +70,7 @@ public class HeadersMessage extends Message {
|
||||
cursor = saveCursor;
|
||||
|
||||
// Each header has 80 bytes and one more byte for transactions number which is 00.
|
||||
length = 81 * (int)numHeaders;
|
||||
length = (Block.HEADER_SIZE + 1) * (int)numHeaders;
|
||||
}
|
||||
|
||||
long numHeaders = readVarInt();
|
||||
@@ -83,11 +83,11 @@ public class HeadersMessage extends Message {
|
||||
for (int i = 0; i < numHeaders; ++i) {
|
||||
// Read 80 bytes of the header and one more byte for the transaction list, which is always a 00 because the
|
||||
// transaction list is empty.
|
||||
byte[] blockHeader = readBytes(81);
|
||||
if (blockHeader[80] != 0)
|
||||
byte[] blockHeader = readBytes(Block.HEADER_SIZE + 1);
|
||||
if (blockHeader[Block.HEADER_SIZE] != 0)
|
||||
throw new ProtocolException("Block header does not end with a null byte");
|
||||
Block newBlockHeader = this.params.getSerializer(true)
|
||||
.makeBlock(blockHeader, 81);
|
||||
.makeBlock(blockHeader, Block.HEADER_SIZE + 1);
|
||||
blockHeaders.add(newBlockHeader);
|
||||
}
|
||||
|
||||
|
||||
@@ -1647,7 +1647,7 @@ public class PeerGroup implements TransactionBroadcaster {
|
||||
@Override
|
||||
public synchronized void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft) {
|
||||
blocksInLastSecond++;
|
||||
bytesInLastSecond += 80; // For the header.
|
||||
bytesInLastSecond += Block.HEADER_SIZE;
|
||||
List<Transaction> blockTransactions = block.getTransactions();
|
||||
// This whole area of the type hierarchy is a mess.
|
||||
int txCount = (blockTransactions != null ? countAndMeasureSize(blockTransactions) : 0) +
|
||||
|
||||
Reference in New Issue
Block a user