def import_gobject_from_monacoCoind(self, monacoCoind, rec):
import monacoCoinlib
import inflection
object_hex = rec['DataHex']
object_hash = rec['Hash']
gobj_dict = {
'object_hash': object_hash,
'object_fee_tx': rec['CollateralHash'],
'absolute_yes_count': rec['AbsoluteYesCount'],
'abstain_count': rec['AbstainCount'],
'yes_count': rec['YesCount'],
'no_count': rec['NoCount'],
}
# shim/monacoCoind conversion
object_hex = monacoCoinlib.SHIM_deserialise_from_monacoCoind(object_hex)
objects = monacoCoinlib.deserialise(object_hex)
subobj = None
obj_type, dikt = objects[0:2:1]
obj_type = inflection.pluralize(obj_type)
subclass = self._meta.reverse_rel[obj_type].model_class
# set object_type in govobj table
gobj_dict['object_type'] = subclass.govobj_type
# exclude any invalid model data from monacoCoind...
valid_keys = subclass.serialisable_fields()
subdikt = {k: dikt[k] for k in valid_keys if k in dikt}
# get/create, then sync vote counts from monacoCoind, with every run
govobj, created = self.get_or_create(object_hash=object_hash, defaults=gobj_dict)
if created:
printdbg("govobj created = %s" % created)
count = govobj.update(**gobj_dict).where(self.id == govobj.id).execute()
if count:
printdbg("govobj updated = %d" % count)
subdikt['governance_object'] = govobj
# get/create, then sync payment amounts, etc. from monacoCoind - monacoCoind is the master
try:
subobj, created = subclass.get_or_create(object_hash=object_hash, defaults=subdikt)
except (peewee.OperationalError, peewee.IntegrityError) as e:
# in this case, vote as delete, and log the vote in the DB
printdbg("Got invalid object from monacoCoind! %s" % e)
if not govobj.voted_on(signal=VoteSignals.delete, outcome=VoteOutcomes.yes):
govobj.vote(monacoCoind, VoteSignals.delete, VoteOutcomes.yes)
return (govobj, None)
if created:
printdbg("subobj created = %s" % created)
count = subobj.update(**subdikt).where(subclass.id == subobj.id).execute()
if count:
printdbg("subobj updated = %d" % count)
# ATM, returns a tuple w/gov attributes and the govobj
return (govobj, subobj)
评论列表
文章目录