forked from CALEOS/launch-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParseSnapshot.js
116 lines (97 loc) · 2.57 KB
/
ParseSnapshot.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
'use strict'
const ArgumentParser = require('argparse').ArgumentParser;
const Parser = require('./Parser.js');
var argParser = new ArgumentParser({
version: '1.0.0',
addHelp: true,
description: 'Telos snapshot injection and validation'
});
argParser.addArgument(
'http-endpoint',
{
help: 'HTTP Endpoint of the node'
}
);
argParser.addArgument(
'snapshot-input',
{
help: 'The path to the snapshot file to use'
}
);
argParser.addArgument(
'--inject',
{
defaultValue: "false",
choices: ["true", "false"],
help: 'Inject a snapshot, if true then --private-key must also be provided'
}
);
argParser.addArgument(
'--private-key',
{
help: 'Private key to use for signing account injection transactions'
}
);
argParser.addArgument(
'--validate',
{
defaultValue: "false",
choices: ["true", "false"],
help: 'Validate a snapshot'
}
)
argParser.addArgument(
'--validate-stake',
{
defaultValue: "false",
choices: ["true", "false"],
help: 'Validate the CPU/NET staking amounts'
}
);
argParser.addArgument(
'--write-csv',
{
help: 'WIP: Write a CSV with original snapshot broken into cpu/bw/liquid, if true then --snapshot-output must also be provided'
}
);
argParser.addArgument(
'--snapshot-output',
{
help: 'If --write-csv is passed, this will be the file to write to'
}
);
argParser.addArgument(
'--debug-accounts',
{
defaultValue: '[]',
help: 'For debugging, a JSON array of accounts to debug thru the process'
}
);
argParser.addArgument(
'--debug',
{
defaultValue: 'false',
help: 'Enable verbose debugging'
}
);
let args = argParser.parseArgs();
if (!args["http-endpoint"])
throw new Error("Must provide an http endpoint for the node");
if (!args["snapshot-input"])
throw new Error("Must provide a snapshot file to do injection");
if (args.inject == "true" && !args.private_key)
throw new Error("Must provide a private key to do injection");
let debugAccounts = JSON.parse(args.debug_accounts);
let opts = {
httpEndpoint: args["http-endpoint"],
snapshotInput: args["snapshot-input"],
inject: args.inject === "true",
privateKey: args.private_key,
validate: args.validate === "true",
validateStake: args.validate_stake === "true",
writeCsv: args.write_csv === "true",
snapshotOutput: args.snapshot_output,
debugAccounts: debugAccounts,
debug: args.debug === "true"
};
(new Parser(opts).parse());