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

Commitf1375a9

Browse files
author
Kotsias, Panagiotis-Christos
committed
Converted to static factory
1 parent1a12786 commitf1375a9

File tree

1 file changed

+33
-35
lines changed

1 file changed

+33
-35
lines changed

‎etherscan/client.py‎

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,37 @@
1-
importrequestsasreq
1+
importjson
22

3+
importrequests
34

4-
classClient:
5-
def__init__(self,api_key:str):
6-
self.api_key=api_key
7-
8-
# accounts
9-
defget_eth_balance(self,wallet:str):
10-
pass
11-
12-
defget_eth_balance_multiple(self):
13-
pass
14-
15-
defget_hist_eth_balance(self):
16-
# throttled to 2 calls/sec
17-
pass
18-
19-
defget_normal_txs_by_address(self):
20-
pass
21-
22-
defget_internal_txs_by_address(self):
23-
pass
5+
importetherscan
6+
frometherscan.enums.fields_enumimportFieldsEnumasfields
7+
frometherscan.parsingimportResponseParserasparser
248

25-
defget_internal_txs_by_txhash(self):
26-
pass
27-
28-
defget_internal_txs_by_block_range(self):
29-
pass
30-
31-
defget_erc20_transfer_events_by_address(self):
32-
pass
33-
34-
defget_erc721_transfer_events_by_address(self):
35-
pass
36-
37-
defget_mined_blocks_by_address(self):
38-
pass
399

10+
classClient:
11+
@staticmethod
12+
def__load_config(config_path:str)->dict:
13+
withopen(config_path,"r")asf:
14+
returnjson.load(f)
15+
16+
@staticmethod
17+
def__auth(func,api_key):
18+
defwrapper(*args,**kwargs):
19+
url= (
20+
f"{fields.PREFIX}"
21+
f"{func(*args,**kwargs)}"
22+
f"{fields.API_KEY}"
23+
f"{api_key}"
24+
)
25+
r=requests.get(url)
26+
returnparser.get_result(r)
27+
28+
returnwrapper
29+
30+
@classmethod
31+
deffrom_config(cls,config_path:str,api_key:str):
32+
config=cls.__load_config(config_path)
33+
fork,vinconfig.items():
34+
ifnotk.startswith("_"):
35+
attr=getattr(getattr(etherscan,v),k)
36+
setattr(cls,k,cls.__auth(attr,api_key))
37+
returncls

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp