generated from nathanwoodburn/python-webserver-template
Nathan Woodburn
6ff1afd46d
All checks were successful
Build Docker / BuildImage (push) Successful in 51s
109 lines
3.1 KiB
Python
109 lines
3.1 KiB
Python
import os
|
|
import json
|
|
import importlib
|
|
import sys
|
|
import hashlib
|
|
|
|
if not os.path.exists("chain_data"):
|
|
os.mkdir("chain_data")
|
|
|
|
if not os.path.exists("api_keys"):
|
|
os.mkdir("api_keys")
|
|
|
|
def listChains():
|
|
chains = []
|
|
for file in os.listdir("chains"):
|
|
if file.endswith(".py"):
|
|
if file != "main.py":
|
|
chain = importlib.import_module("chains."+file[:-3])
|
|
if "info" not in dir(chain):
|
|
continue
|
|
details = chain.info
|
|
details["link"] = file[:-3]
|
|
chains.append(details)
|
|
|
|
return chains
|
|
|
|
|
|
def chainExists(chain: str):
|
|
for file in os.listdir("chains"):
|
|
if file == chain+".py":
|
|
return True
|
|
return False
|
|
|
|
|
|
def validateChainAddress(chain: str, address: str):
|
|
chain = importlib.import_module("chains."+chain)
|
|
if "validateAddress" not in dir(chain):
|
|
return False
|
|
return chain.validateAddress(address)
|
|
|
|
def getChainData(chain: str):
|
|
chain = importlib.import_module("chains."+chain)
|
|
return chain.info
|
|
|
|
def importAddress(chain: str, address: str):
|
|
chain = importlib.import_module("chains."+chain)
|
|
if "importAddress" not in dir(chain):
|
|
return False
|
|
return chain.importAddress(address)
|
|
|
|
|
|
def getAllAddresses():
|
|
addresses = []
|
|
for file in os.listdir("chains"):
|
|
if file.endswith(".py"):
|
|
if file != "main.py":
|
|
chain = importlib.import_module("chains."+file[:-3])
|
|
if "listAddresses" in dir(chain):
|
|
chainAddresses = chain.listAddresses()
|
|
addresses.append({"chain": file[:-3].capitalize(), "addresses": chainAddresses})
|
|
|
|
return addresses
|
|
|
|
def getAddresses(chain: str):
|
|
chain = importlib.import_module("chains."+chain)
|
|
if "listAddresses" in dir(chain):
|
|
return chain.listAddresses()
|
|
return []
|
|
|
|
def deleteAddress(chain: str, address: str):
|
|
chain = importlib.import_module("chains."+chain)
|
|
if "deleteAddress" not in dir(chain):
|
|
return False
|
|
return chain.deleteAddress(address)
|
|
|
|
def syncChains():
|
|
for file in os.listdir("chains"):
|
|
if file.endswith(".py"):
|
|
if file != "main.py":
|
|
chain = importlib.import_module("chains."+file[:-3])
|
|
if "sync" in dir(chain):
|
|
chain.sync()
|
|
|
|
def syncChain(chain: str):
|
|
chain = importlib.import_module("chains."+chain)
|
|
if "sync" in dir(chain):
|
|
chain.sync()
|
|
return True
|
|
return False
|
|
|
|
def addAPIKey(chain: str, apiKey: str):
|
|
chain = importlib.import_module("chains."+chain)
|
|
if "addAPIKey" not in dir(chain):
|
|
return False
|
|
return chain.addAPIKey(apiKey)
|
|
|
|
|
|
def getTransactions(chain: str):
|
|
chain = importlib.import_module("chains."+chain)
|
|
if "getTransactions" not in dir(chain):
|
|
return False
|
|
return chain.getTransactions()
|
|
|
|
def getTransactionsRender(chain:str):
|
|
chain = importlib.import_module("chains."+chain)
|
|
if "getTransactionsRender" not in dir(chain):
|
|
return False
|
|
return chain.getTransactionsRender()
|