Skip to content

Commit 7216fdb

Browse files
author
guochijun
committed
update: more api
1 parent e059d7c commit 7216fdb

File tree

12 files changed

+59
-8
lines changed

12 files changed

+59
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ docs
1515

1616
# eggs
1717
*egg*
18+
build/

etherscan/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
from .modules.stats import Stats as stats
99
from .modules.tokens import Tokens as tokens
1010
from .modules.transactions import Transactions as transactions
11+
from .modules.log import Log as log

etherscan/configs/MAIN-stable.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@
153153
"address": "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413"
154154
}
155155
},
156+
"get_contract_creator":{
157+
"module": "contracts",
158+
"kwargs": {
159+
"addresses": ["0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413"]
160+
}
161+
},
156162
"get_contract_execution_status": {
157163
"module": "transactions",
158164
"kwargs": {
@@ -462,5 +468,11 @@
462468
"end_date": "2019-02-28",
463469
"sort": "asc"
464470
}
471+
},
472+
"get_log": {
473+
"module": "log",
474+
"kwargs": {
475+
"params": "&fromBlock=12878196&toBlock=17868234&page=10&offset=1000&topic0=0xddf252ad1be2c89b69c2b068fc378daa952ba7f16"
476+
}
465477
}
466478
}

etherscan/enums/actions_enum.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class ActionsEnum:
5050
GET_BLOCK_REWARD: str = "getblockreward"
5151
GET_MINED_BLOCKS: str = "getminedblocks"
5252
GET_SOURCE_CODE: str = "getsourcecode"
53+
GET_CTEATOR:str = "getcontractcreation"
5354
GET_STATUS: str = "getstatus"
5455
GET_TX_RECEIPT_STATUS: str = "gettxreceiptstatus"
5556
TOKEN_BALANCE_HISTORY: str = "tokenbalancehistory"
@@ -61,3 +62,4 @@ class ActionsEnum:
6162
TOKENTX: str = "tokentx"
6263
TXLIST_INTERNAL: str = "txlistinternal"
6364
TXLIST: str = "txlist"
65+
GET_LOG:str="getLogs"

etherscan/enums/fields_enum.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class FieldsEnum:
1212
CLIENT_TYPE: str = "&clienttype="
1313
CLOSEST: str = "&closest="
1414
CONTRACT_ADDRESS: str = "&contractaddress="
15+
CONTRACT_ADDRESSES: str = "&contractaddresses="
1516
DATA: str = "&data="
1617
END_BLOCK: str = "&endblock="
1718
END_DATE: str = "&enddate="

etherscan/enums/modules_enum.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ class ModulesEnum:
1111
STATS: str = "stats"
1212
TOKEN: str = "token"
1313
TRANSACTION: str = "transaction"
14+
LOG: str = "logs"
1415

etherscan/etherscan.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,35 @@
1010

1111

1212
class Etherscan:
13-
def __new__(cls, api_key: str, net: str = "MAIN"):
13+
def __new__(cls, api_key: str,net: str = "MAIN", proxies:object={}):
1414
with resources.path(configs, f"{net.upper()}-stable.json") as path:
1515
config_path = str(path)
16-
return cls.from_config(api_key=api_key, config_path=config_path, net=net)
16+
return cls.from_config(api_key=api_key,config_path=config_path, net=net,proxies=proxies)
1717

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

2323
@staticmethod
24-
def __run(func, api_key: str, net: str):
24+
def __run(func, api_key: str, net: str,proxies:object):
2525
def wrapper(*args, **kwargs):
2626
url = (
2727
f"{fields.PREFIX.format(net.lower()).replace('-main','')}"
2828
f"{func(*args, **kwargs)}"
2929
f"{fields.API_KEY}"
3030
f"{api_key}"
3131
)
32-
r = requests.get(url, headers={"User-Agent": ""})
32+
r = requests.get(url, headers={"User-Agent": ""}, proxies=proxies)
3333
return parser.parse(r)
3434

3535
return wrapper
3636

3737
@classmethod
38-
def from_config(cls, api_key: str, config_path: str, net: str):
38+
def from_config(cls, api_key: str, config_path: str, net: str,proxies:object):
3939
config = cls.__load_config(config_path)
4040
for func, v in config.items():
4141
if not func.startswith("_"): # disabled if _
4242
attr = getattr(getattr(etherscan, v["module"]), func)
43-
setattr(cls, func, cls.__run(attr, api_key, net))
43+
setattr(cls, func, cls.__run(attr, api_key, net, proxies))
4444
return cls

etherscan/modules/accounts.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def get_internal_txs_by_block_range_paginated(
170170

171171
@staticmethod
172172
def get_erc20_token_transfer_events_by_address(
173-
address: str, startblock: int, endblock: int, sort: str,
173+
address: str, startblock: int, endblock: int, sort: str,contract_address:str=None
174174
) -> str:
175175
# NOTE: Returns the last 10k events
176176
url = (
@@ -180,6 +180,8 @@ def get_erc20_token_transfer_events_by_address(
180180
f"{actions.TOKENTX}"
181181
f"{fields.ADDRESS}"
182182
f"{address}"
183+
f"{fields.CONTRACT_ADDRESS if contract_address is not None else ''}"
184+
f"{contract_address if contract_address is not None else ''}"
183185
f"{fields.START_BLOCK}"
184186
f"{str(startblock)}"
185187
f"{fields.END_BLOCK}"

etherscan/modules/contracts.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,15 @@ def get_contract_source_code(address: str) -> str:
2727
f"{address}"
2828
)
2929
return url
30+
31+
@staticmethod
32+
def get_contract_creator(addresses: list) -> str:
33+
url = (
34+
f"{fields.MODULE}"
35+
f"{modules.CONTRACT}"
36+
f"{fields.ACTION}"
37+
f"{actions.GET_CTEATOR}"
38+
f"{fields.CONTRACT_ADDRESSES}"
39+
f"{addresses}"
40+
)
41+
return url

etherscan/modules/log.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from etherscan.enums.actions_enum import ActionsEnum as actions
2+
from etherscan.enums.fields_enum import FieldsEnum as fields
3+
from etherscan.enums.modules_enum import ModulesEnum as modules
4+
5+
6+
class Log:
7+
@staticmethod
8+
def get_log(params: str) -> str:
9+
url = (
10+
f"{fields.MODULE}"
11+
f"{modules.LOG}"
12+
f"{fields.ACTION}"
13+
f"{actions.GET_LOG}"
14+
f"{params}"
15+
)
16+
return url

0 commit comments

Comments
 (0)