Skip to content

Instantly share code, notes, and snippets.

@beber89
Last active September 24, 2019 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beber89/8ced85a7b8a5003356a93e3142feb298 to your computer and use it in GitHub Desktop.
Save beber89/8ced85a7b8a5003356a93e3142feb298 to your computer and use it in GitHub Desktop.
miner-dapp-wasm/blockchain/block/struct
// 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