From 60c9a395f68b65a7f07564b8dcb0e50488930c8a Mon Sep 17 00:00:00 2001 From: 0Gitnick Date: Tue, 13 Aug 2019 15:04:20 -0500 Subject: [PATCH] Delegate finding leading zeroes to library functions --- onionr/onionrproofs.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/onionr/onionrproofs.py b/onionr/onionrproofs.py index 8ccc376d..f4f8b540 100755 --- a/onionr/onionrproofs.py +++ b/onionr/onionrproofs.py @@ -52,17 +52,15 @@ def getDifficultyForNewBlock(data, ourBlock=True): return retData -def getHashDifficulty(h): +def getHashDifficulty(hexHash): ''' - Return the amount of leading zeroes in a hex hash string (h) + Return the amount of leading zeroes in a hex hash string (hexHash) ''' difficulty = 0 - assert type(h) is str - for character in h: - if character == '0': - difficulty += 1 - else: - break + assert type(hexHash) is str + + difficulty = len(hexHash) - len(hexHash.lstrip('0')) + return difficulty def hashMeetsDifficulty(h):