Amend hashing API to fit with volatile fields
This commit is contained in:
parent
cc0865cd58
commit
5fd8716b38
@ -120,7 +120,7 @@ class BigInt(EosObject):
|
|||||||
def nbits(self):
|
def nbits(self):
|
||||||
return self.impl.bitLength()
|
return self.impl.bitLength()
|
||||||
|
|
||||||
def serialise(self):
|
def serialise(self, hashed=False):
|
||||||
return str(self)
|
return str(self)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -46,7 +46,7 @@ class BigInt(EosObject):
|
|||||||
def nbits(self):
|
def nbits(self):
|
||||||
return math.ceil(math.log2(self.impl)) if self.impl > 0 else 0
|
return math.ceil(math.log2(self.impl)) if self.impl > 0 else 0
|
||||||
|
|
||||||
def serialise(self):
|
def serialise(self, hashed=False):
|
||||||
return str(self)
|
return str(self)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -71,7 +71,12 @@ class SHA256:
|
|||||||
|
|
||||||
def update_obj(self, *values):
|
def update_obj(self, *values):
|
||||||
for value in values:
|
for value in values:
|
||||||
self.update_text(EosObject.to_json(EosObject.serialise_and_wrap(value)))
|
self.update_text(EosObject.to_json(EosObject.serialise_and_wrap(value, None, True)))
|
||||||
|
return self
|
||||||
|
|
||||||
|
def update_obj_raw(self, *values):
|
||||||
|
for value in values:
|
||||||
|
self.update_text(EosObject.to_json(EosObject.serialise_and_wrap(value, None, False)))
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def hash_as_b64(self):
|
def hash_as_b64(self):
|
||||||
|
@ -152,12 +152,12 @@ class EosObject(metaclass=EosObjectType):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def serialise_and_wrap(value, object_type=None):
|
def serialise_and_wrap(value, object_type=None, hashed=False):
|
||||||
if object_type:
|
if object_type:
|
||||||
if value:
|
if value:
|
||||||
return value.serialise()
|
return value.serialise(hashed)
|
||||||
return None
|
return None
|
||||||
return {'type': value._name, 'value': (value.serialise() if value else None)}
|
return {'type': value._name, 'value': (value.serialise(hashed) if value else None)}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def deserialise_and_unwrap(value, object_type=None):
|
def deserialise_and_unwrap(value, object_type=None):
|
||||||
@ -296,8 +296,8 @@ class DocumentObject(EosObject, metaclass=DocumentObjectType):
|
|||||||
setattr(self, attr, default)
|
setattr(self, attr, default)
|
||||||
|
|
||||||
# TNYI: Strange things happen with py_ attributes
|
# TNYI: Strange things happen with py_ attributes
|
||||||
def serialise(self):
|
def serialise(self, hashed=False):
|
||||||
return {(attr[3:] if attr.startswith('py_') else attr): val.serialise(getattr(self, attr)) for attr, val in self._fields.items()}
|
return {(attr[3:] if attr.startswith('py_') else attr): val.serialise(getattr(self, attr)) for attr, val in self._fields.items() if (val.hashed or not hashed)}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def deserialise(cls, value):
|
def deserialise(cls, value):
|
||||||
|
Loading…
Reference in New Issue
Block a user