Skip to content

Commit f1375a9

Browse files
author
Kotsias, Panagiotis-Christos
committed
Converted to static factory
1 parent 1a12786 commit f1375a9

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-
import requests as req
1+
import json
22

3+
import requests
34

4-
class Client:
5-
def __init__(self, api_key: str):
6-
self.api_key = api_key
7-
8-
# accounts
9-
def get_eth_balance(self, wallet: str):
10-
pass
11-
12-
def get_eth_balance_multiple(self):
13-
pass
14-
15-
def get_hist_eth_balance(self):
16-
# throttled to 2 calls/sec
17-
pass
18-
19-
def get_normal_txs_by_address(self):
20-
pass
21-
22-
def get_internal_txs_by_address(self):
23-
pass
5+
import etherscan
6+
from etherscan.enums.fields_enum import FieldsEnum as fields
7+
from etherscan.parsing import ResponseParser as parser
248

25-
def get_internal_txs_by_txhash(self):
26-
pass
27-
28-
def get_internal_txs_by_block_range(self):
29-
pass
30-
31-
def get_erc20_transfer_events_by_address(self):
32-
pass
33-
34-
def get_erc721_transfer_events_by_address(self):
35-
pass
36-
37-
def get_mined_blocks_by_address(self):
38-
pass
399

10+
class Client:
11+
@staticmethod
12+
def __load_config(config_path: str) -> dict:
13+
with open(config_path, "r") as f:
14+
return json.load(f)
15+
16+
@staticmethod
17+
def __auth(func, api_key):
18+
def wrapper(*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+
return parser.get_result(r)
27+
28+
return wrapper
29+
30+
@classmethod
31+
def from_config(cls, config_path: str, api_key: str):
32+
config = cls.__load_config(config_path)
33+
for k, v in config.items():
34+
if not k.startswith("_"):
35+
attr = getattr(getattr(etherscan, v), k)
36+
setattr(cls, k, cls.__auth(attr, api_key))
37+
return cls

0 commit comments

Comments
 (0)