Skip to content

Instantly share code, notes, and snippets.

@beber89
Created September 24, 2019 09:47
Show Gist options
  • Save beber89/be0b382712f200ff10340509cd7e9bf3 to your computer and use it in GitHub Desktop.
Save beber89/be0b382712f200ff10340509cd7e9bf3 to your computer and use it in GitHub Desktop.
miner-dapp-wasm/blockchain/block/hashValid
func (blk *Block) hashValid() bool {
hash := blk.hash
// put in mind Little Endian
// converting the 8 most significant bytes of hash to one number int
hashAsInt := uint64(0)
for i := uint8(1); i <= uint8(8); i++ {
hashAsInt = uint64(hash[32-i])<<((8-i)*8) + hashAsInt
}
diff := (uint64(1)<<63)>>(blk.difficulty-1) - 1
return hashAsInt <= diff
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment