Skip to content

Instantly share code, notes, and snippets.

@nosequeldeebee
Created February 6, 2018 19:49
Show Gist options
  • Save nosequeldeebee/2fadb1ccb5da8307df9bd614bfb9524b to your computer and use it in GitHub Desktop.
Save nosequeldeebee/2fadb1ccb5da8307df9bd614bfb9524b to your computer and use it in GitHub Desktop.
// make sure block is valid by checking index, and comparing the hash of the previous block
func isBlockValid(newBlock, oldBlock Block) bool {
if oldBlock.Index+1 != newBlock.Index {
return false
}
if oldBlock.Hash != newBlock.PrevHash {
return false
}
if calculateHash(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