diff --git a/rootfs/standard/var/www/mynode/lightning_info.py b/rootfs/standard/var/www/mynode/lightning_info.py index e2ee58b3..d44eb842 100644 --- a/rootfs/standard/var/www/mynode/lightning_info.py +++ b/rootfs/standard/var/www/mynode/lightning_info.py @@ -5,6 +5,7 @@ import os import time import re import datetime +import urllib from flask import current_app as app from threading import Timer from utilities import * @@ -23,6 +24,9 @@ lightning_peer_aliases = {} lightning_channels = None lightning_channel_balance = None lightning_wallet_balance = None +lightning_transactions = None +lightning_payments = None +lightning_invoices = None lightning_watchtower_server_info = None lightning_desync_count = 0 @@ -37,6 +41,9 @@ def update_lightning_info(): global lightning_channels global lightning_channel_balance global lightning_wallet_balance + global lightning_transactions + global lightning_payments + global lightning_invoices global lightning_watchtower_server_info global lightning_desync_count global lnd_ready @@ -69,10 +76,22 @@ def update_lightning_info(): lightning_channels = lnd_get("/channels") lightning_channel_balance = lnd_get("/balance/channels") lightning_wallet_balance = lnd_get("/balance/blockchain") + #lightning_transactions = lnd_get("/transactions") + #lightning_payments = lnd_get("/payments") + #lightning_invoices = lnd_get("/invoices") lightning_watchtower_server_info = lnd_get_v2("/watchtower/server") return True +def update_lightning_tx_info(): + global lightning_transactions + global lightning_payments + global lightning_invoices + if is_lnd_ready(): + tx_cache_limit = 50 + lightning_transactions = lnd_get("/transactions") + lightning_payments = lnd_get("/payments", params={"reversed":"true", "index_offset": "0", "max_payments": tx_cache_limit}) + lightning_invoices = lnd_get("/invoices", params={"reversed":"true", "index_offset": "0", "num_max_invoices": tx_cache_limit}) def get_lnd_deposit_address(): if os.path.isfile("/tmp/lnd_deposit_address"): @@ -230,6 +249,49 @@ def get_lightning_balance_info(): return balance_data +def get_lightning_transactions(): + global lightning_transactions + try: + transactions = [] + data = copy.deepcopy(lightning_transactions) + for tx in data["transactions"]: + tx["amount_str"] = format_sat_amount(tx["amount"]) + tx["date_str"] = time.strftime("%D %H:%M", time.localtime(int(tx["time_stamp"]))) + transactions.append(tx) + return transactions + except: + return None + +def get_lightning_payments(): + global lightning_payments + try: + payments = [] + data = copy.deepcopy(lightning_payments) + for tx in data["payments"]: + tx["value_str"] = format_sat_amount(tx["value_sat"]) + tx["fee_str"] = format_sat_amount(tx["fee"]) + tx["date_str"] = time.strftime("%D %H:%M", time.localtime(int(tx["creation_date"]))) + payments.append(tx) + payments.reverse() + return payments + except: + return None + +def get_lightning_invoices(): + global lightning_invoices + try: + invoices = [] + data = copy.deepcopy(lightning_invoices) + for tx in data["invoices"]: + tx["value_str"] = format_sat_amount(tx["value"]) + tx["date_str"] = time.strftime("%D %H:%M", time.localtime(int(tx["creation_date"]))) + tx["memo"] = urllib.unquote_plus(tx["memo"]) + invoices.append(tx) + invoices.reverse() + return invoices + except: + return None + def get_lightning_watchtower_server_info(): global lightning_watchtower_server_info return copy.deepcopy(lightning_watchtower_server_info) @@ -238,11 +300,11 @@ def is_lnd_ready(): global lnd_ready return lnd_ready -def lnd_get(path, timeout=10): +def lnd_get(path, timeout=10, params={}): try: macaroon = get_macaroon() headers = {"Grpc-Metadata-macaroon":macaroon} - r = requests.get("https://localhost:"+LND_REST_PORT+"/v1"+path, verify=TLS_CERT_FILE,headers=headers, timeout=timeout) + r = requests.get("https://localhost:"+LND_REST_PORT+"/v1"+path, verify=TLS_CERT_FILE,headers=headers, params=params, timeout=timeout) except Exception as e: app.logger.info("ERROR in lnd_get: "+str(e)) return {"error": str(e)} diff --git a/rootfs/standard/var/www/mynode/lnd.py b/rootfs/standard/var/www/mynode/lnd.py index 8c2bc1e2..bceaba25 100644 --- a/rootfs/standard/var/www/mynode/lnd.py +++ b/rootfs/standard/var/www/mynode/lnd.py @@ -133,6 +133,12 @@ def page_lnd(): if wallet_balance_data != None and "unconfirmed_balance" in wallet_balance_data: wallet_pending = wallet_balance_data["unconfirmed_balance"] + # Update TX info + update_lightning_tx_info() + transactions = get_lightning_transactions() + payments = get_lightning_payments() + invoices = get_lightning_invoices() + watchtower_server_info = get_lightning_watchtower_server_info() watchtower_uri = "..." if watchtower_server_info != None: @@ -179,6 +185,10 @@ def page_lnd(): "watchtower_uri": watchtower_uri, "peers": peers, "channels": channels, + "transactions": transactions, + "payments": payments, + "invoices": invoices, + "tx_display_limit": 8, "ui_settings": read_ui_settings() } return render_template('lnd.html', **templateData) diff --git a/rootfs/standard/var/www/mynode/static/images/memo.png b/rootfs/standard/var/www/mynode/static/images/memo.png new file mode 100644 index 00000000..18968b51 Binary files /dev/null and b/rootfs/standard/var/www/mynode/static/images/memo.png differ diff --git a/rootfs/standard/var/www/mynode/templates/lnd.html b/rootfs/standard/var/www/mynode/templates/lnd.html index 6e5c35f2..9191992f 100644 --- a/rootfs/standard/var/www/mynode/templates/lnd.html +++ b/rootfs/standard/var/www/mynode/templates/lnd.html @@ -8,6 +8,8 @@ alias="{{alias}}" + $( document ).tooltip(); + function change_alias() { $("#change_alias_form").submit(); change_alias_dialog.dialog( "close" ); @@ -373,6 +375,94 @@ +
+
Recent Transactions
+
+ {% if transactions and transactions|length > 0 %} + + + + + + + + + + + {% for tx in transactions[:tx_display_limit] %} + + + + + + {% endfor %} + {% if transactions|length >= tx_display_limit %} + + {% endif %} + +
On-chain TX
DateAmountConfirmations
{{ tx.date_str }}{{ tx.amount_str }}{{ tx.num_confirmations }}
more...
+ {% endif %} + + {% if payments and payments|length > 0 %} + + + + + + + + + + + + {% for tx in payments[:tx_display_limit] %} + + + + + + + {% endfor %} + {% if payments|length >= tx_display_limit %} + + {% endif %} + +
Payments
DateAmountFee
{{ tx.date_str }}{{ tx.value_str }}{{ tx.fee_str }}
more...
+ {% endif %} + + {% if invoices and invoices|length > 0 %} + + + + + + + + + + + + {% for tx in invoices[:tx_display_limit] %} + + + + + + + {% if invoices|length >= tx_display_limit %} + + {% endif %} + {% endfor %} + +
Invoices
DateAmountMemoState
{{ tx.date_str }}{{ tx.value_str }} + {% if tx.memo != "" %} + + {% endif %} + {{ tx.state }}
more...
+ {% endif %} +
+ +
Channels