2020-09-28 04:28:34 +02:00
|
|
|
const express = require('express')
|
2020-09-30 17:35:48 +02:00
|
|
|
const status = require('./status')
|
|
|
|
const controller = require('./controller')
|
2020-10-06 13:20:26 +02:00
|
|
|
const { port, rewardAccount } = require('./config')
|
2020-09-28 04:28:34 +02:00
|
|
|
const { version } = require('../package.json')
|
2020-10-06 13:20:26 +02:00
|
|
|
const { isAddress } = require('web3-utils')
|
2020-09-28 04:28:34 +02:00
|
|
|
|
|
|
|
const app = express()
|
|
|
|
app.use(express.json())
|
|
|
|
|
2020-12-18 21:53:35 +01:00
|
|
|
// Add CORS headers
|
|
|
|
app.use((req, res, next) => {
|
|
|
|
res.header('Access-Control-Allow-Origin', '*')
|
|
|
|
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')
|
|
|
|
next()
|
|
|
|
})
|
|
|
|
|
2020-09-28 04:28:34 +02:00
|
|
|
// Log error to console but don't send it to the client to avoid leaking data
|
|
|
|
app.use((err, req, res, next) => {
|
|
|
|
if (err) {
|
|
|
|
console.error(err)
|
|
|
|
return res.sendStatus(500)
|
|
|
|
}
|
|
|
|
next()
|
|
|
|
})
|
|
|
|
|
|
|
|
app.get('/', status.index)
|
|
|
|
app.get('/v1/status', status.status)
|
2020-10-01 15:08:33 +02:00
|
|
|
app.get('/v1/jobs/:id', status.getJob)
|
2020-09-28 04:28:34 +02:00
|
|
|
app.post('/v1/tornadoWithdraw', controller.tornadoWithdraw)
|
2020-09-30 17:35:48 +02:00
|
|
|
app.get('/status', status.status)
|
|
|
|
app.post('/relay', controller.tornadoWithdraw)
|
2020-10-01 08:30:50 +02:00
|
|
|
app.post('/v1/miningReward', controller.miningReward)
|
|
|
|
app.post('/v1/miningWithdraw', controller.miningWithdraw)
|
2020-09-28 04:28:34 +02:00
|
|
|
|
2020-10-06 13:20:26 +02:00
|
|
|
if (!isAddress(rewardAccount)) {
|
|
|
|
throw new Error('No REWARD_ACCOUNT specified')
|
|
|
|
}
|
|
|
|
|
2020-10-01 06:01:02 +02:00
|
|
|
app.listen(port)
|
|
|
|
console.log(`Relayer ${version} started on port ${port}`)
|