Skip to content

Instantly share code, notes, and snippets.

@felixklauke
Last active June 21, 2018 06:57
Show Gist options
  • Save felixklauke/ddbebb032d7fa730d6f82993ee42c4d9 to your computer and use it in GitHub Desktop.
Save felixklauke/ddbebb032d7fa730d6f82993ee42c4d9 to your computer and use it in GitHub Desktop.
Finding a new proof of work.
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