This repository has been archived by the owner on Jun 23, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nutberry-node.js
executable file
·113 lines (103 loc) · 2.45 KB
/
nutberry-node.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
#!/usr/bin/env node
'use strict';
const { Server } = require('./js/index.js');
const OPTIONS = [
{
env: 'BRIDGE_ADDRESS',
key: 'contract',
type: String,
required: true,
help: 'The contract address of the Bridge on the root-chain.',
},
{
env: 'PRIV_KEY',
key: 'privKey',
type: String,
default: '',
help: 'The private key for a root-chain account. That account should have some ether to be useful. ' +
'Required to participate in the network.',
},
{
env: 'PORT',
key: 'rpcPort',
type: Number,
required: true,
help: 'The port to listen on for the JSON-RPC interface.',
},
{
env: 'HOST',
key: 'host',
type: String,
default: 'localhost',
help: 'The address to listen on for the JSON-RPC interface.',
},
{
env: 'ROOT_RPC_URL',
key: 'rootRpcUrl',
type: String,
required: true,
help: 'The URL for the root-chain JSON-RPC provider.',
},
{
env: 'EVENT_CHECK_MS',
key: 'eventCheckMs',
type: Number,
default: 15000,
help: 'Time in milliseconds to check for Bridge event updates.',
},
{
env: 'DEBUG_MODE',
key: 'debugMode',
type: Number,
default: 0,
help: 'Debug mode, for development purposes.',
},
{
env: 'BAD_NODE_MODE',
key: 'badNodeMode',
type: Number,
default: 0,
help: 'For development purposes, simulates a rogue node.',
},
];
function printHelp () {
OPTIONS.forEach(
function (option) {
console.log(`* Option: ${option.env}\n * Type: ${option.type.name}`);
if (option.default !== undefined) {
console.log(` * Default: ${option.default}`);
}
if (option.required) {
console.log(' * Required: true');
}
if (option.help) {
console.log(` * ${option.help}`);
}
}
);
}
function onException (e) {
process.stderr.write(`${e.stack || e}\n`);
process.exit(1);
}
function onSignal () {
process.exit(0);
}
process.on('uncaughtException', onException);
process.on('unhandledRejection', onException);
process.on('SIGINT', onSignal);
process.on('SIGTERM', onSignal);
(async function () {
const config = {};
OPTIONS.forEach(
function (option) {
const v = process.env[option.env] || option.default;
if (option.required && v === undefined) {
printHelp();
throw new Error(`${option.env} is a required argument.`);
}
config[option.key] = option.type(v);
}
);
new Server(config);
})();