feat: Add mempool info
All checks were successful
Build Docker / BuildImage (push) Successful in 32s

This commit is contained in:
Nathan Woodburn 2025-02-05 18:37:13 +11:00
parent 11a6d6c003
commit 5712c07b4d
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
3 changed files with 57 additions and 15 deletions

9
hsd.py
View File

@ -40,4 +40,11 @@ def get_name_resource(name):
def get_address(address): def get_address(address):
return requests.get(f"{HSD_URL}/tx/address/{address}").json() return requests.get(f"{HSD_URL}/tx/address/{address}").json()
def get_mempool():
return requests.get(f"{HSD_URL}/mempool").json()
def get_mempool_info():
return requests.post(HSD_URL, json={"method": "getmempoolinfo"}).json()

View File

@ -75,7 +75,18 @@ def wellknown(path):
# region Main routes # region Main routes
@app.route("/") @app.route("/")
def index(): def index():
return render_template("index.html") txs = hsd.get_mempool()
mempool_info = hsd.get_mempool_info()
if mempool_info['result']:
mempool_info = mempool_info['result']
mempool = f"Total Transactions: {len(txs)}<br><br>"
for txid in txs:
tx = hsd.get_tx(txid)
mempool += f"<a href='/tx?tx={txid}' target='_blank'>{txid}</a>: {len(tx['inputs'])} inputs, {len(tx['outputs'])} outputs, fee: {tx['fee']/1000000}, Total Value: {sum([output['value']/1000000 for output in tx['outputs']]):,.2f} HNS<br><br>"
return render_template("index.html",mempool=mempool)
@app.route("/name") @app.route("/name")
def name(): def name():
@ -178,6 +189,21 @@ def api_address(address):
else: else:
return jsonify({"error": "address not found"}), 404 return jsonify({"error": "address not found"}), 404
@app.route("/api/v1/mempool")
def api_mempool():
mempool = hsd.get_mempool()
if mempool:
return jsonify(mempool)
else:
return jsonify({"error": "mempool not found"}), 404
@app.route("/api/v1/mempool/info")
def api_mempool_info():
mempool_info = hsd.get_mempool_info()
if mempool_info:
return jsonify(mempool_info)
else:
return jsonify({"error": "mempool info not found"}), 404
# endregion # endregion

View File

@ -13,19 +13,28 @@
<div class="spacer"></div> <div class="spacer"></div>
<div class="centre"> <div class="centre">
<h1>Nathan.Woodburn/ EXPLORER ALPHA</h1> <h1>Nathan.Woodburn/ EXPLORER ALPHA</h1>
<form action="/name" method="get"> <h2>MEMPOOL</h2>
<input type="text" name="name" placeholder="Name"> <div>
<button type="submit">Search</button> {{ mempool |safe}}
</form> </div>
<form action="/tx" method="get">
<input type="text" name="tx" placeholder="TXID">
<button type="submit">Search</button> <h2>Search</h2>
</form> <div>
<form action="/block" method="get"> <form action="/name" method="get" style="margin: 10px;">
<input type="text" name="block" placeholder="Blockhash or Height"> <input type="text" name="name" placeholder="Name">
<button type="submit">Search</button> <button type="submit">Search</button>
</form> </form>
<form action="/tx" method="get" style="margin: 10px;">
<input type="text" name="tx" placeholder="TXID">
<button type="submit">Search</button>
</form>
<form action="/block" method="get" style="margin: 10px;">
<input type="text" name="block" placeholder="Blockhash or Height">
<button type="submit">Search</button>
</form>
</div>
</div> </div>
</body> </body>