Here is the Go source to compute Header hash:
Code:
type BlockHeader struct {
// Standard Bitcoin fields.
Version uint32
HashPrevBlock []byte
HashMerkleRoot []byte
Timestamp uint32
Bits uint32
Nonce uint32
}
// HeaderHash calculates the block header hash.
// This is the fixed multiplier when searching for primes.
// NOTE: When converting to an Int the hash must be reversed.
func (bh *BlockHeader) HeaderHash() []byte {
hash := sha256.New()
binary.Write(hash, binary.LittleEndian, bh.Version)
hash.Write(bh.HashPrevBlock)
hash.Write(bh.HashMerkleRoot)
binary.Write(hash, binary.LittleEndian, bh.Timestamp)
binary.Write(hash, binary.LittleEndian, bh.Bits)
binary.Write(hash, binary.LittleEndian, bh.Nonce)
data := sha256.Sum256(hash.Sum(nil))
return data[:]
}
Get the values of the fields from the block:
http://primecoin.21stcenturymoneytalk.org/index.php?block_hash=963d17ba4dc753138078a2f56afb3af9674e2546822badff26837db9a0152106
To get an integer from the hash you need to do:
Code:
// hashToBig converts a hash number to an integer
func hashToBig(hash []byte) *big.Int {
tmp := make([]byte, len(hash))
copy(tmp, hash)
reverse(tmp)
return new(big.Int).SetBytes(tmp)
}
Hope it helps, I can give more examples if still unclear when I have time.