working on adding a wallet list
This commit is contained in:
parent
64647aa2a9
commit
cdfb9e7cde
78
app/app.py
78
app/app.py
@ -1,40 +1,76 @@
|
||||
from flask import Flask, request, jsonify, render_template
|
||||
import json
|
||||
|
||||
from src import create_wallet, read_rpc_config, generate_seed
|
||||
# from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
|
||||
|
||||
app = Flask(__name__, static_folder='static')
|
||||
from src import create_wallet, read_rpc_config, generate_seed, list_wallets
|
||||
|
||||
@app.route('/')
|
||||
app = Flask(__name__, static_folder="static")
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def show_wallet_form():
|
||||
return render_template('index.html')
|
||||
return render_template("index.html")
|
||||
|
||||
@app.route('/create_wallet', methods=['POST'])
|
||||
|
||||
@app.route("/create_wallet", methods=["POST"])
|
||||
def handle_create_wallet():
|
||||
wallet_name = request.form['walletName']
|
||||
wallet_name = request.form["walletName"]
|
||||
result = create_wallet(wallet_name)
|
||||
return jsonify({'message': result})
|
||||
return jsonify({"message": result})
|
||||
|
||||
@app.route('/generate_seed', methods=['POST'])
|
||||
|
||||
@app.route("/generate_seed", methods=["POST"])
|
||||
def handle_generate_seed():
|
||||
seed_length = request.form['seedLength']
|
||||
seed_length = request.form["seedLength"]
|
||||
result = generate_seed(seed_length)
|
||||
return jsonify({'seed': result})
|
||||
return jsonify({"seed": result})
|
||||
|
||||
|
||||
@app.route("/wallets", methods=["GET"])
|
||||
|
||||
# def list_wallets():
|
||||
# try:
|
||||
# rpc_host, rpc_port, rpc_user, rpc_password = read_rpc_config()
|
||||
#
|
||||
# rpc_connection = AuthServiceProxy(
|
||||
# f"http://{rpc_user}:{rpc_password}@{rpc_host}:{rpc_port}"
|
||||
# )
|
||||
#
|
||||
# wallet_list = rpc_connection.listwallets()
|
||||
#
|
||||
# return render_template("wallets.html", wallets=wallet_list)
|
||||
#
|
||||
# except JSONRPCException as json_exception:
|
||||
# error_message = "A JSON RPC Exception occurred: " + str(json_exception)
|
||||
# return render_template("error.html", error=error_message)
|
||||
#
|
||||
# except Exception as general_exception:
|
||||
# error_message = "An Exception occurred: " + str(general_exception)
|
||||
# return render_template("error.html", error=error_message)
|
||||
|
||||
|
||||
# Route to get the current RPC configuration
|
||||
@app.route('/get_rpc_config', methods=['GET'])
|
||||
@app.route("/get_rpc_config", methods=["GET"])
|
||||
def get_rpc_config():
|
||||
rpc_host, rpc_port, rpc_user, rpc_password = read_rpc_config()
|
||||
return jsonify({'rpcHost': rpc_host, 'rpcPort': rpc_port, 'rpcUser': rpc_user, 'rpcPassword': rpc_password})
|
||||
return jsonify(
|
||||
{
|
||||
"rpcHost": rpc_host,
|
||||
"rpcPort": rpc_port,
|
||||
"rpcUser": rpc_user,
|
||||
"rpcPassword": rpc_password,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
# Route to update the RPC configuration
|
||||
@app.route('/update_rpc_config', methods=['POST'])
|
||||
@app.route("/update_rpc_config", methods=["POST"])
|
||||
def update_rpc_config():
|
||||
rpc_host = request.form['rpcHost']
|
||||
rpc_port = request.form['rpcPort']
|
||||
rpc_user = request.form['rpcUser']
|
||||
rpc_password = request.form['rpcPassword']
|
||||
rpc_host = request.form["rpcHost"]
|
||||
rpc_port = request.form["rpcPort"]
|
||||
rpc_user = request.form["rpcUser"]
|
||||
rpc_password = request.form["rpcPassword"]
|
||||
|
||||
# Update the RPC configuration file or database with the new values
|
||||
# You may want to perform validation or error handling here
|
||||
@ -46,13 +82,13 @@ def update_rpc_config():
|
||||
"rpc_host": rpc_host,
|
||||
"rpc_port": rpc_port,
|
||||
"rpc_user": rpc_user,
|
||||
"rpc_password": rpc_password
|
||||
"rpc_password": rpc_password,
|
||||
}
|
||||
json.dump(config, config_file)
|
||||
return jsonify({'message': 'RPC configuration updated successfully.'})
|
||||
return jsonify({"message": "RPC configuration updated successfully."})
|
||||
except Exception as e:
|
||||
return jsonify({'message': f'Error updating RPC configuration: {str(e)}'})
|
||||
return jsonify({"message": f"Error updating RPC configuration: {str(e)}"})
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True)
|
||||
app.run(debug=True)
|
||||
|
@ -1,5 +1,6 @@
|
||||
from .read_rpc_config import read_rpc_config
|
||||
from .create_wallet import create_wallet
|
||||
from .generate_seed import generate_seed
|
||||
from .list_wallets import list_wallets
|
||||
|
||||
__all__ = ['read_rpc_config', 'create_wallet', 'generate_seed']
|
||||
__all__ = ["read_rpc_config", "create_wallet", "generate_seed", "list_wallets"]
|
||||
|
25
app/src/list_wallets.py
Normal file
25
app/src/list_wallets.py
Normal file
@ -0,0 +1,25 @@
|
||||
from flask import render_template
|
||||
|
||||
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
|
||||
from src.read_rpc_config import read_rpc_config
|
||||
|
||||
|
||||
def list_wallets():
|
||||
try:
|
||||
rpc_host, rpc_port, rpc_user, rpc_password = read_rpc_config()
|
||||
|
||||
rpc_connection = AuthServiceProxy(
|
||||
f"http://{rpc_user}:{rpc_password}@{rpc_host}:{rpc_port}"
|
||||
)
|
||||
|
||||
wallet_list = rpc_connection.listwallets()
|
||||
|
||||
return render_template("index.html", wallets=wallet_list)
|
||||
|
||||
except JSONRPCException as json_exception:
|
||||
error_message = "A JSON RPC Exception occurred: " + str(json_exception)
|
||||
return render_template("error.html", error=error_message)
|
||||
|
||||
except Exception as general_exception:
|
||||
error_message = "An Exception occurred: " + str(general_exception)
|
||||
return render_template("error.html", error=error_message)
|
@ -1,47 +1,114 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="stylesheet" type="text/css" href="../static/style/output.css" />
|
||||
<title>Liquid Wallet</title>
|
||||
</head>
|
||||
<body class="font-mono text-white bg-neutral-800">
|
||||
</head>
|
||||
<body class="font-mono text-white bg-neutral-800">
|
||||
<h1 class="mb-4 ml-4 text-xl font-bold">Create a New Wallet</h1>
|
||||
<form id="walletForm">
|
||||
<label for="walletName" class="ml-4">Wallet Name:</label>
|
||||
<input type="text" id="walletName" class="text-black rounded-sm" name="walletName" required><br><br>
|
||||
|
||||
<label for="seedLength" class="ml-4">Choose Seed Phrase Length:</label>
|
||||
<select id="seedLength" class="text-black rounded-sm" name="seedLength">
|
||||
<option value="12">12 Words</option>
|
||||
<option value="24">24 Words</option>
|
||||
</select><br><br>
|
||||
|
||||
<button type="submit" class="p-2 ml-4 font-bold bg-green-600 rounded-sm hover:bg-green-800">Create Wallet</button>
|
||||
<label for="walletName" class="ml-4">Wallet Name:</label>
|
||||
<input
|
||||
type="text"
|
||||
id="walletName"
|
||||
class="text-black rounded-sm"
|
||||
name="walletName"
|
||||
required
|
||||
/><br /><br />
|
||||
|
||||
<label for="seedLength" class="ml-4">Choose Seed Phrase Length:</label>
|
||||
<select id="seedLength" class="text-black rounded-sm" name="seedLength">
|
||||
<option value="12">12 Words</option>
|
||||
<option value="24">24 Words</option></select
|
||||
><br /><br />
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
class="p-2 ml-4 font-bold bg-green-600 rounded-sm hover:bg-green-800"
|
||||
>
|
||||
Create Wallet
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div id="result" class="p-2 ml-4"></div>
|
||||
<script src="{{ url_for('static', filename='java/walletFormResponse.js') }}"></script>
|
||||
|
||||
|
||||
<h1 class="mt-6 mb-4 ml-2 text-xl font-bold">RPC Configuration</h1>
|
||||
<form id="rpcConfigForm">
|
||||
<label for="rpcHost" class="ml-2">RPC Host:</label>
|
||||
<input type="text" id="rpcHost" name="rpcHost" class="text-black rounded-sm" required><br><br>
|
||||
<form id="rpcConfigForm">
|
||||
<label for="rpcHost" class="ml-2">RPC Host:</label>
|
||||
<input
|
||||
type="text"
|
||||
id="rpcHost"
|
||||
name="rpcHost"
|
||||
class="text-black rounded-sm"
|
||||
required
|
||||
/><br /><br />
|
||||
|
||||
<label for="rpcPort" class="ml-2">RPC Port:</label>
|
||||
<input type="text" id="rpcPort" name="rpcPort" class="text-black rounded-sm" required><br><br>
|
||||
<label for="rpcPort" class="ml-2">RPC Port:</label>
|
||||
<input
|
||||
type="text"
|
||||
id="rpcPort"
|
||||
name="rpcPort"
|
||||
class="text-black rounded-sm"
|
||||
required
|
||||
/><br /><br />
|
||||
|
||||
<label for="rpcUser" class="ml-2">RPC User:</label>
|
||||
<input type="text" id="rpcUser" name="rpcUser" class="text-black rounded-sm" required><br><br>
|
||||
<label for="rpcUser" class="ml-2">RPC User:</label>
|
||||
<input
|
||||
type="text"
|
||||
id="rpcUser"
|
||||
name="rpcUser"
|
||||
class="text-black rounded-sm"
|
||||
required
|
||||
/><br /><br />
|
||||
|
||||
<label for="rpcPassword" class="ml-2">RPC Password:</label>
|
||||
<input type="password" id="rpcPassword" name="rpcPassword" class="text-black rounded-sm" required><br><br>
|
||||
<label for="rpcPassword" class="ml-2">RPC Password:</label>
|
||||
<input
|
||||
type="password"
|
||||
id="rpcPassword"
|
||||
name="rpcPassword"
|
||||
class="text-black rounded-sm"
|
||||
required
|
||||
/><br /><br />
|
||||
|
||||
<button type="submit" class="p-2 ml-2 font-bold bg-red-600 rounded-sm hover:bg-red-900">Save Configuration</button>
|
||||
</form>
|
||||
<button
|
||||
type="submit"
|
||||
class="p-2 ml-2 font-bold bg-red-600 rounded-sm hover:bg-red-900"
|
||||
>
|
||||
Save Configuration
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div id="rpcResult"></div>
|
||||
<div id="rpcResult"></div>
|
||||
|
||||
<script src="{{ url_for('static', filename='java/rpcResult.js') }}"></script>
|
||||
</body>
|
||||
<script src="{{ url_for('static', filename='java/rpcResult.js') }}"></script>
|
||||
|
||||
<h1 class="mt-6 mb-4 ml-2 text-xl font-bold">Available Wallets</h1>
|
||||
<div id="walletList" class="ml-4"></div>
|
||||
<script>
|
||||
// Fetch wallet list when the page loads
|
||||
window.onload = function () {
|
||||
fetch("/wallets")
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
const walletList = document.getElementById("walletList");
|
||||
if (data.wallets && data.wallets.length > 0) {
|
||||
const wallets = data.wallets;
|
||||
const walletsHTML = wallets
|
||||
.map((wallet) => `<p>${wallet}</p>`)
|
||||
.join("");
|
||||
walletList.innerHTML = walletsHTML;
|
||||
} else {
|
||||
walletList.innerHTML = "<p>No wallets found.</p>";
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error fetching wallet list:", error);
|
||||
const walletList = document.getElementById("walletList");
|
||||
walletList.innerHTML = "<p>Error fetching wallets.</p>";
|
||||
});
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,4 +1,5 @@
|
||||
python-bitcoinrpc
|
||||
mnemonic
|
||||
flask
|
||||
jsonify
|
||||
jsonify
|
||||
bitcoinlib
|
Loading…
Reference in New Issue
Block a user