Add lightning info to home screen

This commit is contained in:
Taylor Helsper 2021-03-16 23:31:46 -05:00
parent 9a43686431
commit e85de943c9
7 changed files with 143 additions and 74 deletions

View File

@ -69,12 +69,12 @@ def update_lightning_info():
return True
def get_deposit_address():
def get_lnd_deposit_address():
if os.path.isfile("/tmp/lnd_deposit_address"):
return get_file_contents("/tmp/lnd_deposit_address")
return get_new_deposit_address()
return get_new_lnd_deposit_address()
def get_new_deposit_address():
def get_new_lnd_deposit_address():
address = "NEW_ADDR"
try:
addressdata = lnd_get("/newaddress")
@ -91,7 +91,31 @@ def get_lightning_info():
def get_lightning_peers():
global lightning_peers
return copy.deepcopy(lightning_peers)
peerdata = copy.deepcopy(lightning_peers)
peers = []
if peerdata != None and "peers" in peerdata:
for p in peerdata["peers"]:
peer = p
if "bytes_recv" in p:
peer["bytes_recv"] = "{:.2f}".format(float(p["bytes_recv"]) / 1000 / 1000)
else:
peer["bytes_recv"] = "N/A"
if "bytes_sent" in p:
peer["bytes_sent"] = "{:.2f}".format(float(p["bytes_sent"]) / 1000 / 1000)
else:
peer["bytes_sent"] = "N/A"
if "sat_sent" in p:
peer["sat_sent"] = format_sat_amount(peer["sat_sent"])
if "sat_recv" in p:
peer["sat_recv"] = format_sat_amount(peer["sat_recv"])
if "ping_time" not in p:
peer["ping_time"] = "N/A"
if "pub_key" in p:
peer["alias"] = get_lightning_peer_alias( p["pub_key"] )
else:
peer["alias"] = "Unknown"
peers.append(peer)
return peers
def get_lightning_node_info(pubkey):
nodeinfo = lnd_get("/graph/node/{}".format(pubkey), timeout=2)
@ -118,13 +142,40 @@ def get_lightning_peer_count():
def get_lightning_channels():
global lightning_channels
return copy.deepcopy(lightning_channels)
channeldata = copy.deepcopy(lightning_channels)
channels = []
if channeldata != None and "channels" in channeldata:
for c in channeldata["channels"]:
channel = c
if "capacity" in channel:
channel["capacity"] = format_sat_amount(channel["capacity"])
else:
channel["capacity"] = "N/A"
if "local_balance" in channel and "remote_balance" in channel:
l = float(channel["local_balance"])
r = float(channel["remote_balance"])
channel["chan_percent"] = (l / (l+r)) * 100
else:
channel["chan_percent"] = "0"
if "local_balance" in channel:
channel["local_balance"] = format_sat_amount(channel["local_balance"])
else:
channel["local_balance"] = "0"
if "remote_balance" in channel:
channel["remote_balance"] = format_sat_amount(channel["remote_balance"])
else:
channel["remote_balance"] = "0"
if "remote_pubkey" in channel:
channel["remote_alias"] = get_lightning_peer_alias( channel["remote_pubkey"] )
else:
channel["remote_alias"] = "Unknown"
channels.append(channel)
return channels
def get_lightning_channel_count():
channeldata = get_lightning_channels()
if channeldata != None and "channels" in channeldata:
return len(channeldata["channels"])
return 0
channels = get_lightning_channels()
return len(channels)
def get_lightning_channel_balance():
global lightning_channel_balance

View File

@ -53,7 +53,7 @@ def page_lnd():
uri = ""
ip = ""
status = "Starting..."
lnd_deposit_address = get_deposit_address()
lnd_deposit_address = get_lnd_deposit_address()
channel_balance = "N/A"
channel_pending = "0"
wallet_balance = "N/A"
@ -110,52 +110,8 @@ def page_lnd():
uri = "..."
ip = "..."
peerdata = get_lightning_peers()
peers = []
if peerdata != None and "peers" in peerdata:
for p in peerdata["peers"]:
peer = p
if "bytes_recv" in p:
peer["bytes_recv"] = "{:.2f}".format(float(p["bytes_recv"]) / 1000 / 1000)
else:
peer["bytes_recv"] = "N/A"
if "bytes_sent" in p:
peer["bytes_sent"] = "{:.2f}".format(float(p["bytes_sent"]) / 1000 / 1000)
else:
peer["bytes_sent"] = "N/A"
if "sat_sent" in p:
peer["sat_sent"] = format_sat_amount(peer["sat_sent"])
if "sat_recv" in p:
peer["sat_recv"] = format_sat_amount(peer["sat_recv"])
if "ping_time" not in p:
peer["ping_time"] = "N/A"
if "pub_key" in p:
peer["alias"] = get_lightning_peer_alias( p["pub_key"] )
else:
peer["alias"] = "Unknown"
peers.append(peer)
channeldata = get_lightning_channels()
channels = []
if channeldata != None and "channels" in channeldata:
for c in channeldata["channels"]:
channel = c
if "capacity" in channel:
channel["capacity"] = format_sat_amount(channel["capacity"])
if "local_balance" not in channel:
channel["local_balance"] = "0"
else:
channel["local_balance"] = format_sat_amount(channel["local_balance"])
if "remote_balance" not in channel:
channel["remote_balance"] = "0"
else:
channel["remote_balance"] = format_sat_amount(channel["remote_balance"])
if "remote_pubkey" in channel:
channel["remote_alias"] = get_lightning_peer_alias( channel["remote_pubkey"] )
else:
channel["remote_alias"] = "Unknown"
channels.append(channel)
peers = get_lightning_peers()
channels = get_lightning_channels()
balance_info = get_lightning_balance_info()
channel_balance_data = get_lightning_channel_balance()
@ -488,9 +444,9 @@ def lnd_config_page():
##############################################
## LND API Calls
##############################################
@mynode_lnd.route("/lnd/api/get_new_deposit_address", methods=['GET'])
def lnd_api_get_new_deposit_address_page():
@mynode_lnd.route("/lnd/api/get_new_lnd_deposit_address", methods=['GET'])
def lnd_api_get_new_lnd_deposit_address_page():
check_logged_in()
address = get_new_deposit_address()
address = get_new_lnd_deposit_address()
return address

View File

@ -556,6 +556,8 @@ def index():
"lnd_balance_info": get_lightning_balance_info(),
"lnd_wallet_exists": lnd_wallet_exists(),
"lnd_version": get_lnd_version(),
"lnd_deposit_address": get_lnd_deposit_address(),
"lnd_channels": get_lightning_channels(),
"is_testnet_enabled": is_testnet_enabled(),
"tor_status_color": tor_status_color,
"tor_status": tor_status,

View File

@ -290,6 +290,28 @@ td, th {
width: 100%;
}
.lightning_channel {
display: inline-block;
width: 100%;
margin-bottom: 20px;
}
.lightning_channel_bar {
margin: auto;
}
.lightning_channel_bar_label_left {
font-size: 12px;
float: left;
}
.lightning_channel_bar_label_right {
font-size: 12px;
float: right;}
.lightning_channel_bar.ui-progressbar {
background: orange;
}
.lightning_channel_bar .ui-progressbar-value {
background: green;
}
.green { background-color: green; }
.yellow { background-color: yellow; }

View File

@ -86,9 +86,10 @@
</tr>
</table>
<br/>
<!--
{% if lnd_wallet_exists and lnd_ready %}
<img class="" id="show_lightning_details" style="margin: auto; width: 60px; cursor: pointer;" onclick="toggleLightningDetails();" src="{{ url_for('static', filename="images/expand_down.png")}}"/>
-->
{% endif %}
</div>
</div>
</div>
@ -160,17 +161,35 @@
<!-- Show Lightning Details -->
<div class="app_tile_row">
<div class="app_tile_lightning_details" id="lightning_details" style="display: none;">
blah<br/>
blah<br/>
blah<br/>
blah<br/>
blah<br/>
blah<br/>
blah<br/>
blah<br/>
blah<br/>
blah<br/>
blah<br/>
blah<br/>
<!--
<table>
<tr>
<td>
<div id="lnd_deposit_address_qrcode" style="height: 120px; width: 120px; display: inline;"></div>
</td>
<td>
<b>Deposit Address:</b> {{lnd_deposit_address}}<br/>
<b>On-chain Balance:</b> {{lnd_deposit_address}}<br/>
<b>Channel Balance:</b> {{lnd_deposit_address}}<br/>
</td>
</tr>
</table>
-->
<b>Deposit Address</b><br/>
<div id="lnd_deposit_address_qrcode" style="height: 100px; width: 100px; margin: auto; margin-top: 5px; "></div>
<span style="font-size: 12px;">{{lnd_deposit_address}}</span>
{% if lnd_channels|length > 0 %}
<br/><br/>
<b>Channels</b><br/>
{% for c in lnd_channels %}
<div class="lightning_channel">
<div style="text-align: left; font-weight: bold; margin-bottom: 5px;">{{ c.remote_alias }}</div>
<div id="channel_bar_{{ c.chan_id }}" class="lightning_channel_bar"></div>
<div class="lightning_channel_bar_label_left">{{c.local_balance}} sats</div>
<div class="lightning_channel_bar_label_right">{{c.remote_balance}} sats</div>
</div>
{% endfor %}
{% endif %}
</div>
</div>

View File

@ -81,7 +81,7 @@
});
}
$("#gen_new_address_button").on("click", function() {
$.get( "/lnd/api/get_new_deposit_address", function( data ) {
$.get( "/lnd/api/get_new_lnd_deposit_address", function( data ) {
$("#gen_new_address_button").hide();
show_deposit_address(data);
});

View File

@ -4,6 +4,8 @@
{% include 'includes/head.html' %}
<meta http-equiv="refresh" content="{{ refresh_rate }}">
<script src="{{ url_for('static', filename='js/qrcode.js')}}"></script>
<script>
// Update status functions
function update_status(status_name, data) {
@ -46,9 +48,26 @@
} else {
$("#lightning_details").slideDown(400);
$('#show_lightning_details').attr('src', location.protocol+'//'+location.hostname+'/static/images/expand_up.png');
{% for c in lnd_channels %}
// Initialize channel balance bars
$( "#channel_bar_{{ c.chan_id }}" ).progressbar({
value: Math.floor( {{ c.chan_percent }} )
});
$('#channel_bar_{{ c.chan_id }}').height(15);
{% endfor %}
$("#lnd_deposit_address_qrcode").html( "" );
var qrcode = new QRCode("lnd_deposit_address_qrcode", {
text: "{{lnd_deposit_address}}",
width: 100,
height: 100,
correctLevel : QRCode.CorrectLevel.H
});
}
showing_lightning_details = !showing_lightning_details;
}
// Update page function
var lnd_ready = {% if lnd_ready %}true{% else %}false{% endif %};