Created
September 24, 2019 09:39
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