-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.ts
48 lines (42 loc) · 1.51 KB
/
main.ts
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
import fs = require("fs");
import { logDebug } from "./logs";
import { ProtocolSimulator } from "./protocol_simulator";
import { RingsInfo } from "./types";
async function main() {
const args = process.argv.slice(2);
console.log("args:", args );
if (args.length < 2) {
throw new Error("error: not enough params.");
}
const fileName = args[1];
const fileContent = fs.readFileSync(fileName, "utf8");
if (args[0] === "--decode-param") {
try {
const paramInfo: any = JSON.parse(fileContent);
console.log(paramInfo);
const protocolSimulator = new ProtocolSimulator(undefined);
const ringsInfo = protocolSimulator.deserialize(paramInfo.bs, paramInfo.txOrigin);
console.log("deserialized ringsInfo: ", ringsInfo);
} catch (err) {
console.log(err);
}
} else if (args[0] === "--encode-rings") {
let ringsInfo: RingsInfo;
ringsInfo = JSON.parse(fileContent);
console.log("ringsInfo:", ringsInfo);
throw new Error("Not implemented yet.");
// const report = await protocolSimulator.simulateAndReport(ringsInfo);
} else if (args[0] === "--decode-simulate") {
try {
const paramInfo: any = JSON.parse(fileContent);
const protocolSimulator = new ProtocolSimulator(undefined);
const ringsInfo = protocolSimulator.deserialize(paramInfo.bs, paramInfo.txOrigin);
console.log("deserialized ringsInfo: ", ringsInfo);
} catch (err) {
console.log(err);
}
} else {
throw new Error("error: invalid argument:" + args);
}
}
main();