Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.