2020-02-03 15:50:18 +03:00
|
|
|
const Web3 = require('web3')
|
2019-05-08 16:12:02 +03:00
|
|
|
const logger = require('./logger')('checkWorker3')
|
|
|
|
const stuckTransfers = require('./stuckTransfers')
|
2020-01-10 15:55:35 +03:00
|
|
|
const { writeFile, createDir } = require('./utils/file')
|
|
|
|
|
2020-02-03 15:50:18 +03:00
|
|
|
const { MONITOR_BRIDGE_NAME, COMMON_HOME_BRIDGE_ADDRESS, COMMON_HOME_RPC_URL } = process.env
|
|
|
|
const { getBridgeMode, HOME_NATIVE_TO_ERC_ABI, BRIDGE_MODES } = require('../commons')
|
|
|
|
|
|
|
|
const homeProvider = new Web3.providers.HttpProvider(COMMON_HOME_RPC_URL)
|
|
|
|
const web3Home = new Web3(homeProvider)
|
2019-05-08 16:12:02 +03:00
|
|
|
|
|
|
|
async function checkWorker3() {
|
|
|
|
try {
|
2020-02-03 15:50:18 +03:00
|
|
|
const homeBridge = new web3Home.eth.Contract(HOME_NATIVE_TO_ERC_ABI, COMMON_HOME_BRIDGE_ADDRESS)
|
|
|
|
const bridgeMode = await getBridgeMode(homeBridge)
|
|
|
|
if (bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC_V1) {
|
|
|
|
createDir(`/responses/${MONITOR_BRIDGE_NAME}`)
|
|
|
|
logger.debug('calling stuckTransfers()')
|
|
|
|
const transfers = await stuckTransfers()
|
|
|
|
if (!transfers) throw new Error('transfers is empty: ' + JSON.stringify(transfers))
|
|
|
|
transfers.ok = transfers.total.length === 0
|
|
|
|
writeFile(`/responses/${MONITOR_BRIDGE_NAME}/stuckTransfers.json`, transfers)
|
|
|
|
logger.debug('Done')
|
|
|
|
}
|
2019-05-08 16:12:02 +03:00
|
|
|
} catch (e) {
|
|
|
|
logger.error('checkWorker3.js', e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
checkWorker3()
|