Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Bruno Ely Reis Garcia brunoerg

🏠
Working from home
Block or report user

Report or block brunoerg

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@brunoerg
brunoerg / pow.py
Last active Sep 17, 2019
A basic function to understand how PoW works
View pow.py
def hashMatchesDifficulty(self, hash, difficulty):
hashBinary = binascii.unhexlify(hash)
requiredPrefix = '0'*int(difficulty)
return hashBinary.startswith(requiredPrefix)
def findBlock(self, index, previousHash, timestamp, data, difficulty):
nonce = 0
while True:
hash = self.calculateHash(index, previousHash, timestamp, data, difficulty, nonce)
if self.hashMatchesDifficulty(hash, difficulty):
You can’t perform that action at this time.