Skip to content

Commit 25224a8

Browse files
committed
Replace CBlockHeader::GetHash with call to SerializeHash
Removes variability between LE and BE. As suggested by @sipa. adapted from bitcoin/bitcoin@a0ae79d
1 parent 49a7716 commit 25224a8

File tree

1 file changed

+4
-28
lines changed

1 file changed

+4
-28
lines changed

src/primitives/block.cpp

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
uint256 CBlockHeader::GetHash() const
1717
{
18-
#if defined(WORDS_BIGENDIAN)
1918
if (nVersion < 4) {
19+
#if defined(WORDS_BIGENDIAN)
2020
uint8_t data[80];
2121
WriteLE32(&data[0], nVersion);
2222
memcpy(&data[4], hashPrevBlock.begin(), hashPrevBlock.size());
@@ -25,36 +25,12 @@ uint256 CBlockHeader::GetHash() const
2525
WriteLE32(&data[72], nBits);
2626
WriteLE32(&data[76], nNonce);
2727
return HashQuark(data, data + 80);
28-
} else if (nVersion < 7) {
29-
uint8_t data[112];
30-
WriteLE32(&data[0], nVersion);
31-
memcpy(&data[4], hashPrevBlock.begin(), hashPrevBlock.size());
32-
memcpy(&data[36], hashMerkleRoot.begin(), hashMerkleRoot.size());
33-
WriteLE32(&data[68], nTime);
34-
WriteLE32(&data[72], nBits);
35-
WriteLE32(&data[76], nNonce);
36-
memcpy(&data[80], hashMerkleRoot.begin(), hashMerkleRoot.size());
37-
return Hash(data, data + 80);
38-
} else {
39-
uint8_t data[80];
40-
WriteLE32(&data[0], nVersion);
41-
memcpy(&data[4], hashPrevBlock.begin(), hashPrevBlock.size());
42-
memcpy(&data[36], hashMerkleRoot.begin(), hashMerkleRoot.size());
43-
WriteLE32(&data[68], nTime);
44-
WriteLE32(&data[72], nBits);
45-
WriteLE32(&data[76], nNonce);
46-
return Hash(data, data + 80);
47-
}
48-
4928
#else // Can take shortcut for little endian
50-
if (nVersion < 4)
5129
return HashQuark(BEGIN(nVersion), END(nNonce));
52-
53-
if (nVersion < 7)
54-
return Hash(BEGIN(nVersion), END(nAccumulatorCheckpoint));
55-
56-
return Hash(BEGIN(nVersion), END(nNonce));
5730
#endif
31+
}
32+
// version >= 4
33+
return SerializeHash(*this);
5834
}
5935

6036
std::string CBlock::ToString() const

0 commit comments

Comments
 (0)