Last active
September 24, 2019 09:37
-
-
Save beber89/8ced85a7b8a5003356a93e3142feb298 to your computer and use it in GitHub Desktop.
miner-dapp-wasm/blockchain/block/struct
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
// Block is the building entity for the blockchain | |
type Block struct { | |
id uint64 | |
lastBlockHash [32]byte | |
nonce uint64 | |
payload Transaction | |
difficulty uint8 | |
timestamp uint64 | |
hash [32]byte | |
} | |
// NewBlock constructor for Block | |
func NewBlock( | |
lastBlockHash [32]byte, payload Transaction, | |
difficulty uint8, timestamp uint64) Block { | |
var slice = make([]byte, 32) | |
var hash [32]byte | |
copy(hash[:], slice) | |
// Generate a new block id from a singleton blockIDGenerator | |
blk := Block{getBlockIDGenerator().generate(), | |
lastBlockHash, | |
0, | |
payload, | |
difficulty, | |
timestamp, | |
hash} | |
blk.mine() | |
return blk | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment