diff --git a/app/app.py b/app/app.py index 74df12e..ae38d0f 100644 --- a/app/app.py +++ b/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) \ No newline at end of file + app.run(debug=True) diff --git a/app/src/__init__.py b/app/src/__init__.py index 7695b0c..eefcae1 100644 --- a/app/src/__init__.py +++ b/app/src/__init__.py @@ -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"] diff --git a/app/src/list_wallets.py b/app/src/list_wallets.py new file mode 100644 index 0000000..0007add --- /dev/null +++ b/app/src/list_wallets.py @@ -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) diff --git a/app/templates/index.html b/app/templates/index.html index 7275fb1..b20c0c9 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -1,47 +1,114 @@ - - + + Liquid Wallet - - + +

Create a New Wallet

- -

- - -

- - + +

+ + +

+ +
- +

RPC Configuration

-
- -

+ + +

- -

+ +

- -

+ +

- -

+ +

- -
+ + -
+
- - + + +

Available Wallets

+
+ + diff --git a/requirements.txt b/requirements.txt index 6a64a90..b726bfa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ python-bitcoinrpc mnemonic flask -jsonify \ No newline at end of file +jsonify +bitcoinlib \ No newline at end of file