Created
September 24, 2019 09:47
-
-
Save beber89/be0b382712f200ff10340509cd7e9bf3 to your computer and use it in GitHub Desktop.
miner-dapp-wasm/blockchain/block/hashValid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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