def prepare(self, anond): try: object_hash = anond.rpc_command(*self.get_prepare_command()) printdbg("Submitted: [%s]" % object_hash) self.go.object_fee_tx = object_hash self.go.save() manual_submit = ' '.join(self.get_submit_command()) print(manual_submit) except JSONRPCException as e: print("Unable to prepare: %s" % e.message)
def sync(self, anond): golist = anond.rpc_command('gobject', 'list') # objects which are removed from the network should be removed from the DB try: for purged in self.purged_network_objects(list(golist.keys())): # SOMEDAY: possible archive step here purged.delete_instance(recursive=True, delete_nullable=True) for item in golist.values(): (go, subobj) = self.import_gobject_from_anond(anond, item) except Exception as e: printdbg("Got an error upon import: %s" % e)
def vote(self, anond, signal, outcome): import anonlib # At this point, will probably never reach here. But doesn't hurt to # have an extra check just in case objects get out of sync (people will # muck with the DB). if (self.object_hash == '0' or not misc.is_hash(self.object_hash)): printdbg("No governance object hash, nothing to vote on.") return # have I already voted on this gobject with this particular signal and outcome? if self.voted_on(signal=signal): printdbg("Found a vote for this gobject/signal...") vote = self.votes.where(Vote.signal == signal)[0] # if the outcome is the same, move on, nothing more to do if vote.outcome == outcome: # move on. printdbg( "Already voted for this same gobject/signal/outcome, no need to re-vote." ) return else: printdbg( "Found a STALE vote for this gobject/signal, deleting so that we can re-vote." ) vote.delete_instance() else: printdbg("Haven't voted on this gobject/signal yet...") # now ... vote! vote_command = self.get_vote_command(signal, outcome) printdbg(' '.join(vote_command)) output = anond.rpc_command(*vote_command) # extract vote output parsing to external lib voted = anonlib.did_we_vote(output) if voted: printdbg('VOTE success, saving Vote object to database') Vote(governance_object=self, signal=signal, outcome=outcome, object_hash=self.object_hash).save() else: printdbg('VOTE failed, trying to sync with network vote') self.sync_network_vote(anond, signal)