Created
December 18, 2019 14:23
-
-
Save ssaurel/c56374cffb7cfd75b5e7674473d7346e to your computer and use it in GitHub Desktop.
Blockchain for the tutorial on the SSaurel's Blog
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
class Blockchain { | |
constructor(difficulty) { | |
this.difficulty = difficulty; | |
this.blocks = []; | |
// Add Genesis Block | |
var genesisBlock = new Block(0, null, Date.now(), "Genesis block"); | |
genesisBlock.mineBlock(this.difficulty); | |
this.blocks.push(genesisBlock); | |
} | |
} | |
Blockchain.prototype.newBlock = function (data) { | |
var latestBlock = this.blocks[this.blocks.length - 1]; | |
return new Block(latestBlock.index + 1, latestBlock.hash, | |
Date.now(), data); | |
} | |
Blockchain.prototype.addBlock = function(block) { | |
block.mineBlock(this.difficulty); | |
this.blocks.push(block); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment