forked from Shuytrnm/redstone-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
61 lines (52 loc) · 1.61 KB
/
index.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
49
50
51
52
53
54
55
56
57
58
59
60
61
import yargs from "yargs";
import {Consola} from "consola"
import NodeRunner from "./src/NodeRunner";
import {NodeConfig} from "./src/types";
import {readJSON} from "./src/utils/objects";
import { JWKInterface } from "arweave/node/lib/wallet";
const logger = require("./src/utils/logger")("index") as Consola;
const {hideBin} = require("yargs/helpers") as any;
async function start() {
try {
await main();
} catch (e: any) {
logger.error(e.stack);
logger.info(
"USAGE: yarn start:prod [--config <PATH_TO_CONFIG_FILE>] [--config-env <NAME_OF_ENV_VARIABLE_WITH_CONFIG>]");
}
}
async function main(): Promise<void> {
// Reading cli arguments
const argv = yargs(hideBin(process.argv)).argv;
const configFilePath = argv.config as string;
// Validating cli arguments
if (!configFilePath && !argv["config-env"]) {
throw new Error("Either --config or --config-env must be specified");
}
let config: NodeConfig;
let jwk: JWKInterface;
if (configFilePath) {
// Loading config from file
config = readJSON(configFilePath);
jwk = readJSON(config.arweaveKeysFile!);
} else {
// Loading config from environment variable
const configString = process.env[argv["config-env"] as string];
if (!configString) {
throw new Error(`ENV variable '${argv["config-env"]}' is empty`);
}
config = JSON.parse(configString);
jwk = config.arweaveKeysJWK!;
if (!jwk) {
throw new Error('arweaveKeysJWK is empty');
}
}
// Running limestone-node with manifest
const runner = await NodeRunner.create(
jwk,
config
);
await runner.run();
}
start();
export = {};