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)
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)
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)
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)
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)
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)