Skip to content

Instantly share code, notes, and snippets.

@lhartikk
Created February 24, 2017 22:13
Show Gist options
  • Save lhartikk/bfc392a9d0156582de42b0d8fa2a0d5a to your computer and use it in GitHub Desktop.
Save lhartikk/bfc392a9d0156582de42b0d8fa2a0d5a to your computer and use it in GitHub Desktop.
var isValidNewBlock = (newBlock, previousBlock) => {
if (previousBlock.index + 1 !== newBlock.index) {
console.log('invalid index');
return false;
} else if (previousBlock.hash !== newBlock.previousHash) {
console.log('invalid previoushash');
return false;
} else if (calculateHashForBlock(newBlock) !== newBlock.hash) {
console.log('invalid hash: ' + calculateHashForBlock(newBlock) + ' ' + newBlock.hash);
return false;
}
return true;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment