Created
September 24, 2019 09:39
-
-
Save beber89/d4223dd67c1740abf269d6387fe45dc3 to your computer and use it in GitHub Desktop.
miner-dapp-wasm/blockchain/block/doHash
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) 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