added methods for serialization of pow objects
This commit is contained in:
parent
2301264fdd
commit
b95982818e
11
proofow.py
11
proofow.py
@ -1,5 +1,6 @@
|
|||||||
from os import urandom
|
from os import urandom
|
||||||
from itertools import count
|
from itertools import count
|
||||||
|
from base64 import b64encode, b64decode
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
|
|
||||||
|
|
||||||
@ -28,6 +29,16 @@ class pow_base:
|
|||||||
hexresult = self._hexdigest(self._base + str(nonce).encode())
|
hexresult = self._hexdigest(self._base + str(nonce).encode())
|
||||||
return int(hexresult, 16) < self._target
|
return int(hexresult, 16) < self._target
|
||||||
|
|
||||||
|
def export(self):
|
||||||
|
return b64encode(str(self.difficulty).encode()
|
||||||
|
+ b':'
|
||||||
|
+ self.base).decode()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def load(cls, export):
|
||||||
|
difficulty, base = b64decode(export.encode()).split(b':', 1)
|
||||||
|
return cls(int(difficulty), base)
|
||||||
|
|
||||||
|
|
||||||
class pow_hashlib_base(pow_base):
|
class pow_hashlib_base(pow_base):
|
||||||
def _hexdigest(self, data):
|
def _hexdigest(self, data):
|
||||||
|
Loading…
Reference in New Issue
Block a user