|
1 | 1 | import IArbitrator from '@kleros/erc-792/build/contracts/IArbitrator.json';
|
2 | 2 | import Linguo from '@kleros/linguo-contracts/artifacts/contracts/0.7.x/Linguo.sol/Linguo.json';
|
3 |
| -import { subtract } from '~/adapters/big-number'; |
4 | 3 | import { combination } from '~/adapters/js-combinatorics';
|
5 | 4 | import { withProvider } from '~/app/archon';
|
6 | 5 | import {
|
|
9 | 8 | compose,
|
10 | 9 | filter,
|
11 | 10 | flatten,
|
12 |
| - indexBy, |
13 | 11 | map,
|
14 | 12 | mapValues,
|
15 | 13 | omit,
|
@@ -134,7 +132,7 @@ export default async function createApiFacade({ web3, chainId }) {
|
134 | 132 |
|
135 | 133 | const addresses = uniq([
|
136 | 134 | ...hintedAddresses,
|
137 |
| - ...(await getContractAddressesForRequester({ web3, chainId, account, apiInstancesByAddress })), |
| 135 | + ...(await getContractAddressesForRequester({ account, apiInstancesByAddress })), |
138 | 136 | ]);
|
139 | 137 |
|
140 | 138 | const instances = Object.values(pick(addresses, apiInstancesByAddress));
|
@@ -296,63 +294,10 @@ export function getContractInstancesForTranslator({ skills, addressesByLanguageG
|
296 | 294 | return compose(Object.values, pick(addresses))(apiInstancesByAddress);
|
297 | 295 | }
|
298 | 296 |
|
299 |
| -/** |
300 |
| - * Considers 1 block each 13.25 seconds on average. |
301 |
| - */ |
302 |
| -const BLOCK_INTERVAL_SIZE = Math.round(60 * 24 * 60 * 60 * 4.53); |
303 |
| - |
304 |
| -const chainIdToMakeExplorerUrl = { |
305 |
| - 1: ({ account, startBlock, endBlock, apiKey }) => |
306 |
| - `https://api.etherscan.io/api?module=account&action=txlist&address=${account}&startblock=${startBlock}&endblock=${endBlock}&sort=desc&apikey=${apiKey}`, |
307 |
| - 42: ({ account, startBlock, endBlock, apiKey }) => |
308 |
| - `https://api-kovan.etherscan.io/api?module=account&action=txlist&address=${account}&startblock=${startBlock}&endblock=${endBlock}&sort=desc&apikey=${apiKey}`, |
309 |
| - 77: ({ account, startBlock, endBlock }) => |
310 |
| - `https://blockscout.com/poa/sokol/api?module=account&action=txlist&address=${account}&startblock=${startBlock}&endblock=${endBlock}&sort=desc`, |
311 |
| - 100: ({ account, startBlock, endBlock }) => |
312 |
| - `https://blockscout.com/xdai/mainnet/api?module=account&action=txlist&address=${account}&startblock=${startBlock}&endblock=${endBlock}&sort=desc`, |
313 |
| -}; |
314 |
| - |
315 |
| -async function getContractAddressesForRequester({ chainId, account, web3, apiInstancesByAddress }) { |
| 297 | +async function getContractAddressesForRequester({ account, apiInstancesByAddress }) { |
316 | 298 | if (!account) {
|
317 | 299 | return [];
|
318 | 300 | }
|
319 | 301 |
|
320 |
| - const endBlock = await web3.eth.getBlockNumber(); |
321 |
| - const startBlock = subtract(endBlock, BLOCK_INTERVAL_SIZE); |
322 |
| - |
323 |
| - const url = chainIdToMakeExplorerUrl[chainId]({ |
324 |
| - account, |
325 |
| - startBlock, |
326 |
| - endBlock, |
327 |
| - apiKey: process.env.ETHERSCAN_API_KEY, |
328 |
| - }); |
329 |
| - |
330 |
| - let response; |
331 |
| - try { |
332 |
| - response = await fetch(url, { mode: 'cors' }); |
333 |
| - |
334 |
| - if (![200, 304].includes(response.status)) { |
335 |
| - console.warn(`Failed to fetch Linguo contracts account ${account} interacted with.`); |
336 |
| - return Object.keys(apiInstancesByAddress); |
337 |
| - } |
338 |
| - } catch (err) { |
339 |
| - console.warn(`Failed to fetch Linguo contracts account ${account} interacted with:`, err); |
340 |
| - return Object.keys(apiInstancesByAddress); |
341 |
| - } |
342 |
| - |
343 |
| - const { result } = await response.json(); |
344 |
| - |
345 |
| - /** |
346 |
| - * Etherscan API returns addresses converted all to lowercase. |
347 |
| - * To actually be able to compare them, we need to convert everything to lowercase |
348 |
| - * and then back when returning. |
349 |
| - */ |
350 |
| - const addressesLowercaseKey = indexBy(addr => String(addr).toLowerCase(), Object.keys(apiInstancesByAddress)); |
351 |
| - |
352 |
| - return compose( |
353 |
| - map(lowercaseAddr => addressesLowercaseKey[lowercaseAddr]), |
354 |
| - uniq, |
355 |
| - map(prop('to')), |
356 |
| - filter(compose(to => prop(to, addressesLowercaseKey), prop('to'))) |
357 |
| - )(result); |
| 302 | + return Object.keys(apiInstancesByAddress); |
358 | 303 | }
|
0 commit comments