blockchain-poc/block.go
Brian Buller 72004f2396 Step 2:
- Proof of work established
2017-09-22 11:48:05 -05:00

36 lines
592 B
Go

package main
import (
"math"
"time"
)
var (
maxNonce = math.MaxInt64
)
type Block struct {
Timestamp int64
Data []byte
PrevBlockHash []byte
Hash []byte
Nonce int
}
// NewBlock returns a new block, ready to be added to the chain
func NewBlock(data string, prevBlockHash []byte) *Block {
block := &Block{
Timestamp: time.Now().Unix(),
Data: []byte(data),
PrevBlockHash: prevBlockHash,
Hash: []byte{},
}
pow := NewProofOfWork(block)
nonce, hash := pow.Run()
block.Hash = hash[:]
block.Nonce = nonce
return block
}