• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

GoodDollar / GoodServer / 6979629480

24 Nov 2023 10:28AM UTC coverage: 48.446% (-0.06%) from 48.501%
6979629480

push

github

sirpy
fix: alt explorer for celo

519 of 1295 branches covered (0.0%)

Branch coverage included in aggregate %.

0 of 5 new or added lines in 1 file covered. (0.0%)

1 existing line in 1 file now uncovered.

1617 of 3114 relevant lines covered (51.93%)

8.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

4.76
/src/server/blockchain/explorer.js
1
import axios from 'axios'
2
import { isArray } from 'lodash'
3
import { retry as retryAttempt, fallback } from '../utils/async'
1!
4
import { default as getNetworks } from '../networks'
×
5

×
6
const NETWORKS = getNetworks()
×
7
export const getExplorerTxs = async (address, chainId, query, from = null, allPages = true) => {
8
  const txs = []
×
9
  const url = ''
UNCOV
10

×
11
  const networkExplorerUrls = NETWORKS[Number(chainId)].explorer
×
12

×
13
  const params = { module: 'account', address, sort: 'asc', page: 1, ...query }
14

15
  if (from) {
×
NEW
16
    params.start_block = from
×
17
    params.startblock = from //etherscan
18
  }
NEW
19

×
NEW
20
  for (;;) {
×
NEW
21
    const calls = networkExplorerUrls.split(',').map(networkExplorerUrl => {
×
22
      const options = { baseURL: networkExplorerUrl, params }
23
      return () =>
NEW
24
        axios.get(url, options).then(result => {
×
25
          if (isArray(result.data.result)) {
26
            return result
×
27
          }
×
28
          throw new Error(`NOTOK ${result.data.result}`)
×
29
        })
30
    })
×
31

32
    const {
×
33
      data: { result = [] }
34
    } = await retryAttempt(() => fallback(calls), 3, 1500)
35

36
    const chunk = result.filter(({ value }) => value !== '0')
×
37
    params.page += 1
38
    txs.push(...chunk)
39

1✔
40
    if (allPages === false || result.length < params.offset) {
×
41
      // default page size by explorer.fuse.io
42
      break
43
    }
44
  }
45

46
  return txs
47
}
×
48

×
49
export const findFaucetAbuse = async (address, chainId) => {
×
50
  const lastTxs = await getExplorerTxs(
51
    address,
×
52
    chainId,
53
    //blockscout has a bug with offset that causes timeout, temporarily remove 19/2/2025
54
    // { action: 'txlist', sort: 'desc', offset: 200 },
55
    { action: 'txlist', sort: 'desc' },
56
    undefined,
×
57
    false
58
  )
59
  const daysAgo = 3
60
  // const maxFaucetValue = 0.0075
61
  const foundAbuse = lastTxs.find(
62
    _ =>
63
      _.from.toLowerCase() === address.toLowerCase() &&
64
      Number(_.value) / 1e18 > 0 &&
65
      Date.now() / 1000 - Number(_.timeStamp) <= 60 * 60 * 24 * daysAgo
66
  )
67

68
  return foundAbuse
69
}
70

71
export const findGDTx = async (address, chainId, gdAddress) => {
72
  const lastTxs = await getExplorerTxs(
73
    address,
74
    chainId,
75
    { action: 'tokentx', sort: 'desc', offset: 10, contractaddress: gdAddress },
76
    undefined,
77
    false
78
  )
79
  const daysAgo = 3
80
  const foundTx = lastTxs.find(_ => Date.now() / 1000 - Number(_.timeStamp) <= 60 * 60 * 24 * daysAgo)
81

82
  return foundTx
83
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc