diff --git a/app/app.py b/app/app.py index 2a56907..5fcb76e 100644 --- a/app/app.py +++ b/app/app.py @@ -1,9 +1,8 @@ from flask import Flask, request, jsonify, render_template -import json from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException -from src import create_wallet, read_rpc_config +from src import create_wallet app = Flask(__name__, static_folder="static") @@ -22,9 +21,19 @@ def show_wallet_form(): @app.route("/create_wallet", methods=["POST"]) def handle_create_wallet(): wallet_name = request.form["walletName"] - result = create_wallet(wallet_name) + + # Retrieve RPC credentials from localStorage (cookies) + rpc_host = request.cookies.get("rpcHost") + rpc_port = request.cookies.get("rpcPort") + rpc_user = request.cookies.get("rpcUser") + rpc_password = request.cookies.get("rpcPassword") + + # Create wallet using retrieved RPC credentials + result = create_wallet(wallet_name, rpc_host, rpc_port, rpc_user, rpc_password) + return jsonify({"message": result}) + # Fetch wallets route using RPC credentials from localStorage @app.route("/wallets", methods=["GET"]) def list_wallets(): diff --git a/app/src/__init__.py b/app/src/__init__.py index 7870c4f..1f7d0fb 100644 --- a/app/src/__init__.py +++ b/app/src/__init__.py @@ -1,5 +1,4 @@ -from .read_rpc_config import read_rpc_config from .create_wallet import create_wallet -__all__ = ["read_rpc_config", "create_wallet"] +__all__ = ["create_wallet",] diff --git a/app/src/create_wallet.py b/app/src/create_wallet.py index d7bcf9a..790c327 100644 --- a/app/src/create_wallet.py +++ b/app/src/create_wallet.py @@ -1,9 +1,7 @@ from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException -from src.read_rpc_config import read_rpc_config -def create_wallet(wallet_name): +def create_wallet(wallet_name, rpc_host, rpc_port, rpc_user, rpc_password): 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_info = rpc_connection.listwallets() @@ -16,4 +14,4 @@ def create_wallet(wallet_name): except JSONRPCException as json_exception: return "A JSON RPC Exception occurred: " + str(json_exception) except Exception as general_exception: - return "An Exception occurred: " + str(general_exception) \ No newline at end of file + return "An Exception occurred: " + str(general_exception) diff --git a/app/src/read_rpc_config.py b/app/src/read_rpc_config.py deleted file mode 100644 index d97214f..0000000 --- a/app/src/read_rpc_config.py +++ /dev/null @@ -1,12 +0,0 @@ -import json - -def read_rpc_config(filename="rpc_config.json"): - with open(filename, "r") as config_file: - config = json.load(config_file) - - rpc_host = config["rpc_host"] - rpc_port = config["rpc_port"] - rpc_user = config["rpc_user"] - rpc_password = config["rpc_password"] - - return rpc_host, rpc_port, rpc_user, rpc_password \ No newline at end of file