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

Skip to content

Commit 43fbfc7

Browse files
author
Kotsias, Panagiotis-Christos
committed
Added docstrings and changed kwargs
1 parent 4c10b21 commit 43fbfc7

File tree

5 files changed

+206
-50
lines changed

5 files changed

+206
-50
lines changed

etherscan/client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def wrapper(*args, **kwargs):
3131
def from_config(cls, config_path: str, api_key: str):
3232
config = cls.__load_config(config_path)
3333
for func, v in config.items():
34-
if not func.startswith("_"):
34+
if not func.startswith("_"): # disabled if _
3535
attr = getattr(getattr(etherscan, v["module"]), func)
3636
setattr(cls, func, cls.__auth(attr, api_key))
3737
return cls

etherscan/modules/accounts.py

+149-34
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from functools import reduce
22
from typing import List
33

4-
from etherscan.utils.datatypes import TxHash, WalletAddress
54
from etherscan.enums.actions_enum import ActionsEnum as actions
65
from etherscan.enums.fields_enum import FieldsEnum as fields
76
from etherscan.enums.modules_enum import ModulesEnum as modules
@@ -10,14 +9,21 @@
109

1110
class Accounts:
1211
@staticmethod
13-
def get_eth_balance(wallet: WalletAddress) -> str:
12+
def get_eth_balance(address: str) -> str:
13+
"""Returns ether balance for a single wallet.
14+
15+
:param address: Wallet address
16+
:type address: str
17+
:return: The url to get
18+
:rtype: str
19+
"""
1420
url = (
1521
f"{fields.MODULE}"
1622
f"{modules.ACCOUNT}"
1723
f"{fields.ACTION}"
1824
f"{actions.BALANCE}"
1925
f"{fields.ADDRESS}"
20-
f"{wallet}"
26+
f"{address}"
2127
f"{fields.TAG}"
2228
f"{tags.LATEST}"
2329
)
@@ -26,16 +32,22 @@ def get_eth_balance(wallet: WalletAddress) -> str:
2632
# return conversions.to_ticker_unit(parser.get_result(r))
2733

2834
@staticmethod
29-
def get_eth_balance_multiple(wallets: List[WalletAddress]) -> str:
30-
# max 20 wallets
31-
wallet_list = reduce(lambda w1, w2: str(w1) + "," + str(w2), wallets)
35+
def get_eth_balance_multiple(addresses: List[str]) -> str:
36+
"""Returns ether balance for a list of wallets. Max of 20 wallets at a time.
37+
38+
:param addresses: List of wallets
39+
:type addresses: List[str]
40+
:return: The url to get
41+
:rtype: str
42+
"""
43+
address_list = reduce(lambda w1, w2: str(w1) + "," + str(w2), addresses)
3244
url = (
3345
f"{fields.MODULE}"
3446
f"{modules.ACCOUNT}"
3547
f"{fields.ACTION}"
3648
f"{actions.BALANCE_MULTI}"
3749
f"{fields.ADDRESS}"
38-
f"{wallet_list}"
50+
f"{address_list}"
3951
f"{fields.TAG}"
4052
f"{tags.LATEST}"
4153
)
@@ -45,19 +57,32 @@ def get_eth_balance_multiple(wallets: List[WalletAddress]) -> str:
4557

4658
@staticmethod
4759
def get_normal_txs_by_address(
48-
wallet: WalletAddress,
60+
address: str,
4961
startblock: int = 0000,
5062
endblock: int = 99999999,
5163
sort: str = "asc",
5264
) -> str:
65+
"""Returns the last 10k normal transactions for an address.
66+
67+
:param address: Wallet address
68+
:type address: str
69+
:param startblock: Starting block, defaults to 0000
70+
:type startblock: int, optional
71+
:param endblock: Ending block, defaults to 99999999
72+
:type endblock: int, optional
73+
:param sort: Sort results, defaults to "asc"
74+
:type sort: str, optional
75+
:return: The url to get
76+
:rtype: str
77+
"""
5378
# last 10,000 txs only
5479
url = (
5580
f"{fields.MODULE}"
5681
f"{modules.ACCOUNT}"
5782
f"{fields.ACTION}"
5883
f"{actions.TXLIST}"
5984
f"{fields.ADDRESS}"
60-
f"{wallet}"
85+
f"{address}"
6186
f"{fields.START_BLOCK}"
6287
f"{str(startblock)}"
6388
f"{fields.END_BLOCK}"
@@ -69,20 +94,37 @@ def get_normal_txs_by_address(
6994

7095
@staticmethod
7196
def get_normal_txs_by_address_paginated(
72-
wallet: WalletAddress,
97+
address: str,
7398
page: int,
7499
offset: int,
75100
startblock: int = 0000,
76101
endblock: int = 99999999,
77102
sort: str = "asc",
78103
) -> str:
104+
"""Returns the paginated normal transactions for an address.
105+
106+
:param address: Wallet address
107+
:type address: str
108+
:param page: Page number
109+
:type page: int
110+
:param offset: Max records to return
111+
:type offset: int
112+
:param startblock: Starting block, defaults to 0000
113+
:type startblock: int, optional
114+
:param endblock: Ending block, defaults to 99999999
115+
:type endblock: int, optional
116+
:param sort: Sort results, defaults to "asc"
117+
:type sort: str, optional
118+
:return: The url to get
119+
:rtype: str
120+
"""
79121
url = (
80122
f"{fields.MODULE}"
81123
f"{modules.ACCOUNT}"
82124
f"{fields.ACTION}"
83125
f"{actions.TXLIST}"
84126
f"{fields.ADDRESS}"
85-
f"{wallet}"
127+
f"{address}"
86128
f"{fields.START_BLOCK}"
87129
f"{str(startblock)}"
88130
f"{fields.END_BLOCK}"
@@ -98,19 +140,31 @@ def get_normal_txs_by_address_paginated(
98140

99141
@staticmethod
100142
def get_internal_txs_by_address(
101-
wallet: WalletAddress,
143+
address: str,
102144
startblock: int = 0000,
103145
endblock: int = 99999999,
104146
sort: str = "asc",
105147
) -> str:
106-
# last 10,000 txs only
148+
"""Returns the last 10k internal transactions for an address.
149+
150+
:param address: Wallet address
151+
:type address: str
152+
:param startblock: Starting block, defaults to 0000
153+
:type startblock: int, optional
154+
:param endblock: Ending block, defaults to 99999999
155+
:type endblock: int, optional
156+
:param sort: Sort results, defaults to "asc"
157+
:type sort: str, optional
158+
:return: The url to get
159+
:rtype: str
160+
"""
107161
url = (
108162
f"{fields.MODULE}"
109163
f"{modules.ACCOUNT}"
110164
f"{fields.ACTION}"
111165
f"{actions.TXLIST_INTERNAL}"
112166
f"{fields.ADDRESS}"
113-
f"{wallet}"
167+
f"{address}"
114168
f"{fields.START_BLOCK}"
115169
f"{str(startblock)}"
116170
f"{fields.END_BLOCK}"
@@ -122,20 +176,37 @@ def get_internal_txs_by_address(
122176

123177
@staticmethod
124178
def get_internal_txs_by_address_paginated(
125-
wallet: WalletAddress,
179+
address: str,
126180
page: int,
127181
offset: int,
128182
startblock: int = 0000,
129183
endblock: int = 99999999,
130184
sort: str = "asc",
131185
) -> str:
186+
"""Returns the paginated internal transactions for an address.
187+
188+
:param address: Wallet address
189+
:type address: str
190+
:param page: Page number
191+
:type page: int
192+
:param offset: Max records to return
193+
:type offset: int
194+
:param startblock: Starting block, defaults to 0000
195+
:type startblock: int, optional
196+
:param endblock: Ending block, defaults to 99999999
197+
:type endblock: int, optional
198+
:param sort: Sort results, defaults to "asc"
199+
:type sort: str, optional
200+
:return: The url to get
201+
:rtype: str
202+
"""
132203
url = (
133204
f"{fields.MODULE}"
134205
f"{modules.ACCOUNT}"
135206
f"{fields.ACTION}"
136207
f"{actions.TXLIST_INTERNAL}"
137208
f"{fields.ADDRESS}"
138-
f"{wallet}"
209+
f"{address}"
139210
f"{fields.START_BLOCK}"
140211
f"{str(startblock)}"
141212
f"{fields.END_BLOCK}"
@@ -150,8 +221,14 @@ def get_internal_txs_by_address_paginated(
150221
return url
151222

152223
@staticmethod
153-
def get_internal_txs_by_txhash(txhash: TxHash) -> str:
154-
# last 10,000 txs only
224+
def get_internal_txs_by_txhash(txhash: str) -> str:
225+
"""Returns the last 10k internal transactions for a transaction hash.
226+
227+
:param txhash: Transaction hash
228+
:type txhash: str
229+
:return: The url to get
230+
:rtype: str
231+
"""
155232
url = (
156233
f"{fields.MODULE}"
157234
f"{modules.ACCOUNT}"
@@ -166,8 +243,21 @@ def get_internal_txs_by_txhash(txhash: TxHash) -> str:
166243
def get_internal_txs_by_block_range_paginated(
167244
startblock: int, endblock: int, page: int, offset: int, sort: str = "asc",
168245
) -> str:
169-
# last 10,000 txs only
170-
# BUG: returns empty message
246+
"""Returns the last 10k paginated internal transactions for a block range.
247+
248+
:param startblock: Starting block
249+
:type startblock: int
250+
:param endblock: Ending block
251+
:type endblock: int
252+
:param page: Page number
253+
:type page: int
254+
:param offset: Max records to return
255+
:type offset: int
256+
:param sort: Sort results, defaults to "asc"
257+
:type sort: str, optional
258+
:return: The url to get
259+
:rtype: str
260+
"""
171261
url = (
172262
f"{fields.MODULE}"
173263
f"{modules.ACCOUNT}"
@@ -188,19 +278,28 @@ def get_internal_txs_by_block_range_paginated(
188278

189279
@staticmethod
190280
def get_erc20_token_transfer_events_by_address(
191-
wallet: WalletAddress,
192-
startblock: int = 0,
193-
endblock: int = 999999999,
194-
sort: str = "asc",
281+
address: str, startblock: int = 0, endblock: int = 999999999, sort: str = "asc",
195282
) -> str:
196-
# last 10,000 txs only
283+
"""Returns the last 10k ERC20 token transfer events for an address.
284+
285+
:param address: Wallet address
286+
:type address: str
287+
:param startblock: Starting block, defaults to 0
288+
:type startblock: int, optional
289+
:param endblock: Ending block, defaults to 999999999
290+
:type endblock: int, optional
291+
:param sort: Sort results, defaults to "asc"
292+
:type sort: str, optional
293+
:return: The url to get
294+
:rtype: str
295+
"""
197296
url = (
198297
f"{fields.MODULE}"
199298
f"{modules.ACCOUNT}"
200299
f"{fields.ACTION}"
201300
f"{actions.TOKENTX}"
202301
f"{fields.ADDRESS}"
203-
f"{wallet}"
302+
f"{address}"
204303
f"{fields.START_BLOCK}"
205304
f"{str(startblock)}"
206305
f"{fields.END_BLOCK}"
@@ -212,19 +311,28 @@ def get_erc20_token_transfer_events_by_address(
212311

213312
@staticmethod
214313
def get_erc721_token_transfer_events_by_address(
215-
wallet: WalletAddress,
216-
startblock: int = 0,
217-
endblock: int = 999999999,
218-
sort: str = "asc",
314+
address: str, startblock: int = 0, endblock: int = 999999999, sort: str = "asc",
219315
) -> str:
220-
# last 10,000 txs only
316+
"""Returns the last 10k ERC721 token transfer events for an address.
317+
318+
:param address: Wallet address
319+
:type address: str
320+
:param startblock: Starting block, defaults to 0
321+
:type startblock: int, optional
322+
:param endblock: Ending block, defaults to 999999999
323+
:type endblock: int, optional
324+
:param sort: Sort results, defaults to "asc"
325+
:type sort: str, optional
326+
:return: The url to get
327+
:rtype: str
328+
"""
221329
url = (
222330
f"{fields.MODULE}"
223331
f"{modules.ACCOUNT}"
224332
f"{fields.ACTION}"
225333
f"{actions.TOKENNFTTX}"
226334
f"{fields.ADDRESS}"
227-
f"{wallet}"
335+
f"{address}"
228336
f"{fields.START_BLOCK}"
229337
f"{str(startblock)}"
230338
f"{fields.END_BLOCK}"
@@ -235,14 +343,21 @@ def get_erc721_token_transfer_events_by_address(
235343
return url
236344

237345
@staticmethod
238-
def get_mined_blocks_by_address(wallet: WalletAddress) -> str:
346+
def get_mined_blocks_by_address(address: str) -> str:
347+
"""Returns list of blocks mined by an address.
348+
349+
:param address: Wallet address
350+
:type address: str
351+
:return: The url to get
352+
:rtype: str
353+
"""
239354
url = (
240355
f"{fields.MODULE}"
241356
f"{modules.ACCOUNT}"
242357
f"{fields.ACTION}"
243358
f"{actions.GET_MINED_BLOCKS}"
244359
f"{fields.ADDRESS}"
245-
f"{wallet}"
360+
f"{address}"
246361
f"{fields.BLOCK_TYPE}"
247362
f"blocks"
248363
)

0 commit comments

Comments
 (0)