1010
1111
1212class 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" ):
1414with resources .path (configs ,f"{ net .upper ()} -stable.json" )as path :
1515config_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 )
1717
1818@staticmethod
1919def __load_config (config_path :str )-> dict :
2020with open (config_path ,"r" )as f :
2121return json .load (f )
2222
2323@staticmethod
24- def __run (func ,api_key :str ,net :str ):
24+ def __run (func ,endpoint :str ,api_key :str ):
2525def wrapper (* args ,** kwargs ):
2626url = (
27- f"{ fields . PREFIX . format ( net . lower ()). replace ( '-main' , '' ) } "
27+ f"{ endpoint } "
2828f"{ func (* args ,** kwargs )} "
2929f"{ fields .API_KEY } "
3030f"{ api_key } "
@@ -35,10 +35,10 @@ def wrapper(*args, **kwargs):
3535return wrapper
3636
3737@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 ):
3939config = cls .__load_config (config_path )
4040for func ,v in config .items ():
4141if not func .startswith ("_" ):# disabled if _
4242attr = 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 ))
4444return cls