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 , net : str = "MAIN" , chain_id : str = "1" ):
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 (
17
+ api_key = api_key , chain_id = chain_id , config_path = config_path , net = net
18
+ )
17
19
18
20
@staticmethod
19
21
def __load_config (config_path : str ) -> dict :
20
22
with open (config_path , "r" ) as f :
21
23
return json .load (f )
22
24
23
25
@staticmethod
24
- def __run (func , api_key : str , net : str ):
26
+ def __run (func , api_key : str , net : str , chain_id : str ):
25
27
def wrapper (* args , ** kwargs ):
26
28
url = (
27
29
f"{ fields .PREFIX .format (net .lower ()).replace ('-main' ,'' )} "
28
30
f"{ func (* args , ** kwargs )} "
31
+ f"{ fields .CHAIN_ID } "
32
+ f"{ chain_id } "
29
33
f"{ fields .API_KEY } "
30
34
f"{ api_key } "
31
35
)
@@ -35,10 +39,10 @@ def wrapper(*args, **kwargs):
35
39
return wrapper
36
40
37
41
@classmethod
38
- def from_config (cls , api_key : str , config_path : str , net : str ):
42
+ def from_config (cls , api_key : str , config_path : str , net : str , chain_id : str ):
39
43
config = cls .__load_config (config_path )
40
44
for func , v in config .items ():
41
45
if not func .startswith ("_" ): # disabled if _
42
46
attr = getattr (getattr (etherscan , v ["module" ]), func )
43
- setattr (cls , func , cls .__run (attr , api_key , net ))
47
+ setattr (cls , func , cls .__run (attr , api_key , net , chain_id ))
44
48
return cls
0 commit comments