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

make URL endpoint configurable#28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
cgumpert wants to merge1 commit intopcko1:master
base:master
Choose a base branch
Loading
fromcgumpert:configurable-endpoint
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletionsetherscan/etherscan.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,21 +10,21 @@


class Etherscan:
def __new__(cls, api_key: str, net: str = "MAIN"):
def __new__(cls, api_key: str,endpoint: str = "https://api.etherscan.io/api?",net: str = "MAIN"):
with resources.path(configs, f"{net.upper()}-stable.json") as path:
config_path = str(path)
return cls.from_config(api_key=api_key,config_path=config_path, net=net)
return cls.from_config(api_key=api_key,endpoint=endpoint, config_path=config_path)

@staticmethod
def __load_config(config_path: str) -> dict:
with open(config_path, "r") as f:
return json.load(f)

@staticmethod
def __run(func,api_key: str,net: str):
def __run(func,endpoint: str,api_key: str):
def wrapper(*args, **kwargs):
url = (
f"{fields.PREFIX.format(net.lower()).replace('-main','')}"
f"{endpoint}"
f"{func(*args, **kwargs)}"
f"{fields.API_KEY}"
f"{api_key}"
Expand All@@ -35,10 +35,10 @@ def wrapper(*args, **kwargs):
return wrapper

@classmethod
def from_config(cls, api_key: str,config_path: str,net: str):
def from_config(cls, api_key: str,endpoint: str,config_path: str):
config = cls.__load_config(config_path)
for func, v in config.items():
if not func.startswith("_"): # disabled if _
attr = getattr(getattr(etherscan, v["module"]), func)
setattr(cls, func, cls.__run(attr,api_key, net))
setattr(cls, func, cls.__run(attr,endpoint=endpoint, api_key=api_key))
return cls
2 changes: 1 addition & 1 deletiontest/test_modules.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,7 +29,7 @@ def methods(self, net):
print(f"\nNET: {net}")
print(f"MODULE: {self._MODULE}")
config = load(CONFIG_PATH.format(net))
etherscan = Etherscan(API_KEY, net)
etherscan = Etherscan(api_key=API_KEY,net=net)
for fun, v in config.items():
if not fun.startswith("_"): # disabled if _
if v["module"] == self._MODULE:
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp