11from functools import reduce
22from typing import List
33
4- from etherscan .utils .datatypes import TxHash ,WalletAddress
54from etherscan .enums .actions_enum import ActionsEnum as actions
65from etherscan .enums .fields_enum import FieldsEnum as fields
76from etherscan .enums .modules_enum import ModulesEnum as modules
109
1110class 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+ """
1420url = (
1521f"{ fields .MODULE } "
1622f"{ modules .ACCOUNT } "
1723f"{ fields .ACTION } "
1824f"{ actions .BALANCE } "
1925f"{ fields .ADDRESS } "
20- f"{ wallet } "
26+ f"{ address } "
2127f"{ fields .TAG } "
2228f"{ 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 )
3244url = (
3345f"{ fields .MODULE } "
3446f"{ modules .ACCOUNT } "
3547f"{ fields .ACTION } "
3648f"{ actions .BALANCE_MULTI } "
3749f"{ fields .ADDRESS } "
38- f"{ wallet_list } "
50+ f"{ address_list } "
3951f"{ fields .TAG } "
4052f"{ tags .LATEST } "
4153 )
@@ -45,19 +57,32 @@ def get_eth_balance_multiple(wallets: List[WalletAddress]) -> str:
4557
4658@staticmethod
4759def get_normal_txs_by_address (
48- wallet : WalletAddress ,
60+ address : str ,
4961startblock :int = 0000 ,
5062endblock :int = 99999999 ,
5163sort :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
5479url = (
5580f"{ fields .MODULE } "
5681f"{ modules .ACCOUNT } "
5782f"{ fields .ACTION } "
5883f"{ actions .TXLIST } "
5984f"{ fields .ADDRESS } "
60- f"{ wallet } "
85+ f"{ address } "
6186f"{ fields .START_BLOCK } "
6287f"{ str (startblock )} "
6388f"{ fields .END_BLOCK } "
@@ -69,20 +94,37 @@ def get_normal_txs_by_address(
6994
7095@staticmethod
7196def get_normal_txs_by_address_paginated (
72- wallet : WalletAddress ,
97+ address : str ,
7398page :int ,
7499offset :int ,
75100startblock :int = 0000 ,
76101endblock :int = 99999999 ,
77102sort :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+ """
79121url = (
80122f"{ fields .MODULE } "
81123f"{ modules .ACCOUNT } "
82124f"{ fields .ACTION } "
83125f"{ actions .TXLIST } "
84126f"{ fields .ADDRESS } "
85- f"{ wallet } "
127+ f"{ address } "
86128f"{ fields .START_BLOCK } "
87129f"{ str (startblock )} "
88130f"{ fields .END_BLOCK } "
@@ -98,19 +140,31 @@ def get_normal_txs_by_address_paginated(
98140
99141@staticmethod
100142def get_internal_txs_by_address (
101- wallet : WalletAddress ,
143+ address : str ,
102144startblock :int = 0000 ,
103145endblock :int = 99999999 ,
104146sort :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+ """
107161url = (
108162f"{ fields .MODULE } "
109163f"{ modules .ACCOUNT } "
110164f"{ fields .ACTION } "
111165f"{ actions .TXLIST_INTERNAL } "
112166f"{ fields .ADDRESS } "
113- f"{ wallet } "
167+ f"{ address } "
114168f"{ fields .START_BLOCK } "
115169f"{ str (startblock )} "
116170f"{ fields .END_BLOCK } "
@@ -122,20 +176,37 @@ def get_internal_txs_by_address(
122176
123177@staticmethod
124178def get_internal_txs_by_address_paginated (
125- wallet : WalletAddress ,
179+ address : str ,
126180page :int ,
127181offset :int ,
128182startblock :int = 0000 ,
129183endblock :int = 99999999 ,
130184sort :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+ """
132203url = (
133204f"{ fields .MODULE } "
134205f"{ modules .ACCOUNT } "
135206f"{ fields .ACTION } "
136207f"{ actions .TXLIST_INTERNAL } "
137208f"{ fields .ADDRESS } "
138- f"{ wallet } "
209+ f"{ address } "
139210f"{ fields .START_BLOCK } "
140211f"{ str (startblock )} "
141212f"{ fields .END_BLOCK } "
@@ -150,8 +221,14 @@ def get_internal_txs_by_address_paginated(
150221return 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+ """
155232url = (
156233f"{ fields .MODULE } "
157234f"{ modules .ACCOUNT } "
@@ -166,8 +243,21 @@ def get_internal_txs_by_txhash(txhash: TxHash) -> str:
166243def get_internal_txs_by_block_range_paginated (
167244startblock :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+ """
171261url = (
172262f"{ fields .MODULE } "
173263f"{ modules .ACCOUNT } "
@@ -188,19 +278,28 @@ def get_internal_txs_by_block_range_paginated(
188278
189279@staticmethod
190280def 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+ """
197296url = (
198297f"{ fields .MODULE } "
199298f"{ modules .ACCOUNT } "
200299f"{ fields .ACTION } "
201300f"{ actions .TOKENTX } "
202301f"{ fields .ADDRESS } "
203- f"{ wallet } "
302+ f"{ address } "
204303f"{ fields .START_BLOCK } "
205304f"{ str (startblock )} "
206305f"{ fields .END_BLOCK } "
@@ -212,19 +311,28 @@ def get_erc20_token_transfer_events_by_address(
212311
213312@staticmethod
214313def 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+ """
221329url = (
222330f"{ fields .MODULE } "
223331f"{ modules .ACCOUNT } "
224332f"{ fields .ACTION } "
225333f"{ actions .TOKENNFTTX } "
226334f"{ fields .ADDRESS } "
227- f"{ wallet } "
335+ f"{ address } "
228336f"{ fields .START_BLOCK } "
229337f"{ str (startblock )} "
230338f"{ fields .END_BLOCK } "
@@ -235,14 +343,21 @@ def get_erc721_token_transfer_events_by_address(
235343return 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+ """
239354url = (
240355f"{ fields .MODULE } "
241356f"{ modules .ACCOUNT } "
242357f"{ fields .ACTION } "
243358f"{ actions .GET_MINED_BLOCKS } "
244359f"{ fields .ADDRESS } "
245- f"{ wallet } "
360+ f"{ address } "
246361f"{ fields .BLOCK_TYPE } "
247362f"blocks"
248363 )