moved some funtions into src in app, moved cli to it's own directory

This commit is contained in:
0ceanSlim 2023-12-21 09:56:52 -05:00
parent 899689bb81
commit 407bae12cf
22 changed files with 79 additions and 32 deletions

7
.gitignore vendored
View File

@ -1,6 +1,7 @@
rpc_config.json
bfg.jar
/build
/dist
build
dist
*.spec
__pycache__/
__pycache__/
*.exe

View File

@ -14,12 +14,18 @@ cd elements.py
## Usage
**Windows**
Just run the `cli.exe` in the root directory of this repository. The program will walk you through all the necessay steps to begin using the cli and when all requirements are met, the cli will load with initial instructions.
### Windows
Download the latest cli.exe from the releases page of this repository and place it in the cli folder before running it. The exe will walk you through all the necessay steps to begin using the cli and when all requirements are met, the cli will load with initial instructions.
If you are on Linux or MacOS, you will need python installed before you can run cli.py
You can download Python [Here](https://www.python.org/downloads/)
### Running with Python (any system)
**From the cli directory** run:
```bash
python cli.py
```
## Flask App Development
First install the requirements with
```bash

View File

@ -1,20 +1,22 @@
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
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 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}"
@ -22,22 +24,22 @@ def create_rpc_connection(rpc_host, rpc_port, rpc_user, rpc_password):
# 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)
#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):

7
app/src/__init__.py Normal file
View File

@ -0,0 +1,7 @@
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
# You can add more imports here
__all__ = ['read_rpc_config', 'create_wallet'] # 'create_rpc_connection', 'generate_seed']

19
app/src/create_wallet.py Normal file
View File

@ -0,0 +1,19 @@
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
from src.read_rpc_config import read_rpc_config
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)

View File

@ -0,0 +1,12 @@
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

View File

@ -70,7 +70,7 @@ def main():
while not check_python_installation():
install_python()
subprocess.run(["pip", "install", "-r", "requirements.txt"])
subprocess.run(["pip", "install", "-r", "../requirements.txt"])
while not check_rpc_config():
clear_console()

View File