Skip to content

Instantly share code, notes, and snippets.

@matheusml
Created December 5, 2017 20:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save matheusml/0cae69ff3b61192d747660b52c8a3e10 to your computer and use it in GitHub Desktop.
isValid() {
for (let i = 1; i < this.blocks.length; i++) {
const currentBlock = this.blocks[i]
const previousBlock = this.blocks[i - 1]
if (currentBlock.hash !== currentBlock.generateHash()) {
return false
}
if (currentBlock.index !== previousBlock.index + 1) {
return false
}
if (currentBlock.previousHash !== previousBlock.hash) {
return false
}
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment