From 713b33d05fdfc19ea92057fd12fc61987f713fa4 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 28 Dec 2023 16:32:20 +1100 Subject: [PATCH] fix: Update to use better sending api --- account.py | 38 ++++++++++++++++++-------------------- domainLookup.py | 4 ++-- templates/404.html | 2 +- templates/index.html | 2 +- templates/send.html | 2 +- templates/success.html | 2 +- templates/tx.html | 2 +- 7 files changed, 25 insertions(+), 27 deletions(-) diff --git a/account.py b/account.py index f388095..8ca7144 100644 --- a/account.py +++ b/account.py @@ -128,6 +128,9 @@ def check_hip2(domain: str): return 'Invalid address' address = domainLookup.hip2(domain) + if address.startswith("Hip2: "): + return address + if not check_address(address, False,True): return 'Hip2: Lookup succeeded but address is invalid' return address @@ -139,32 +142,27 @@ def send(account,address,amount): password = ":".join(account.split(":")[1:]) - # Unlock the account - response = requests.post(f"http://x:{APIKEY}@127.0.0.1:12039/wallet/{account_name}/unlock", - json={"passphrase": password,"timeout": 10}) - - if response.status_code != 200: + + + response = hsw.rpc_selectWallet(account_name) + if response['error'] is not None: return { - "error": "Failed to unlock account" - } - if 'success' not in response.json(): - return { - "error": "Failed to unlock account" + "error": response['error']['message'] } - # Send the transaction - response = requests.post(f"http://x:{APIKEY}@127.0.0.1:12039",json={ - "method": "sendtoaddress", - "params": [address,amount] - }) - if response.status_code != 200: + response = hsw.rpc_walletPassphrase(password,10) + # Unlock the account + # response = requests.post(f"http://x:{APIKEY}@127.0.0.1:12039/wallet/{account_name}/unlock", + # json={"passphrase": password,"timeout": 10}) + if response['error'] is not None: return { - "error": "Failed to send transaction" + "error": response['error']['message'] } - response = response.json() - if 'error' in response: + + response = hsw.rpc_sendToAddress(address,amount) + if response['error'] is not None: return { - "error": json.dumps(response['error']) + "error": response['error']['message'] } return { "tx": response['result'] diff --git a/domainLookup.py b/domainLookup.py index c16eaef..8c92a82 100644 --- a/domainLookup.py +++ b/domainLookup.py @@ -7,7 +7,7 @@ import binascii import datetime import dns.asyncresolver import httpx -from requests_doh import DNSOverHTTPSSession, add_dns_provider, remove_dns_provider +from requests_doh import DNSOverHTTPSSession, add_dns_provider def hip2(domain: str): @@ -114,7 +114,7 @@ def hip2(domain: str): # Catch all exceptions except Exception as e: - return "Hip2: " + str(e) + return "Hip2: Lookup failed." def resolve_with_doh(query_name, doh_url="https://hnsdoh.com/dns-query"): diff --git a/templates/404.html b/templates/404.html index a64da57..a03b659 100644 --- a/templates/404.html +++ b/templates/404.html @@ -18,7 +18,7 @@