2022-03-23 16:35:41 +01:00
|
|
|
const { setSafeInterval, toBN, fromWei } = require('./utils')
|
|
|
|
const { privateKey, minimumBalance } = require('./config')
|
|
|
|
const { redis } = require('./modules/redis')
|
|
|
|
const web3 = require('./modules/web3')()
|
2021-02-09 16:53:28 +01:00
|
|
|
|
|
|
|
async function main() {
|
|
|
|
try {
|
|
|
|
const { address } = web3.eth.accounts.privateKeyToAccount(privateKey)
|
|
|
|
const balance = await web3.eth.getBalance(address)
|
|
|
|
|
2022-03-23 16:35:41 +01:00
|
|
|
const errors = await redis.zrevrange('errors', 0, -1)
|
|
|
|
if (errors.length > 3) {
|
|
|
|
console.log({ errors })
|
|
|
|
throw new Error('Too many errors on relayer')
|
|
|
|
}
|
2021-02-09 16:53:28 +01:00
|
|
|
if (toBN(balance).lt(toBN(minimumBalance))) {
|
2021-02-15 12:07:15 +01:00
|
|
|
throw new Error(`Not enough balance, less than ${fromWei(minimumBalance)} ETH`)
|
2021-02-09 16:53:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
await redis.hset('health', { status: true, error: '' })
|
|
|
|
} catch (e) {
|
|
|
|
console.error('healthWatcher', e.message)
|
|
|
|
await redis.hset('health', { status: false, error: e.message })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setSafeInterval(main, 30 * 1000)
|