From da9354cb23ba57ba8abd3e56ebb34ab3b4558764 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 21 Nov 2024 15:40:02 +1100 Subject: [PATCH 1/3] fix: Hide expired domains --- account.py | 19 ++++++++++++++++++- example.env | 3 ++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/account.py b/account.py index 5b3dde1..7a37793 100644 --- a/account.py +++ b/account.py @@ -15,6 +15,9 @@ ip = os.getenv("hsd_ip") if ip is None: ip = "localhost" +show_expired = os.getenv("show_expired") +if show_expired is None: + show_expired = False hsd = api.hsd(APIKEY,ip) hsw = api.hsw(APIKEY,ip) @@ -179,7 +182,21 @@ def getDomains(account,own=True): else: response = requests.get(f"http://x:{APIKEY}@{ip}:12039/wallet/{account}/name") info = response.json() - return info + + if show_expired: + return info + + # Remove any expired domains + domains = [] + for domain in info: + if 'stats' in domain: + if 'daysUntilExpire' in domain['stats']: + if domain['stats']['daysUntilExpire'] < 0: + continue + domains.append(domain) + + + return domains def getTransactions(account): # Get the transactions diff --git a/example.env b/example.env index 4b8ae7a..96a6a46 100644 --- a/example.env +++ b/example.env @@ -1,3 +1,4 @@ hsd_api=123480615465636893475aCwyaae6s45 hsd_ip=localhost -theme=black \ No newline at end of file +theme=black +show_expired=false \ No newline at end of file From 00379aaa8f6df5c1e408c96822b7303fd7835ae8 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 21 Nov 2024 16:10:28 +1100 Subject: [PATCH 2/3] feat: Add new batch renewal plugin --- account.py | 4 -- plugins/renewal.py | 99 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 plugins/renewal.py diff --git a/account.py b/account.py index 7a37793..6398e6f 100644 --- a/account.py +++ b/account.py @@ -256,10 +256,6 @@ def check_hip2(domain: str): def send(account,address,amount): account_name = check_account(account) password = ":".join(account.split(":")[1:]) - - - - response = hsw.rpc_selectWallet(account_name) if response['error'] is not None: return { diff --git a/plugins/renewal.py b/plugins/renewal.py new file mode 100644 index 0000000..587e930 --- /dev/null +++ b/plugins/renewal.py @@ -0,0 +1,99 @@ +import json +import account +import requests +import os +import sys +import dotenv + +# Plugin Data +info = { + "name": "Batch Renew Domains", + "description": "Renew the next 100 domains", + "version": "1.0", + "author": "Nathan.Woodburn/" +} + +# Functions +functions = { + "main":{ + "name": "Renew", + "type": "default", + "description": "Renew the next 100 domains in one transaction. Please wait for at least 1 block confirmation before renewing the next 100 domains", + "params": {}, + "returns": { + "status": + { + "name": "Status of the function", + "type": "text" + }, + "transaction": + { + "name": "Transaction ID", + "type": "tx" + } + } + } +} + +def main(params, authentication): + password = authentication.split(":")[1] + wallet = authentication.split(":")[0] + domains = account.getDomains(wallet) + domains = sorted(domains, key=lambda k: k['renewal']) + + names = [] + for domain in domains: + name = domain["name"] + names.append(name) + + # Split names into batches of 100 + batches = [] + for i in range(0, len(names), 100): + batches.append(names[i:i+100]) + + # Unlock wallet + api_key = os.getenv("hsd_api") + if api_key is None: + print("API key not set") + return {"status": "API key not set", "transaction": "None"} + response = requests.post(f'http://x:{api_key}@127.0.0.1:12039/wallet/{wallet}/unlock', + json={'passphrase': password, 'timeout': 600}) + if response.status_code != 200: + print("Failed to unlock wallet") + print(f'Status code: {response.status_code}') + print(f'Response: {response.text}') + return {"status": "Failed unlocking wallet", "transaction": "None"} + + + tx = "None" + for batch in batches: + batch = [] + + for domain in names: + batch.append(f'["RENEW", "{domain}"]') + + + batchTX = "[" + ", ".join(batch) + "]" + responseContent = f'{{"method": "sendbatch","params":[ {batchTX} ]}}' + response = requests.post(f'http://x:{api_key}@127.0.0.1:12039', data=responseContent) + if response.status_code != 200: + print("Failed to create batch") + print(f'Status code: {response.status_code}') + print(f'Response: {response.text}') + return {"status": "Failed", "transaction": "None"} + + batch = response.json() + # Verify the batch + print("Verifying tx...") + if batch["error"]: + if batch["error"] != "": + print("Failed to verify batch") + print(batch["error"]["message"]) + return {"status": "Failed", "transaction": "None"} + + if 'result' in batch: + if batch['result'] != None: + tx = batch['result']['hash'] + return {"status": "Success", "transaction": tx} + # Note only one batch can be sent at a time + \ No newline at end of file From 0be6b8b43583b1207b811e7b143bf7bc209738e8 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 21 Nov 2024 16:21:20 +1100 Subject: [PATCH 3/3] fix: Remove unused imports --- plugins/renewal.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/renewal.py b/plugins/renewal.py index 587e930..ac4ef44 100644 --- a/plugins/renewal.py +++ b/plugins/renewal.py @@ -2,8 +2,6 @@ import json import account import requests import os -import sys -import dotenv # Plugin Data info = {