Expose stuckTransfer endpoint only if v1 bridge

This commit is contained in:
Gerardo Nardelli 2019-06-03 09:47:12 -03:00
parent baf65b7001
commit 369b90a6d5
2 changed files with 34 additions and 9 deletions

@ -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)

@ -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
}