Skip to content
Snippets Groups Projects
Commit a546dc36 authored by Mariusz Trela's avatar Mariusz Trela
Browse files

Extensions fix in `update_proposal` operation

parent 4b44fa5e
No related branches found
No related tags found
1 merge request!3Update branch + fix regarding `update_proposal` operation
......@@ -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)
......@@ -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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment