1
1
import json
2
+ from functools import wraps
2
3
3
4
import requests
4
5
@@ -14,7 +15,8 @@ def __load_config(config_path: str) -> dict:
14
15
return json .load (f )
15
16
16
17
@staticmethod
17
- def __auth (func , api_key ):
18
+ def __run (func , api_key ):
19
+ # decorator to authorize and get urls
18
20
def wrapper (* args , ** kwargs ):
19
21
url = (
20
22
f"{ fields .PREFIX } "
@@ -27,11 +29,21 @@ def wrapper(*args, **kwargs):
27
29
28
30
return wrapper
29
31
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
+
30
42
@classmethod
31
43
def from_config (cls , config_path : str , api_key : str ):
32
44
config = cls .__load_config (config_path )
33
45
for func , v in config .items ():
34
46
if not func .startswith ("_" ): # disabled if _
35
47
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 ) ))
37
49
return cls
0 commit comments