Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fdd3d73

Browse files
author
Kotsias, Panagiotis-Christos
committed
Changed auth to run
1 parent 52a34ff commit fdd3d73

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

etherscan/client.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
from functools import wraps
23

34
import requests
45

@@ -14,7 +15,8 @@ def __load_config(config_path: str) -> dict:
1415
return json.load(f)
1516

1617
@staticmethod
17-
def __auth(func, api_key):
18+
def __run(func, api_key):
19+
# decorator to authorize and get urls
1820
def wrapper(*args, **kwargs):
1921
url = (
2022
f"{fields.PREFIX}"
@@ -27,11 +29,21 @@ def wrapper(*args, **kwargs):
2729

2830
return wrapper
2931

32+
@staticmethod
33+
def __check_status(func):
34+
# decorator to assert message status
35+
def wrapper(*args, **kwargs):
36+
res, status, msg = func(*args, **kwargs)
37+
assert bool(status), msg
38+
return (res, msg)
39+
40+
return wrapper
41+
3042
@classmethod
3143
def from_config(cls, config_path: str, api_key: str):
3244
config = cls.__load_config(config_path)
3345
for func, v in config.items():
3446
if not func.startswith("_"): # disabled if _
3547
attr = getattr(getattr(etherscan, v["module"]), func)
36-
setattr(cls, func, cls.__auth(attr, api_key))
48+
setattr(cls, func, cls.__check_status(cls.__run(attr, api_key)))
3749
return cls

0 commit comments

Comments
 (0)