-
-
Save matheusml/3ff5e25ea8a3989fcfae387b6b910c55 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
const Block = require('./block') | |
class Blockchain { | |
constructor() { | |
this.blocks = [new Block()] | |
this.index = 1 | |
} | |
getLastBlock() { | |
return this.blocks[this.blocks.length - 1] | |
} | |
addBlock(data) { | |
const index = this.index | |
const previousHash = this.getLastBlock().hash | |
const block = new Block(index, previousHash, data) | |
this.index++ | |
this.blocks.push(block) | |
} | |
} | |
module.exports = Blockchain |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment