|
| 1 | +from functools import reduce |
| 2 | +from typing import List |
| 3 | + |
| 4 | +from etherscan.utils.datatypes import TxHash, WalletAddress |
| 5 | +from etherscan.enums.actions_enum import ActionsEnum as actions |
| 6 | +from etherscan.enums.fields_enum import FieldsEnum as fields |
| 7 | +from etherscan.enums.modules_enum import ModulesEnum as modules |
| 8 | +from etherscan.enums.tags_enum import TagsEnum as tags |
| 9 | + |
| 10 | + |
| 11 | +class Accounts: |
| 12 | + @staticmethod |
| 13 | + def get_eth_balance(wallet: WalletAddress) -> str: |
| 14 | + url = ( |
| 15 | + f"{fields.MODULE}" |
| 16 | + f"{modules.ACCOUNT}" |
| 17 | + f"{fields.ACTION}" |
| 18 | + f"{actions.BALANCE}" |
| 19 | + f"{fields.ADDRESS}" |
| 20 | + f"{wallet}" |
| 21 | + f"{fields.TAG}" |
| 22 | + f"{tags.LATEST}" |
| 23 | + ) |
| 24 | + return url |
| 25 | + # r = requests.get(url) |
| 26 | + # return conversions.to_ticker_unit(parser.get_result(r)) |
| 27 | + |
| 28 | + @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) |
| 32 | + url = ( |
| 33 | + f"{fields.MODULE}" |
| 34 | + f"{modules.ACCOUNT}" |
| 35 | + f"{fields.ACTION}" |
| 36 | + f"{actions.BALANCE_MULTI}" |
| 37 | + f"{fields.ADDRESS}" |
| 38 | + f"{wallet_list}" |
| 39 | + f"{fields.TAG}" |
| 40 | + f"{tags.LATEST}" |
| 41 | + ) |
| 42 | + return url |
| 43 | + # r = requests.get(url) |
| 44 | + # return [conversions.to_ticker_unit(r["balance"]) for r in parser.get_result(r)] |
| 45 | + |
| 46 | + @staticmethod |
| 47 | + def get_hist_eth_balance_by_block(wallet: WalletAddress, block: int) -> str: |
| 48 | + # throttled to 2 calls/sec |
| 49 | + # BUG: returns 'Error! Missing Or invalid Action name' |
| 50 | + url = ( |
| 51 | + f"{fields.MODULE}" |
| 52 | + f"{modules.ACCOUNT}" |
| 53 | + f"{fields.ACTION}" |
| 54 | + f"{actions.BALANCE_HISTORY}" |
| 55 | + f"{fields.ADDRESS}" |
| 56 | + f"{wallet}" |
| 57 | + f"{fields.BLOCKNO}" |
| 58 | + f"{str(block)}" |
| 59 | + ) |
| 60 | + return url |
| 61 | + |
| 62 | + @staticmethod |
| 63 | + def get_normal_txs_by_address( |
| 64 | + wallet: WalletAddress, |
| 65 | + startblock: int = 0000, |
| 66 | + endblock: int = 99999999, |
| 67 | + sort: str = "asc", |
| 68 | + ) -> str: |
| 69 | + # last 10,000 txs only |
| 70 | + url = ( |
| 71 | + f"{fields.MODULE}" |
| 72 | + f"{modules.ACCOUNT}" |
| 73 | + f"{fields.ACTION}" |
| 74 | + f"{actions.TXLIST}" |
| 75 | + f"{fields.ADDRESS}" |
| 76 | + f"{wallet}" |
| 77 | + f"{fields.START_BLOCK}" |
| 78 | + f"{str(startblock)}" |
| 79 | + f"{fields.END_BLOCK}" |
| 80 | + f"{str(endblock)}" |
| 81 | + f"{fields.SORT}" |
| 82 | + f"{sort}" |
| 83 | + ) |
| 84 | + return url |
| 85 | + |
| 86 | + @staticmethod |
| 87 | + def get_normal_txs_by_address_paginated( |
| 88 | + wallet: WalletAddress, |
| 89 | + page: int, |
| 90 | + offset: int, |
| 91 | + startblock: int = 0000, |
| 92 | + endblock: int = 99999999, |
| 93 | + sort: str = "asc", |
| 94 | + ) -> str: |
| 95 | + url = ( |
| 96 | + f"{fields.MODULE}" |
| 97 | + f"{modules.ACCOUNT}" |
| 98 | + f"{fields.ACTION}" |
| 99 | + f"{actions.TXLIST}" |
| 100 | + f"{fields.ADDRESS}" |
| 101 | + f"{wallet}" |
| 102 | + f"{fields.START_BLOCK}" |
| 103 | + f"{str(startblock)}" |
| 104 | + f"{fields.END_BLOCK}" |
| 105 | + f"{str(endblock)}" |
| 106 | + f"{fields.SORT}" |
| 107 | + f"{sort}" |
| 108 | + f"{fields.PAGE}" |
| 109 | + f"{str(page)}" |
| 110 | + f"{fields.OFFSET}" |
| 111 | + f"{str(offset)}" |
| 112 | + ) |
| 113 | + return url |
| 114 | + |
| 115 | + @staticmethod |
| 116 | + def get_internal_txs_by_address( |
| 117 | + wallet: WalletAddress, |
| 118 | + startblock: int = 0000, |
| 119 | + endblock: int = 99999999, |
| 120 | + sort: str = "asc", |
| 121 | + ) -> str: |
| 122 | + # last 10,000 txs only |
| 123 | + url = ( |
| 124 | + f"{fields.MODULE}" |
| 125 | + f"{modules.ACCOUNT}" |
| 126 | + f"{fields.ACTION}" |
| 127 | + f"{actions.TXLIST_INTERNAL}" |
| 128 | + f"{fields.ADDRESS}" |
| 129 | + f"{wallet}" |
| 130 | + f"{fields.START_BLOCK}" |
| 131 | + f"{str(startblock)}" |
| 132 | + f"{fields.END_BLOCK}" |
| 133 | + f"{str(endblock)}" |
| 134 | + f"{fields.SORT}" |
| 135 | + f"{sort}" |
| 136 | + ) |
| 137 | + return url |
| 138 | + |
| 139 | + @staticmethod |
| 140 | + def get_internal_txs_by_address_paginated( |
| 141 | + wallet: WalletAddress, |
| 142 | + page: int, |
| 143 | + offset: int, |
| 144 | + startblock: int = 0000, |
| 145 | + endblock: int = 99999999, |
| 146 | + sort: str = "asc", |
| 147 | + ) -> str: |
| 148 | + url = ( |
| 149 | + f"{fields.MODULE}" |
| 150 | + f"{modules.ACCOUNT}" |
| 151 | + f"{fields.ACTION}" |
| 152 | + f"{actions.TXLIST_INTERNAL}" |
| 153 | + f"{fields.ADDRESS}" |
| 154 | + f"{wallet}" |
| 155 | + f"{fields.START_BLOCK}" |
| 156 | + f"{str(startblock)}" |
| 157 | + f"{fields.END_BLOCK}" |
| 158 | + f"{str(endblock)}" |
| 159 | + f"{fields.SORT}" |
| 160 | + f"{sort}" |
| 161 | + f"{fields.PAGE}" |
| 162 | + f"{str(page)}" |
| 163 | + f"{fields.OFFSET}" |
| 164 | + f"{str(offset)}" |
| 165 | + ) |
| 166 | + return url |
| 167 | + |
| 168 | + @staticmethod |
| 169 | + def get_internal_txs_by_txhash(txhash: TxHash) -> str: |
| 170 | + # last 10,000 txs only |
| 171 | + url = ( |
| 172 | + f"{fields.MODULE}" |
| 173 | + f"{modules.ACCOUNT}" |
| 174 | + f"{fields.ACTION}" |
| 175 | + f"{actions.TXLIST_INTERNAL}" |
| 176 | + f"{fields.TXHASH}" |
| 177 | + f"{txhash}" |
| 178 | + ) |
| 179 | + return url |
| 180 | + |
| 181 | + @staticmethod |
| 182 | + def get_internal_txs_by_block_range_paginated( |
| 183 | + startblock: int, endblock: int, page: int, offset: int, sort: str = "asc", |
| 184 | + ) -> str: |
| 185 | + # last 10,000 txs only |
| 186 | + # BUG: returns empty message |
| 187 | + url = ( |
| 188 | + f"{fields.MODULE}" |
| 189 | + f"{modules.ACCOUNT}" |
| 190 | + f"{fields.ACTION}" |
| 191 | + f"{actions.TXLIST_INTERNAL}" |
| 192 | + f"{fields.START_BLOCK}" |
| 193 | + f"{str(startblock)}" |
| 194 | + f"{fields.END_BLOCK}" |
| 195 | + f"{str(endblock)}" |
| 196 | + f"{fields.SORT}" |
| 197 | + f"{sort}" |
| 198 | + f"{fields.PAGE}" |
| 199 | + f"{str(page)}" |
| 200 | + f"{fields.OFFSET}" |
| 201 | + f"{str(offset)}" |
| 202 | + ) |
| 203 | + return url |
| 204 | + |
| 205 | + @staticmethod |
| 206 | + def get_erc20_token_transfer_events_by_address( |
| 207 | + wallet: WalletAddress, |
| 208 | + startblock: int = 0, |
| 209 | + endblock: int = 999999999, |
| 210 | + sort: str = "asc", |
| 211 | + ) -> str: |
| 212 | + # last 10,000 txs only |
| 213 | + url = ( |
| 214 | + f"{fields.MODULE}" |
| 215 | + f"{modules.ACCOUNT}" |
| 216 | + f"{fields.ACTION}" |
| 217 | + f"{actions.TOKENTX}" |
| 218 | + f"{fields.ADDRESS}" |
| 219 | + f"{wallet}" |
| 220 | + f"{fields.START_BLOCK}" |
| 221 | + f"{str(startblock)}" |
| 222 | + f"{fields.END_BLOCK}" |
| 223 | + f"{str(endblock)}" |
| 224 | + f"{fields.SORT}" |
| 225 | + f"{sort}" |
| 226 | + ) |
| 227 | + return url |
| 228 | + |
| 229 | + @staticmethod |
| 230 | + def get_erc721_token_transfer_events_by_address( |
| 231 | + wallet: WalletAddress, |
| 232 | + startblock: int = 0, |
| 233 | + endblock: int = 999999999, |
| 234 | + sort: str = "asc", |
| 235 | + ) -> str: |
| 236 | + # last 10,000 txs only |
| 237 | + url = ( |
| 238 | + f"{fields.MODULE}" |
| 239 | + f"{modules.ACCOUNT}" |
| 240 | + f"{fields.ACTION}" |
| 241 | + f"{actions.TOKENNFTTX}" |
| 242 | + f"{fields.ADDRESS}" |
| 243 | + f"{wallet}" |
| 244 | + f"{fields.START_BLOCK}" |
| 245 | + f"{str(startblock)}" |
| 246 | + f"{fields.END_BLOCK}" |
| 247 | + f"{str(endblock)}" |
| 248 | + f"{fields.SORT}" |
| 249 | + f"{sort}" |
| 250 | + ) |
| 251 | + return url |
| 252 | + |
| 253 | + @staticmethod |
| 254 | + def get_mined_blocks_by_address(wallet: WalletAddress) -> str: |
| 255 | + url = ( |
| 256 | + f"{fields.MODULE}" |
| 257 | + f"{modules.ACCOUNT}" |
| 258 | + f"{fields.ACTION}" |
| 259 | + f"{actions.GET_MINED_BLOCKS}" |
| 260 | + f"{fields.ADDRESS}" |
| 261 | + f"{wallet}" |
| 262 | + f"{fields.BLOCK_TYPE}" |
| 263 | + f"blocks" |
| 264 | + ) |
| 265 | + return url |
0 commit comments