Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit621a8a2

Browse files
author
Christian Gumpert
committed
make URL endpoint configurable
1 parente059d7c commit621a8a2

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

‎etherscan/etherscan.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@
1010

1111

1212
classEtherscan:
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"):
1414
withresources.path(configs,f"{net.upper()}-stable.json")aspath:
1515
config_path=str(path)
16-
returncls.from_config(api_key=api_key,config_path=config_path,net=net)
16+
returncls.from_config(api_key=api_key,endpoint=endpoint,config_path=config_path)
1717

1818
@staticmethod
1919
def__load_config(config_path:str)->dict:
2020
withopen(config_path,"r")asf:
2121
returnjson.load(f)
2222

2323
@staticmethod
24-
def__run(func,api_key:str,net:str):
24+
def__run(func,endpoint:str,api_key:str):
2525
defwrapper(*args,**kwargs):
2626
url= (
27-
f"{fields.PREFIX.format(net.lower()).replace('-main','')}"
27+
f"{endpoint}"
2828
f"{func(*args,**kwargs)}"
2929
f"{fields.API_KEY}"
3030
f"{api_key}"
@@ -35,10 +35,10 @@ def wrapper(*args, **kwargs):
3535
returnwrapper
3636

3737
@classmethod
38-
deffrom_config(cls,api_key:str,config_path:str,net:str):
38+
deffrom_config(cls,api_key:str,endpoint:str,config_path:str):
3939
config=cls.__load_config(config_path)
4040
forfunc,vinconfig.items():
4141
ifnotfunc.startswith("_"):# disabled if _
4242
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))
4444
returncls

‎test/test_modules.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def methods(self, net):
2929
print(f"\nNET:{net}")
3030
print(f"MODULE:{self._MODULE}")
3131
config=load(CONFIG_PATH.format(net))
32-
etherscan=Etherscan(API_KEY,net)
32+
etherscan=Etherscan(api_key=API_KEY,net=net)
3333
forfun,vinconfig.items():
3434
ifnotfun.startswith("_"):# disabled if _
3535
ifv["module"]==self._MODULE:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp