-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
153 lines (128 loc) · 4.11 KB
/
server.js
File metadata and controls
153 lines (128 loc) · 4.11 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const express = require('express');
const sqlite3 = require('sqlite3');
const { open } = require('sqlite');
const cors = require('cors');
const app = express();
const PORT = 5001;
app.use(cors());
app.get('/api/events', async (req, res) => {
const { chain } = req.query;
const pair = req.query.pair.toLowerCase();
try {
const db = await open({
filename: 'monitor-node.db',
driver: sqlite3.Database
});
const getEventsQuery = `SELECT * FROM screener_events
WHERE chainId = ? AND pairAddress = ?
ORDER BY block, txIndex, logIndex`;
const results = await db.all(getEventsQuery, [chain, pair]);
res.json(results);
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Failed to fetch data from the database' });
}
});
app.get('/api/pairs', async (req, res) => {
try {
const db = await open({
filename: 'monitor-node.db',
driver: sqlite3.Database
});
const getPairsQuery = `SELECT sp.*, COUNT(se.txId) AS eventCount
FROM screener_pairs sp
LEFT JOIN screener_events se ON sp.pairAddress = se.pairAddress AND sp.chainId = se.chainId
GROUP BY sp.pairAddress;
ORDER BY deployBlock DESC`;
const results = await db.all(getPairsQuery);
res.json(results);
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Failed to fetch data from the database' });
}
});
app.get('/api/pair', async (req, res) => {
const { chain } = req.query;
const pair = req.query.pair.toLowerCase();
try {
const db = await open({
filename: 'monitor-node.db',
driver: sqlite3.Database
});
const getPairQuery = `SELECT * FROM screener_pairs
WHERE chainId = ? AND pairAddress = ?
ORDER BY deployBlock DESC`;
const results = await db.get(getPairQuery, [chain, pair]);
res.json(results);
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Failed to fetch data from the database' });
}
});
app.get('/api/watched-pairs', async (req, res) => {
try {
const db = await open({
filename: 'monitor-node.db',
driver: sqlite3.Database
});
const getWatchedPairsQuery = `SELECT wp.*, COUNT(se.txId) AS eventCount
FROM watched_pairs wp
LEFT JOIN screener_events se ON wp.pairAddress = se.pairAddress AND wp.chainId = se.chainId
GROUP BY wp.pairAddress
ORDER BY deployBlock DESC`;
const results = await db.all(getWatchedPairsQuery);
res.json(results);
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Failed to fetch data from the database' });
}
});
app.get('/api/contracts', async (req, res) => {
try {
const db = await open({
filename: 'monitor-node.db',
driver: sqlite3.Database
});
const getContractTagsQuery = 'SELECT * FROM contracts';
const results = await db.all(getContractTagsQuery);
const contractsDictionary = results.reduce((dictionary, contract) => {
dictionary[contract.address] = contract.name;
return dictionary;
}, {});
res.json(contractsDictionary);
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Failed to fetch data from the database' });
}
});
app.get('/api/wallets', async (req, res) => {
try {
const db = await open({
filename: 'monitor-node.db',
driver: sqlite3.Database
});
const getWalletTagsQuery = 'SELECT * FROM wallets';
const results = await db.all(getWalletTagsQuery);
res.json(results);
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Failed to fetch data from the database' });
}
});
app.get('/api/wallets-for-review', async (req, res) => {
try {
const db = await open({
filename: 'monitor-node.db',
driver: sqlite3.Database
});
const getWalletsForReviewQuery = 'SELECT * FROM wallets_for_review';
const results = await db.all(getWalletsForReviewQuery);
res.json(results);
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Failed to fetch data from the database' });
}
});
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});