2020-06-10 16:22:01 +03:00
|
|
|
require('dotenv').config()
|
2019-05-08 16:12:02 +03:00
|
|
|
const logger = require('./logger')('checkWorker3')
|
2020-12-20 01:19:49 +03:00
|
|
|
const detectMediators = require('./detectMediators')
|
2021-02-19 04:26:07 +03:00
|
|
|
const detectFailures = require('./detectFailures')
|
2020-01-10 15:55:35 +03:00
|
|
|
const { writeFile, createDir } = require('./utils/file')
|
2020-10-29 11:25:43 +03:00
|
|
|
const { web3Home } = require('./utils/web3')
|
2020-12-20 01:19:49 +03:00
|
|
|
const { saveCache } = require('./utils/web3Cache')
|
2020-01-10 15:55:35 +03:00
|
|
|
|
2020-10-29 11:25:43 +03:00
|
|
|
const { MONITOR_BRIDGE_NAME, COMMON_HOME_BRIDGE_ADDRESS } = process.env
|
2021-05-08 18:50:46 +03:00
|
|
|
const { getBridgeMode, HOME_ERC_TO_NATIVE_ABI, BRIDGE_MODES } = require('../commons')
|
2020-02-03 15:50:18 +03:00
|
|
|
|
2019-05-08 16:12:02 +03:00
|
|
|
async function checkWorker3() {
|
|
|
|
try {
|
2021-05-08 18:50:46 +03:00
|
|
|
const homeBridge = new web3Home.eth.Contract(HOME_ERC_TO_NATIVE_ABI, COMMON_HOME_BRIDGE_ADDRESS)
|
2020-02-03 15:50:18 +03:00
|
|
|
const bridgeMode = await getBridgeMode(homeBridge)
|
2021-05-08 18:50:46 +03:00
|
|
|
if (bridgeMode === BRIDGE_MODES.ARBITRARY_MESSAGE) {
|
2020-12-20 01:19:49 +03:00
|
|
|
createDir(`/responses/${MONITOR_BRIDGE_NAME}`)
|
2021-02-19 04:26:07 +03:00
|
|
|
|
2020-12-20 01:19:49 +03:00
|
|
|
logger.debug('calling detectMediators()')
|
|
|
|
const mediators = await detectMediators(bridgeMode)
|
|
|
|
mediators.ok = true
|
|
|
|
mediators.health = true
|
|
|
|
writeFile(`/responses/${MONITOR_BRIDGE_NAME}/mediators.json`, mediators)
|
2021-02-19 04:26:07 +03:00
|
|
|
|
|
|
|
logger.debug('calling detectFailures()')
|
|
|
|
const failures = await detectFailures(bridgeMode)
|
|
|
|
failures.ok = true
|
|
|
|
failures.health = true
|
|
|
|
writeFile(`/responses/${MONITOR_BRIDGE_NAME}/failures.json`, failures)
|
|
|
|
|
2020-12-20 01:19:49 +03:00
|
|
|
saveCache()
|
|
|
|
logger.debug('Done')
|
2020-02-03 15:50:18 +03:00
|
|
|
}
|
2019-05-08 16:12:02 +03:00
|
|
|
} catch (e) {
|
|
|
|
logger.error('checkWorker3.js', e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
checkWorker3()
|