Skip to content

Instantly share code, notes, and snippets.

@fernandoporazzi
Created January 18, 2019 14:16
Show Gist options
  • Save fernandoporazzi/8023e0d00b3374c283dd79f17161a3fe to your computer and use it in GitHub Desktop.
Save fernandoporazzi/8023e0d00b3374c283dd79f17161a3fe to your computer and use it in GitHub Desktop.
func (b *Blockchain) CreateGenesisBlock() {
block := block.CreateBlock()
block.Index = 0
block.PreviousHash = "0000000000000000000000000000000000000000000000000000000000000000"
block.Data = "Genesis Block"
block.Difficulty = b.Difficulty
block.Mine()
b.Append(block)
}
func (b *Blockchain) AddBlock(data string) {
block := block.CreateBlock()
block.Index = b.Index
block.PreviousHash = b.GetLastBlock().Hash
block.Data = data
block.Difficulty = b.Difficulty
block.Mine()
b.Append(block)
}
func (b *Blockchain) Append(block block.Block) {
b.Index = b.Index + 1
b.Blocks = append(b.Blocks, block)
}
func (b *Blockchain) GetLastBlock() block.Block {
return b.Blocks[len(b.Blocks)-1]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment