-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenergywebx-config.js
58 lines (42 loc) · 1.83 KB
/
energywebx-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
const polkadot = require('@polkadot/api');
const URLS = {
PEX: 'https://public-rpc.testnet.energywebx.com',
MAINNET: 'https://public-rpc.mainnet.energywebx.com'
};
const matchRpcToSubsquid = (rpcUrl) => {
if (rpcUrl === URLS.PEX) {
return 'https://ewx-subsquid-dev.energyweb.org/graphql'
} else if (rpcUrl === URLS.MAINNET) {
return 'https://ewx-indexer.mainnet.energywebx.com/graphql';
}
return process.env.__EWX_SUBSQUID_URL;
}
module.exports = function (RED) {
function EnergyWebXConfigNode(config) {
RED.nodes.createNode(this, config);
const ewxRemoteConfig = config.__envConfig;
this.workerUrl = 'http://localhost:3002';
this.workerAddress = ewxRemoteConfig.EWX_WORKER_ADDRESS;
this.solutionNamespace = ewxRemoteConfig.EWX_SOLUTION_ID;
this.solutionGroupId = ewxRemoteConfig.EWX_SOLUTION_GROUP_ID;
this.rpcUrl = ewxRemoteConfig.EWX_RPC_URL;
this.subsquidUrl = matchRpcToSubsquid(this.rpcUrl);
this.log(`worker address = ${this.workerAddress}, solution namespace = ${this.solutionNamespace}, solution group id = ${this.solutionGroupId}, rpc url = ${this.rpcUrl}, subsquid url = ${this.subsquidUrl}`)
const provider = new polkadot.HttpProvider(this.rpcUrl);
const api = new polkadot.ApiPromise({
provider,
throwOnUnknown: true,
throwOnConnect: true,
});
api.connect()
.then(() => {
this.log(`connected to ${this.rpcUrl}`);
this.status({fill: "green", shape: "dot", text: "connected"});
})
.catch((e) => {
this.log(e);
this.status({fill: "red", shape: "ring", text: "disconnected"});
})
}
RED.nodes.registerType("energywebx-config", EnergyWebXConfigNode);
}