Use NewBlock in Blockchain.AddBlock
This commit is contained in:
parent
6a8b988a61
commit
469281645c
|
@ -1,7 +1,5 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "time"
|
|
||||||
|
|
||||||
// Blockchain keeps a sequence of Blocks
|
// Blockchain keeps a sequence of Blocks
|
||||||
type Blockchain struct {
|
type Blockchain struct {
|
||||||
blocks []*Block
|
blocks []*Block
|
||||||
|
@ -10,8 +8,7 @@ type Blockchain struct {
|
||||||
// AddBlock saves provided data as a block in the blockchain
|
// AddBlock saves provided data as a block in the blockchain
|
||||||
func (bc *Blockchain) AddBlock(data string) {
|
func (bc *Blockchain) AddBlock(data string) {
|
||||||
prevBlock := bc.blocks[len(bc.blocks)-1]
|
prevBlock := bc.blocks[len(bc.blocks)-1]
|
||||||
newBlock := &Block{time.Now().Unix(), []byte(data), prevBlock.Hash, []byte("")}
|
newBlock := NewBlock(data, prevBlock.Hash)
|
||||||
newBlock.SetHash()
|
|
||||||
bc.blocks = append(bc.blocks, newBlock)
|
bc.blocks = append(bc.blocks, newBlock)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue