|
| 1 | +from functools import reduce |
| 2 | +from typing import List |
| 3 | + |
| 4 | +from etherscan.enums.actions_enum import ActionsEnum as actions |
| 5 | +from etherscan.enums.fields_enum import FieldsEnum as fields |
| 6 | +from etherscan.enums.modules_enum import ModulesEnum as modules |
| 7 | +from etherscan.enums.tags_enum import TagsEnum as tags |
| 8 | + |
| 9 | + |
| 10 | +class Accounts: |
| 11 | + @staticmethod |
| 12 | + def get_eth_balance(address: str) -> str: |
| 13 | + url = ( |
| 14 | + f"{fields.MODULE}" |
| 15 | + f"{modules.ACCOUNT}" |
| 16 | + f"{fields.ACTION}" |
| 17 | + f"{actions.BALANCE}" |
| 18 | + f"{fields.ADDRESS}" |
| 19 | + f"{address}" |
| 20 | + f"{fields.TAG}" |
| 21 | + f"{tags.LATEST}" |
| 22 | + ) |
| 23 | + return url |
| 24 | + # r = requests.get(url) |
| 25 | + # return conversions.to_ticker_unit(parser.get_result(r)) |
| 26 | + |
| 27 | + @staticmethod |
| 28 | + def get_eth_balance_multiple(addresses: List[str]) -> str: |
| 29 | + # NOTE: Max 20 wallets at a time |
| 30 | + address_list = reduce(lambda w1, w2: str(w1) + "," + str(w2), addresses) |
| 31 | + url = ( |
| 32 | + f"{fields.MODULE}" |
| 33 | + f"{modules.ACCOUNT}" |
| 34 | + f"{fields.ACTION}" |
| 35 | + f"{actions.BALANCE_MULTI}" |
| 36 | + f"{fields.ADDRESS}" |
| 37 | + f"{address_list}" |
| 38 | + f"{fields.TAG}" |
| 39 | + f"{tags.LATEST}" |
| 40 | + ) |
| 41 | + return url |
| 42 | + # r = requests.get(url) |
| 43 | + # return [conversions.to_ticker_unit(r["balance"]) for r in parser.get_result(r)] |
| 44 | + |
| 45 | + @staticmethod |
| 46 | + def get_normal_txs_by_address( |
| 47 | + address: str, |
| 48 | + startblock: int, |
| 49 | + endblock: int, |
| 50 | + sort: str, |
| 51 | + ) -> str: |
| 52 | + # NOTE: Returns the last 10k events |
| 53 | + url = ( |
| 54 | + f"{fields.MODULE}" |
| 55 | + f"{modules.ACCOUNT}" |
| 56 | + f"{fields.ACTION}" |
| 57 | + f"{actions.TXLIST}" |
| 58 | + f"{fields.ADDRESS}" |
| 59 | + f"{address}" |
| 60 | + f"{fields.START_BLOCK}" |
| 61 | + f"{str(startblock)}" |
| 62 | + f"{fields.END_BLOCK}" |
| 63 | + f"{str(endblock)}" |
| 64 | + f"{fields.SORT}" |
| 65 | + f"{sort}" |
| 66 | + ) |
| 67 | + return url |
| 68 | + |
| 69 | + @staticmethod |
| 70 | + def get_normal_txs_by_address_paginated( |
| 71 | + address: str, |
| 72 | + page: int, |
| 73 | + offset: int, |
| 74 | + startblock: int, |
| 75 | + endblock: int, |
| 76 | + sort: str, |
| 77 | + ) -> str: |
| 78 | + url = ( |
| 79 | + f"{fields.MODULE}" |
| 80 | + f"{modules.ACCOUNT}" |
| 81 | + f"{fields.ACTION}" |
| 82 | + f"{actions.TXLIST}" |
| 83 | + f"{fields.ADDRESS}" |
| 84 | + f"{address}" |
| 85 | + f"{fields.START_BLOCK}" |
| 86 | + f"{str(startblock)}" |
| 87 | + f"{fields.END_BLOCK}" |
| 88 | + f"{str(endblock)}" |
| 89 | + f"{fields.SORT}" |
| 90 | + f"{sort}" |
| 91 | + f"{fields.PAGE}" |
| 92 | + f"{str(page)}" |
| 93 | + f"{fields.OFFSET}" |
| 94 | + f"{str(offset)}" |
| 95 | + ) |
| 96 | + return url |
| 97 | + |
| 98 | + @staticmethod |
| 99 | + def get_internal_txs_by_address( |
| 100 | + address: str, |
| 101 | + startblock: int, |
| 102 | + endblock: int, |
| 103 | + sort: str, |
| 104 | + ) -> str: |
| 105 | + # NOTE: Returns the last 10k events |
| 106 | + url = ( |
| 107 | + f"{fields.MODULE}" |
| 108 | + f"{modules.ACCOUNT}" |
| 109 | + f"{fields.ACTION}" |
| 110 | + f"{actions.TXLIST_INTERNAL}" |
| 111 | + f"{fields.ADDRESS}" |
| 112 | + f"{address}" |
| 113 | + f"{fields.START_BLOCK}" |
| 114 | + f"{str(startblock)}" |
| 115 | + f"{fields.END_BLOCK}" |
| 116 | + f"{str(endblock)}" |
| 117 | + f"{fields.SORT}" |
| 118 | + f"{sort}" |
| 119 | + ) |
| 120 | + return url |
| 121 | + |
| 122 | + @staticmethod |
| 123 | + def get_internal_txs_by_address_paginated( |
| 124 | + address: str, |
| 125 | + page: int, |
| 126 | + offset: int, |
| 127 | + startblock: int, |
| 128 | + endblock: int, |
| 129 | + sort: str, |
| 130 | + ) -> str: |
| 131 | + url = ( |
| 132 | + f"{fields.MODULE}" |
| 133 | + f"{modules.ACCOUNT}" |
| 134 | + f"{fields.ACTION}" |
| 135 | + f"{actions.TXLIST_INTERNAL}" |
| 136 | + f"{fields.ADDRESS}" |
| 137 | + f"{address}" |
| 138 | + f"{fields.START_BLOCK}" |
| 139 | + f"{str(startblock)}" |
| 140 | + f"{fields.END_BLOCK}" |
| 141 | + f"{str(endblock)}" |
| 142 | + f"{fields.SORT}" |
| 143 | + f"{sort}" |
| 144 | + f"{fields.PAGE}" |
| 145 | + f"{str(page)}" |
| 146 | + f"{fields.OFFSET}" |
| 147 | + f"{str(offset)}" |
| 148 | + ) |
| 149 | + return url |
| 150 | + |
| 151 | + @staticmethod |
| 152 | + def get_internal_txs_by_txhash(txhash: str) -> str: |
| 153 | + # NOTE: Returns the last 10k events |
| 154 | + url = ( |
| 155 | + f"{fields.MODULE}" |
| 156 | + f"{modules.ACCOUNT}" |
| 157 | + f"{fields.ACTION}" |
| 158 | + f"{actions.TXLIST_INTERNAL}" |
| 159 | + f"{fields.TXHASH}" |
| 160 | + f"{txhash}" |
| 161 | + ) |
| 162 | + return url |
| 163 | + |
| 164 | + @staticmethod |
| 165 | + def get_internal_txs_by_block_range_paginated( |
| 166 | + startblock: int, |
| 167 | + endblock: int, |
| 168 | + page: int, |
| 169 | + offset: int, |
| 170 | + sort: str, |
| 171 | + ) -> str: |
| 172 | + # NOTE: Returns the last 10k events |
| 173 | + url = ( |
| 174 | + f"{fields.MODULE}" |
| 175 | + f"{modules.ACCOUNT}" |
| 176 | + f"{fields.ACTION}" |
| 177 | + f"{actions.TXLIST_INTERNAL}" |
| 178 | + f"{fields.START_BLOCK}" |
| 179 | + f"{str(startblock)}" |
| 180 | + f"{fields.END_BLOCK}" |
| 181 | + f"{str(endblock)}" |
| 182 | + f"{fields.SORT}" |
| 183 | + f"{sort}" |
| 184 | + f"{fields.PAGE}" |
| 185 | + f"{str(page)}" |
| 186 | + f"{fields.OFFSET}" |
| 187 | + f"{str(offset)}" |
| 188 | + ) |
| 189 | + return url |
| 190 | + |
| 191 | + @staticmethod |
| 192 | + def get_erc20_token_transfer_events_by_address( |
| 193 | + address: str, |
| 194 | + startblock: int, |
| 195 | + endblock: int, |
| 196 | + sort: str, |
| 197 | + ) -> str: |
| 198 | + # NOTE: Returns the last 10k events |
| 199 | + url = ( |
| 200 | + f"{fields.MODULE}" |
| 201 | + f"{modules.ACCOUNT}" |
| 202 | + f"{fields.ACTION}" |
| 203 | + f"{actions.TOKENTX}" |
| 204 | + f"{fields.ADDRESS}" |
| 205 | + f"{address}" |
| 206 | + f"{fields.START_BLOCK}" |
| 207 | + f"{str(startblock)}" |
| 208 | + f"{fields.END_BLOCK}" |
| 209 | + f"{str(endblock)}" |
| 210 | + f"{fields.SORT}" |
| 211 | + f"{sort}" |
| 212 | + ) |
| 213 | + return url |
| 214 | + |
| 215 | + @staticmethod |
| 216 | + def get_erc20_token_transfer_events_by_contract_address_paginated( |
| 217 | + contract_address: str, page: int, offset: int, sort: str |
| 218 | + ) -> str: |
| 219 | + |
| 220 | + url = ( |
| 221 | + f"{fields.MODULE}" |
| 222 | + f"{modules.ACCOUNT}" |
| 223 | + f"{fields.ACTION}" |
| 224 | + f"{actions.TOKENTX}" |
| 225 | + f"{fields.CONTRACT_ADDRESS}" |
| 226 | + f"{contract_address}" |
| 227 | + f"{fields.SORT}" |
| 228 | + f"{sort}" |
| 229 | + f"{fields.PAGE}" |
| 230 | + f"{str(page)}" |
| 231 | + f"{fields.OFFSET}" |
| 232 | + f"{str(offset)}" |
| 233 | + ) |
| 234 | + return url |
| 235 | + |
| 236 | + @staticmethod |
| 237 | + def get_erc20_token_transfer_events_by_address_and_contract_paginated( |
| 238 | + contract_address: str, address: str, page: int, offset: int, sort: str |
| 239 | + ) -> str: |
| 240 | + |
| 241 | + url = ( |
| 242 | + f"{fields.MODULE}" |
| 243 | + f"{modules.ACCOUNT}" |
| 244 | + f"{fields.ACTION}" |
| 245 | + f"{actions.TOKENTX}" |
| 246 | + f"{fields.CONTRACT_ADDRESS}" |
| 247 | + f"{contract_address}" |
| 248 | + f"{fields.ADDRESS}" |
| 249 | + f"{address}" |
| 250 | + f"{fields.SORT}" |
| 251 | + f"{sort}" |
| 252 | + f"{fields.PAGE}" |
| 253 | + f"{str(page)}" |
| 254 | + f"{fields.OFFSET}" |
| 255 | + f"{str(offset)}" |
| 256 | + ) |
| 257 | + return url |
| 258 | + |
| 259 | + @staticmethod |
| 260 | + def get_erc721_token_transfer_events_by_address( |
| 261 | + address: str, |
| 262 | + startblock: int, |
| 263 | + endblock: int, |
| 264 | + sort: str, |
| 265 | + ) -> str: |
| 266 | + url = ( |
| 267 | + f"{fields.MODULE}" |
| 268 | + f"{modules.ACCOUNT}" |
| 269 | + f"{fields.ACTION}" |
| 270 | + f"{actions.TOKENNFTTX}" |
| 271 | + f"{fields.ADDRESS}" |
| 272 | + f"{address}" |
| 273 | + f"{fields.START_BLOCK}" |
| 274 | + f"{str(startblock)}" |
| 275 | + f"{fields.END_BLOCK}" |
| 276 | + f"{str(endblock)}" |
| 277 | + f"{fields.SORT}" |
| 278 | + f"{sort}" |
| 279 | + ) |
| 280 | + return url |
| 281 | + |
| 282 | + @staticmethod |
| 283 | + def get_erc721_token_transfer_events_by_contract_address_paginated( |
| 284 | + contract_address: str, page: int, offset: int, sort: str |
| 285 | + ) -> str: |
| 286 | + url = ( |
| 287 | + f"{fields.MODULE}" |
| 288 | + f"{modules.ACCOUNT}" |
| 289 | + f"{fields.ACTION}" |
| 290 | + f"{actions.TOKENNFTTX}" |
| 291 | + f"{fields.CONTRACT_ADDRESS}" |
| 292 | + f"{contract_address}" |
| 293 | + f"{fields.SORT}" |
| 294 | + f"{sort}" |
| 295 | + f"{fields.PAGE}" |
| 296 | + f"{str(page)}" |
| 297 | + f"{fields.OFFSET}" |
| 298 | + f"{str(offset)}" |
| 299 | + ) |
| 300 | + return url |
| 301 | + |
| 302 | + @staticmethod |
| 303 | + def get_erc721_token_transfer_events_by_address_and_contract_paginated( |
| 304 | + contract_address: str, address: str, page: int, offset: int, sort: str |
| 305 | + ) -> str: |
| 306 | + url = ( |
| 307 | + f"{fields.MODULE}" |
| 308 | + f"{modules.ACCOUNT}" |
| 309 | + f"{fields.ACTION}" |
| 310 | + f"{actions.TOKENNFTTX}" |
| 311 | + f"{fields.CONTRACT_ADDRESS}" |
| 312 | + f"{contract_address}" |
| 313 | + f"{fields.ADDRESS}" |
| 314 | + f"{address}" |
| 315 | + f"{fields.SORT}" |
| 316 | + f"{sort}" |
| 317 | + f"{fields.PAGE}" |
| 318 | + f"{str(page)}" |
| 319 | + f"{fields.OFFSET}" |
| 320 | + f"{str(offset)}" |
| 321 | + ) |
| 322 | + return url |
| 323 | + |
| 324 | + @staticmethod |
| 325 | + def get_mined_blocks_by_address(address: str) -> str: |
| 326 | + url = ( |
| 327 | + f"{fields.MODULE}" |
| 328 | + f"{modules.ACCOUNT}" |
| 329 | + f"{fields.ACTION}" |
| 330 | + f"{actions.GET_MINED_BLOCKS}" |
| 331 | + f"{fields.ADDRESS}" |
| 332 | + f"{address}" |
| 333 | + f"{fields.BLOCK_TYPE}" |
| 334 | + f"blocks" |
| 335 | + ) |
| 336 | + return url |
| 337 | + |
| 338 | + @staticmethod |
| 339 | + def get_mined_blocks_by_address_paginated( |
| 340 | + address: str, page: int, offset: int |
| 341 | + ) -> str: |
| 342 | + url = ( |
| 343 | + f"{fields.MODULE}" |
| 344 | + f"{modules.ACCOUNT}" |
| 345 | + f"{fields.ACTION}" |
| 346 | + f"{actions.GET_MINED_BLOCKS}" |
| 347 | + f"{fields.ADDRESS}" |
| 348 | + f"{address}" |
| 349 | + f"{fields.BLOCK_TYPE}" |
| 350 | + f"blocks" |
| 351 | + f"{fields.PAGE}" |
| 352 | + f"{str(page)}" |
| 353 | + f"{fields.OFFSET}" |
| 354 | + f"{str(offset)}" |
| 355 | + ) |
| 356 | + return url |
0 commit comments