diff --git a/graphenebase/account.py b/graphenebase/account.py index ebb41ea9..f492255f 100644 --- a/graphenebase/account.py +++ b/graphenebase/account.py @@ -331,6 +331,14 @@ def __bytes__(self): """ Returns the raw public key (has length 33)""" return bytes(self._pk) + @staticmethod + def fromBytes(d, prefix="GPH"): + _pk = hexlify(d[:33]).decode('ascii') + + k = PublicKey(_pk) + + return k, d[33:] + def __lt__(self, other): """ For sorting of public keys (due to graphene), we actually sort according to addresses diff --git a/graphenebase/types.py b/graphenebase/types.py index ca51da05..bcf85e02 100644 --- a/graphenebase/types.py +++ b/graphenebase/types.py @@ -33,6 +33,22 @@ def varintdecode(data): # pragma: no cover return result +def varintdecode2(data): + """ Varint decoding (with length counting) + """ + nbytes = 0 + shift = 0 + result = 0 + for c in data: + b = c # ord(c) not needed, `data` is bytes + result |= ((b & 0x7f) << shift) + nbytes += 1 + if not (b & 0x80): + break + shift += 7 + return result, nbytes + + def variable_buffer(s): """ Encode variable length buffer """ @@ -88,6 +104,11 @@ def __bytes__(self): def __str__(self): return '%d' % self.data + @staticmethod + def fromBytes(d): + val = struct.unpack("