Use NewBlock in Blockchain.AddBlock

This commit is contained in:
Ivan Kuznetsov 2017-08-16 13:55:18 +07:00
parent 6a8b988a61
commit 469281645c
1 changed files with 1 additions and 4 deletions

View File

@ -1,7 +1,5 @@
package main
import "time"
// Blockchain keeps a sequence of Blocks
type Blockchain struct {
blocks []*Block
@ -10,8 +8,7 @@ type Blockchain struct {
// AddBlock saves provided data as a block in the blockchain
func (bc *Blockchain) AddBlock(data string) {
prevBlock := bc.blocks[len(bc.blocks)-1]
newBlock := &Block{time.Now().Unix(), []byte(data), prevBlock.Hash, []byte("")}
newBlock.SetHash()
newBlock := NewBlock(data, prevBlock.Hash)
bc.blocks = append(bc.blocks, newBlock)
}