Compare commits
9 Commits
5ee5f518a4
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
7546957298
|
|||
|
1705e47476
|
|||
|
33311d7799
|
|||
|
27613bc1aa
|
|||
|
5445a31a76
|
|||
|
baca2845e1
|
|||
|
0d7b55c12e
|
|||
|
a35e41b656
|
|||
|
0a074a4bbf
|
@@ -8,3 +8,6 @@ Import this URL:
|
|||||||
```
|
```
|
||||||
https://git.woodburn.au/nathanwoodburn/multi-wallet-plugin.git
|
https://git.woodburn.au/nathanwoodburn/multi-wallet-plugin.git
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Screenshots
|
||||||
|

|
||||||
228
multi-wallet.py
228
multi-wallet.py
@@ -1,5 +1,8 @@
|
|||||||
import json
|
import json
|
||||||
import account
|
import account
|
||||||
|
import os
|
||||||
|
import time
|
||||||
|
import datetime
|
||||||
|
|
||||||
# Plugin Data
|
# Plugin Data
|
||||||
info = {
|
info = {
|
||||||
@@ -23,8 +26,117 @@ functions = {
|
|||||||
"type": "list"
|
"type": "list"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"domains": {
|
||||||
|
"name": "Domains",
|
||||||
|
"type": "default",
|
||||||
|
"description": "List number of domains in each wallet",
|
||||||
|
"params": {},
|
||||||
|
"returns": {
|
||||||
|
"result":
|
||||||
|
{
|
||||||
|
"name": "Result",
|
||||||
|
"type": "list"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"find": {
|
||||||
|
"name": "Find domain wallet",
|
||||||
|
"type": "default",
|
||||||
|
"description": "Find which wallet owns a domain",
|
||||||
|
"params": {
|
||||||
|
"domain": {
|
||||||
|
"name": "List of Domain to find",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"returns": {
|
||||||
|
"result":
|
||||||
|
{
|
||||||
|
"name": "Result",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"expiring": {
|
||||||
|
"name": "Expiring Domains",
|
||||||
|
"type": "default",
|
||||||
|
"description": "List domains that are expiring and their wallet",
|
||||||
|
"params": {
|
||||||
|
"days": {
|
||||||
|
"name": "Days until expiry (default 30)",
|
||||||
|
"type": "number"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"returns": {
|
||||||
|
"result":
|
||||||
|
{
|
||||||
|
"name": "Result",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"export": {
|
||||||
|
"name": "Export Domains",
|
||||||
|
"type": "default",
|
||||||
|
"description": "Export domains to a file",
|
||||||
|
"params": {
|
||||||
|
},
|
||||||
|
"returns": {
|
||||||
|
"result":
|
||||||
|
{
|
||||||
|
"name": "result.csv",
|
||||||
|
"type": "file"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"dash": {
|
||||||
|
"name": "Dashboard widget",
|
||||||
|
"type": "dashboard",
|
||||||
|
"description": "List total balance of all wallets on your dashboard",
|
||||||
|
"params": {},
|
||||||
|
"returns": {
|
||||||
|
"result":
|
||||||
|
{
|
||||||
|
"name": "Total Holdings",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"enable": {
|
||||||
|
"name": "Enable Dashboard widget",
|
||||||
|
"type": "default",
|
||||||
|
"description": "Enable the dashboard widget",
|
||||||
|
"params": {},
|
||||||
|
"returns": {
|
||||||
|
"result":
|
||||||
|
{
|
||||||
|
"name": "Result",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"disable": {
|
||||||
|
"name": "Disable Dashboard widget",
|
||||||
|
"type": "default",
|
||||||
|
"description": "Disable the dashboard widget",
|
||||||
|
"params": {},
|
||||||
|
"returns": {
|
||||||
|
"result":
|
||||||
|
{
|
||||||
|
"name": "Result",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if not os.path.exists("user_data/multiwallet.json"):
|
||||||
|
with open("user_data/multiwallet.json", "w") as f:
|
||||||
|
json.dump({
|
||||||
|
"enabled": False,
|
||||||
|
"lastUpdate": 0
|
||||||
|
}, f)
|
||||||
|
|
||||||
def balance(params, authentication):
|
def balance(params, authentication):
|
||||||
wallets = account.listWallets()
|
wallets = account.listWallets()
|
||||||
@@ -40,3 +152,119 @@ def balance(params, authentication):
|
|||||||
balances.append(f"Total: Available: {available:,.2f} HNS, Total: {total:,.2f} HNS")
|
balances.append(f"Total: Available: {available:,.2f} HNS, Total: {total:,.2f} HNS")
|
||||||
|
|
||||||
return {"result": balances}
|
return {"result": balances}
|
||||||
|
|
||||||
|
def expiring(params, authentication):
|
||||||
|
days = params['days']
|
||||||
|
if days == None or days == '':
|
||||||
|
days = 30
|
||||||
|
else:
|
||||||
|
days = int(days)
|
||||||
|
wallets = account.listWallets()
|
||||||
|
expiring = ''
|
||||||
|
|
||||||
|
for wallet in wallets:
|
||||||
|
walletExpiring = []
|
||||||
|
domains = account.getDomains(wallet)
|
||||||
|
for domain in domains:
|
||||||
|
if 'stats' in domain and 'daysUntilExpire' in domain['stats']:
|
||||||
|
if domain['stats']['daysUntilExpire'] <= days and domain['stats']['daysUntilExpire'] >= 0:
|
||||||
|
walletExpiring.append({"domain": domain['name'], "wallet": wallet, "days": domain['stats']['daysUntilExpire']})
|
||||||
|
if len(walletExpiring) > 0:
|
||||||
|
expiring += f"<div class='row'><div class='col-md-12'><h3>Expiring Domains in {wallet}</h3><table class='table table-striped'><thead><tr><th>Domain</th><th>Days Until Expiration</th></tr></thead><tbody>"
|
||||||
|
for domain in walletExpiring:
|
||||||
|
expiring += f"<tr><td>{domain['domain']}</td><td>{domain['days']}</td></tr>"
|
||||||
|
expiring += "</tbody></table></div></div>"
|
||||||
|
return {"result": expiring}
|
||||||
|
|
||||||
|
def BlocksToDate(blocks):
|
||||||
|
date = datetime.datetime.now() + datetime.timedelta(minutes=blocks*10)
|
||||||
|
return date.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
def export(params, authentication):
|
||||||
|
wallets = account.listWallets()
|
||||||
|
result = "name,expiry,expiryBlock,value,wallet"
|
||||||
|
currentBlock = account.getBlockHeight()
|
||||||
|
|
||||||
|
for wallet in wallets:
|
||||||
|
domains = account.getDomains(wallet)
|
||||||
|
for domain in domains:
|
||||||
|
if 'stats' in domain and 'renewalPeriodEnd' in domain['stats']:
|
||||||
|
expiryBlock = domain['stats']['renewalPeriodEnd']
|
||||||
|
result += f"\n{domain['name']},{BlocksToDate(expiryBlock - currentBlock)},{expiryBlock},{domain['value']/1000000},{wallet}"
|
||||||
|
else:
|
||||||
|
result += f"\n{domain['name']},N/A,N/A,{domain['value']/1000000},{wallet}"
|
||||||
|
|
||||||
|
return {"result": result}
|
||||||
|
|
||||||
|
def dash(params, authentication):
|
||||||
|
with open("user_data/multiwallet.json", "r") as f:
|
||||||
|
multiwallet = json.load(f)
|
||||||
|
|
||||||
|
if multiwallet['enabled'] == False:
|
||||||
|
return {"result": None}
|
||||||
|
# Check time
|
||||||
|
currentTime = int(time.time())
|
||||||
|
if currentTime - multiwallet['lastUpdate'] < 60*10:
|
||||||
|
return {"result": f"Available: {multiwallet['total']['available']:,.2f} HNS<br>Total: {multiwallet['total']['total']:,.2f} HNS"}
|
||||||
|
|
||||||
|
wallets = account.listWallets()
|
||||||
|
total = 0
|
||||||
|
available = 0
|
||||||
|
for wallet in wallets:
|
||||||
|
info = account.getBalance(wallet)
|
||||||
|
total += info['total']
|
||||||
|
available += info['available']
|
||||||
|
|
||||||
|
multiwallet['total'] = {
|
||||||
|
"available": available,
|
||||||
|
"total": total
|
||||||
|
}
|
||||||
|
multiwallet['lastUpdate'] = currentTime
|
||||||
|
with open("user_data/multiwallet.json", "w") as f:
|
||||||
|
json.dump(multiwallet, f)
|
||||||
|
|
||||||
|
return {"result": f"Available: {available:,.2f} HNS<br>Total: {total:,.2f} HNS"}
|
||||||
|
|
||||||
|
def domains(params, authentication):
|
||||||
|
wallets = account.listWallets()
|
||||||
|
domains = []
|
||||||
|
total = 0
|
||||||
|
for wallet in wallets:
|
||||||
|
numDomains = len(account.getDomains(wallet))
|
||||||
|
domains.append(f"{wallet}: {numDomains}")
|
||||||
|
total += numDomains
|
||||||
|
|
||||||
|
domains.append(f"Total: {total}")
|
||||||
|
return {"result": domains}
|
||||||
|
|
||||||
|
def find(params, authentication):
|
||||||
|
wallets = account.listWallets()
|
||||||
|
domain_owners = {}
|
||||||
|
for wallet in wallets:
|
||||||
|
domains = account.getDomains(wallet)
|
||||||
|
for domain in domains:
|
||||||
|
if domain['name'] in params['domain'].split(","):
|
||||||
|
domain_owners[domain['name']] = wallet
|
||||||
|
if len(domain_owners) > 0:
|
||||||
|
result = ''
|
||||||
|
for domain, wallet in domain_owners.items():
|
||||||
|
result += f"{domain}: {wallet}<br>"
|
||||||
|
return {"result": result}
|
||||||
|
else:
|
||||||
|
return {"result": "Not found"}
|
||||||
|
|
||||||
|
def enable(params, authentication):
|
||||||
|
with open("user_data/multiwallet.json", "r") as f:
|
||||||
|
multiwallet = json.load(f)
|
||||||
|
multiwallet['enabled'] = True
|
||||||
|
with open("user_data/multiwallet.json", "w") as f:
|
||||||
|
json.dump(multiwallet, f)
|
||||||
|
return {"result": "Success"}
|
||||||
|
|
||||||
|
def disable(params, authentication):
|
||||||
|
with open("user_data/multiwallet.json", "r") as f:
|
||||||
|
multiwallet = json.load(f)
|
||||||
|
multiwallet['enabled'] = False
|
||||||
|
with open("user_data/multiwallet.json", "w") as f:
|
||||||
|
json.dump(multiwallet, f)
|
||||||
|
return {"result": "Success"}
|
||||||
|
|||||||
Reference in New Issue
Block a user