diff --git a/README.md b/README.md index d7bd7d5..35db089 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,8 @@ sudo docker run -p 5000:5000 -e hsd_api=yourapikeyhere -e hsd_ip=hsdcontainer gi ## Features - Basic wallet functionality + - Create new wallet + - Import wallet from seed - Send HNS - Receive HNS - Have multiple wallets diff --git a/account.py b/account.py index 0b14571..c7ca96d 100644 --- a/account.py +++ b/account.py @@ -84,6 +84,31 @@ def createWallet(account: str, password: str): "password": password } +def importWallet(account: str, password: str,seed: str): + # Import the wallet + data = { + "passphrase": password, + "mnemonic": seed, + } + + response = requests.put(f"http://x:{APIKEY}@{ip}:12039/wallet/{account}",json=data) + print(response) + print(response.json()) + + if response.status_code != 200: + return { + "error": { + "message": "Error creating account" + } + } + + return { + "seed": seed, + "account": account, + "password": password + } + + def listWallets(): # List the wallets response = hsw.listWallets() @@ -461,7 +486,21 @@ def finalize(account,domain): } try: - response = hsw.sendFINALIZE(account_name,password,domain) + response = hsw.rpc_selectWallet(account_name) + if response['error'] is not None: + return { + "error": { + "message": response['error']['message'] + } + } + response = hsw.rpc_walletPassphrase(password,10) + if response['error'] is not None: + return { + "error": { + "message": response['error']['message'] + } + } + response = hsw.rpc_sendFINALIZE(domain) return response except Exception as e: return { diff --git a/main.py b/main.py index 36fbdbe..d85b946 100644 --- a/main.py +++ b/main.py @@ -391,11 +391,11 @@ def finalize(domain: str): domain = domain.lower() print(domain) response = account_module.finalize(request.cookies.get("account"),domain) - if 'error' in response: + if response['error'] != None: print(response) return redirect("/manage/" + domain + "?error=" + response['error']['message']) - return redirect("/success?tx=" + response['hash']) + return redirect("/success?tx=" + response['result']['hash']) @app.route('/manage//cancel') def cancelTransfer(domain: str): @@ -966,6 +966,50 @@ def register(): response.set_cookie("account", account+":"+password) return response +@app.route('/import-wallet', methods=["POST"]) +def import_wallet(): + # Get the account and password + account = request.form.get("name") + password = request.form.get("password") + repeatPassword = request.form.get("password_repeat") + seed = request.form.get("seed") + + # Check if the passwords match + if password != repeatPassword: + return render_template("import-wallet.html", + error="Passwords do not match", + name=account,password=password,password_repeat=repeatPassword, + seed=seed) + + # Check if the account is valid + if account.count(":") > 0: + return render_template("import-wallet.html", + error="Invalid account", + name=account,password=password,password_repeat=repeatPassword, + seed=seed) + + # List wallets + wallets = account_module.listWallets() + if account in wallets: + return render_template("import-wallet.html", + error="Account already exists", + name=account,password=password,password_repeat=repeatPassword, + seed=seed) + + # Create the account + response = account_module.importWallet(account,password,seed) + + if 'error' in response: + return render_template("import-wallet.html", + error=response['error'], + name=account,password=password,password_repeat=repeatPassword, + seed=seed) + + + # Set the cookie + response = make_response(redirect("/")) + response.set_cookie("account", account+":"+password) + return response @app.route('/report') def report(): diff --git a/templates/import-wallet.html b/templates/import-wallet.html new file mode 100644 index 0000000..a103c43 --- /dev/null +++ b/templates/import-wallet.html @@ -0,0 +1,52 @@ + + + + + + + Import Wallet - FireWallet + + + + + + + + + + + +
+
+
+
+
+
+
+
+
+

{{error}}

+
+

Import a wallet!

+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ + + + + \ No newline at end of file diff --git a/templates/login.html b/templates/login.html index 1ea980d..5c53471 100644 --- a/templates/login.html +++ b/templates/login.html @@ -37,7 +37,8 @@

-
Create a wallet!
+
Create a wallet
+
Import an existing wallet
diff --git a/templates/register.html b/templates/register.html index 655396b..ffec1a3 100644 --- a/templates/register.html +++ b/templates/register.html @@ -27,14 +27,14 @@

{{error}}

-

Create an Account!

+

Create a new wallet!

-
+

Didn't mean to create a new wallet? Login!