diff --git a/monitor/index.js b/monitor/index.js index 98dede16..d92dbfc1 100644 --- a/monitor/index.js +++ b/monitor/index.js @@ -1,6 +1,7 @@ require('dotenv').config() const express = require('express') const fs = require('fs') +const { isV1Bridge } = require('./utils/serverUtils') const app = express() @@ -21,6 +22,21 @@ async function readFile(path) { } } +async function initV1routes(app) { + const exposeV1Routes = await isV1Bridge() + if (exposeV1Routes) { + app.get('/stuckTransfers', async (req, res, next) => { + try { + const results = await readFile('./responses/stuckTransfers.json') + results.ok = results.total.length === 0 + res.json(results) + } catch (e) { + next(e) + } + }) + } +} + app.get('/', async (req, res, next) => { try { const results = await readFile('./responses/getBalances.json') @@ -83,15 +99,7 @@ app.get('/alerts', async (req, res, next) => { } }) -app.get('/stuckTransfers', async (req, res, next) => { - try { - const results = await readFile('./responses/stuckTransfers.json') - results.ok = results.total.length === 0 - res.json(results) - } catch (e) { - next(e) - } -}) +initV1routes(app) const port = process.env.PORT || 3003 app.set('port', port) diff --git a/monitor/utils/serverUtils.js b/monitor/utils/serverUtils.js new file mode 100644 index 00000000..33854e2d --- /dev/null +++ b/monitor/utils/serverUtils.js @@ -0,0 +1,17 @@ +const Web3 = require('web3') +const { getBridgeMode, BRIDGE_MODES } = require('./bridgeMode') +const HOME_ERC_TO_ERC_ABI = require('../../contracts/build/contracts/HomeBridgeErcToErc').abi + +const { HOME_BRIDGE_ADDRESS, HOME_RPC_URL } = process.env +const homeProvider = new Web3.providers.HttpProvider(HOME_RPC_URL) +const web3Home = new Web3(homeProvider) + +async function isV1Bridge() { + const homeBridge = new web3Home.eth.Contract(HOME_ERC_TO_ERC_ABI, HOME_BRIDGE_ADDRESS) + const bridgeMode = await getBridgeMode(homeBridge) + return bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC_V1 +} + +module.exports = { + isV1Bridge +}