Last active
June 21, 2018 06:57
-
-
Save felixklauke/ddbebb032d7fa730d6f82993ee42c4d9 to your computer and use it in GitHub Desktop.
Finding a new proof of work.
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
private static final String VALIDATION_PREFIX = "00"; | |
public int proofOfWork() { | |
return proofOfWork(getLastBlock().getProofOfWork()); | |
} | |
private int proofOfWork(int lastProof) { | |
int proof = 0; | |
while (!validate(lastProof, proof)) { | |
proof++; | |
} | |
return proof; | |
} | |
private boolean validateProofOfWork(int lastProof, int currentProof) { | |
String result = lastProof + "" + currentProof; | |
return DigestUtils.sha256Hex(result).startsWith(VALIDATION_PREFIX); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment