Created
May 14, 2019 16:02
-
-
Save cyberpirate92/7f040c92251410e97289b784ab10368a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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