Last active
June 14, 2019 16:11
-
-
Save oldgitdaddy/086500d35b34c0bf38f8424b4d42522f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| function proof_of_work(difficulty, prev_hash, timestamp, merkle_root) { | |
| var hash = “1111111111111111111111111111111111111111111111111111111111111111”; | |
| var nonce = 0; | |
| //check if hash meets difficulty criteria (by counting number of zeros) | |
| while (hash.substring(0, difficulty) !== Array(difficulty + 1).join("0")) { | |
| //incrementing the nonce value every time the loop runs. | |
| nonce++; | |
| //recalculating the hash value | |
| hash = this.calculateHash(nonce, prev_hash, timestamp, merkle_root); | |
| } | |
| console.log("Block mined: " + hash) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment