Skip to content

Instantly share code, notes, and snippets.

@beber89
Created September 24, 2019 09:39
Show Gist options
  • Save beber89/d4223dd67c1740abf269d6387fe45dc3 to your computer and use it in GitHub Desktop.
Save beber89/d4223dd67c1740abf269d6387fe45dc3 to your computer and use it in GitHub Desktop.
miner-dapp-wasm/blockchain/block/doHash
func (blk *Block) doHash() {
type toBeHashed struct {
id uint64
lastBlockHash [32]byte
nonce uint64
payload Transaction
difficulty uint8
timestamp uint64
}
h := sha256.New()
var blkToBeHashed = toBeHashed{
blk.id, blk.lastBlockHash,
blk.nonce, blk.payload,
blk.difficulty, blk.timestamp}
byteBlk := fmt.Sprintf("%v", blkToBeHashed)
h.Write([]byte(byteBlk))
// transferring bits from sum into blk.hash
copy(blk.hash[:], h.Sum(nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment