-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
68 lines (65 loc) · 1.91 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
const uWS = require('uWebSockets.js');
const server = uWS.App();
const path = require('path');
const fs = require('fs');
const config = require('./config.json');
const { BroadcastChannel, Worker } = require('node:worker_threads');
const centralChannel = new BroadcastChannel('centralChannel');
const vdf = require('./weselowski-vdf-native.js/lib/index.js');
const start = async function (server, opts) {
let carrier = { options: opts, config };
const loadRoutes = (app, dirPath, carrier) => {
const files = fs.readdirSync(dirPath);
files.forEach((file) => {
const fullPath = path.join(dirPath, file);
if (fs.statSync(fullPath).isDirectory()) {
loadRoutes(app, fullPath, carrier);
} else if (path.extname(file) === '.js') {
const route = require(fullPath);
route(app, carrier);
}
});
};
loadRoutes(server, path.join(__dirname, 'plugins'), carrier);
loadRoutes(server, path.join(__dirname, 'routes'), carrier);
new Worker(path.join(__dirname, 'daemons', 'sequencer-tx-fetcher.js'));
new Worker(path.join(__dirname, 'daemons', 'execution-core.js'));
centralChannel.onmessage = async (interaction) => {
if (interaction.data.type == 'publish') {
server.publish(interaction.data.topic, Buffer.from(interaction.data.data), true);
}
};
server.listen(config.port, function (listenSocket) {
if (listenSocket) {
console.log('Highlayerd node listening on port ' + config.port);
}
});
};
start(server, {
dbPath: path.join(config.dataDir, 'node-state'),
archiveDBPath: path.join(config.archiveDataDir, 'slow-node-state'),
databases: [
{
name: 'transactions',
dbName: 'transactions',
archive: true,
},
{
name: 'balances',
dbName: 'balances',
},
{
name: 'dataBlobs',
dbName: 'data-blobs',
},
{
name: 'sequencerSigToNumber',
dbName: 'sequencer-sig-to-number',
},
{ name: 'contracts', dbName: 'contracts' },
{
name: 'accountKV',
dbName: 'account-kv',
},
],
});