Show wallet info on bitcoin page

This commit is contained in:
Taylor Helsper 2021-03-13 22:30:41 -06:00
parent 1b14ea73a3
commit 232c68485b
4 changed files with 69 additions and 40 deletions

View File

@ -22,6 +22,9 @@ rpcallowip=192.168.0.0/16
main.wallet=wallet.dat
main.wallet=joinmarket_wallet.dat
test.wallet=wallet.dat
test.wallet=joinmarket_wallet.dat
# Enable Bloom filters
whitelist=bloomfilter@127.0.0.1
whitelist=bloomfilter@10.0.0.0/8

View File

@ -1,6 +1,7 @@
from config import *
from threading import Timer
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
import urllib
import subprocess
import copy
import time
@ -14,7 +15,7 @@ bitcoin_recent_blocks = None
bitcoin_recent_blocks_last_cache_height = 566000
bitcoin_peers = []
bitcoin_network_info = None
bitcoin_wallet_info = None
bitcoin_wallets = None
bitcoin_mempool = None
bitcoin_version = None
@ -71,7 +72,7 @@ def update_bitcoin_other_info():
global bitcoin_peers
global bitcoin_network_info
global bitcoin_mempool
global bitcoin_wallet_info
global bitcoin_wallets
while bitcoin_blockchain_info == None:
# Wait until we have gotten the important info...
@ -103,7 +104,14 @@ def update_bitcoin_other_info():
bitcoin_mempool = rpc_connection.getmempoolinfo()
# Get wallet info
bitcoin_wallet_info = rpc_connection.getwalletinfo()
wallets = rpc_connection.listwallets()
wallet_data = []
for w in wallets:
wallet_name = urllib.pathname2url(w)
wallet_rpc_connection = AuthServiceProxy("http://%s:%s@127.0.0.1:8332/wallet/%s"%(rpc_user, rpc_pass, wallet_name), timeout=60)
wallet_info = wallet_rpc_connection.getwalletinfo()
wallet_data.append(wallet_info)
bitcoin_wallets = wallet_data
except:
pass
@ -187,9 +195,9 @@ def get_bitcoin_mempool_size():
size = float(info["bytes"]) / 1000 / 1000
return "{:.3} MB".format(size)
def get_bitcoin_wallet_info():
global bitcoin_wallet_info
return copy.deepcopy(bitcoin_wallet_info)
def get_bitcoin_wallets():
global bitcoin_wallets
return copy.deepcopy(bitcoin_wallets)
def get_default_bitcoin_config():
try:

View File

@ -23,6 +23,8 @@ def runcmd(cmd):
results = str(e)
return results
def cleanup_download_wallets():
os.system("rm -rf /tmp/download_wallets/*")
### Page functions
@mynode_bitcoind.route("/bitcoind")
@ -35,7 +37,7 @@ def bitcoind_status_page():
blockdata = get_bitcoin_recent_blocks()
peerdata = get_bitcoin_peers()
networkdata = get_bitcoin_network_info()
walletdata = get_bitcoin_wallet_info()
walletdata = get_bitcoin_wallets()
version = get_bitcoin_version()
rpc_password = get_bitcoin_rpc_password()
@ -89,16 +91,6 @@ def bitcoind_status_page():
if ("localaddresses" in networkdata) and (len(networkdata["localaddresses"]) > 0):
local_address = "{}:{}".format(networkdata["localaddresses"][0]["address"], networkdata["localaddresses"][0]["port"])
# Balance
walletinfo = {}
walletinfo["balance"] = 0.0
walletinfo["unconfirmed_balance"] = 0.0
if walletdata != None:
if "balance" in walletdata:
walletinfo["balance"] = walletdata["balance"]
if "unconfirmed_balance" in walletdata:
walletinfo["unconfirmed_balance"] = walletdata["unconfirmed_balance"]
except Exception as e:
templateData = {
"title": "myNode Bitcoin Error",
@ -121,18 +113,33 @@ def bitcoind_status_page():
"mempool_tx": mempool["size"],
"mempool_size": "{:.3} MB".format(float(mempool["bytes"]) / 1000 / 1000),
"is_testnet_enabled": is_testnet_enabled(),
"confirmed_balance": walletinfo["balance"],
"unconfirmed_balance": walletinfo["unconfirmed_balance"],
"wallets": walletdata,
"bitcoin_whitepaper_exists": bitcoin_whitepaper_exists,
"version": version,
"ui_settings": read_ui_settings()
}
return render_template('bitcoind_status.html', **templateData)
@mynode_bitcoind.route("/bitcoind/wallet.dat")
def bitcoin_wallet_dat():
@mynode_bitcoind.route("/bitcoind/download_wallet", methods=["GET"])
def bitcoin_download_wallet():
check_logged_in()
return send_from_directory(directory="/mnt/hdd/mynode/bitcoin/", filename="wallet.dat")
wallet_name = request.args.get('wallet')
if wallet_name is None:
flash("Error finding wallet to download!", category="error")
return redirect("/bitcoind")
os.system("mkdir -p /tmp/download_wallets")
os.system("chmod 777 /tmp/download_wallets")
runcmd("-rpcwallet='"+wallet_name+"' dumpwallet '/tmp/download_wallets/"+wallet_name+"'")
if not os.path.isfile("/tmp/download_wallets/"+wallet_name):
flash("Error exporting wallet data for download", category="error")
return redirect("/bitcoind")
t = Timer(3.0, cleanup_download_wallets)
t.start()
return send_from_directory(directory="/tmp/download_wallets/", filename=wallet_name, as_attachment=True)
@mynode_bitcoind.route("/bitcoind/bitcoin_whitepaper.pdf")
def bitcoin_whitepaper_pdf():

View File

@ -22,6 +22,8 @@
<a class="ui-button ui-widget ui-corner-all mynode_back" href="/"><span class="ui-icon ui-icon-home"></span>home&nbsp;</a>
</div>
{% include 'includes/message_display.html' %}
<div class="main_header">Bitcoin Status</div>
<br/>
@ -93,22 +95,16 @@
<table class="info_table">
<tr>
<th>Config</th>
<td><a class="ui-button ui-widget ui-corner-all mynode_button_small" style="width: 70%;" href="/bitcoind/config">view / edit</a></td>
<td><a class="ui-button ui-widget ui-corner-all mynode_button_small" style="width: 100px;" href="/bitcoind/config">view / edit</a></td>
</tr>
<tr>
<th>CLI</th>
<td><a class="ui-button ui-widget ui-corner-all mynode_button_small" style="width: 70%;" href="/bitcoind/cli">CLI</a></td>
<td><a class="ui-button ui-widget ui-corner-all mynode_button_small" style="width: 100px;" href="/bitcoind/cli">CLI</a></td>
</tr>
<tr>
<th>Whitepaper</th>
<td><a class="ui-button ui-widget ui-corner-all mynode_button_small" style="width: 70%;" href="/bitcoind/bitcoin_whitepaper.pdf">download</a></td>
<td><a class="ui-button ui-widget ui-corner-all mynode_button_small" style="width: 100px;" href="/bitcoind/bitcoin_whitepaper.pdf">download</a></td>
</tr>
{% if confirmed_balance > 0.0 or unconfirmed_balance > 0.0 %}
<tr>
<th>Wallet Backup</th>
<td><a class="ui-button ui-widget ui-corner-all mynode_button_small" style="width: 70%;" href="/bitcoind/wallet.dat">download</a></td>
</tr>
{% endif %}
</table>
</div>
</div>
@ -121,22 +117,37 @@
</div>
</div>
{% if confirmed_balance > 0.0 %}
{% if wallets is not none %}
<br/>
<div class="main_header">Wallet balance</div>
<div class="main_header">Wallets</div>
<table class="bitcoind_table">
<thead class="bitcoind_table_header">
<td>Confirmed Balance</td>
<td>Unconfirmed Balance</td>
<td>Wallet</td>
<td>Balance</td>
<td>Actions</td>
</thead>
<tbody>
{% for wallet in wallets %}
<tr>
<td>{{ "%.8f"|format(confirmed_balance) }}</td>
<td>{{ "%.8f"|format(unconfirmed_balance) }}</td>
<td>{{ wallet.walletname }}</td>
<td>
{{ "%.8f"|format(wallet.balance) }}
{% if wallet.unconfirmed_balance > 0 %}
<br/>
<span style="font-size: 12px;">{{ "%.8f"|format(wallet.unconfirmed_balance) }} pending</span>
{% endif %}
</td>
<td>
<a class="ui-button ui-widget ui-corner-all mynode_button_small" style="width: 100px;" href="/bitcoind/download_wallet?wallet={{wallet.walletname|urlencode}}">download</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<p style="font-size: 12px; color: gray; text-align: center;">
*These wallets are not your main lightning wallet. These have been created manually or via other applications.<br/>
**Wallet files may contain private keys and sensitive data. Be very cautious when downloading copies.
</p>
{% endif %}
<br/>