Add Lightning TX data to home screen

This commit is contained in:
Taylor Helsper 2021-05-02 22:28:02 -05:00
parent 05a552760c
commit f1dd6510a4
15 changed files with 154 additions and 11 deletions

View File

@ -86,8 +86,8 @@ def update_lightning_info():
lightning_wallet_balance = lnd_get("/balance/blockchain")
lightning_watchtower_server_info = lnd_get_v2("/watchtower/server")
# Poll slower
if lightning_update_count % 2 == 0:
# Poll slower (make sure we gather data early)
if lightning_update_count < 30 or lightning_update_count % 2 == 0:
update_lightning_tx_info()
return True
@ -243,19 +243,27 @@ def get_lightning_balance_info():
balance_data["channel_pending"] = "N/A"
balance_data["wallet_balance"] = "N/A"
balance_data["wallet_pending"] = "N/A"
balance_data["total_balance"] = "N/A"
channel_num = -1
wallet_num = -1
channel_balance_data = get_lightning_channel_balance()
if channel_balance_data != None and "balance" in channel_balance_data:
balance_data["channel_balance"] = format_sat_amount( channel_balance_data["balance"] )
channel_num = int(channel_balance_data["balance"])
if channel_balance_data != None and "pending_open_balance" in channel_balance_data:
balance_data["channel_pending"] = format_sat_amount( channel_balance_data["pending_open_balance"] )
wallet_balance_data = get_lightning_wallet_balance()
if wallet_balance_data != None and "confirmed_balance" in wallet_balance_data:
balance_data["wallet_balance"] = format_sat_amount( wallet_balance_data["confirmed_balance"] )
wallet_num = int(wallet_balance_data["confirmed_balance"])
if wallet_balance_data != None and "unconfirmed_balance" in wallet_balance_data:
balance_data["wallet_pending"] = format_sat_amount( wallet_balance_data["unconfirmed_balance"] )
if channel_num >= 0 and wallet_num >= 0:
balance_data["total_balance"] = format_sat_amount(channel_num + wallet_num)
return balance_data
def get_lightning_transactions():
@ -277,9 +285,11 @@ def get_lightning_payments():
payments = []
data = copy.deepcopy(lightning_payments)
for tx in data["payments"]:
tx["type"] = "PAYMENT"
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"])))
tx["memo"] = ""
payments.append(tx)
payments.reverse()
return payments
@ -292,6 +302,7 @@ def get_lightning_invoices():
invoices = []
data = copy.deepcopy(lightning_invoices)
for tx in data["invoices"]:
tx["type"] = "INVOICE"
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"])
@ -301,6 +312,40 @@ def get_lightning_invoices():
except:
return None
def get_lightning_payments_and_invoices():
payments = get_lightning_payments()
invoices = get_lightning_invoices()
txs = []
if payments == None and invoices == None:
return None
elif payments == None and invoices != None:
return invoices
elif payments != None and invoices == None:
return payments
elif len(payments) == 0 and len(invoices) == 0:
return None
while len(payments) or len(invoices):
if len(payments) == 0:
txs.insert(0, invoices.pop())
elif len(invoices) == 0:
txs.insert(0, payments.pop())
else:
# Prepend oldest to list
p = payments[-1]
i = invoices[-1]
if int(p["creation_date"]) < int(i["creation_date"]):
txs.insert(0, payments.pop())
else:
txs.insert(0, invoices.pop())
for tx in txs:
if tx["type"] == "PAYMENT":
tx["value_str"] = "-" + tx["value_str"]
return txs
def get_lightning_watchtower_server_info():
global lightning_watchtower_server_info
return copy.deepcopy(lightning_watchtower_server_info)

View File

@ -511,6 +511,9 @@ def index():
"lnd_wallet_exists": lnd_wallet_exists(),
"lnd_version": get_lnd_version(),
"lnd_deposit_address": get_lnd_deposit_address(),
"lnd_transactions": get_lightning_transactions(),
"lnd_payments_and_invoices": get_lightning_payments_and_invoices(),
"lnd_tx_display_limit": 6,
"lnd_channels": get_lightning_channels(),
"electrs_active": electrs_active,
"is_testnet_enabled": is_testnet_enabled(),

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

View File

@ -180,11 +180,103 @@
</tr>
</table>
-->
<b>Deposit Address</b><br/>
<img style='width: 120px; height: 120px; margin: auto; margin-top: 5px; margin-bottom: 5px;' src='/api/get_qr_code_image?url={{ lnd_deposit_address }}' title="{{ lnd_deposit_address }}"/>
<br/>
<span style="font-size: 12px;">{{lnd_deposit_address}}</span>
<!-- Top Wallet Section -->
<p style="font-size: 16px; font-weight: bold;">Wallet</p>
<div style="display: flex; margin: auto;">
<div>
<b>Balance</b><br/>
<span id="lnd_total_balance" style="font-size: 12px; margin-top: 5px;">{{lnd_balance_info['total_balance']}} sats</span>
<br/><br/>
<b>Deposit</b><br/>
<img style='width: 160px; height: 160px; margin: auto; margin-top: 5px; margin-bottom: 5px;' src='/api/get_qr_code_image?url={{ lnd_deposit_address }}' title="{{ lnd_deposit_address }}"/>
<br/>
<span style="font-size: 10px;">{{lnd_deposit_address}}</span>
</div>
<div>
<b>On-chain Transactions</b>
<table style="font-size: 12px; width: 270px; margin: 10px;">
<tr>
<td>Date</td>
<td>Amount</td>
<td></td>
</tr>
{% if lnd_transactions and lnd_transactions|length > 0 %}
{% for tx in lnd_transactions[:lnd_tx_display_limit] %}
<tr>
<td>{{ tx.date_str }}</td>
<td>{{ tx.amount_str }}</td>
<td>
{% if tx.num_confirmations < 1 %}
<img style="width: 16px;" src="{{ url_for('static', filename="images/")}}confirm_pending.png" title="pending transaction"/>
{% elif tx.num_confirmations <= 3 %}
<img style="width: 16px;" src="{{ url_for('static', filename="images/")}}confirm_bars_{{tx.num_confirmations}}.png" title="{{ tx.num_confirmations }} confirmations"/>
{% else %}
<img style="width: 16px;" src="{{ url_for('static', filename="images/")}}confirm_complete.png" title="{{ tx.num_confirmations }} confirmations"/>
{% endif %}
</td>
</tr>
{% endfor %}
{% if lnd_transactions|length >= lnd_tx_display_limit %}
<tr><td colspan=9>more...</td></tr>
{% endif %}
{% else %}
<tr><td colspan=9 style="text-align: center;"><br/><br/>None yet!</td></tr>
{% endif %}
</table>
</div>
<div>
<b>Lightning Transactions</b>
<table style="font-size: 12px; width: 270px; margin: 10px;">
<tr>
<td>Date</td>
<td>Amount</td>
<td></td>
</tr>
{% if lnd_payments_and_invoices and lnd_payments_and_invoices|length > 0 %}
{% for tx in lnd_payments_and_invoices[:lnd_tx_display_limit] %}
<tr>
<td>{{ tx.date_str }}</td>
<td>{{ tx.value_str }}</td>
<td>
{% if tx.type == "PAYMENT" %}
<img style="width: 16px;" src="{{ url_for('static', filename="images/ln_send.png")}}" title="{{ tx.memo }}"/>
{% else %}
<img style="width: 16px;" src="{{ url_for('static', filename="images/ln_recv.png")}}" title="{{ tx.memo }}"/>
{% endif %}
{% if tx.state == "OPEN" %}
<img style="width: 16px;" src="{{ url_for('static', filename="images/")}}invoice_pending.png" title="open invoice"/>
{% elif tx.state == "SETTLED" %}
<img style="width: 16px;" src="{{ url_for('static', filename="images/")}}invoice_complete.png" title="settled invoice"/>
{% elif tx.state == "CANCELED" or tx.state == "CANCELLED" %}
<img style="width: 16px;" src="{{ url_for('static', filename="images/")}}invoice_cancelled.png" title="cancelled invoice"/>
{% endif %}
{% if tx.memo != None and tx.memo != "" %}
<img style="width: 16px;" src="{{ url_for('static', filename="images/memo.png")}}" title="{{ tx.memo }}"/>
{% endif %}
</td>
</tr>
{% endfor %}
{% if lnd_invoices|length >= lnd_tx_display_limit %}
<tr><td colspan=9>more...</td></tr>
{% endif %}
{% else %}
<tr><td colspan=9 style="text-align: center;"><br/><br/>None yet!</td></tr>
{% endif %}
</table>
</div>
</div>
<!-- Channels -->
{% if lnd_channels|length > 0 %}
<br/><br/>
<b>Channels</b><br/>

View File

@ -402,7 +402,7 @@
</tr>
{% endfor %}
{% if transactions|length >= tx_display_limit %}
<td colspan=9>more...</td>
<tr><td colspan=9>more...</td></tr>
{% endif %}
</tbody>
</table>
@ -429,7 +429,7 @@
</tr>
{% endfor %}
{% if payments|length >= tx_display_limit %}
<td colspan=9>more...</td>
<tr><td colspan=9>more...</td></tr>
{% endif %}
</tbody>
</table>
@ -458,10 +458,10 @@
</td>
<td>{{ tx.state }}</td>
</tr>
{% if invoices|length >= tx_display_limit %}
<td colspan=9>more...</td>
{% endif %}
{% endfor %}
{% if invoices|length >= tx_display_limit %}
<tr><td colspan=9>more...</td></tr>
{% endif %}
</tbody>
</table>
{% endif %}

View File

@ -188,6 +188,9 @@
if ("channel_balance" in balances && balances["channel_balance"] != null) {
$("#lnd_channel_balance").html(balances["channel_balance"]);
}
if ("total_balance" in balances && balances["total_balance"] != null) {
$("#lnd_total_balance").html(balances["total_balance"] + " sats");
}
}
if ("lnd_ready" in data && data["lnd_ready"] != null) {
if (lnd_ready != data["lnd_ready"]) {