This repository has been archived by the owner on Oct 1, 2021. It is now read-only.
forked from pbca26/komodo-rpc-lib
-
Notifications
You must be signed in to change notification settings - Fork 3
/
start-chain-with-log.js
74 lines (61 loc) · 1.75 KB
/
start-chain-with-log.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
/**
* Use KomodoRPC to start KMDICE chain and read its log
* How to run:
*
* $ npm run devtest -- examples/start-chain-with-log.js
*/
import d from "debug";
import KomodoRPC from "../src";
import { kmdice, getBinPath } from "./config";
const logs = "kmdrpc:test";
const debug = d(`${logs}:start-chain-with-log`);
d.enable(`${logs}:*`);
function wait(delay) {
return new Promise(resovle => {
setTimeout(resovle, delay);
});
}
(async () => {
const application = "Agama";
const { coin, args } = kmdice;
try {
// Step 1: create application
const api = KomodoRPC(application, {
bin: getBinPath()
});
// Step 2: start the chain
debug(`start ${coin} chain`);
const komodod = await api.startDaemon(coin);
const cpResult = await komodod.start({
logs: true,
args
});
debug(`cpResult = ${JSON.stringify(cpResult)}`);
komodod.on("exit", (code, signal) => {
debug(`child process terminated due to receipt of signal ${signal}`);
setTimeout(() => {
process.exit(0);
}, 2000);
});
// Step 3: wait until ready
debug(`waiting until ${coin} ready`);
const waitUntilReady = await komodod.waitUntilReady();
debug(`waitUntilReady = ${JSON.stringify(waitUntilReady)}`);
debug(`waiting in 30s`);
await wait(30 * 1000);
const getLog = await komodod.getLog();
debug(`getLog = ${getLog}`);
const getErrorLog = await komodod.getErrorLog();
debug(`getErrorLog = ${getErrorLog}`);
// Step 4: stop daemon
if (komodod.isRunning() === true) {
const rs = await komodod.stop();
debug(`rs.ok === done = ${rs.ok === "done"}`);
}
} catch (err) {
debug(err.message);
setTimeout(() => {
process.exit(1);
}, 2000);
}
})();