Expose stuckTransfer endpoint only if v1 bridge
This commit is contained in:
parent
baf65b7001
commit
369b90a6d5
@ -1,6 +1,7 @@
|
|||||||
require('dotenv').config()
|
require('dotenv').config()
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
|
const { isV1Bridge } = require('./utils/serverUtils')
|
||||||
|
|
||||||
const app = express()
|
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) => {
|
app.get('/', async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const results = await readFile('./responses/getBalances.json')
|
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) => {
|
initV1routes(app)
|
||||||
try {
|
|
||||||
const results = await readFile('./responses/stuckTransfers.json')
|
|
||||||
results.ok = results.total.length === 0
|
|
||||||
res.json(results)
|
|
||||||
} catch (e) {
|
|
||||||
next(e)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const port = process.env.PORT || 3003
|
const port = process.env.PORT || 3003
|
||||||
app.set('port', port)
|
app.set('port', port)
|
||||||
|
17
monitor/utils/serverUtils.js
Normal file
17
monitor/utils/serverUtils.js
Normal file
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user