feat: Add mempool info
All checks were successful
Build Docker / BuildImage (push) Successful in 32s
All checks were successful
Build Docker / BuildImage (push) Successful in 32s
This commit is contained in:
parent
11a6d6c003
commit
5712c07b4d
7
hsd.py
7
hsd.py
@ -41,3 +41,10 @@ def get_name_resource(name):
|
||||
|
||||
def get_address(address):
|
||||
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()
|
28
server.py
28
server.py
@ -75,7 +75,18 @@ def wellknown(path):
|
||||
# region Main routes
|
||||
@app.route("/")
|
||||
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")
|
||||
def name():
|
||||
@ -178,6 +189,21 @@ def api_address(address):
|
||||
else:
|
||||
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
|
||||
|
||||
|
@ -14,19 +14,28 @@
|
||||
<div class="centre">
|
||||
<h1>Nathan.Woodburn/ EXPLORER ALPHA</h1>
|
||||
|
||||
<form action="/name" method="get">
|
||||
<h2>MEMPOOL</h2>
|
||||
<div>
|
||||
{{ mempool |safe}}
|
||||
</div>
|
||||
|
||||
|
||||
<h2>Search</h2>
|
||||
<div>
|
||||
<form action="/name" method="get" style="margin: 10px;">
|
||||
<input type="text" name="name" placeholder="Name">
|
||||
<button type="submit">Search</button>
|
||||
</form>
|
||||
<form action="/tx" method="get">
|
||||
<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">
|
||||
<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>
|
||||
|
||||
</body>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user