create wallet using localstorage credentials, removed read_rpc_config

This commit is contained in:
0ceanSlim 2024-01-02 12:02:31 -05:00
parent 4f8290ae53
commit 98b8494967
4 changed files with 15 additions and 21 deletions

View File

@ -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():

View File

@ -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",]

View File

@ -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)
return "An Exception occurred: " + str(general_exception)

View File

@ -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