-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
96 lines (89 loc) · 2.91 KB
/
index.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
85
86
87
88
89
90
91
92
93
94
95
96
const { main } = require('./src/strategy');
const { profileBlockArrivals, profileMempool } = require('./src/profiler');
// Check if flag build is set
const args = process.argv.slice(2);
const buildFlag = args[0];
if (buildFlag == '-build' || buildFlag == '-b') {
console.log('Building zip file...');
// Create a new zip file containing the following content:
// - abi/*
// - data/*.json (ignore .log files)
// - src/*
// index.js
// .env
// package.json
// package-lock.json
// Create a new zip file
const fs = require('fs');
const archiver = require('archiver');
const output = fs.createWriteStream('build.zip');
const archive = archiver('zip', {
// Set max compression level
zlib: { level: 9 },
});
output.on('close', () => {
console.log(
`Build complete. Build size: ${archive.pointer()} total bytes`
);
});
archive.on('error', (err) => {
console.log('Error building zip file. Error: ', err);
throw err;
});
archive.pipe(output);
// Add simple files to the zip
archive.file('index.js');
archive.file('.env');
archive.file('package.json');
archive.file('package-lock.json');
archive.directory('abi', 'abi');
archive.directory('src', 'src');
// Add data files to the zip
const dataFiles = fs.readdirSync('data');
for (const dataFile of dataFiles) {
if (dataFile.endsWith('.json')) {
archive.file(`data/${dataFile}`, { name: `data/${dataFile}` });
}
}
archive.finalize();
return;
} else if (buildFlag == '-profileblocks' || buildFlag == '-pb') {
let probeDuration = args[1];
if (!probeDuration) {
console.log('Please specify a duration in minutes.');
return;
}
console.log(`Profiling block arrivals for ${probeDuration} minutes...`);
// Profile block arrivals
profileBlockArrivals(probeDuration * 60 * 1000);
} else if (buildFlag == '-mempool') {
const wssURL = args[1];
const numBlocks = args[2];
profileMempool(wssURL, numBlocks);
} else if (!buildFlag) {
// Run the bot. First, check if the .env file exists
const dotenv = require('dotenv');
const fs = require('fs');
if (!fs.existsSync('.env')) {
console.log('No .env file found. Please create one.');
return;
}
// Check wether all the modules are installed
// const { exec } = require('child_process');
// exec('npm install', (err, stdout, stderr) => {
// if (err) {
// console.log("Error installing modules. Error: ", err);
// return;
// }
// console.log("Modules installed. Starting bot...");
// });
(async () => {
// Start the bot by running the "main" function of strategy.js
await main();
})();
} else {
console.log(
'Invalid flag. Valid flags are: -build, -b, -profileblocks, -pb'
);
return;
}