auto broadcast pending txns, show net info

This commit is contained in:
Dobromir Popov
2025-09-30 01:33:23 +03:00
parent b96778196c
commit 499ad9690e
2 changed files with 147 additions and 42 deletions

View File

@@ -140,13 +140,26 @@ def get_network_info():
mempool = rpc_call("getrawmempool")
blockchain_info = rpc_call("getblockchaininfo")
# Format peer information
peers = []
for peer in peer_info:
peers.append({
"addr": peer.get("addr", ""),
"services": peer.get("servicesnames", []),
"relaytxes": peer.get("relaytxes", False),
"synced_blocks": peer.get("synced_blocks", 0),
"last_transaction": peer.get("last_transaction", 0),
"version": peer.get("subver", ""),
"pingtime": round(peer.get("pingtime", 0) * 1000, 1),
})
return jsonify({
"network": {
"connections": network_info.get("connections", 0),
"networkactive": network_info.get("networkactive", False),
"relayfee": network_info.get("relayfee", 0),
},
"peers": len(peer_info),
"peers": peers,
"mempool_size": len(mempool),
"blockchain": {
"blocks": blockchain_info.get("blocks", 0),
@@ -159,6 +172,34 @@ def get_network_info():
return jsonify({"error": str(exc)}), 500
@app.route("/api/rebroadcast", methods=["POST"])
@require_token
def rebroadcast_pending():
try:
# Get all pending transactions
txs = rpc_call("listtransactions", "*", 100, 0, True)
pending = [tx for tx in txs if tx.get("confirmations", 0) == 0]
rebroadcasted = []
for tx in pending:
txid = tx.get("txid")
if txid:
try:
# Get raw transaction
tx_data = rpc_call("gettransaction", txid, True)
raw_hex = tx_data.get("hex")
if raw_hex:
# Rebroadcast
rpc_call("sendrawtransaction", raw_hex)
rebroadcasted.append(txid)
except Exception:
pass # Already in mempool or other error
return jsonify({"rebroadcasted": rebroadcasted, "count": len(rebroadcasted)})
except RuntimeError as exc:
return jsonify({"error": str(exc)}), 500
@app.route("/")
def root():
return send_from_directory(app.static_folder, "index.html")