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

GoodDollar / GoodServer / 13131260700

04 Feb 2025 08:27AM UTC coverage: 49.717% (+0.05%) from 49.666%
13131260700

push

github

sirpy
add: allow explorers with apikey from env

589 of 1463 branches covered (40.26%)

Branch coverage included in aggregate %.

3 of 4 new or added lines in 2 files covered. (75.0%)

1 existing line in 1 file now uncovered.

1869 of 3481 relevant lines covered (53.69%)

8.46 hits per line

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

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

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

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

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

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

20
  for (;;) {
×
21
    const calls = networkExplorerUrls.split(',').map(networkExplorerUrl => {
×
22
      const options = { baseURL: networkExplorerUrl, params }
×
23
      return () =>
×
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

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) => {
3✔
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
}
3✔
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

© 2026 Coveralls, Inc