commit 341bf151eb21dd4af7a79e600fa09fc5da19cb95 Author: Nathan Woodburn Date: Sat Feb 1 16:53:05 2025 +1100 feat: Template code drop diff --git a/README.md b/README.md new file mode 100644 index 0000000..9772bc3 --- /dev/null +++ b/README.md @@ -0,0 +1,109 @@ +# Plugin Template +This is a template for creating a plugin for Firewallet. It is not meant to be used as is, but rather as a guide for creating your own plugin. + + +## Format + +```python +info = { + "name": "Plugin Name", + "description": "Plugin Description", + "version": "Version number", + "author": "Your Name", +} +functions = { + "internalName":{ + "name": "Human readable name", + "type": "Type of plugin", + "description": "Function description", + "params": { # For plugins other than default use {} for no params + "paramName": { + "name":"Human readable paramiter name", + "type":"type of paramiter", + } + }, + "returns": { + "returnName": + { + "name": "Human readable return name", + "type": "type of return" + } + } + } +} + +def internalName(params, authentication): # This should always have the same inputs + paramName = params["paramName"] + wallet = authentication.split(":")[0] + + # Do stuff + output = "Return value of stuff: " + paramName + + + + return {"returnName": output} + +``` + + +## Types +### Default +Type: `default` +This is the default type and is used when no type is specified. +This type is displayed in the plugin page only. +This is the onlu type of plugin that takes user input + +### Manage & Search +For manage page use type: `domain` +For search page use type: `search` + +This type is used for domain plugins. It shows in the manage domain page or the search page. +It gets the `domain` paramater as the only input (in addition to authentication) + +### Dashboard +Type: `dashboard` +This type is used for dashboard plugins. +It shows in the dashboard page. It doesn't get any inputs other than the authentication + + +## Inputs + +### Plain Text +Type: `text` + +### Long Text +Type: `longText` + +### Number +Type: `number` + + +### Checkbox +Type: `checkbox` + +### Address +Type: `address` +This will handle hip2 resolution for you so the function will always receive a valid address + +### DNS +Type: `dns` +This isn't done yet but use it over text as it includes parsing + + + +## Outputs +### Plain Text +Type: `text` + + +### List +Type: `list` +This is a list if text items (or HTML items) + +### Transaction hash +Type: `tx` +This will display the hash and links to explorers + +### DNS records +Type: `dns` +This will display DNS in a table format diff --git a/example.py b/example.py new file mode 100644 index 0000000..bcf5cfa --- /dev/null +++ b/example.py @@ -0,0 +1,175 @@ +import json +import account +import requests + + +# Plugin Data +info = { + "name": "Example Plugin", + "description": "This is a plugin to be used as an example", + "version": "1.0", + "author": "Nathan.Woodburn/" +} + + +# Functions +functions = { + "search":{ + "name": "Search Owned", + "type": "default", + "description": "Search for owned domains containing a string", + "params": { + "search": { + "name":"Search string", + "type":"text" + } + }, + "returns": { + "domains": + { + "name": "List of owned domains", + "type": "list" + } + } + }, + "transfer":{ + "name": "Bulk Transfer Domains", + "type": "default", + "description": "Transfer domains to another wallet", + "params": { + "address": { + "name":"Address to transfer to", + "type":"address" + }, + "domains": { + "name":"List of domains to transfer", + "type":"longText" + } + }, + "returns": { + "hash": { + "name": "Hash of the transaction", + "type": "tx" + }, + "address":{ + "name": "Address of the new owner", + "type": "text" + } + } + }, + "dns":{ + "name": "Set DNS for Domains", + "type": "default", + "description": "Set DNS for domains", + "params": { + "domains": { + "name":"List of domains to set DNS for", + "type":"longText" + }, + "dns": { + "name":"DNS", + "type":"dns" + } + }, + "returns": { + "hash": { + "name": "Hash of the transaction", + "type": "tx" + }, + "dns":{ + "name": "DNS", + "type": "dns" + } + } + }, + "niami": { + "name": "Niami info", + "type": "domain", + "description": "Check the domains niami rating", + "params": {}, + "returns": { + "rating": + { + "name": "Niami Rating", + "type": "text" + } + } + }, + "niamiSearch": { + "name": "Niami info", + "type": "search", + "description": "Check the domains niami rating", + "params": {}, + "returns": { + "rating": + { + "name": "Niami Rating", + "type": "text" + } + } + }, + "connections":{ + "name": "HSD Connections", + "type": "dashboard", + "description": "Show the number of connections the HSD node is connected to", + "params": {}, + "returns": { + "connections": + { + "name": "HSD Connections", + "type": "text" + } + } + } +} + +def check(params, authentication): + domains = params["domains"] + domains = domains.splitlines() + + wallet = authentication.split(":")[0] + owned = account.getDomains(wallet) + # Only keep owned domains ["name"] + ownedNames = [domain["name"] for domain in owned] + + domains = [domain for domain in domains if domain in ownedNames] + + + return {"domains": domains} + +def search(params, authentication): + search = params["search"].lower() + wallet = authentication.split(":")[0] + owned = account.getDomains(wallet) + # Only keep owned domains ["name"] + ownedNames = [domain["name"] for domain in owned] + + domains = [domain for domain in ownedNames if search in domain] + + return {"domains": domains} + + +def transfer(params, authentication): + address = params["address"] + return {"hash":"f921ffe1bb01884bf515a8079073ee9381cb93a56b486694eda2cce0719f27c0","address":address} + +def dns(params,authentication): + dns = params["dns"] + return {"hash":"f921ffe1bb01884bf515a8079073ee9381cb93a56b486694eda2cce0719f27c0","dns":dns} + +def niami(params, authentication): + domain = params["domain"] + response = requests.get(f"https://api.handshake.niami.io/domain/{domain}") + data = response.json()["data"] + if 'rating' not in data: + return {"rating":"No rating found."} + rating = str(data["rating"]["score"]) + " (" + data["rating"]["rarity"] + ")" + return {"rating":rating} + +def niamiSearch(params, authentication): + return niami(params, authentication) + + +def connections(params,authentication): + outbound = account.hsd.getInfo()['pool']['outbound'] + return {"connections": outbound} \ No newline at end of file diff --git a/template.py b/template.py new file mode 100644 index 0000000..53ed5e1 --- /dev/null +++ b/template.py @@ -0,0 +1,32 @@ +import json +import account +import requests + +# Plugin Data +info = { + "name": "Plugin Template", + "description": "Plugin Description", + "version": "1.0", + "author": "Nathan.Woodburn/" +} + +# Functions +functions = { + "main":{ + "name": "Function name", + "type": "default", + "description": "Description", + "params": {}, + "returns": { + "status": + { + "name": "Status of the function", + "type": "text" + } + } + } +} + +def main(params, authentication): + return {"status": "Success"} + \ No newline at end of file