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):
|
||||
return self.impl.bitLength()
|
||||
|
||||
def serialise(self):
|
||||
def serialise(self, hashed=False):
|
||||
return str(self)
|
||||
|
||||
@classmethod
|
||||
|
@ -46,7 +46,7 @@ class BigInt(EosObject):
|
||||
def nbits(self):
|
||||
return math.ceil(math.log2(self.impl)) if self.impl > 0 else 0
|
||||
|
||||
def serialise(self):
|
||||
def serialise(self, hashed=False):
|
||||
return str(self)
|
||||
|
||||
@classmethod
|
||||
|
@ -71,7 +71,12 @@ class SHA256:
|
||||
|
||||
def update_obj(self, *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
|
||||
|
||||
def hash_as_b64(self):
|
||||
|
@ -152,12 +152,12 @@ class EosObject(metaclass=EosObjectType):
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def serialise_and_wrap(value, object_type=None):
|
||||
def serialise_and_wrap(value, object_type=None, hashed=False):
|
||||
if object_type:
|
||||
if value:
|
||||
return value.serialise()
|
||||
return value.serialise(hashed)
|
||||
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
|
||||
def deserialise_and_unwrap(value, object_type=None):
|
||||
@ -296,8 +296,8 @@ class DocumentObject(EosObject, metaclass=DocumentObjectType):
|
||||
setattr(self, attr, default)
|
||||
|
||||
# TNYI: Strange things happen with py_ attributes
|
||||
def serialise(self):
|
||||
return {(attr[3:] if attr.startswith('py_') else attr): val.serialise(getattr(self, attr)) for attr, val in self._fields.items()}
|
||||
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() if (val.hashed or not hashed)}
|
||||
|
||||
@classmethod
|
||||
def deserialise(cls, value):
|
||||
|
Loading…
Reference in New Issue
Block a user