import json # import account import requests import os import subprocess # Plugin Data info = { "name": "HNS-Address Functions", "description": "Run HNS-Address functions within FireWallet", "version": "1.0", "author": "Nathan.Woodburn/" } # Functions functions = { "generate": { "name": "Generate HNS Addresses", "type": "default", "description": "Generate HNS addresses", "params": { "count": { "name": "Count", "type": "number", "description": "Number of addresses to generate (default 1000)" }, "startIndex": { "name": "Start Index", "type": "number", "description": "Start index for the generated addresses (default 0)" }, "xpub": { "name": "XPUB", "type": "text", "description": "Extended public key to use for generating addresses (default account xpub)" } }, "returns": { "result": { "name": "Result", "type": "list" } } } } def initialize(): # Check if hns-address is installed if not os.path.exists(os.path.join(os.path.dirname(os.path.realpath(__file__)), "hns-address")): # Try to install hns-address try: print("Cloning hns-address...") result = subprocess.run(["git", "clone", "https://git.woodburn.au/nathanwoodburn/hns-address.git"], capture_output=True, text=True) if result.returncode != 0: return -1 except: return -1 # Check if npm install was successful if not os.path.exists(os.path.join(os.path.dirname(os.path.realpath(__file__)), "hns-address", "node_modules")): try: print("Installing hns-address dependencies...") result = subprocess.run(["npm", "install"], cwd=os.path.join(os.path.dirname(os.path.realpath(__file__)), "hns-address"), capture_output=True, text=True) if result.returncode != 0: return -1 except: return -1 return 0 def generate(params, authentication): # Check if hns-address is installed if (initialize() != 0): return {"result": ["Failed to initialize hns-address"]} count = params["count"] startIndex = params["startIndex"] xpub = params["xpub"] if (count == None): count = 1000 if (startIndex == None): startIndex = 0 if (xpub == None): xpub = "xpub6BvF6DnLZRV6my62FuQ8nw5TRebL8qr9Wa7u2tE1aEedHWBt4XAfSaNTmP1SM2nXErGWSzxRAHVwqstPzRrsXtA2vn1a4KzLwAVEgLNmfca" result = subprocess.run(["node", "generate-address.js", "--xpub", xpub, "--number", str(count), "--startIndex", str(startIndex)], capture_output=True, text=True, cwd=os.path.join(os.path.dirname(os.path.realpath(__file__)), "hns-address")) with open(f"{xpub}-addresses.txt", "w") as f: f.write(result.stdout) return {"result": result.stdout.split("\n")[2:-1]} if __name__ == "__main__": print(generate({ "count": 1000, "startIndex": 0, "xpub": "xpub6BvF6DnLZRV6my62FuQ8nw5TRebL8qr9Wa7u2tE1aEedHWBt4XAfSaNTmP1SM2nXErGWSzxRAHVwqstPzRrsXtA2vn1a4KzLwAVEgLNmfca" }, None))