|
1 | | -importrequestsasreq |
| 1 | +importjson |
2 | 2 |
|
| 3 | +importrequests |
3 | 4 |
|
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 |
24 | 8 |
|
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 |
39 | 9 |
|
| 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 |