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

Commit71c2dfa

Browse files
committed
support v2 api
1 parente059d7c commit71c2dfa

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
# coverage
88
*coverage*
9+
logs/
910

1011
# VSCode
1112
.vscode/*

‎etherscan/enums/fields_enum.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class FieldsEnum:
99
BLOCK_TYPE:str="&blocktype="
1010
BLOCKNO:str="&blockno="
1111
BOOLEAN:str="&boolean="
12+
CHAIN_ID:str="&chainid="
1213
CLIENT_TYPE:str="&clienttype="
1314
CLOSEST:str="&closest="
1415
CONTRACT_ADDRESS:str="&contractaddress="
@@ -23,7 +24,7 @@ class FieldsEnum:
2324
OFFSET:str="&offset="
2425
PAGE:str="&page="
2526
POSITION:str="&position="
26-
PREFIX:str="https://api-{}.etherscan.io/api?"
27+
PREFIX:str="https://api-{}.etherscan.io/v2/api?"
2728
SORT:str="&sort="
2829
START_BLOCK:str="&startblock="
2930
START_DATE:str="&startdate="

‎etherscan/etherscan.py‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,26 @@
1010

1111

1212
classEtherscan:
13-
def__new__(cls,api_key:str,net:str="MAIN"):
13+
def__new__(cls,api_key:str,net:str="MAIN",chain_id:str="1"):
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(
17+
api_key=api_key,chain_id=chain_id,config_path=config_path,net=net
18+
)
1719

1820
@staticmethod
1921
def__load_config(config_path:str)->dict:
2022
withopen(config_path,"r")asf:
2123
returnjson.load(f)
2224

2325
@staticmethod
24-
def__run(func,api_key:str,net:str):
26+
def__run(func,api_key:str,net:str,chain_id:str):
2527
defwrapper(*args,**kwargs):
2628
url= (
2729
f"{fields.PREFIX.format(net.lower()).replace('-main','')}"
2830
f"{func(*args,**kwargs)}"
31+
f"{fields.CHAIN_ID}"
32+
f"{chain_id}"
2933
f"{fields.API_KEY}"
3034
f"{api_key}"
3135
)
@@ -35,10 +39,10 @@ def wrapper(*args, **kwargs):
3539
returnwrapper
3640

3741
@classmethod
38-
deffrom_config(cls,api_key:str,config_path:str,net:str):
42+
deffrom_config(cls,api_key:str,config_path:str,net:str,chain_id:str):
3943
config=cls.__load_config(config_path)
4044
forfunc,vinconfig.items():
4145
ifnotfunc.startswith("_"):# disabled if _
4246
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))
4448
returncls

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp