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

Commit61abdba

Browse files
committed
Added support for testnets
1 parent2be8440 commit61abdba

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

‎etherscan/enums/fields_enum.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class FieldsEnum:
2323
OFFSET:str="&offset="
2424
PAGE:str="&page="
2525
POSITION:str="&position="
26-
PREFIX:str="https://api.etherscan.io/api?"
26+
PREFIX:str="https://api-{}.etherscan.io/api?"
2727
SORT:str="&sort="
2828
START_BLOCK:str="&startblock="
2929
START_DATE:str="&startdate="

‎etherscan/etherscan.py‎

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

1111

1212
classEtherscan:
13-
def__new__(cls,api_key:str):
14-
withresources.path(configs,"stable.json")aspath:
13+
def__new__(cls,api_key:str,net:str="MAIN"):
14+
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)
16+
returncls.from_config(api_key=api_key,config_path=config_path,net=net)
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):
24+
def__run(func,api_key:str,net:str):
2525
defwrapper(*args,**kwargs):
2626
url= (
27-
f"{fields.PREFIX}"
27+
f"{fields.PREFIX.format(net.lower()).replace('-main','')}"
2828
f"{func(*args,**kwargs)}"
2929
f"{fields.API_KEY}"
3030
f"{api_key}"
3131
)
32-
r=requests.get(url)
32+
r=requests.get(url,headers={'User-Agent':''})
3333
returnparser.parse(r)
3434

3535
returnwrapper
3636

3737
@classmethod
38-
deffrom_config(cls,api_key:str,config_path:str):
38+
deffrom_config(cls,api_key:str,config_path:str,net: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))
43+
setattr(cls,func,cls.__run(attr,api_key,net))
4444
returncls

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp