def process_next_creation(): if len(nodes_recently_updated) == 0: return next_uid = nodes_recently_updated.popleft() logging.info("Processing uid: %s" % next_uid) account = Account(next_uid) if not account.node_created.get(): if account.unconf_minutes.get() < MIN_TIME: account.add_msg('Node creation failed! A minimum of %d minutes need to be purchased at a time. You need %d more minutes.' % (MIN_TIME, MIN_TIME - account.unconf_minutes.get())) return if account.destroyed.get(): account.add_msg('Node creation failed as it has already been destroyed, please use a new account and contact [email protected] to get your coins back.') return account.add_msg('Creating server now. ETA 10-20 minutes.') dcid = random.choice([1, 5, 7]) # NJ, LA, Amsterdam try: res = requests.post("https://api.vultr.com/v1/server/create?api_key=%s" % vultr_api_key.get(), data={"DCID": dcid, "VPSPLANID": 87, "OSID": 192, "SSHKEYID": ssh_management_key.get(), "label": str(account.uid), "enable_private_network": 'yes', 'enable_ipv6 string': 'yes'}) except Exception as e: nodes_recently_updated.prepend(next_uid) logging.error('Attempted to create server / Exception: %s' % repr(e)) if res.status_code == 200: # accepted response = res.json() subid = response['SUBID'] logging.info(response) account.creation_ts.set(int(time.time())) account.droplet_id.set(subid) account.node_created.set(True) account.dcid.set(dcid) droplets_to_configure.add(subid, account.creation_ts.get()) droplet_to_uid[subid] = account.uid active_servers.add(subid) account.add_msg('Server created successfully! Server ID %s' % (account.droplet_id.get(),)) account.tweet_creation() node_creation_issues.set(False) else: logging.error('Server creation failed! Status %d' % res.status_code) if res.status_code == 412 and res.content == NODE_CREATION_LIMIT_MSG: node_creation_issues.set(True) logging.error(res.content) nodes_recently_updated.append(next_uid) account.add_msg('Server creation failed... will keep retrying') return 'CREATION_FAILED' # import pdb; pdb.set_trace() else: logging.warning('Account already has a node created.') print(account.node_created.get())
def check_compiling_node(id): account = Account(droplet_to_uid[id]) ip = droplet_ips[id].decode() s = socket.socket() try: s.connect((ip, 8333)) # VEEERRRRY simple except: # can't connect, check we're not way out in terms of time if int(time.time()) - account.compile_ts.get() > 60 * 180: # 60 min account.add_msg('Possible compile issue (taking >180 minutes). Restarting.') droplets_to_configure.add(id, 0) currently_compiling.remove(id) return s.close() account.add_msg('Node detected! Check at https://getaddr.bitnodes.io/nodes/%s-%d/' % (ip, 8333)) account.email_node_up(ip) logging.info('Detected node %s' % id) currently_compiling.remove(id) nodes_currently_syncing.add(id)
if args.xpub != '': xpub.set(args.xpub) if args.test_uid_create_node != '': uid = process_uid(args.test_uid_create_node) account = Account(uid) account.node_created.set(False) account.unconf_minutes.incr(MIN_TIME + 1) nodes_recently_updated.prepend(uid) process_next_creation() if args.msgs_for_uid != '': print(Account(process_uid(args.msgs_for_uid)).get_msgs(100000)) if args.configure_droplet != '': droplets_to_configure.add(args.configure_droplet, 0) configure_droplet(args.configure_droplet) if args.create_startup_script != '': raise Exception('Unimplemented') if args.show_account != '': uids = [args.show_account.encode(), process_uid(args.show_account)] for uid in uids: if uid in uid_to_addr: account = Account(uid) print(account.pretty_string()) if args.show_all_active_nodes: print('%d servers total' % len(active_servers)) for id in active_servers:
def handle(method, **params): response = {} real_uid = params['uid'] uid = process_uid(params['uid']) # not user chosen any longer account = Account(uid) fieldMap = { 'emailNotify': account.email_notify, 'email': account.email, 'name': account.name, 'client': account.client, 'tip': account.tip, 'branch': account.branch, } if method == 'getPaymentDetails': client = params['client'] months = max(0, int(params['months'])) tip = account.tip.get() amount = actually_charge(months, tip, exchange_rate.get()) # note: this URI cannot contain spaces as some wallets cannot read it. response['uri'] = "bitcoin:%s?amount=%.8f&label=nodeup.xk.io_sponsored_node_funding_address" % (account.address, amount) response['status'] = 'Payment received.' if account.unconf_minutes.get() > 0 else 'Waiting for payment...' elif method == '': pass elif method == 'saveField': field = params['field'] value = params['value'] if field == 'name' and len(value) > 140: value = value[:140] fieldMap[field].set(value) elif method == 'loadField': field = params['field'] response['field'] = field response['value'] = fieldMap[field].get() elif method == 'getMsgs': if 'n' in params: n = params['n'] else: n = 10 response['msgs'] = account.get_msgs(n) elif method == 'getStats': response['nodeMinutes'] = int(total_nodeminutes.get()) response['totalMinutesPaid'] = account.total_minutes.get() response['totalCoinsPaid'] = account.total_coins.get() response['exchangeRate'] = exchange_rate.get() response['activeNodes'] = len(active_servers) response['nodeCreationIssues'] = node_creation_issues.get() elif method == 'recompile': if account.node_created.get(): droplets_to_configure.add(account.droplet_id.get(), 0) account.add_msg('Queued node for recompilation.') response['recompile_queued'] = True else: response['recompile_queued'] = False elif method == 'sendNodeDetails': account.email_user('Node Details', NODE_DETAILS_EMAIL.format(uid=real_uid), force=True) return response