The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
woop/blockchain.go

20 lines
515 B

package main
// Blockchain keeps a sequence of Blocks
type Blockchain struct {
blocks []*Block
}
// AddBlock saves provided data as a block in the blockchain
func (bc *Blockchain) AddBlock(data string) {
prevBlock := bc.blocks[len(bc.blocks)-1]
// TODO(minhdoan): Parse data.
newBlock := NewBlock({}, prevBlock.Hash)
bc.blocks = append(bc.blocks, newBlock)
}
// NewBlockchain creates a new Blockchain with genesis Block
func NewBlockchain() *Blockchain {
return &Blockchain{[]*Block{NewGenesisBlock()}}
}