11import json
2+ from functools import wraps
23
34import requests
45
@@ -14,7 +15,8 @@ def __load_config(config_path: str) -> dict:
1415 return json .load (f )
1516
1617 @staticmethod
17- def __auth (func , api_key ):
18+ def __run (func , api_key ):
19+ # decorator to authorize and get urls
1820 def wrapper (* args , ** kwargs ):
1921 url = (
2022 f"{ fields .PREFIX } "
@@ -27,11 +29,21 @@ def wrapper(*args, **kwargs):
2729
2830 return wrapper
2931
32+ @staticmethod
33+ def __check_status (func ):
34+ # decorator to assert message status
35+ def wrapper (* args , ** kwargs ):
36+ res , status , msg = func (* args , ** kwargs )
37+ assert bool (status ), msg
38+ return (res , msg )
39+
40+ return wrapper
41+
3042 @classmethod
3143 def from_config (cls , config_path : str , api_key : str ):
3244 config = cls .__load_config (config_path )
3345 for func , v in config .items ():
3446 if not func .startswith ("_" ): # disabled if _
3547 attr = getattr (getattr (etherscan , v ["module" ]), func )
36- setattr (cls , func , cls .__auth ( attr , api_key ))
48+ setattr (cls , func , cls .__check_status ( cls . __run ( attr , api_key ) ))
3749 return cls
0 commit comments