Last active
July 3, 2018 07:05
-
-
Save snavruzov/9b2f88928d1c5acb09e4915100f31758 to your computer and use it in GitHub Desktop.
Pseudocode of PoW
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
function proof_of_work(self, last_proof) { | |
/** | |
Найти такое число B который hash(AB) содержит последующие 10 нулей | |
где A есть предыдущее значение B | |
A - предыдущее доказательство | |
B - новое доказательство | |
**/ | |
proof = 0; | |
while validate_proof(last_proof, proof) is False: | |
proof += 1; //nonce | |
return proof; | |
} | |
function validate_proof(last_proof, proof) { | |
/** | |
Вычисляем значение хеша пока не получим 10 последующих нулей в начале хеша | |
**/ | |
guess = (last_proof)+(proof); | |
enocoded_guess = guess.encode() // Кодируем значение | |
guess_hash = hashlib.sha256(guess).hexdigest(); //генерим хеш | |
return guess_hash[:10] == '0000000000'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment