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
/
read-config.js
58 lines (47 loc) · 1.4 KB
/
read-config.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
/**
* Use KomodoRPC to start KMDICE chain and read its config
* How to run:
*
* $ npm run devtest -- examples/read-config.js
*/
import KomodoRPC from "../src";
import { kmdice, getBinPath } from "./config";
const debug = require("debug")("kmdrpc:test:read-config");
(async () => {
const application = "Agama";
const { coin, args } = kmdice;
try {
// Step 1: create application
const api = KomodoRPC(application, {
bin: getBinPath()
});
// Step 2: start the chain
const komodod = await api.startDaemon(coin);
const cpResult = await komodod.start({
args
});
debug(`cpResult = ${JSON.stringify(cpResult)}`);
// add event via childProcess
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
const waitUntilReady = await komodod.waitUntilReady();
debug(`waitUntilReady = ${JSON.stringify(waitUntilReady)}`);
const config = await komodod.getConfig();
debug(`config = ${JSON.stringify(config)}`);
// Step 4: stop daemon
if (komodod.isRunning() === true) {
const rs = await api.stopDaemon(coin);
debug(`rs.ok === done = ${rs.ok === "done"}`);
}
} catch (err) {
debug(err.message);
setTimeout(() => {
process.exit(1);
}, 2000);
}
})();