generated from nathanwoodburn/python-webserver-template
89 lines
2.5 KiB
Python
89 lines
2.5 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 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 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()
|