blockchain-poc/blockchain.go
Brian Buller 7ffe75002c Step 1 Complete
Create blockchain
- Genesis Block
- Additional Blocks
2017-09-22 11:28:11 -05:00

22 lines
514 B
Go

package main
type Blockchain struct {
blocks []*Block
}
func NewBlockchain() *Blockchain {
return &Blockchain{[]*Block{NewGenesisBlock()}}
}
// NewGenesisBlock creates a new Genesis Block to start the blockchain
func NewGenesisBlock() *Block {
return NewBlock("Genesis Block", []byte{})
}
// AddBlock adds a block to the blockchain
func (bc *Blockchain) AddBlock(data string) {
prevBlock := bc.blocks[len(bc.blocks)-1]
newBlock := NewBlock(data, prevBlock.Hash)
bc.blocks = append(bc.blocks, newBlock)
}