added property base to pow_base

This commit is contained in:
Kjistóf 2017-12-01 23:57:52 +01:00
parent dcf203111c
commit 921352c8d9

View File

@ -3,8 +3,11 @@ from itertools import count
from hashlib import sha256 from hashlib import sha256
class pow_base: class pow_base:
@property
def base(self):
return self._base
def __init__(self, difficulty, base=None): def __init__(self, difficulty, base=None):
self._base = urandom(self._bits//8) if not base else base self._base = urandom(self._bits//8) if not base else base
self._target = 2 ** (self._bits - difficulty) self._target = 2 ** (self._bits - difficulty)
@ -19,13 +22,11 @@ class pow_base:
return int(hexresult, 16) < self._target return int(hexresult, 16) < self._target
class pow_hashlib_base(pow_base): class pow_hashlib_base(pow_base):
def _hexdigest(self, data): def _hexdigest(self, data):
return self._hasher(data).hexdigest() return self._hasher(data).hexdigest()
class pow256(pow_hashlib_base): class pow256(pow_hashlib_base):
_bits = 256 _bits = 256
_hasher = sha256 _hasher = sha256