def submit_votes(win, ballot, s): if s < votecount: return s votes_to_send = {} for entry in sorted(ballot, key=lambda s: s.lower()): if ballot[entry][u'vote'] != 'ABSTAIN': votes_to_send[entry] = ballot[entry] votewin.clear() stdscr.move(0, 0) if votes_to_send.keys(): stdscr.addstr("sending time-randomized votes\n\n", C_GREEN) stdscr.refresh() for vote in sorted(votes_to_send, key=lambda s: s.lower()): castvote = str(votes_to_send[vote][u'vote']) stdscr.addstr(' ' + vote, C_YELLOW) stdscr.addstr(" --> ") stdscr.addstr(castvote, castvote == 'YES' and C_GREEN or C_RED) stdscr.addstr(" -- ") stdscr.addstr(str(votes_to_send[vote][u'Hash'])) stdscr.addstr("\n") for mn in sorted(masternodes): node = masternodes[mn] alias = masternodes[mn]['alias'] random_ts = random_timestamp() ts = datetime.datetime.fromtimestamp(random_ts) stdscr.addstr(' ' + alias, C_CYAN) stdscr.addstr(' ' + str(ts) + ' ', C_YELLOW) netvote = str(node['fundtx']) + str( votes_to_send[vote][u'Hash']) + str( votes_to_send[vote][u'vote'] == 'YES' and 1 or 2) + str(random_ts) mnprivkey = node['mnprivkey'] signature = dashutil.sign_vote(netvote, mnprivkey) command = 'dash-cli mnbudgetvoteraw ' + str( node['txid']) + ' ' + str(node['txout']) + ' ' + str( votes_to_send[vote][u'Hash']) + ' ' + str( votes_to_send[vote][u'vote']).lower() + ' ' + str( random_ts) + ' ' + signature # print netvote + ' ' + signature # print command stdout = run_command(command) stdscr.addstr( stdout.rstrip("\n") + "\n", 'successfully' in stdout and C_GREEN or C_RED) stdscr.refresh() stdscr.addstr("\nHit any key to exit." + "\n", C_GREEN) stdscr.refresh() stdscr.getch() quit()
def submit_votes(win, ballot, s): if s < votecount: return s votes_to_send = {} for entry in sorted(ballot, key=lambda s: s.lower()): if ballot[entry][u'vote'] != 'ABSTAIN': votes_to_send[entry] = ballot[entry] votewin.clear() stdscr.move(0, 0) if votes_to_send.keys(): stdscr.addstr("sending time-randomized votes\n\n", C_GREEN) stdscr.refresh() for vote in sorted(votes_to_send, key=lambda s: s.lower()): castvote = str(votes_to_send[vote][u'vote']) stdscr.addstr(' ' + vote, C_YELLOW) stdscr.addstr(" --> ") stdscr.addstr(castvote, castvote == 'YES' and C_GREEN or C_RED) stdscr.addstr(" -- ") stdscr.addstr(str(votes_to_send[vote][u'Hash'])) stdscr.addstr("\n") for mn in sorted(masternodes): node = masternodes[mn] alias = masternodes[mn]['alias'] random_ts = random_timestamp() ts = datetime.datetime.fromtimestamp(random_ts) stdscr.addstr(' ' + alias, C_CYAN) stdscr.addstr(' ' + str(ts) + ' ', C_YELLOW) netvote = str(node['fundtx']) + str(votes_to_send [vote][u'Hash']) + str(votes_to_send[vote][u'vote'] == 'YES' and 1 or 2) + str(random_ts) mnprivkey = node['mnprivkey'] signature = dashutil.sign_vote(netvote, mnprivkey) command = 'dash-cli mnbudgetvoteraw ' + str(node['txid']) + ' ' + str(node['txout']) + ' ' + str( votes_to_send[vote][u'Hash']) + ' ' + str(votes_to_send[vote][u'vote']).lower() + ' ' + str(random_ts) + ' ' + signature # print netvote + ' ' + signature # print command stdout = run_command(command) stdscr.addstr( stdout.rstrip("\n") + "\n", 'successfully' in stdout and C_GREEN or C_RED) stdscr.refresh() stdscr.addstr("\nHit any key to exit." + "\n", C_GREEN) stdscr.refresh() stdscr.getch() quit()
def submit_votes(win, ballot, s): if s < votecount: return s background_send = 0 if len(masternodes) > 2: background_send = 1 votes_to_send = {} for entry in sorted(ballot, key=lambda s: s.lower()): if ballot[entry][u'vote'] != 'SKIP': votes_to_send[entry] = ballot[entry] votewin.clear() stdscr.move(0, 0) if votes_to_send.keys(): if background_send: deferred_votes = tempfile.NamedTemporaryFile( prefix='sending_dashvote_votes-', delete=False) deferred_votes.write("#!/bin/sh\n") os.chmod(deferred_votes.name, 0700) stdscr.addstr("writing time-randomized votes to disk\n\n", C_GREEN) else: stdscr.addstr("sending time-randomized votes\n\n", C_GREEN) stdscr.refresh() # spread out over a day total_sends = (len(votes_to_send) * len(masternodes)) vote_delay = total_sends > 1 and 86400 / total_sends or 30 for vote in sorted(votes_to_send, key=lambda s: s.lower()): castvote = str(votes_to_send[vote][u'vote']) stdscr.addstr(' ' + vote, C_YELLOW) stdscr.addstr(" --> ") stdscr.addstr(castvote, castvote == 'YES' and C_GREEN or C_RED) stdscr.addstr(" -- ") stdscr.addstr(str(votes_to_send[vote][u'Hash'])) stdscr.addstr("\n") for mn in sorted(masternodes): node = masternodes[mn] alias = masternodes[mn]['alias'] random_ts = random_timestamp() ts = datetime.datetime.fromtimestamp(random_ts) stdscr.addstr(' ' + alias, C_CYAN) stdscr.addstr(' ' + str(ts) + ' ', C_YELLOW) netvote = '|'.join([ str(node['fundtx']), str(votes_to_send[vote][u'Hash']), "1", str(votes_to_send[vote][u'vote'] == 'YES' and 1 or votes_to_send[vote][u'vote'] == 'NO' and 2 or 3), str(random_ts) ]) mnprivkey = node['mnprivkey'] signature = dashutil.sign_vote(netvote, mnprivkey) command = ( '%s' % dash_cli_path is not None and dash_cli_path or 'dash-cli') + ' voteraw ' + str( node['txid']) + ' ' + str(node['txout']) + ' ' + str( votes_to_send[vote][u'Hash']) + ' funding ' + str( votes_to_send[vote][u'vote']).lower( ) + ' ' + str(random_ts) + ' ' + signature if background_send: deferred_votes.write( "sleep %s\n" % (vote_delay + random_offset(vote_delay))) deferred_votes.write("%s\n" % (command)) stdout = 'vote successfully created' else: try: stdout = run_command(command) except subprocess.CalledProcessError, e: stdout = 'error running vote command: %s' % command stdscr.addstr( stdout.rstrip("\n") + "\n", 'successfully' in stdout and C_GREEN or C_RED) stdscr.refresh() if background_send: if deferred_votes.tell() > 1: deferred_votes.write("rm -- \"$0\"\n") stdout = 'sending votes in background' stdscr.addstr("\n" + stdout.rstrip("\n") + "\n", C_YELLOW) stdscr.refresh() exec_path = deferred_votes.name deferred_votes = None p = subprocess.Popen([exec_path], cwd="/tmp", stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout = 'votes being sent by: %s, pid %s' % (exec_path, p.pid) stdscr.addstr("\n" + stdout.rstrip("\n") + "\n", C_CYAN) stdscr.refresh()
def submit_votes(win, ballot, s): if s < votecount: return s background_send = 0 if len(masternodes) > 2: background_send = 1 votes_to_send = {} for entry in sorted(ballot, key=lambda s: s.lower()): if ballot[entry][u'vote'] != 'SKIP': votes_to_send[entry] = ballot[entry] votewin.clear() stdscr.move(0, 0) votenum = 0 if votes_to_send.keys(): if background_send: stdscr.addstr("writing time-randomized votes to disk\n\n", C_GREEN) else: stdscr.addstr("sending time-randomized votes\n\n", C_GREEN) stdscr.refresh() # spread out over remaining voting duration total_sends = (len(votes_to_send) * len(masternodes)) vote_window = int(86400 * (float(days_to_finalization) - 0.5)) randset = urnd.sample(xrange(1, vote_window), len(masternodes) * len(votes_to_send)) vote_files = [] shuffled_mn_keys = masternodes.keys() urnd.shuffle(shuffled_mn_keys) batch_timestamp = datetime.datetime.strftime(datetime.datetime.now(), '%Y%m%d%H%M%S') for mn in shuffled_mn_keys: offsets = sorted(randset[:len(votes_to_send)]) del randset[:len(votes_to_send)] delays = offsets[:1] + [ y - x for x, y in zip(offsets, offsets[1:]) ] if background_send: deferred_votes = tempfile.NamedTemporaryFile( prefix=('sending_dashvote_votes-%s=' % batch_timestamp), delete=False) deferred_votes.write("#!/bin/bash\n") deferred_votes.write("set -x\n") os.chmod(deferred_votes.name, 0700) vote_files.append(deferred_votes) shuffled_vote_keys = votes_to_send.keys() urnd.shuffle(shuffled_vote_keys) for vote in shuffled_vote_keys: castvote = str(votes_to_send[vote][u'vote']) stdscr.addstr(' ' + vote, C_YELLOW) stdscr.addstr(" --> ") stdscr.addstr(castvote, castvote == 'YES' and C_GREEN or C_RED) stdscr.addstr(" -- ") stdscr.addstr(str(votes_to_send[vote][u'Hash'])) stdscr.addstr("\n") votenum += 1 node = masternodes[mn] alias = masternodes[mn]['alias'] random_ts = random_timestamp() ts = datetime.datetime.fromtimestamp(random_ts) stdscr.addstr(' ' + alias, C_CYAN) stdscr.addstr(' ' + str(ts) + ' ', C_YELLOW) netvote = '|'.join([ str(node['fundtx']), str(votes_to_send[vote][u'Hash']), "1", str(votes_to_send[vote][u'vote'] == 'YES' and 1 or votes_to_send[vote][u'vote'] == 'NO' and 2 or 3), str(random_ts) ]) mnprivkey = node['mnprivkey'] signature = dashutil.sign_vote(netvote, mnprivkey) command = ( '%s' % dash_cli_path is not None and dash_cli_path or 'dash-cli') + ' voteraw ' + str( node['txid']) + ' ' + str(node['txout']) + ' ' + str( votes_to_send[vote][u'Hash']) + ' funding ' + str( votes_to_send[vote][u'vote']).lower( ) + ' ' + str(random_ts) + ' ' + signature if background_send: sleeptime = delays.pop(0) deferred_votes.write( "echo \"sleeping %s seconds then casting vote %s/%s\"\n" % (sleeptime, votenum, total_sends)) deferred_votes.write("sleep %s\n" % sleeptime) deferred_votes.write("%s\n" % (command)) #msg = 'vote successfully created - %s' % sleeptime msg = 'vote successfully created' else: try: msg = run_command(command) except subprocess.CalledProcessError, e: msg = 'error running vote command: %s' % command stdscr.addstr( msg.rstrip("\n") + "\n", 'successfully' in msg and C_GREEN or C_RED) stdscr.refresh() if background_send: voter_parent = tempfile.NamedTemporaryFile( prefix=('sending_dash_votes-%s-' % batch_timestamp), delete=False) voter_parent.write("#!/bin/bash\n") voter_parent.write( 'trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT' + "\n") os.chmod(voter_parent.name, 0700) for deferred_votes in vote_files: if deferred_votes.tell() > 1: deferred_votes.write("rm -- \"$0\"\n") deferred_votes.close() exec_path = deferred_votes.name log_path = exec_path + '.log' voter_parent.write("%s > %s &\n" % (exec_path, log_path)) voter_parent.write("wait\n") exec_path = voter_parent.name voter_parent.close() log_path = exec_path + '.log' with open(log_path, 'wb') as log: p = subprocess.Popen([exec_path], cwd="/tmp", stdout=log, stderr=log) msg = 'sending votes in background' stdscr.addstr("\n" + msg + "\n", C_YELLOW) stdscr.refresh() msg = 'votes being sent by: %s, pid %s' % (voter_parent.name, p.pid) stdscr.addstr("\n" + msg + "\n", C_CYAN) stdscr.refresh()