From 4f163756debb2a977353aa89ca1fc35f3a75f4c7 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Mon, 12 Feb 2024 21:53:17 +1100 Subject: [PATCH] feat: Add automation plugin --- plugin.py | 21 ----------- plugins/automations.py | 83 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 21 deletions(-) create mode 100644 plugins/automations.py diff --git a/plugin.py b/plugin.py index b5d7f34..b7bb4cf 100644 --- a/plugin.py +++ b/plugin.py @@ -63,32 +63,13 @@ def verifyPlugin(plugin: str): def hashPlugin(plugin: str): BUF_SIZE = 65536 - - # Initializing the sha256() method sha256 = hashlib.sha256() - - # Opening the file provided as the first - # commandline argument with open("plugins/"+plugin+".py", 'rb') as f: while True: - # reading data = BUF_SIZE from the - # file and saving it in a variable data = f.read(BUF_SIZE) - - # True if eof = 1 if not data: break - - # Passing that data to that sh256 hash - # function (updating the function with that data) sha256.update(data) - - # sha256.hexdigest() hashes all the input data passed - # to the sha256() via sha256.update() - # Acts as a finalize method, after which - # all the input data gets hashed - # hexdigest() hashes the data, and returns - # the output in hexadecimal format return sha256.hexdigest() @@ -114,8 +95,6 @@ def getPluginData(pluginStr: str): info = plugin.info # Hash the plugin file pluginHash = hashPlugin(pluginStr) - print(pluginHash) - print(signatures) if pluginHash not in signatures: info["verified"] = False else: diff --git a/plugins/automations.py b/plugins/automations.py new file mode 100644 index 0000000..38f8e50 --- /dev/null +++ b/plugins/automations.py @@ -0,0 +1,83 @@ +import json +import account +import requests +import threading +import os +import datetime + +APIKEY = os.environ.get("hsd_api") +ip = os.getenv("hsd_ip") +if ip is None: + ip = "localhost" + + +# Plugin Data +info = { + "name": "Automations", + "description": "This plugin will automatically renew domains, reveal and redeem bids.", + "version": "1.0", + "author": "Nathan.Woodburn/" +} + + +# Functions +functions = { + "automation":{ + "name": "Function to automate", + "type": "dashboard", + "description": "This used type dashboard to trigger the function whenever you access the dashboard.", + "params": {}, + "returns": { + "Status": + { + "name": "Status of the automation", + "type": "text" + } + } + } +} + +started = 0 + +# Main entry point only lets the main function run every 5 mins +def automation(params, authentication): + global started + now = datetime.datetime.now().timestamp() + # Add 5 mins + now = now - 300 + if now < started: + return {"Status": "Waiting before checking for new actions"} + started = datetime.datetime.now().timestamp() + threading.Thread(target=automations_background, args=(authentication,)).start() + return {"Status": "Checking for actions"} + +# Background function to run the automations +def automations_background(authentication): + print("Running automations") + # Get account details + account_name = account.check_account(authentication) + password = ":".join(authentication.split(":")[1:]) + + if account_name == False: + return { + "error": { + "message": "Invalid account" + } + } + + try: + # Try to select and login to the wallet + response = account.hsw.rpc_selectWallet(account_name) + if response['error'] is not None: + return + response = account.hsw.rpc_walletPassphrase(password,10) + if response['error'] is not None: + return + # Try to send the batch of all renew, reveal and redeem actions + response = requests.post(f"http://x:{APIKEY}@{ip}:12039",json={ + "method": "sendbatch", + "params": [[["RENEW"], ["REVEAL"], ["REDEEM"]]] + }).json() + print(response) + except Exception as e: + print(e) \ No newline at end of file