Ejemplo n.º 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()))
Ejemplo n.º 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)
Ejemplo n.º 3
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)