Start BTC RPC Explorer after Electrs

This commit is contained in:
Taylor Helsper 2019-12-10 20:31:32 -06:00
parent bdf54d088f
commit 97a770ab26
5 changed files with 36 additions and 5 deletions

View File

@ -8,6 +8,7 @@ After=bitcoind.service
[Service]
ExecStartPre=/usr/bin/wait_on_bitcoin.sh
ExecStartPre=/usr/bin/wait_on_electrs.sh
WorkingDirectory=/opt/mynode/btc-rpc-explorer
ExecStart=/usr/bin/npm start

View File

@ -0,0 +1,13 @@
#!/bin/bash
set -x
set -e
# Wait to see if bitcoind is synced
echo "Checking if electrum server is ready is synced..."
while [ ! -f "/tmp/electrs_up_to_date" ]; do
echo "electrs not synced, sleeping 1m"
/bin/sleep 30s
done
exit 0

View File

@ -4,6 +4,7 @@ import subprocess
import requests
import socket
import json
import os
electrum_server_current_block = None
@ -15,6 +16,7 @@ def get_electrum_server_current_block():
def update_electrs_info():
global electrum_server_current_block
global electrs_active
try:
raw_data = requests.get("http://localhost:4224")
@ -23,6 +25,12 @@ def update_electrs_info():
for sample in family.samples:
if sample.name == "electrs_index_height":
electrum_server_current_block = int(sample.value)
bitcoin_block_height = get_bitcoin_block_height()
if electrum_server_current_block != None and bitcoin_block_height != None:
if electrum_server_current_block > bitcoin_block_height - 2:
os.system("touch /tmp/electrs_up_to_date")
electrs_active = True
except:
pass

View File

@ -299,11 +299,16 @@ def index():
# Find btc-rpc-explorer status
btcrpcexplorer_status = "BTC RPC Explorer"
if is_btcrpcexplorer_enabled():
if is_electrs_active():
status = os.system("systemctl status btc_rpc_explorer --no-pager")
if status != 0:
btcrpcexplorer_status_color = "red"
else:
btcrpcexplorer_status_color = "green"
btcrpcexplorer_ready = True
else:
btcrpcexplorer_status_color = "green"
btcrpcexplorer_status = "Waiting on electrs..."
# Find explorer status
explorer_status_color = electrs_status_color

View File

@ -59,9 +59,13 @@
<div class="app_status">{{ btcrpcexplorer_status }}</div>
<div class="app_contents">
{% if btcrpcexplorer_enabled %}
{% if btcrpcexplorer_ready %}
<a class="ui-button ui-widget ui-corner-all mynode_button" href="#" id="btcrpcexplorer">Explorer</a>
<a class="ui-button ui-widget ui-corner-all mynode_button" href="#" id="toggle-btcrpcexplorer">Disable</a>
{% endif %}
{% else %}
<a class="ui-button ui-widget ui-corner-all mynode_button" href="#" id="toggle-btcrpcexplorer">Enable</a>
{% endif %}
<a class="ui-button ui-widget ui-corner-all mynode_button" href="#" id="toggle-btcrpcexplorer">{% if btcrpcexplorer_enabled %}Disable{% else %}Enable{% endif %}</a>
</div>
</div>
<div class="app_tile">