def doPrepare( self, event ): printd( "doPrepare: event = ", event.__dict__ ) govobj = GFACTORY.createById( event.governance_object_id ) printd( "doPrepare: govobj = ", govobj.__dict__ ) if isinstance( govobj, Superblock ): # Superblocks now require no preparation event.prepare_time = misc.get_epoch() event.store() return cmd = "gobject prepare %(object_parent_hash)s %(object_revision)s %(object_creation_time)s %(object_name)s %(object_data)s" % govobj.__dict__ printd( "doPrepare: cmd = ", cmd ) result = rpc_command( cmd ) printd( "doPrepare: result = ", result ) if misc.is_hash( result ): hashtx = misc.clean_hash( result ) printd( " -- got hash:", hashtx ) govobj.object_fee_tx = hashtx printd( "doPrepare: Calling govobj.store, govobj = ", govobj.__dict__ ) govobj.store() event.prepare_time = misc.get_epoch() event.store() else: printd( " -- got error:", result ) event.error_time = misc.get_epoch() # separately update event error message event.error_message = result event.store()
def submit_events(): sql = "select id from event where start_time < NOW() and prepare_time < NOW() and prepare_time > 0 and submit_time = 0" c = libmysql.db.cursor() c.execute( sql ) rows = c.fetchall() for row in rows: event = Event() event.load(row[0]) govobj = GovernanceObject() print event.get_id() govobj.load(event.get_id()) hash = govobj.get_field("object_fee_tx") print "# SUBMIT PREPARED EVENTS FOR DASH NETWORK" print print " -- cmd : ", govobj.get_submit_command() print print " -- executing event ... getting fee_tx hash" if misc.is_hash(hash): tx = dashd.CTransaction() if tx.load(hash): print " -- confirmations: ", tx.get_confirmations() if tx.get_confirmations() >= CONFIRMATIONS_REQUIRED: event.set_submitted() print " -- executing event ... getting fee_tx hash" result = dashd.rpc_command(govobj.get_submit_command()) if misc.is_hash(result): print " -- got result", result govobj.update_field("object_hash", result) event.save() govobj.save() libmysql.db.commit() return 1 else: print " -- got error", result else: print " -- waiting for confirmation" return 0
def vote( self, govObj, signal, outcome ): objHash = govObj.object_hash if not misc.is_hash( objHash ): raise( Exception( "AutoVoteTask.vote ERROR: Missing object hash for object: %s" % ( govObj.__dict__ ) ) ) command = "gobject vote-conf %s %s %s" % ( objHash, signal, outcome ) printd( "vote: command = ", command ) rpc_command( command ) govObj.object_status = 'VOTED' govObj.store()
def doSubmit( self, event ): govobj = GFACTORY.createById( event.governance_object_id ) if isinstance( govobj, Superblock ): # Fee no longer needed for Superblocks cmd = "gobject submit %(object_parent_hash)s %(object_revision)s %(object_creation_time)s %(object_name)s %(object_data)s" % govobj.__dict__ else: cmd = "gobject submit %(object_parent_hash)s %(object_revision)s %(object_creation_time)s %(object_name)s %(object_data)s %(object_fee_tx)s" % govobj.__dict__ if not misc.is_hash( govobj.object_fee_tx ): printd( "doSubmit: Warning no object_fee_tx hash" ) return printd( "doSubmit: cmd = ", cmd ) result = rpc_command( cmd ) printd( "doSubmit: result = ", result ) if misc.is_hash( result ): event.submit_time = misc.get_epoch() event.store() govobj.object_hash = result govobj.store()
def vote(self, agnid, signal, outcome): import agnilib # 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 = agnid.rpc_command(*vote_command) # extract vote output parsing to external lib voted = agnilib.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(agnid, signal)
def is_valid(self, chaincoind): import decimal printdbg("In Superblock#is_valid, for SB: %s" % self.__dict__) # it's a string from the DB... addresses = self.payment_addresses.split('|') for addr in addresses: if not chaincoind.validate_address(addr): printdbg("\tInvalid address [%s], returning False" % addr) return False amounts = self.payment_amounts.split('|') for amt in amounts: if not misc.is_numeric(amt): printdbg("\tAmount [%s] is not numeric, returning False" % amt) return False # no negative or zero amounts allowed damt = decimal.Decimal(amt) if not damt > 0: printdbg("\tAmount [%s] is zero or negative, returning False" % damt) return False # verify proposal hashes correctly formatted... if len(self.proposal_hashes) > 0: hashes = self.proposal_hashes.split('|') for object_hash in hashes: if not misc.is_hash(object_hash): printdbg("\tInvalid proposal hash [%s], returning False" % object_hash) return False # ensure number of payment addresses matches number of payments if len(addresses) != len(amounts): printdbg( "\tNumber of payment addresses [%s] != number of payment amounts [%s], returning False" % (len(addresses), len(amounts))) return False printdbg("Leaving Superblock#is_valid, Valid = True") return True
def prepare_events(): sql = "select id from event where start_time < NOW() and error_time = 0 and prepare_time = 0" c = libmysql.db.cursor() c.execute( sql ) rows = c.fetchall() for row in rows: event = Event() event.load(row[0]) govobj = GovernanceObject() govobj.load(event.get_id()) print "# PREPARING EVENTS FOR DASH NETWORK" print print " -- cmd : ", govobj.get_prepare_command() print result = dashd.rpc_command(govobj.get_prepare_command()) print " -- executing event ... getting fee_tx hash" # todo: what should it do incase of error? if misc.is_hash(result): hashtx = misc.clean_hash(result) print " -- got hash:", hashtx govobj.update_field("object_fee_tx", hashtx) govobj.save() event.update_field("prepare_time", misc.get_epoch()) event.save() libmysql.db.commit() return 1 else: print " -- got error:", result event.update_field("error_time", misc.get_epoch()) event.save() # separately update event error message event.update_error_message(result) libmysql.db.commit() return 0
for amt in amounts: icbet misc.is_numeric(amt): printdbg("\tAmount [%s] is not numeric, returning False" % amt) return False # no negative or zero amounts allowed damt = decimal.Decimal(amt) icbet damt > 0: printdbg("\tAmount [%s] is zero or negative, returning False" % damt) return False # verify proposal hashes correctly formatted... if len(self.proposal_hashes) > 0: hashes = self.proposal_hashes.split('|') for object_hash in hashes: icbet misc.is_hash(object_hash): printdbg("\tInvalid proposal hash [%s], returning False" % object_hash) return False # ensure number of payment addresses matches number of payments if len(addresses) != len(amounts): printdbg("\tNumber of payment addresses [%s] != number of payment amounts [%s], returning False" % (len(addresses), len(amounts))) return False printdbg("Leaving Superblock#is_valid, Valid = True") return True def hash(self): import combodelib return combodelib.hashit(self.serialise())