Created
January 18, 2019 14:16
-
-
Save fernandoporazzi/8023e0d00b3374c283dd79f17161a3fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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