-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_timestamp_in_genesis.js
50 lines (28 loc) · 1.33 KB
/
update_timestamp_in_genesis.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
import path from 'path';
import {fileURLToPath} from 'url';
import fs from 'fs';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const netRunnerConfigsPath = path.join(__dirname, 'netrunner_configs.json');
const netRunnerConfigs = JSON.parse(fs.readFileSync(netRunnerConfigsPath, 'utf8'));
const baseDir = path.join(__dirname,`X${netRunnerConfigs.testnetDir}`);
const timestampToSet = new Date().getTime();
const updateGenesisTimestamp = () => {
for (let i = 1; i <= 21; i++) {
const versionDir = path.join(baseDir, `V${i}`);
const genesisFilePath = path.join(versionDir, 'GENESIS', 'genesis.json');
const chainDataDir = path.join(versionDir, 'CHAINDATA');
if (fs.existsSync(genesisFilePath)) {
const genesisData = JSON.parse(fs.readFileSync(genesisFilePath, 'utf8'));
genesisData.FIRST_EPOCH_START_TIMESTAMP = timestampToSet;
fs.writeFileSync(genesisFilePath, JSON.stringify(genesisData, null, 2));
console.log(`Updated timestamp in ${genesisFilePath}`);
}
if (fs.existsSync(chainDataDir)) {
fs.rmSync(chainDataDir, { recursive: true, force: true });
console.log(`Deleted CHAINDATA directory in ${versionDir}`);
}
}
console.log('Timestamps updated and CHAINDATA directories deleted');
};
updateGenesisTimestamp();