示例#1
0
def check_unprocessed(top_height):
    for tx_hash in unprocessed_txs.members():
        txid = hash_to_hex(tx_hash).decode()
        tx = Tx.tx_from_hex(txs[tx_hash].decode())
        tx_blockchain = get_tx(txid)
        logging.info('Checking %s' % txid)
        if tx_blockchain.block_height == -1:
            continue
        if top_height - tx_blockchain.block_height + 1 >= REQUIRED_CONFIRMATIONS:  # off by one error - if tx in top block that is 1 conf
            unprocessed_txs.remove(tx_hash)
            for out in tx.txs_out:
                address = out.bitcoin_address()
                if address not in all_addresses:
                    continue
                account = Account(addr_to_uid[address])
                satoshis = out.coin_value
                satoshis = int(satoshis / (1 + account.tip.get()))  # scale for tip
                account.total_coins.incr(satoshis)
                node_minutes_d = calc_node_minutes(satoshis, exchange_rate=exchange_rate.get())
                account.total_minutes.incr(node_minutes_d)
                total_nodeminutes.incr(node_minutes_d)
                nodes_recently_updated.append(account.uid)
                account.add_msg('Detected payment via txid: %s' % (txid,))
                account.add_msg('Increased total paid by %.8f to %.8f (considering tip of %d %%)' % (satoshis / COIN, account.total_coins.get() / COIN, account.tip.get() * 100))
                account.add_msg('Increased node life by %d minutes; expiring around %s' % (node_minutes_d, account.get_expiry().isoformat()))
示例#2
0
def process_tx_initial(tx_obj: Tx):
    found_relevant_address = False
    for out in tx_obj.txs_out:
        address = out.bitcoin_address()
        if address in all_addresses:
            found_relevant_address = True
            break
    if not found_relevant_address:
        logging.info('Found irrelevant tx %s' % hash_to_hex(tx_obj.hash()))
        return

    tx_hash = tx_obj.hash()
    txid = hash_to_hex(tx_hash).decode()
    if tx_hash in known_txs:
        return
    known_txs.add(tx_hash)
    txs[tx_hash] = tx_obj.as_hex()
    for out in tx_obj.txs_out:
        address = out.bitcoin_address()
        if address in all_addresses and address is not None:
            unprocessed_txs.add(tx_hash)
            uid = addr_to_uid[address]
            account = Account(uid)
            account.txs.add(tx_hash)
            account.unconf_minutes.incr(calc_node_minutes(satoshi_amount=out.coin_value, exchange_rate=exchange_rate.get()))
            account.add_msg('Found tx for %.08f, %s' % (out.coin_value / COIN, txid))
            nodes_recently_updated.append(account.uid)
示例#3
0
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())
示例#4
0
            time.sleep(10)  # only do this at most once per block
            continue
        logging.info('Latest block: %s' % best_block_hash)

        for tx_hash in unprocessed_txs.members():
            txid = hash_to_hex(tx_hash).decode()
            tx = Tx.tx_from_hex(txs[tx_hash].decode())
            tx_blockchain = get_tx(txid)
            logging.info('Checking %s' % txid)
            if tx_blockchain.block_height == -1:
                continue
            if top_height - tx_blockchain.block_height + 1 >= REQUIRED_CONFIRMATIONS:  # off by one error - if tx in top block that is 1 conf
                unprocessed_txs.remove(tx_hash)
                for out in tx.txs_out:
                    address = out.bitcoin_address()
                    if address not in all_addresses:
                        continue
                    account = Account(addr_to_uid[address])
                    satoshis = out.coin_value
                    satoshis = int(satoshis / (1 + account.tip.get()))  # scale for tip
                    account.total_coins.incr(satoshis)
                    node_minutes_d = calc_node_minutes(satoshis, exchange_rate=exchange_rate.get())
                    account.total_minutes.incr(node_minutes_d)
                    total_nodeminutes.incr(node_minutes_d)
                    nodes_recently_updated.append(account.uid)
                    account.add_msg('Detected payment via txid: %s' % (txid,))
                    account.add_msg('Increased total paid by %.8f to %.8f (considering tip of %d %%)' % (satoshis / COIN, account.total_coins.get() / COIN, account.tip.get() * 100))
                    account.add_msg('Increased node life by %d minutes; expiring around %s' % (node_minutes_d, account.get_expiry().isoformat()))

        last_block_checked.set(best_block_hash)
        logging.info('Checked: %s' % best_block_hash)