Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions etherscan/etherscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@


class Etherscan:
def __new__(cls, api_key: str, net: str = "MAIN"):
def __new__(cls, api_key: str, endpoint: str = "https://api.etherscan.io/api?", net: str = "MAIN"):
with resources.path(configs, f"{net.upper()}-stable.json") as path:
config_path = str(path)
return cls.from_config(api_key=api_key, config_path=config_path, net=net)
return cls.from_config(api_key=api_key, endpoint=endpoint, config_path=config_path)

@staticmethod
def __load_config(config_path: str) -> dict:
with open(config_path, "r") as f:
return json.load(f)

@staticmethod
def __run(func, api_key: str, net: str):
def __run(func, endpoint: str, api_key: str):
def wrapper(*args, **kwargs):
url = (
f"{fields.PREFIX.format(net.lower()).replace('-main','')}"
f"{endpoint}"
f"{func(*args, **kwargs)}"
f"{fields.API_KEY}"
f"{api_key}"
Expand All @@ -35,10 +35,10 @@ def wrapper(*args, **kwargs):
return wrapper

@classmethod
def from_config(cls, api_key: str, config_path: str, net: str):
def from_config(cls, api_key: str, endpoint: str, config_path: str):
config = cls.__load_config(config_path)
for func, v in config.items():
if not func.startswith("_"): # disabled if _
attr = getattr(getattr(etherscan, v["module"]), func)
setattr(cls, func, cls.__run(attr, api_key, net))
setattr(cls, func, cls.__run(attr, endpoint=endpoint, api_key=api_key))
return cls
2 changes: 1 addition & 1 deletion test/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def methods(self, net):
print(f"\nNET: {net}")
print(f"MODULE: {self._MODULE}")
config = load(CONFIG_PATH.format(net))
etherscan = Etherscan(API_KEY, net)
etherscan = Etherscan(api_key=API_KEY, net=net)
for fun, v in config.items():
if not fun.startswith("_"): # disabled if _
if v["module"] == self._MODULE:
Expand Down