FireTax/chain_module.py

109 lines
3.1 KiB
Python
Raw Permalink Normal View History

2024-11-28 14:05:27 +11:00
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
2024-11-28 17:13:39 +11:00
def getAddresses(chain: str):
chain = importlib.import_module("chains."+chain)
if "listAddresses" in dir(chain):
return chain.listAddresses()
return []
2024-11-28 14:05:27 +11:00
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()
2024-11-28 17:13:39 +11:00
def syncChain(chain: str):
chain = importlib.import_module("chains."+chain)
if "sync" in dir(chain):
chain.sync()
return True
return False
2024-11-28 14:05:27 +11:00
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
2024-11-28 17:13:39 +11:00
return chain.getTransactions()
def getTransactionsRender(chain:str):
chain = importlib.import_module("chains."+chain)
if "getTransactionsRender" not in dir(chain):
return False
return chain.getTransactionsRender()