firewalletbrowser/plugins/example.py

178 lines
4.7 KiB
Python
Raw Normal View History

2024-02-02 21:40:02 +11:00
import json
import account
2024-02-07 13:58:03 +11:00
import requests
2024-02-02 21:40:02 +11:00
2024-02-07 13:58:03 +11:00
# Plugin Data
info = {
"name": "Example Plugin",
"description": "This is a plugin to be used as an example",
"version": "1.0",
"author": "Nathan.Woodburn/"
}
# Functions
2024-02-02 21:40:02 +11:00
functions = {
"search":{
"name": "Search Owned",
2024-02-07 13:58:03 +11:00
"type": "default",
2024-02-02 21:40:02 +11:00
"description": "Search for owned domains containing a string",
"params": {
"search": {
"name":"Search string",
"type":"text"
}
},
"returns": {
"domains":
{
"name": "List of owned domains",
"type": "list"
}
}
2024-02-04 15:08:24 +11:00
},
"transfer":{
"name": "Bulk Transfer Domains",
2024-02-07 13:58:03 +11:00
"type": "default",
2024-02-04 15:08:24 +11:00
"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",
2024-02-07 13:58:03 +11:00
"type": "default",
2024-02-04 15:08:24 +11:00
"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"
}
}
2024-02-07 13:58:03 +11:00
},
"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"
}
}
2024-02-02 21:40:02 +11:00
}
}
2024-02-07 13:58:03 +11:00
def check(params, authentication):
domains = params["domains"]
2024-02-02 21:40:02 +11:00
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}
2024-02-07 13:58:03 +11:00
def search(params, authentication):
search = params["search"].lower()
2024-02-02 21:40:02 +11:00
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}
2024-02-04 15:08:24 +11:00
2024-02-07 13:58:03 +11:00
def transfer(params, authentication):
address = params["address"]
2024-02-04 15:08:24 +11:00
return {"hash":"f921ffe1bb01884bf515a8079073ee9381cb93a56b486694eda2cce0719f27c0","address":address}
2024-02-07 13:58:03 +11:00
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}")
print(response.text)
if response.status_code != 200:
return {"rating":"Error fetching rating from Niami.io"}
if response.json()["success"] == False:
return {"rating":"Error fetching rating from Niami.io"}
2024-02-07 13:58:03 +11:00
data = response.json()["data"]
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}