added a max_attempts parameter to work()
This commit is contained in:
parent
85baa0d61f
commit
d1244f8b00
@ -12,10 +12,12 @@ class pow_base:
|
||||
self._base = urandom(self._bits//8) if not base else base
|
||||
self._target = 2 ** (self._bits - difficulty)
|
||||
|
||||
def work(self):
|
||||
for nonce in count():
|
||||
def work(self, max_attempts=0):
|
||||
cycles = count() if max_attempts == 0 else range(max_attempts)
|
||||
for nonce in cycles:
|
||||
if self.verify(nonce):
|
||||
return nonce
|
||||
raise RuntimeError('Failed to find a nonce in {} iterations!'.format(max_attempts))
|
||||
|
||||
def verify(self, nonce):
|
||||
hexresult = self._hexdigest(self._base + str(nonce).encode())
|
||||
|
Loading…
Reference in New Issue
Block a user