forked from alleotech/grid3_client_ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_loader.ts
59 lines (54 loc) · 1.64 KB
/
client_loader.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
import fs from "fs";
import path from "path";
import { env } from "process";
import { MessageBusClientInterface } from "ts-rmb-client-base";
import { HTTPMessageBusClient } from "ts-rmb-http-client";
import { MessageBusClient } from "ts-rmb-redis-client";
import { BackendStorageType, GridClient, KeypairType } from "../src";
const network = env.NETWORK;
const mnemonic = env.MNEMONIC;
const rmb_proxy = env.RMB_PROXY;
const storeSecret = env.STORE_SECRET;
const ssh_key = env.SSH_KEY;
let config;
if (
network === undefined ||
mnemonic === undefined ||
rmb_proxy === undefined ||
storeSecret === undefined ||
ssh_key === undefined
) {
console.log("Credentials not all found in env variables. Loading all credentials from default config.json...");
config = JSON.parse(fs.readFileSync(path.join(__dirname, "./config.json"), "utf-8"));
} else {
console.log("Credentials loaded from env variables...");
config = {
network: network,
mnemonic: mnemonic,
rmb_proxy: rmb_proxy,
storeSecret: storeSecret,
ssh_key: ssh_key,
};
}
async function getClient(): Promise<GridClient> {
let rmb: MessageBusClientInterface;
if (config.rmb_proxy) {
rmb = new HTTPMessageBusClient(0, "", "", "");
} else {
rmb = new MessageBusClient();
}
const gridClient = new GridClient(
config.network,
config.mnemonic,
config.storeSecret,
rmb,
"",
BackendStorageType.auto,
KeypairType.sr25519,
config.backendStorage,
config.seed,
);
await gridClient.connect();
return gridClient;
}
export { config, getClient };