1
1
from functools import reduce
2
2
from typing import List
3
3
4
- from etherscan .utils .datatypes import TxHash , WalletAddress
5
4
from etherscan .enums .actions_enum import ActionsEnum as actions
6
5
from etherscan .enums .fields_enum import FieldsEnum as fields
7
6
from etherscan .enums .modules_enum import ModulesEnum as modules
10
9
11
10
class Accounts :
12
11
@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
+ """
14
20
url = (
15
21
f"{ fields .MODULE } "
16
22
f"{ modules .ACCOUNT } "
17
23
f"{ fields .ACTION } "
18
24
f"{ actions .BALANCE } "
19
25
f"{ fields .ADDRESS } "
20
- f"{ wallet } "
26
+ f"{ address } "
21
27
f"{ fields .TAG } "
22
28
f"{ tags .LATEST } "
23
29
)
@@ -26,16 +32,22 @@ def get_eth_balance(wallet: WalletAddress) -> str:
26
32
# return conversions.to_ticker_unit(parser.get_result(r))
27
33
28
34
@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 )
32
44
url = (
33
45
f"{ fields .MODULE } "
34
46
f"{ modules .ACCOUNT } "
35
47
f"{ fields .ACTION } "
36
48
f"{ actions .BALANCE_MULTI } "
37
49
f"{ fields .ADDRESS } "
38
- f"{ wallet_list } "
50
+ f"{ address_list } "
39
51
f"{ fields .TAG } "
40
52
f"{ tags .LATEST } "
41
53
)
@@ -45,19 +57,32 @@ def get_eth_balance_multiple(wallets: List[WalletAddress]) -> str:
45
57
46
58
@staticmethod
47
59
def get_normal_txs_by_address (
48
- wallet : WalletAddress ,
60
+ address : str ,
49
61
startblock : int = 0000 ,
50
62
endblock : int = 99999999 ,
51
63
sort : str = "asc" ,
52
64
) -> 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
+ """
53
78
# last 10,000 txs only
54
79
url = (
55
80
f"{ fields .MODULE } "
56
81
f"{ modules .ACCOUNT } "
57
82
f"{ fields .ACTION } "
58
83
f"{ actions .TXLIST } "
59
84
f"{ fields .ADDRESS } "
60
- f"{ wallet } "
85
+ f"{ address } "
61
86
f"{ fields .START_BLOCK } "
62
87
f"{ str (startblock )} "
63
88
f"{ fields .END_BLOCK } "
@@ -69,20 +94,37 @@ def get_normal_txs_by_address(
69
94
70
95
@staticmethod
71
96
def get_normal_txs_by_address_paginated (
72
- wallet : WalletAddress ,
97
+ address : str ,
73
98
page : int ,
74
99
offset : int ,
75
100
startblock : int = 0000 ,
76
101
endblock : int = 99999999 ,
77
102
sort : str = "asc" ,
78
103
) -> 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
+ """
79
121
url = (
80
122
f"{ fields .MODULE } "
81
123
f"{ modules .ACCOUNT } "
82
124
f"{ fields .ACTION } "
83
125
f"{ actions .TXLIST } "
84
126
f"{ fields .ADDRESS } "
85
- f"{ wallet } "
127
+ f"{ address } "
86
128
f"{ fields .START_BLOCK } "
87
129
f"{ str (startblock )} "
88
130
f"{ fields .END_BLOCK } "
@@ -98,19 +140,31 @@ def get_normal_txs_by_address_paginated(
98
140
99
141
@staticmethod
100
142
def get_internal_txs_by_address (
101
- wallet : WalletAddress ,
143
+ address : str ,
102
144
startblock : int = 0000 ,
103
145
endblock : int = 99999999 ,
104
146
sort : str = "asc" ,
105
147
) -> 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
+ """
107
161
url = (
108
162
f"{ fields .MODULE } "
109
163
f"{ modules .ACCOUNT } "
110
164
f"{ fields .ACTION } "
111
165
f"{ actions .TXLIST_INTERNAL } "
112
166
f"{ fields .ADDRESS } "
113
- f"{ wallet } "
167
+ f"{ address } "
114
168
f"{ fields .START_BLOCK } "
115
169
f"{ str (startblock )} "
116
170
f"{ fields .END_BLOCK } "
@@ -122,20 +176,37 @@ def get_internal_txs_by_address(
122
176
123
177
@staticmethod
124
178
def get_internal_txs_by_address_paginated (
125
- wallet : WalletAddress ,
179
+ address : str ,
126
180
page : int ,
127
181
offset : int ,
128
182
startblock : int = 0000 ,
129
183
endblock : int = 99999999 ,
130
184
sort : str = "asc" ,
131
185
) -> 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
+ """
132
203
url = (
133
204
f"{ fields .MODULE } "
134
205
f"{ modules .ACCOUNT } "
135
206
f"{ fields .ACTION } "
136
207
f"{ actions .TXLIST_INTERNAL } "
137
208
f"{ fields .ADDRESS } "
138
- f"{ wallet } "
209
+ f"{ address } "
139
210
f"{ fields .START_BLOCK } "
140
211
f"{ str (startblock )} "
141
212
f"{ fields .END_BLOCK } "
@@ -150,8 +221,14 @@ def get_internal_txs_by_address_paginated(
150
221
return url
151
222
152
223
@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
+ """
155
232
url = (
156
233
f"{ fields .MODULE } "
157
234
f"{ modules .ACCOUNT } "
@@ -166,8 +243,21 @@ def get_internal_txs_by_txhash(txhash: TxHash) -> str:
166
243
def get_internal_txs_by_block_range_paginated (
167
244
startblock : int , endblock : int , page : int , offset : int , sort : str = "asc" ,
168
245
) -> 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
+ """
171
261
url = (
172
262
f"{ fields .MODULE } "
173
263
f"{ modules .ACCOUNT } "
@@ -188,19 +278,28 @@ def get_internal_txs_by_block_range_paginated(
188
278
189
279
@staticmethod
190
280
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" ,
195
282
) -> 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
+ """
197
296
url = (
198
297
f"{ fields .MODULE } "
199
298
f"{ modules .ACCOUNT } "
200
299
f"{ fields .ACTION } "
201
300
f"{ actions .TOKENTX } "
202
301
f"{ fields .ADDRESS } "
203
- f"{ wallet } "
302
+ f"{ address } "
204
303
f"{ fields .START_BLOCK } "
205
304
f"{ str (startblock )} "
206
305
f"{ fields .END_BLOCK } "
@@ -212,19 +311,28 @@ def get_erc20_token_transfer_events_by_address(
212
311
213
312
@staticmethod
214
313
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" ,
219
315
) -> 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
+ """
221
329
url = (
222
330
f"{ fields .MODULE } "
223
331
f"{ modules .ACCOUNT } "
224
332
f"{ fields .ACTION } "
225
333
f"{ actions .TOKENNFTTX } "
226
334
f"{ fields .ADDRESS } "
227
- f"{ wallet } "
335
+ f"{ address } "
228
336
f"{ fields .START_BLOCK } "
229
337
f"{ str (startblock )} "
230
338
f"{ fields .END_BLOCK } "
@@ -235,14 +343,21 @@ def get_erc721_token_transfer_events_by_address(
235
343
return url
236
344
237
345
@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
+ """
239
354
url = (
240
355
f"{ fields .MODULE } "
241
356
f"{ modules .ACCOUNT } "
242
357
f"{ fields .ACTION } "
243
358
f"{ actions .GET_MINED_BLOCKS } "
244
359
f"{ fields .ADDRESS } "
245
- f"{ wallet } "
360
+ f"{ address } "
246
361
f"{ fields .BLOCK_TYPE } "
247
362
f"blocks"
248
363
)
0 commit comments