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 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 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 doPrepare(self, event): printd("doPrepare: event = ", event.__dict__) govobj = GFACTORY.createById(event.governance_object_id) printd("doPrepare: govobj = ", govobj.__dict__) 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 sync(self, dashd): golist = dashd.rpc_command('gobject', 'list') # objects which are removed from the network should be removed from the DB 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_dashd(dashd, item)
def isTestnet(): result = rpc_command("getinfo") lines = result.splitlines() for line in lines: m = re.match(r'^.*testnet.*:\s*(\S+)\s*,\s*$', line) if m is not None: value = m.group(1).lower() if value == "true": return True else: return False return None
def isTestnet(): result = rpc_command( "getinfo" ) lines = result.splitlines() for line in lines: m = re.match( r'^.*testnet.*:\s*(\S+)\s*,\s*$', line ) if m is not None: value = m.group( 1 ).lower() if value == "true": return True else: return False return None
def prepare(self, dashd): try: object_hash = dashd.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 getMyVin(): result = rpc_command( "masternode status" ) rec = json.loads( result ) #print "rec = ", rec if 'vin' not in rec: return None vinstr = rec['vin'] #print "vinstr = ", vinstr m = re.match( r'^\s*CTxIn\(COutPoint\(\s*([0-9a-fA-F]+)\s*,\s*(\d+)\s*\).*$', vinstr ) if m is None: print "No match" return None vin = m.group( 1 ) + "-" + m.group( 2 ) return vin.strip()
def sync(self, dashd): golist = dashd.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_dashd(dashd, item) except (peewee.InternalError, peewee.OperationalError, peewee.ProgrammingError) as e: printdbg("Got an error upon import: %s" % e)
def vote(self, dashd, signal, outcome): import dashlib # 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 = dashd.rpc_command(*vote_command) # extract vote output parsing to external lib voted = dashlib.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(dashd, signal)
def getMyVin(): result = rpc_command("masternode status") rec = json.loads(result) #print "rec = ", rec if 'vin' not in rec: return None vinstr = rec['vin'] #print "vinstr = ", vinstr m = re.match( r'^\s*CTxIn\(COutPoint\(\s*([0-9a-fA-F]+)\s*,\s*(\d+)\s*\).*$', vinstr) if m is None: print "No match" return None vin = m.group(1) + "-" + m.group(2) return vin.strip()
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 sync(self, dashd): golist = dashd.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(): try: (go, subobj) = self.import_gobject_from_dashd(dashd, item) except Exception as e: printdbg("Chances are this was a Superblock: %s" % e) continue except Exception as e: printdbg("Got an error upon import: %s" % e)
def doSubmit(self, event): govobj = GFACTORY.createById(event.governance_object_id) cmd = "gobject submit %(object_fee_tx)s %(object_parent_hash)s %(object_revision)s %(object_creation_time)s %(object_name)s %(object_data)s" % govobj.__dict__ printd("doSubmit: cmd = ", cmd) if not misc.is_hash(govobj.object_fee_tx): printd("doSubmit: Warning no object_fee_tx hash") return 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 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
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(hash): command = "gobject vote-conf %s funding yes" % (hash) print "vote: command = ", command rpc_command(command)
def get_block_count(): blockCount = int(rpc_command("getblockcount")) return blockCount
PAYMENT_AMOUNT1 = "0.127" PAYMENT_ADDRESS2 = "yPY6JNMQXdhxqP41yK6rL9ZNbZhDGyfmTB" PAYMENT_AMOUNT2 = "23" DESCRIPTION_URL = "'www.dashwhale.org/p/sb-test'" START_DATE = "2016-08-01" END_DATE = "2017-01-01" print "config.username = "******"getblockcount") print "response = ", response blockCount = int(response) print "block count = ", blockCount def get_block_count(): blockCount = int(rpc_command("getblockcount")) return blockCount def wait_for_blocks(n, initial=None): if initial is None: initial = get_block_count()
def getBlockCount(): result = rpc_command( "getblockcount" ) return int( result )
def do_test(): parent = GovernanceObject() parent.init() start_epoch = datetime.datetime.strptime(START_DATE, "%Y-%m-%d").strftime('%s') end_epoch = datetime.datetime.strptime(END_DATE, "%Y-%m-%d").strftime('%s') # Step 1 - Create superblock superblock_name = "sb" + str(random.randint(1000000, 9999999)) while GovernanceObjectMananger.object_with_name_exists(superblock_name): superblock_name = "sb" + str(random.randint(1000000, 9999999)) fee_tx = CTransaction() newObj = GovernanceObject() newObj.create_new(parent, superblock_name, govtypes.trigger, govtypes.FIRST_REVISION, fee_tx) last_id = newObj.save() blockCount = int(rpc_command("getblockcount")) event_block_height = "%d" % (blockCount + 10) if last_id is None: raise(Exception("do_test: superblock creation failed")) # ADD OUR PROPOSAL AS A SUB-OBJECT WITHIN GOVERNANCE OBJECT c = Superblock() c.set_field("governance_object_id", last_id) c.set_field("type", govtypes.trigger) c.set_field("subtype", "superblock") c.set_field("superblock_name", superblock_name) c.set_field("event_block_height", event_block_height) c.set_field("payment_addresses", PAYMENT_ADDRESS1) c.set_field("payment_amounts", PAYMENT_AMOUNT1) # APPEND TO GOVERNANCE OBJECT newObj.add_subclass("trigger", c) newObj.save() # CREATE EVENT TO TALK TO DASHD / PREPARE / SUBMIT OBJECT event = Event() event.create_new(last_id) event.save() libmysql.db.commit() # Step 2 - Prepare/submit events do_events() # Step 3 - Create proposal proposal_name = "tprop-" + str(random.randint(1000000, 9999999)) while GovernanceObjectMananger.object_with_name_exists(proposal_name): proposal_name = "test-proposal-" + str(random.randint(1000000, 9999999)) quoted_proposal_name = "'%s'" % ( proposal_name ) fee_tx = CTransaction() newObj = GovernanceObject() newObj.create_new(parent, proposal_name, govtypes.proposal, govtypes.FIRST_REVISION, fee_tx) last_id = newObj.save() if last_id is None: raise(Exception("do_test: proposal creation failed")) c = Proposal() c.set_field("governance_object_id", last_id) c.set_field("type", govtypes.proposal) c.set_field("proposal_name", quoted_proposal_name) c.set_field("description_url", DESCRIPTION_URL) c.set_field("start_epoch", start_epoch) c.set_field("end_epoch", end_epoch) c.set_field("payment_address", PAYMENT_ADDRESS2) c.set_field("payment_amount", PAYMENT_AMOUNT2) # APPEND TO GOVERNANCE OBJECT newObj.add_subclass("proposal", c) newObj.save() # CREATE EVENT TO TALK TO DASHD / PREPARE / SUBMIT OBJECT event = Event() event.create_new(last_id) event.save() libmysql.db.commit() # Step 4 - Prepare/submit events do_events()
PAYMENT_ADDRESS1 = "yNaE8Le2MVwk1zpwuEKveTMCEQHVxdcfCS" PAYMENT_AMOUNT1 = "0.127" PAYMENT_ADDRESS2 = "yPY6JNMQXdhxqP41yK6rL9ZNbZhDGyfmTB" PAYMENT_AMOUNT2 = "23" DESCRIPTION_URL = "'www.dashwhale.org/p/sb-test'" START_DATE = "2016-08-01" END_DATE = "2017-01-01" print "config.username = "******"getblockcount" ) print "response = ", response blockCount = int( response ) print "block count = ", blockCount def get_block_count(): blockCount = int(rpc_command("getblockcount")) return blockCount def wait_for_blocks(n,initial=None): if initial is None: initial = get_block_count() while (get_block_count() - initial) < n: time.sleep(30)
def getCurrentBlockHash(): height = getBlockCount() result = rpc_command("getblockhash %d" % (height)) return result
def getBlockCount(): result = rpc_command("getblockcount") return int(result)
def getCurrentBlockHash(): height = getBlockCount() result = rpc_command( "getblockhash %d" % ( height ) ) return result
def getMasternodes(): result = rpc_command("masternodelist full") #print "result = ", result rec = json.loads(result) #print "rec = ", rec return rec
def do_test(): parent = GovernanceObject() parent.init() start_epoch = datetime.datetime.strptime(START_DATE, "%Y-%m-%d").strftime('%s') end_epoch = datetime.datetime.strptime(END_DATE, "%Y-%m-%d").strftime('%s') # Step 1 - Create superblock superblock_name = "sb" + str(random.randint(1000000, 9999999)) while GovernanceObjectMananger.object_with_name_exists(superblock_name): superblock_name = "sb" + str(random.randint(1000000, 9999999)) fee_tx = CTransaction() sbObj = GovernanceObject() sbObj.create_new(parent, superblock_name, govtypes.trigger, govtypes.FIRST_REVISION, fee_tx) last_id = sbObj.save() blockCount = int(rpc_command("getblockcount")) event_block_height = "%d" % (blockCount + crontab.CONFIRMATIONS_REQUIRED + 5) if last_id is None: raise (Exception("do_test: superblock creation failed")) # ADD OUR PROPOSAL AS A SUB-OBJECT WITHIN GOVERNANCE OBJECT c = Superblock() c.set_field("governance_object_id", last_id) c.set_field("type", govtypes.trigger) c.set_field("subtype", "superblock") c.set_field("superblock_name", superblock_name) c.set_field("event_block_height", event_block_height) c.set_field("payment_addresses", PAYMENT_ADDRESS1) c.set_field("payment_amounts", PAYMENT_AMOUNT1) # APPEND TO GOVERNANCE OBJECT sbObj.add_subclass("trigger", c) sbObj.save() # CREATE EVENT TO TALK TO DASHD / PREPARE / SUBMIT OBJECT event = Event() event.create_new(last_id) event.save() libmysql.db.commit() # Step 2 - Prepare/submit events print "Before do_events" do_events() print "After do_events" # Step 3 - Vote up the superblock sbObj.load(sbObj.governance_object['id']) print "sbObj.governance_object = %s" % (sbObj.governance_object) print "Getting objectHash" objectHash = sbObj.get_field("object_hash").strip() print "preparing to vote: objectHash = %s, length = %d" % (objectHash, len(objectHash)) if len(objectHash) == 64: vote(objectHash) # Step 4 - Create proposal proposal_name = "tprop-" + str(random.randint(1000000, 9999999)) while GovernanceObjectMananger.object_with_name_exists(proposal_name): proposal_name = "test-proposal-" + str(random.randint( 1000000, 9999999)) quoted_proposal_name = "'%s'" % (proposal_name) fee_tx = CTransaction() newObj = GovernanceObject() newObj.create_new(parent, proposal_name, govtypes.proposal, govtypes.FIRST_REVISION, fee_tx) last_id = newObj.save() if last_id is None: raise (Exception("do_test: proposal creation failed")) c = Proposal() c.set_field("governance_object_id", last_id) c.set_field("type", govtypes.proposal) c.set_field("proposal_name", quoted_proposal_name) c.set_field("description_url", DESCRIPTION_URL) c.set_field("start_epoch", start_epoch) c.set_field("end_epoch", end_epoch) c.set_field("payment_address", PAYMENT_ADDRESS2) c.set_field("payment_amount", PAYMENT_AMOUNT2) # APPEND TO GOVERNANCE OBJECT newObj.add_subclass("proposal", c) newObj.save() # CREATE EVENT TO TALK TO DASHD / PREPARE / SUBMIT OBJECT event = Event() event.create_new(last_id) event.save() libmysql.db.commit() # Step 5 - Prepare/submit events do_events()
def getMasternodes(): result = rpc_command( "masternodelist full" ) #print "result = ", result rec = json.loads( result ) #print "rec = ", rec return rec
def getGovernanceObjects(): result = rpc_command( "gobject list" ) #print "result = ", result govobjs = json.loads( result ) return govobjs
def getGovernanceObjects(): result = rpc_command("gobject list") #print "result = ", result govobjs = json.loads(result) return govobjs
def vote(hash): command = "gobject vote-conf %s funding yes" % ( hash ) print "vote: command = ", command rpc_command(command)