From 5354abca42b189e01b924ef4cecd314c45232fe2 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Mon, 3 Jun 2024 15:56:00 +1000 Subject: [PATCH] fix: Use variables for data file locations --- hsd.py | 26 +++++++++++++------------- main.py | 6 ++++-- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/hsd.py b/hsd.py index 1d39ebb..a8190ef 100644 --- a/hsd.py +++ b/hsd.py @@ -33,12 +33,12 @@ if not os.path.exists('.local'): wallet_file = '/data/wallets.json' # Create any missing files -if not os.path.exists('accounts.json'): - with open('accounts.json', 'w') as f: +if not os.path.exists(account_file): + with open(account_file, 'w') as f: json.dump({}, f, indent=4) -if not os.path.exists('wallets.json'): - with open('wallets.json', 'w') as f: +if not os.path.exists(wallet_file): + with open(wallet_file, 'w') as f: json.dump([], f, indent=4) @@ -65,7 +65,7 @@ def create_account() -> dict: # Generate a UUID userID = str(uuid.uuid4()) - with open('accounts.json', 'r') as f: + with open(account_file, 'r') as f: accounts = json.load(f) # Check if the user already exists @@ -78,7 +78,7 @@ def create_account() -> dict: 'wallets': [] } - with open('accounts.json', 'w') as f: + with open(account_file, 'w') as f: json.dump(accounts, f, indent=4) return { @@ -96,7 +96,7 @@ def get_account(userID:str) -> dict: def get_accounts() -> dict: # Read from accounts - with open('accounts.json', 'r') as f: + with open(account_file, 'r') as f: accounts = json.load(f) return accounts @@ -118,7 +118,7 @@ def import_wallet(name:str,userID:str,xpub:str) -> dict: # Create the wallet using a UUID walletID = str(uuid.uuid4()) - with open('wallets.json', 'r') as f: + with open(wallet_file, 'r') as f: wallets = json.load(f) if walletID in wallets: @@ -144,11 +144,11 @@ def import_wallet(name:str,userID:str,xpub:str) -> dict: } accounts[userID]['wallets'].append(wallet) - with open('accounts.json', 'w') as f: + with open(account_file, 'w') as f: json.dump(accounts, f, indent=4) wallets.append(walletID) - with open('wallets.json', 'w') as f: + with open(wallet_file, 'w') as f: json.dump(wallets, f, indent=4) # Rescan the wallet to get the balance @@ -241,7 +241,7 @@ def get_domains(userID:str, name:str) -> dict: }) # Save name value to accounts - with open('accounts.json', 'r') as f: + with open(account_file, 'r') as f: accounts = json.load(f) @@ -253,7 +253,7 @@ def get_domains(userID:str, name:str) -> dict: wallet['names_value'] = names_value break - with open('accounts.json', 'w') as f: + with open(account_file, 'w') as f: json.dump(accounts, f, indent=4) return names @@ -266,7 +266,7 @@ def get_domains_value(userID:str, name:str) -> int: 'error': 'Wallet not found' } - with open('accounts.json', 'r') as f: + with open(account_file, 'r') as f: accounts = json.load(f) for account in accounts: diff --git a/main.py b/main.py index 3da70cc..ea01580 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,4 @@ -from flask import Flask, request, jsonify +from flask import Flask, redirect, request, jsonify import requests import json import hsd @@ -95,7 +95,9 @@ def get_auctions(): return jsonify(auction_json) - +@app.route('/') +def index(): + return redirect("https://firewallet.au") if __name__ == "__main__": app.run(host="0.0.0.0", port=8080, debug=True)