-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
84 lines (70 loc) · 2.66 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const express = require('express')
var bodyParser = require('body-parser')
const app = express()
const port = 3000
// EXAMPLE REQUIRE CUSTOM MODULES
// =============================================================================
var calculator = require('./app_modules/calculator');
var monitor = require('./app_modules/monitor');
app.use(express.static('public'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// ROUTES FOR OUR API
// =============================================================================
var router = express.Router(); // get an instance of the express Router
// middleware to use for all requests
router.use(function(req, res, next) {
// do logging
console.log('-------------------------------------------------------');
console.log(' Monitor');
console.log('-------------------------------------------------------');
next(); // make sure we go to the next routes and don't stop here
});
// update_provider route
router.post('/update_provider', function(req, res) {
console.log('# Request received to update provider')
var provider = req.body.provider;
console.log('Provider URL:');
console.log(provider);
var msg = monitor.update_provider(provider);
res.json({ message: msg});
});
// start_monitor route
router.get('/start_monitor', function (req, res) {
console.log('# Request received to start monitor')
var msg = monitor.start_monitor();
res.json({ message: msg});
});
// stop_monitor route
router.get('/stop_monitor', function (req, res) {
console.log('# Request received to stop monitor')
var msg = monitor.stop_monitor();
res.json({ message: msg});
});
// update_params route
router.get('/update_params/:transactionSender/:routerAddress/:token0/:token1/:pair', function(req, res) {
console.log('# Request received to update params');
var transactionSender = req.params.transactionSender;
var routerAddress = req.params.routerAddress;
var token0 = req.params.token0;
var token1 = req.params.token1;
var pair = req.params.pair;
// TODO - add the other params
var msg = monitor.update_params(
transactionSender, routerAddress, token0, token1, pair
);
res.json({ message: msg});
});
// get_update route
router.get('/get_update', function (req, res) {
console.log('# Request received to get update')
var transactions = monitor.get_update()
res.json({ transactions });
})
// REGISTER OUR ROUTES -------------------------------
// all of our routes will be prefixed with /api
app.use('/monitor', router);
app.listen(port, () => {
console.log(`<---------------------Mempool Monitor app running----------------------->`)
monitor.start();
})