Skip to content

Instantly share code, notes, and snippets.

@matheusml
Created December 5, 2017 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matheusml/3ff5e25ea8a3989fcfae387b6b910c55 to your computer and use it in GitHub Desktop.
Save matheusml/3ff5e25ea8a3989fcfae387b6b910c55 to your computer and use it in GitHub Desktop.
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