parser: present block hashes in big endian order

This commit is contained in:
George Tankersley
2018-11-16 21:57:21 +00:00
parent f4d5ff96ed
commit f42dea2b1e
2 changed files with 9 additions and 2 deletions

View File

@@ -150,6 +150,7 @@ func parseNBits(b []byte) *big.Int {
return new(big.Int).SetBytes(targetBytes)
}
// GetHash returns the bytes of a block hash in big-endian order.
func (hdr *blockHeader) GetHash() []byte {
if hdr.cachedHash != nil {
return hdr.cachedHash
@@ -165,6 +166,12 @@ func (hdr *blockHeader) GetHash() []byte {
digest := sha256.Sum256(serializedHeader)
digest = sha256.Sum256(digest[:])
// Reverse byte order
for i := 0; i < len(digest)/2; i++ {
j := len(digest) - 1 - i
digest[i], digest[j] = digest[j], digest[i]
}
hdr.cachedHash = digest[:]
return hdr.cachedHash
}