예제 #1
0
def block_hash(bhash):
    data = Block().hash(bhash)

    if data["error"] is None:
        result = data["result"]
        return Esplora().block(result)

    else:
        return Response("Block not found", mimetype="text/plain", status=404)
예제 #2
0
def transaction_info(thash):
    data = Transaction().info(thash)

    if data["error"] is None:
        result = data["result"]
        return Esplora().transaction(result)

    else:
        return Response("Transaction not found",
                        mimetype="text/plain",
                        status=404)
예제 #3
0
def blocks_range(height):
    data = General().info()
    blocks = []

    if not height:
        height = data["result"]["blocks"]

    data = Block().range(height, config.block_page)

    for block in data:
        blocks.append(Esplora().block(block))

    return jsonify(blocks)
예제 #4
0
def mempool_recent():
    data = General().mempool()
    result = []

    for txid in data["result"]["tx"]:
        transaction = Transaction().info(txid)["result"]
        item = Esplora().transaction(transaction)

        result.append({
            "txid": item["txid"],
            "fee": item["fee"],
            "vsize": item["weight"],
            "value": item["value"]
        })

    return jsonify(result)
예제 #5
0
def block_transactions(bhash, start=0):
    data = Block().hash(bhash)
    transactions = []

    if start % config.tx_page != 0:
        return Response(
            f"start index must be a multipication of {config.tx_page}",
            mimetype="text/plain",
            status=400)

    if data["error"] is None:
        result = data["result"]

        for thash in result["tx"][start:start + config.tx_page]:
            transaction = Transaction().info(thash)["result"]
            transactions.append(Esplora().transaction(transaction))

        return jsonify(transactions)

    else:
        return Response("Block not found", mimetype="text/plain", status=404)
예제 #6
0
def address_transactions(address, thash):
    data = Address().history(address)
    transactions = []
    start = 0

    if data["error"] is None:
        result = data["result"]

        if thash in result["tx"]:
            start = result["tx"].index(thash) + 1

        for thash in result["tx"][start:start + config.tx_page]:
            transaction = Transaction().info(thash)["result"]
            transactions.append(Esplora().transaction(transaction))

        return jsonify(transactions)

    else:
        return Response("Invalid Bitcoin address",
                        mimetype="text/plain",
                        status=400)