diff --git a/proofow.py b/proofow.py index c6e524f..6f0e205 100644 --- a/proofow.py +++ b/proofow.py @@ -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())