2019-11-23 03:18:54 -05:00
|
|
|
const express = require('express')
|
2019-12-02 07:49:24 -05:00
|
|
|
const { netId, port, relayerServiceFee } = require('../config')
|
2019-11-23 03:18:54 -05:00
|
|
|
const relayController = require('./relayController')
|
|
|
|
const { fetcher, web3 } = require('./instances')
|
2019-12-02 07:49:24 -05:00
|
|
|
const { getMixers } = require('./utils')
|
|
|
|
const mixers = getMixers()
|
2019-11-23 03:18:54 -05:00
|
|
|
|
|
|
|
const app = express()
|
|
|
|
app.use(express.json())
|
|
|
|
|
|
|
|
app.use((err, req, res, next) => {
|
|
|
|
if (err) {
|
|
|
|
console.log('Invalid Request data')
|
|
|
|
res.send('Invalid Request data')
|
|
|
|
} else {
|
|
|
|
next()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
app.use(function(req, res, next) {
|
|
|
|
res.header('Access-Control-Allow-Origin', '*')
|
|
|
|
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')
|
|
|
|
next()
|
|
|
|
})
|
|
|
|
|
|
|
|
app.get('/', function (req, res) {
|
|
|
|
// just for testing purposes
|
|
|
|
res.send('This is <a href=https://tornado.cash>tornado.cash</a> Relayer service. Check the /status for settings')
|
|
|
|
})
|
|
|
|
|
|
|
|
app.get('/status', function (req, res) {
|
|
|
|
const { ethPrices, gasPrices } = fetcher
|
2019-11-26 10:01:37 -05:00
|
|
|
res.json({ relayerAddress: web3.eth.defaultAccount, mixers, gasPrices, netId, ethPrices, relayerServiceFee })
|
2019-11-23 03:18:54 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
app.post('/relay', relayController)
|
|
|
|
|
|
|
|
app.listen(port || 8000)
|
2019-11-25 04:50:15 -05:00
|
|
|
console.log('Gas price oracle started.')
|
|
|
|
fetcher.fetchGasPrice()
|
|
|
|
fetcher.fetchPrices()
|
2019-11-23 03:18:54 -05:00
|
|
|
|
|
|
|
console.log('Relayer started on port', port || 8000)
|
|
|
|
console.log(`relayerAddress: ${web3.eth.defaultAccount}`)
|
|
|
|
console.log(`mixers: ${JSON.stringify(mixers)}`)
|
|
|
|
console.log(`gasPrices: ${JSON.stringify(fetcher.gasPrices)}`)
|
|
|
|
console.log(`netId: ${netId}`)
|
2019-11-26 10:01:37 -05:00
|
|
|
console.log(`ethPrices: ${JSON.stringify(fetcher.ethPrices)}`)
|
2019-11-26 15:34:52 -05:00
|
|
|
console.log(`Service fee: ${relayerServiceFee}%`)
|