diff --git a/beembase/objects.py b/beembase/objects.py index 934f5b6db4d923411f5e257a484dab46a4234e79..0b712c1df26e4e07269be646431902ef83ae6055 100644 --- a/beembase/objects.py +++ b/beembase/objects.py @@ -336,7 +336,7 @@ class UpdateProposalEndDate(GrapheneObject): super(UpdateProposalEndDate, self).__init__( OrderedDict([ - ('end_date', PointInTime(kwargs['update_proposal_end_date'])), + ('end_date', PointInTime(kwargs['end_date'])), ])) @@ -347,25 +347,26 @@ class UpdateProposalExtensions(Static_variant): Example:: - [1, - {'end_date': '2021-03-28T04:00:00'} - ] + { + 'type': '1', + 'value': + { + 'end_date': '2021-04-05T13:39:48' + } + } """ def __init__(self, o): - if type(o) == dict and 'type' in o and 'value' in o: - if o['type'] == "end_date": - type_id = 1 - else: - type_id = ~0 - data = o['value'] - else: - type_id, data = o + if isinstance(o, dict) and 'type' in o and 'value' in o: + if o['type'] == "update_proposal_end_date": + type_id = 1 + else: + type_id = ~0 if type_id == 1: - data = (UpdateProposalEndDate(data)) + data = (UpdateProposalEndDate(o['value'])) else: raise Exception("Unknown UpdateProposalExtension") - super(UpdateProposalExtensions, self).__init__(data, type_id) + super(UpdateProposalExtensions, self).__init__(data, type_id, False) diff --git a/beemgraphenebase/types.py b/beemgraphenebase/types.py index b62bd2a532eb8bcc9854bd03145c7dd107757147..62e0f66ddf28eda1c50c61f2137a7ed97ddacdd7 100644 --- a/beemgraphenebase/types.py +++ b/beemgraphenebase/types.py @@ -347,18 +347,23 @@ class Optional(object): class Static_variant(object): - def __init__(self, d, type_id): + def __init__(self, d, type_id, legacy_style = True): self.data = d self.type_id = type_id + #`legacy_style = True` it means, that static variant is treated like an array, otherwise like an object + self.legacy_style = legacy_style + def __bytes__(self): """Returns bytes representation.""" return varint(self.type_id) + py23_bytes(self.data) def __str__(self): """Returns data as string.""" - return json.dumps([self.type_id, self.data.json()]) - + if self.legacy_style: + return json.dumps([self.type_id, self.data.json()]) + else: + return json.dumps({ 'type': self.type_id, 'value': self.data.json() }) class Map(object): def __init__(self, data):