diff --git a/etherscan/etherscan.py b/etherscan/etherscan.py index 5749aa8..fb435fa 100644 --- a/etherscan/etherscan.py +++ b/etherscan/etherscan.py @@ -10,10 +10,10 @@ 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: @@ -21,10 +21,10 @@ def __load_config(config_path: str) -> dict: 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}" @@ -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 diff --git a/test/test_modules.py b/test/test_modules.py index 8ad9f9b..ac7c6a4 100644 --- a/test/test_modules.py +++ b/test/test_modules.py @@ -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:
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: