10
10
11
11
12
12
class Etherscan :
13
- def __new__ (cls , api_key : str , net : str = "MAIN" ):
13
+ def __new__ (cls , api_key : str , endpoint : str = "https://api.etherscan.io/api?" , net : str = "MAIN" ):
14
14
with resources .path (configs , f"{ net .upper ()} -stable.json" ) as path :
15
15
config_path = str (path )
16
- return cls .from_config (api_key = api_key , config_path = config_path , net = net )
16
+ return cls .from_config (api_key = api_key , endpoint = endpoint , config_path = config_path )
17
17
18
18
@staticmethod
19
19
def __load_config (config_path : str ) -> dict :
20
20
with open (config_path , "r" ) as f :
21
21
return json .load (f )
22
22
23
23
@staticmethod
24
- def __run (func , api_key : str , net : str ):
24
+ def __run (func , endpoint : str , api_key : str ):
25
25
def wrapper (* args , ** kwargs ):
26
26
url = (
27
- f"{ fields . PREFIX . format ( net . lower ()). replace ( '-main' , '' ) } "
27
+ f"{ endpoint } "
28
28
f"{ func (* args , ** kwargs )} "
29
29
f"{ fields .API_KEY } "
30
30
f"{ api_key } "
@@ -35,10 +35,10 @@ def wrapper(*args, **kwargs):
35
35
return wrapper
36
36
37
37
@classmethod
38
- def from_config (cls , api_key : str , config_path : str , net : str ):
38
+ def from_config (cls , api_key : str , endpoint : str , config_path : str ):
39
39
config = cls .__load_config (config_path )
40
40
for func , v in config .items ():
41
41
if not func .startswith ("_" ): # disabled if _
42
42
attr = getattr (getattr (etherscan , v ["module" ]), func )
43
- setattr (cls , func , cls .__run (attr , api_key , net ))
43
+ setattr (cls , func , cls .__run (attr , endpoint = endpoint , api_key = api_key ))
44
44
return cls
0 commit comments