feat: Template code drop
This commit is contained in:
commit
341bf151eb
109
README.md
Normal file
109
README.md
Normal file
@ -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
|
175
example.py
Normal file
175
example.py
Normal file
@ -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}
|
32
template.py
Normal file
32
template.py
Normal file
@ -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"}
|
||||
|
Loading…
Reference in New Issue
Block a user