multi-wallet-plugin/multi-wallet.py

135 lines
3.7 KiB
Python

import json
import account
import os
import time
# Plugin Data
info = {
"name": "Multi Wallet Functions",
"description": "Access and manage multiple wallets at once",
"version": "1.0",
"author": "Nathan.Woodburn/"
}
# Functions
functions = {
"balance": {
"name": "Wallet Balances",
"type": "default",
"description": "List balances of all wallets",
"params": {},
"returns": {
"result":
{
"name": "Result",
"type": "list"
}
}
},
"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):
wallets = account.listWallets()
balances = []
total = 0
available = 0
for wallet in wallets:
info = account.getBalance(wallet)
balances.append(f"{wallet}: Available: {info['available']:,.2f} HNS, Total: {info['total']:,.2f} HNS")
total += info['total']
available += info['available']
balances.append(f"Total: Available: {available:,.2f} HNS, Total: {total:,.2f} HNS")
return {"result": balances}
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 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"}