all functions not related to app routing have been split form app.py and put into the src folder
This commit is contained in:
parent
86453c793a
commit
559fda1418
56
app/app.py
56
app/app.py
@ -1,60 +1,10 @@
|
||||
from flask import Flask, request, jsonify, render_template
|
||||
|
||||
from src import create_wallet, read_rpc_config
|
||||
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
|
||||
from mnemonic import Mnemonic
|
||||
import json
|
||||
|
||||
from src import create_wallet, read_rpc_config, generate_seed
|
||||
|
||||
app = Flask(__name__, static_folder='static')
|
||||
|
||||
#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
|
||||
|
||||
def create_rpc_connection(rpc_host, rpc_port, rpc_user, rpc_password):
|
||||
rpc_url = f"http://{rpc_user}:{rpc_password}@{rpc_host}:{rpc_port}"
|
||||
return AuthServiceProxy(rpc_url)
|
||||
|
||||
|
||||
# Function to create a wallet
|
||||
#def create_wallet(wallet_name):
|
||||
# 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()
|
||||
#
|
||||
# if wallet_name not in wallet_info:
|
||||
# rpc_connection.createwallet(wallet_name)
|
||||
# return f"Wallet '{wallet_name}' created successfully."
|
||||
# else:
|
||||
# return f"Wallet '{wallet_name}' already exists."
|
||||
# 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)
|
||||
|
||||
# Function to generate seed based on seed length
|
||||
def generate_seed(seed_length):
|
||||
try:
|
||||
if seed_length == "12" or seed_length == "24":
|
||||
entropy_bits = 128 if seed_length == "12" else 256
|
||||
mnemonic = Mnemonic("english")
|
||||
seed_words = mnemonic.generate(entropy_bits)
|
||||
return seed_words
|
||||
else:
|
||||
return "Invalid choice. Please choose 12 or 24."
|
||||
except Exception as e:
|
||||
return "An error occurred: " + str(e)
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def show_wallet_form():
|
||||
return render_template('index.html')
|
||||
@ -91,7 +41,7 @@ def update_rpc_config():
|
||||
|
||||
# For demonstration purposes, let's update the configuration and return success
|
||||
try:
|
||||
with open("../rpc_config.json", "w") as config_file:
|
||||
with open("rpc_config.json", "w") as config_file:
|
||||
config = {
|
||||
"rpc_host": rpc_host,
|
||||
"rpc_port": rpc_port,
|
||||
|
@ -1,7 +1,5 @@
|
||||
from .read_rpc_config import read_rpc_config
|
||||
from .create_wallet import create_wallet
|
||||
#from .rpc_connection import create_rpc_connection
|
||||
#from .wallet_operations import create_wallet, generate_seed
|
||||
from .generate_seed import generate_seed
|
||||
|
||||
# You can add more imports here
|
||||
__all__ = ['read_rpc_config', 'create_wallet'] # 'create_rpc_connection', 'generate_seed']
|
||||
__all__ = ['read_rpc_config', 'create_wallet', 'generate_seed']
|
||||
|
13
app/src/generate_seed.py
Normal file
13
app/src/generate_seed.py
Normal file
@ -0,0 +1,13 @@
|
||||
from mnemonic import Mnemonic
|
||||
|
||||
def generate_seed(seed_length):
|
||||
try:
|
||||
if seed_length == "12" or seed_length == "24":
|
||||
entropy_bits = 128 if seed_length == "12" else 256
|
||||
mnemonic = Mnemonic("english")
|
||||
seed_words = mnemonic.generate(entropy_bits)
|
||||
return seed_words
|
||||
else:
|
||||
return "Invalid choice. Please choose 12 or 24."
|
||||
except Exception as e:
|
||||
return "An error occurred: " + str(e)
|
Loading…
Reference in New Issue
Block a user