Skip to content

Instantly share code, notes, and snippets.

@cyberpirate92
Created May 14, 2019 16:02
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 cyberpirate92/7f040c92251410e97289b784ab10368a to your computer and use it in GitHub Desktop.
Save cyberpirate92/7f040c92251410e97289b784ab10368a to your computer and use it in GitHub Desktop.
public boolean isValid() throws NoSuchAlgorithmException {
var pre = "";
for(;pre.length() < difficulty; pre += "0");
for (var i=1; i < chain.size(); ++i) {
var previousBlock = chain.get(i-1);
var currentBlock = chain.get(i);
if (!currentBlock.getHash().startsWith(pre) || !currentBlock.previousBlockHash.equals(previousBlock.getHash())) {
return false;
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment