From 7216fdb30b0e58f7ef6c204c7805d02eda43a000 Mon Sep 17 00:00:00 2001 From: guochijun Date: Wed, 9 Aug 2023 18:50:10 +0800 Subject: [PATCH] update: more api --- .gitignore | 1 + etherscan/__init__.py | 1 + etherscan/configs/MAIN-stable.json | 12 ++++++++++++ etherscan/enums/actions_enum.py | 2 ++ etherscan/enums/fields_enum.py | 1 + etherscan/enums/modules_enum.py | 1 + etherscan/etherscan.py | 12 ++++++------ etherscan/modules/accounts.py | 4 +++- etherscan/modules/contracts.py | 12 ++++++++++++ etherscan/modules/log.py | 16 ++++++++++++++++ setup.py | 2 +- test/test_modules.py | 3 +++ 12 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 etherscan/modules/log.py diff --git a/.gitignore b/.gitignore index a7f9bdb..1304958 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ docs # eggs *egg* +build/ \ No newline at end of file diff --git a/etherscan/__init__.py b/etherscan/__init__.py index 7b527d3..82581f7 100644 --- a/etherscan/__init__.py +++ b/etherscan/__init__.py @@ -8,3 +8,4 @@ from .modules.stats import Stats as stats from .modules.tokens import Tokens as tokens from .modules.transactions import Transactions as transactions +from .modules.log import Log as log \ No newline at end of file diff --git a/etherscan/configs/MAIN-stable.json b/etherscan/configs/MAIN-stable.json index 272ed0b..74ea507 100644 --- a/etherscan/configs/MAIN-stable.json +++ b/etherscan/configs/MAIN-stable.json @@ -153,6 +153,12 @@ "address": "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413" } }, + "get_contract_creator":{ + "module": "contracts", + "kwargs": { + "addresses": ["0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413"] + } + }, "get_contract_execution_status": { "module": "transactions", "kwargs": { @@ -462,5 +468,11 @@ "end_date": "2019-02-28", "sort": "asc" } + }, + "get_log": { + "module": "log", + "kwargs": { + "params": "&fromBlock=12878196&toBlock=17868234&page=10&offset=1000&topic0=0xddf252ad1be2c89b69c2b068fc378daa952ba7f16" + } } } \ No newline at end of file diff --git a/etherscan/enums/actions_enum.py b/etherscan/enums/actions_enum.py index 20c81cb..d2253d3 100644 --- a/etherscan/enums/actions_enum.py +++ b/etherscan/enums/actions_enum.py @@ -50,6 +50,7 @@ class ActionsEnum: GET_BLOCK_REWARD: str = "getblockreward" GET_MINED_BLOCKS: str = "getminedblocks" GET_SOURCE_CODE: str = "getsourcecode" + GET_CTEATOR:str = "getcontractcreation" GET_STATUS: str = "getstatus" GET_TX_RECEIPT_STATUS: str = "gettxreceiptstatus" TOKEN_BALANCE_HISTORY: str = "tokenbalancehistory" @@ -61,3 +62,4 @@ class ActionsEnum: TOKENTX: str = "tokentx" TXLIST_INTERNAL: str = "txlistinternal" TXLIST: str = "txlist" + GET_LOG:str="getLogs" diff --git a/etherscan/enums/fields_enum.py b/etherscan/enums/fields_enum.py index b0bcc4d..d1d42ed 100644 --- a/etherscan/enums/fields_enum.py +++ b/etherscan/enums/fields_enum.py @@ -12,6 +12,7 @@ class FieldsEnum: CLIENT_TYPE: str = "&clienttype=" CLOSEST: str = "&closest=" CONTRACT_ADDRESS: str = "&contractaddress=" + CONTRACT_ADDRESSES: str = "&contractaddresses=" DATA: str = "&data=" END_BLOCK: str = "&endblock=" END_DATE: str = "&enddate=" diff --git a/etherscan/enums/modules_enum.py b/etherscan/enums/modules_enum.py index e02e11c..5f73ace 100644 --- a/etherscan/enums/modules_enum.py +++ b/etherscan/enums/modules_enum.py @@ -11,4 +11,5 @@ class ModulesEnum: STATS: str = "stats" TOKEN: str = "token" TRANSACTION: str = "transaction" + LOG: str = "logs" diff --git a/etherscan/etherscan.py b/etherscan/etherscan.py index 5749aa8..a37bad9 100644 --- a/etherscan/etherscan.py +++ b/etherscan/etherscan.py @@ -10,10 +10,10 @@ class Etherscan: - def __new__(cls, api_key: str, net: str = "MAIN"): + def __new__(cls, api_key: str,net: str = "MAIN", proxies:object={}): 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,config_path=config_path, net=net,proxies=proxies) @staticmethod def __load_config(config_path: str) -> dict: @@ -21,7 +21,7 @@ def __load_config(config_path: str) -> dict: return json.load(f) @staticmethod - def __run(func, api_key: str, net: str): + def __run(func, api_key: str, net: str,proxies:object): def wrapper(*args, **kwargs): url = ( f"{fields.PREFIX.format(net.lower()).replace('-main','')}" @@ -29,16 +29,16 @@ def wrapper(*args, **kwargs): f"{fields.API_KEY}" f"{api_key}" ) - r = requests.get(url, headers={"User-Agent": ""}) + r = requests.get(url, headers={"User-Agent": ""}, proxies=proxies) return parser.parse(r) return wrapper @classmethod - def from_config(cls, api_key: str, config_path: str, net: str): + def from_config(cls, api_key: str, config_path: str, net: str,proxies:object): 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, api_key, net, proxies)) return cls diff --git a/etherscan/modules/accounts.py b/etherscan/modules/accounts.py index 831b90d..8139888 100644 --- a/etherscan/modules/accounts.py +++ b/etherscan/modules/accounts.py @@ -170,7 +170,7 @@ def get_internal_txs_by_block_range_paginated( @staticmethod def get_erc20_token_transfer_events_by_address( - address: str, startblock: int, endblock: int, sort: str, + address: str, startblock: int, endblock: int, sort: str,contract_address:str=None ) -> str: # NOTE: Returns the last 10k events url = ( @@ -180,6 +180,8 @@ def get_erc20_token_transfer_events_by_address( f"{actions.TOKENTX}" f"{fields.ADDRESS}" f"{address}" + f"{fields.CONTRACT_ADDRESS if contract_address is not None else ''}" + f"{contract_address if contract_address is not None else ''}" f"{fields.START_BLOCK}" f"{str(startblock)}" f"{fields.END_BLOCK}" diff --git a/etherscan/modules/contracts.py b/etherscan/modules/contracts.py index 6e8b85a..fddb8a2 100644 --- a/etherscan/modules/contracts.py +++ b/etherscan/modules/contracts.py @@ -27,3 +27,15 @@ def get_contract_source_code(address: str) -> str: f"{address}" ) return url + + @staticmethod + def get_contract_creator(addresses: list) -> str: + url = ( + f"{fields.MODULE}" + f"{modules.CONTRACT}" + f"{fields.ACTION}" + f"{actions.GET_CTEATOR}" + f"{fields.CONTRACT_ADDRESSES}" + f"{addresses}" + ) + return url \ No newline at end of file diff --git a/etherscan/modules/log.py b/etherscan/modules/log.py new file mode 100644 index 0000000..b9fc7d3 --- /dev/null +++ b/etherscan/modules/log.py @@ -0,0 +1,16 @@ +from etherscan.enums.actions_enum import ActionsEnum as actions +from etherscan.enums.fields_enum import FieldsEnum as fields +from etherscan.enums.modules_enum import ModulesEnum as modules + + +class Log: + @staticmethod + def get_log(params: str) -> str: + url = ( + f"{fields.MODULE}" + f"{modules.LOG}" + f"{fields.ACTION}" + f"{actions.GET_LOG}" + f"{params}" + ) + return url \ No newline at end of file diff --git a/setup.py b/setup.py index 9a4410a..4bec809 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="etherscan-python", - version="2.1.0", + version="2.1.4", description="A minimal, yet complete, python API for etherscan.io.", url="https://github.com/pcko1/etherscan-python", author="Panagiotis-Christos Kotsias", diff --git a/test/test_modules.py b/test/test_modules.py index 8ad9f9b..8a64e16 100644 --- a/test/test_modules.py +++ b/test/test_modules.py @@ -86,3 +86,6 @@ class TestTokens(Case): class TestTransactions(Case): _MODULE = "transactions" + +class TestLog(Case): + _MODULE = "log" \ No newline at end of file pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy