parser: clarify difference between block hash and block header hash
This commit is contained in:
parent
e69779195f
commit
c947b00d36
|
@ -64,13 +64,6 @@ type EquihashSize struct {
|
||||||
Size uint16 // always 1344
|
Size uint16 // always 1344
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadBlockHeader(blockHeader *BlockHeader, data []byte) error {
|
|
||||||
if blockHeader.rawBlockHeader == nil {
|
|
||||||
blockHeader.rawBlockHeader = new(rawBlockHeader)
|
|
||||||
}
|
|
||||||
return blockHeader.UnmarshalBinary(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hdr *rawBlockHeader) MarshalBinary() ([]byte, error) {
|
func (hdr *rawBlockHeader) MarshalBinary() ([]byte, error) {
|
||||||
serBytes := make([]byte, 0, SER_BLOCK_HEADER_SIZE)
|
serBytes := make([]byte, 0, SER_BLOCK_HEADER_SIZE)
|
||||||
serBuf := bytes.NewBuffer(serBytes)
|
serBuf := bytes.NewBuffer(serBytes)
|
||||||
|
@ -89,12 +82,12 @@ func (hdr *rawBlockHeader) UnmarshalBinary(data []byte) error {
|
||||||
|
|
||||||
type BlockHeader struct {
|
type BlockHeader struct {
|
||||||
*rawBlockHeader
|
*rawBlockHeader
|
||||||
cachedBlockHash []byte
|
cachedHash []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hdr *BlockHeader) GetBlockHash() []byte {
|
func (hdr *BlockHeader) GetBlockHeaderHash() []byte {
|
||||||
if hdr.cachedBlockHash != nil {
|
if hdr.cachedHash != nil {
|
||||||
return hdr.cachedBlockHash
|
return hdr.cachedHash
|
||||||
}
|
}
|
||||||
|
|
||||||
serializedHeader, err := hdr.MarshalBinary()
|
serializedHeader, err := hdr.MarshalBinary()
|
||||||
|
@ -107,11 +100,19 @@ func (hdr *BlockHeader) GetBlockHash() []byte {
|
||||||
digest := sha256.Sum256(serializedHeader)
|
digest := sha256.Sum256(serializedHeader)
|
||||||
digest = sha256.Sum256(digest[:])
|
digest = sha256.Sum256(digest[:])
|
||||||
|
|
||||||
hdr.cachedBlockHash = digest[:]
|
hdr.cachedHash = digest[:]
|
||||||
return hdr.cachedBlockHash
|
return hdr.cachedHash
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hdr *BlockHeader) GetSerializedSize() int {
|
func (hdr *BlockHeader) GetSerializedSize() int {
|
||||||
// TODO: Make this dynamic. Low priority; it's unlikely to change.
|
// TODO: Make this dynamic. Low priority; it's unlikely to change.
|
||||||
return SER_BLOCK_HEADER_SIZE
|
return SER_BLOCK_HEADER_SIZE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ReadBlockHeader(blockHeader *BlockHeader, data []byte) error {
|
||||||
|
if blockHeader.rawBlockHeader == nil {
|
||||||
|
blockHeader.rawBlockHeader = new(rawBlockHeader)
|
||||||
|
}
|
||||||
|
return blockHeader.UnmarshalBinary(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ func TestBlockHeader(t *testing.T) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
hash := blockHeader.GetBlockHash()
|
hash := blockHeader.GetBlockHeaderHash()
|
||||||
|
|
||||||
// This is not necessarily true for anything but our current test cases.
|
// This is not necessarily true for anything but our current test cases.
|
||||||
for _, b := range hash[28:] {
|
for _, b := range hash[28:] {
|
||||||
|
|
Loading…
Reference in New Issue