@xyo-network/xl1-cli-lib 1.20.5 → 1.20.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/node/commands/api/apiCommand.d.ts +5 -0
- package/dist/node/commands/api/apiCommand.d.ts.map +1 -0
- package/dist/node/commands/api/index.d.ts +2 -0
- package/dist/node/commands/api/index.d.ts.map +1 -0
- package/dist/node/commands/bridge/bridgeCommand.d.ts +5 -0
- package/dist/node/commands/bridge/bridgeCommand.d.ts.map +1 -0
- package/dist/node/commands/bridge/index.d.ts +1 -0
- package/dist/node/commands/bridge/index.d.ts.map +1 -1
- package/dist/node/commands/index.d.ts +6 -0
- package/dist/node/commands/index.d.ts.map +1 -1
- package/dist/node/commands/mempool/index.d.ts +2 -0
- package/dist/node/commands/mempool/index.d.ts.map +1 -0
- package/dist/node/commands/mempool/mempoolCommand.d.ts +5 -0
- package/dist/node/commands/mempool/mempoolCommand.d.ts.map +1 -0
- package/dist/node/commands/producer/index.d.ts +2 -0
- package/dist/node/commands/producer/index.d.ts.map +1 -0
- package/dist/node/commands/producer/producerCommand.d.ts +5 -0
- package/dist/node/commands/producer/producerCommand.d.ts.map +1 -0
- package/dist/node/commands/rewardRedemption/index.d.ts +1 -0
- package/dist/node/commands/rewardRedemption/index.d.ts.map +1 -1
- package/dist/node/commands/rewardRedemption/rewardRedemptionCommand.d.ts +5 -0
- package/dist/node/commands/rewardRedemption/rewardRedemptionCommand.d.ts.map +1 -0
- package/dist/node/commands/start/index.d.ts +2 -0
- package/dist/node/commands/start/index.d.ts.map +1 -0
- package/dist/node/commands/start/startCommand.d.ts +5 -0
- package/dist/node/commands/start/startCommand.d.ts.map +1 -0
- package/dist/node/commands/types.d.ts +8 -0
- package/dist/node/commands/types.d.ts.map +1 -0
- package/dist/node/commands/withDeprecationWarning.d.ts +3 -0
- package/dist/node/commands/withDeprecationWarning.d.ts.map +1 -0
- package/dist/node/configMiddleware.d.ts +3 -0
- package/dist/node/configMiddleware.d.ts.map +1 -0
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.mjs +351 -176
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/runCLI.d.ts.map +1 -1
- package/dist/node/xl1.mjs +350 -176
- package/dist/node/xl1.mjs.map +1 -1
- package/package.json +16 -27
- package/src/commands/api/apiCommand.ts +39 -0
- package/src/commands/api/index.ts +1 -0
- package/src/commands/bridge/bridgeCommand.ts +19 -0
- package/src/commands/bridge/index.ts +1 -0
- package/src/commands/index.ts +6 -0
- package/src/commands/mempool/index.ts +1 -0
- package/src/commands/mempool/mempoolCommand.ts +19 -0
- package/src/commands/producer/index.ts +1 -0
- package/src/commands/producer/producerCommand.ts +19 -0
- package/src/commands/rewardRedemption/index.ts +1 -0
- package/src/commands/rewardRedemption/rewardRedemptionCommand.ts +19 -0
- package/src/commands/start/index.ts +1 -0
- package/src/commands/start/startCommand.ts +127 -0
- package/src/commands/types.ts +9 -0
- package/src/commands/withDeprecationWarning.ts +17 -0
- package/src/configMiddleware.ts +55 -0
- package/src/index.ts +1 -0
- package/src/runCLI.ts +31 -142
package/dist/node/xl1.mjs
CHANGED
|
@@ -5,21 +5,70 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
5
5
|
import { config } from "dotenv";
|
|
6
6
|
|
|
7
7
|
// src/runCLI.ts
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { ApiConfigZod, BridgeConfigZod, contextFromConfigWithoutLocator, locatorsFromConfig, MempoolConfigZod, Orchestrator, ProducerConfigZod, RewardRedemptionConfigZod, tryParseConfig, ValidatorConfigZod } from "@xyo-network/chain-orchestration";
|
|
12
|
-
import { runProducer } from "@xyo-network/chain-producer";
|
|
13
|
-
import { ActorConfigZod, ConfigZod, isZodError, resolveConfig } from "@xyo-network/xl1-sdk";
|
|
8
|
+
import { isDefined as isDefined2 } from "@xylabs/sdk-js";
|
|
9
|
+
import { contextFromConfigWithoutLocator, locatorsFromConfig, Orchestrator } from "@xyo-network/chain-orchestration";
|
|
10
|
+
import { ActorConfigZod, ConfigZod as ConfigZod2 } from "@xyo-network/xl1-sdk";
|
|
14
11
|
import yargs from "yargs";
|
|
15
12
|
import { hideBin } from "yargs/helpers";
|
|
16
13
|
|
|
17
|
-
// src/commands/
|
|
14
|
+
// src/commands/api/apiCommand.ts
|
|
15
|
+
import { getApiActor } from "@xyo-network/chain-api";
|
|
16
|
+
import { getMempoolActor } from "@xyo-network/chain-mempool";
|
|
17
|
+
import { ApiConfigZod, MempoolConfigZod, ValidatorConfigZod } from "@xyo-network/chain-orchestration";
|
|
18
|
+
|
|
19
|
+
// src/commands/validator/runValidator.ts
|
|
18
20
|
import { exists } from "@xylabs/sdk-js";
|
|
21
|
+
import { initActorWallet, ValidatorActor } from "@xyo-network/chain-orchestration";
|
|
22
|
+
var getValidatorActor = /* @__PURE__ */ __name(async (config2, locator) => {
|
|
23
|
+
const account = await initActorWallet({
|
|
24
|
+
config: config2,
|
|
25
|
+
logger: locator.context.logger,
|
|
26
|
+
singletons: {},
|
|
27
|
+
caches: {}
|
|
28
|
+
});
|
|
29
|
+
return await ValidatorActor.create({
|
|
30
|
+
account,
|
|
31
|
+
config: config2,
|
|
32
|
+
locator
|
|
33
|
+
});
|
|
34
|
+
}, "getValidatorActor");
|
|
35
|
+
|
|
36
|
+
// src/commands/api/apiCommand.ts
|
|
37
|
+
function apiCommand(getConfiguration2, getLocatorsFromConfig2) {
|
|
38
|
+
return {
|
|
39
|
+
command: "api",
|
|
40
|
+
deprecated: 'Use "start api" instead',
|
|
41
|
+
describe: "Run a XL1 API Node",
|
|
42
|
+
handler: /* @__PURE__ */ __name(async () => {
|
|
43
|
+
const configuration2 = getConfiguration2();
|
|
44
|
+
const { locators, orchestrator } = await getLocatorsFromConfig2([
|
|
45
|
+
"api",
|
|
46
|
+
"mempool",
|
|
47
|
+
"validator"
|
|
48
|
+
], configuration2);
|
|
49
|
+
const actors = await Promise.all([
|
|
50
|
+
getApiActor(ApiConfigZod.parse(locators["api"].context.config), locators["api"]),
|
|
51
|
+
getMempoolActor(MempoolConfigZod.parse(locators["mempool"].context.config), locators["mempool"]),
|
|
52
|
+
getValidatorActor(ValidatorConfigZod.parse(locators["validator"].context.config), locators["validator"])
|
|
53
|
+
]);
|
|
54
|
+
for (const actor of actors) {
|
|
55
|
+
await orchestrator.registerActor(actor);
|
|
56
|
+
}
|
|
57
|
+
await orchestrator.start();
|
|
58
|
+
}, "handler")
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
__name(apiCommand, "apiCommand");
|
|
62
|
+
|
|
63
|
+
// src/commands/bridge/bridgeCommand.ts
|
|
64
|
+
import { BridgeConfigZod } from "@xyo-network/chain-orchestration";
|
|
65
|
+
|
|
66
|
+
// src/commands/bridge/runBridge.ts
|
|
67
|
+
import { exists as exists2 } from "@xylabs/sdk-js";
|
|
19
68
|
import { BridgeActor } from "@xyo-network/chain-bridge";
|
|
20
|
-
import { initActorWallet } from "@xyo-network/chain-orchestration";
|
|
69
|
+
import { initActorWallet as initActorWallet2 } from "@xyo-network/chain-orchestration";
|
|
21
70
|
var getBridgeActor = /* @__PURE__ */ __name(async (config2, locator) => {
|
|
22
|
-
const account = await
|
|
71
|
+
const account = await initActorWallet2({
|
|
23
72
|
config: config2,
|
|
24
73
|
logger: locator.context.logger,
|
|
25
74
|
singletons: {},
|
|
@@ -35,19 +84,77 @@ var runBridge = /* @__PURE__ */ __name(async (config2, orchestrator, locator) =>
|
|
|
35
84
|
const bridge = await getBridgeActor(config2, locator);
|
|
36
85
|
const actors = [
|
|
37
86
|
bridge
|
|
38
|
-
].filter(
|
|
87
|
+
].filter(exists2);
|
|
39
88
|
for (const actor of actors) {
|
|
40
89
|
await orchestrator.registerActor(actor);
|
|
41
90
|
}
|
|
42
91
|
await orchestrator.start();
|
|
43
92
|
}, "runBridge");
|
|
44
93
|
|
|
94
|
+
// src/commands/bridge/bridgeCommand.ts
|
|
95
|
+
function bridgeCommand(getConfiguration2, getLocatorsFromConfig2) {
|
|
96
|
+
return {
|
|
97
|
+
command: "bridge",
|
|
98
|
+
deprecated: 'Use "start bridge" instead',
|
|
99
|
+
describe: "Run a XL1 Bridge Node",
|
|
100
|
+
handler: /* @__PURE__ */ __name(async () => {
|
|
101
|
+
const configuration2 = getConfiguration2();
|
|
102
|
+
const { locators, orchestrator } = await getLocatorsFromConfig2([
|
|
103
|
+
"bridge"
|
|
104
|
+
], configuration2);
|
|
105
|
+
await runBridge(BridgeConfigZod.parse(locators["bridge"].context.config), orchestrator, locators["bridge"]);
|
|
106
|
+
}, "handler")
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
__name(bridgeCommand, "bridgeCommand");
|
|
110
|
+
|
|
111
|
+
// src/commands/mempool/mempoolCommand.ts
|
|
112
|
+
import { runMempool } from "@xyo-network/chain-mempool";
|
|
113
|
+
import { MempoolConfigZod as MempoolConfigZod2 } from "@xyo-network/chain-orchestration";
|
|
114
|
+
function mempoolCommand(getConfiguration2, getLocatorsFromConfig2) {
|
|
115
|
+
return {
|
|
116
|
+
command: "mempool",
|
|
117
|
+
deprecated: 'Use "start mempool" instead',
|
|
118
|
+
describe: "Run a XL1 Mempool Node",
|
|
119
|
+
handler: /* @__PURE__ */ __name(async () => {
|
|
120
|
+
const configuration2 = getConfiguration2();
|
|
121
|
+
const { locators, orchestrator } = await getLocatorsFromConfig2([
|
|
122
|
+
"mempool"
|
|
123
|
+
], configuration2);
|
|
124
|
+
await runMempool(MempoolConfigZod2.parse(locators["mempool"].context.config), orchestrator, locators["mempool"]);
|
|
125
|
+
}, "handler")
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
__name(mempoolCommand, "mempoolCommand");
|
|
129
|
+
|
|
130
|
+
// src/commands/producer/producerCommand.ts
|
|
131
|
+
import { ProducerConfigZod } from "@xyo-network/chain-orchestration";
|
|
132
|
+
import { runProducer } from "@xyo-network/chain-producer";
|
|
133
|
+
function producerCommand(getConfiguration2, getLocatorsFromConfig2) {
|
|
134
|
+
return {
|
|
135
|
+
command: "producer",
|
|
136
|
+
deprecated: 'Use "start producer" instead',
|
|
137
|
+
describe: "Run a XL1 Producer Node",
|
|
138
|
+
handler: /* @__PURE__ */ __name(async () => {
|
|
139
|
+
const configuration2 = getConfiguration2();
|
|
140
|
+
const { locators, orchestrator } = await getLocatorsFromConfig2([
|
|
141
|
+
"producer"
|
|
142
|
+
], configuration2);
|
|
143
|
+
await runProducer(ProducerConfigZod.parse(locators["producer"].context.config), orchestrator, locators["producer"]);
|
|
144
|
+
}, "handler")
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
__name(producerCommand, "producerCommand");
|
|
148
|
+
|
|
149
|
+
// src/commands/rewardRedemption/rewardRedemptionCommand.ts
|
|
150
|
+
import { RewardRedemptionConfigZod } from "@xyo-network/chain-orchestration";
|
|
151
|
+
|
|
45
152
|
// src/commands/rewardRedemption/runRewardRedemptionApi.ts
|
|
46
|
-
import { exists as
|
|
47
|
-
import { initActorWallet as
|
|
153
|
+
import { exists as exists3 } from "@xylabs/sdk-js";
|
|
154
|
+
import { initActorWallet as initActorWallet3 } from "@xyo-network/chain-orchestration";
|
|
48
155
|
import { RewardRedemptionActor } from "@xyo-network/chain-reward-redemption";
|
|
49
156
|
async function getRewardRedemptionActor(config2, locator) {
|
|
50
|
-
const account = await
|
|
157
|
+
const account = await initActorWallet3({
|
|
51
158
|
config: config2,
|
|
52
159
|
logger: locator.context.logger,
|
|
53
160
|
singletons: {},
|
|
@@ -64,7 +171,7 @@ async function runRewardRedemptionApi(config2, orchestrator, locator) {
|
|
|
64
171
|
const rewardRedemption = await getRewardRedemptionActor(config2, locator);
|
|
65
172
|
const actors = [
|
|
66
173
|
rewardRedemption
|
|
67
|
-
].filter(
|
|
174
|
+
].filter(exists3);
|
|
68
175
|
for (const actor of actors) {
|
|
69
176
|
await orchestrator.registerActor(actor);
|
|
70
177
|
}
|
|
@@ -72,22 +179,216 @@ async function runRewardRedemptionApi(config2, orchestrator, locator) {
|
|
|
72
179
|
}
|
|
73
180
|
__name(runRewardRedemptionApi, "runRewardRedemptionApi");
|
|
74
181
|
|
|
75
|
-
// src/commands/
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
182
|
+
// src/commands/rewardRedemption/rewardRedemptionCommand.ts
|
|
183
|
+
function rewardRedemptionCommand(getConfiguration2, getLocatorsFromConfig2) {
|
|
184
|
+
return {
|
|
185
|
+
command: "reward-redemption-api",
|
|
186
|
+
deprecated: 'Use "start rewardRedemption" instead',
|
|
187
|
+
describe: "Run a XL1 Rewards Redemption API Node",
|
|
188
|
+
handler: /* @__PURE__ */ __name(async () => {
|
|
189
|
+
const configuration2 = getConfiguration2();
|
|
190
|
+
const { locators, orchestrator } = await getLocatorsFromConfig2([
|
|
191
|
+
"rewardRedemption"
|
|
192
|
+
], configuration2);
|
|
193
|
+
await runRewardRedemptionApi(RewardRedemptionConfigZod.parse(locators["rewardRedemption"].context.config), orchestrator, locators["rewardRedemption"]);
|
|
194
|
+
}, "handler")
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
__name(rewardRedemptionCommand, "rewardRedemptionCommand");
|
|
198
|
+
|
|
199
|
+
// src/commands/start/startCommand.ts
|
|
200
|
+
import { getApiActor as getApiActor2 } from "@xyo-network/chain-api";
|
|
201
|
+
import { getMempoolActor as getMempoolActor2 } from "@xyo-network/chain-mempool";
|
|
202
|
+
import { ApiConfigZod as ApiConfigZod2, BridgeConfigZod as BridgeConfigZod2, MempoolConfigZod as MempoolConfigZod3, ProducerConfigZod as ProducerConfigZod2, RewardRedemptionConfigZod as RewardRedemptionConfigZod2, ValidatorConfigZod as ValidatorConfigZod2 } from "@xyo-network/chain-orchestration";
|
|
203
|
+
import { runProducer as runProducer2 } from "@xyo-network/chain-producer";
|
|
204
|
+
|
|
205
|
+
// src/waitForHostPort.ts
|
|
206
|
+
import net from "net";
|
|
207
|
+
var waitForHostPort = /* @__PURE__ */ __name((host, port) => {
|
|
208
|
+
return new Promise((resolve) => {
|
|
209
|
+
const tryConnect = /* @__PURE__ */ __name(() => {
|
|
210
|
+
const socket = new net.Socket();
|
|
211
|
+
socket.setTimeout(1e3).once("error", () => {
|
|
212
|
+
socket.destroy();
|
|
213
|
+
setTimeout(tryConnect, 500);
|
|
214
|
+
}).once("timeout", () => {
|
|
215
|
+
socket.destroy();
|
|
216
|
+
setTimeout(tryConnect, 500);
|
|
217
|
+
}).connect(port, host, () => {
|
|
218
|
+
socket.end();
|
|
219
|
+
resolve();
|
|
220
|
+
});
|
|
221
|
+
}, "tryConnect");
|
|
222
|
+
tryConnect();
|
|
89
223
|
});
|
|
90
|
-
}, "
|
|
224
|
+
}, "waitForHostPort");
|
|
225
|
+
|
|
226
|
+
// src/commands/start/startCommand.ts
|
|
227
|
+
var KNOWN_ACTORS = [
|
|
228
|
+
"api",
|
|
229
|
+
"bridge",
|
|
230
|
+
"mempool",
|
|
231
|
+
"producer",
|
|
232
|
+
"rewardRedemption",
|
|
233
|
+
"validator"
|
|
234
|
+
];
|
|
235
|
+
function getActorsFromConfig(configuration2) {
|
|
236
|
+
const enabledActors = configuration2.actors.filter((actor) => actor.enabled !== false).map((actor) => actor.name);
|
|
237
|
+
return enabledActors.length > 0 ? enabledActors : void 0;
|
|
238
|
+
}
|
|
239
|
+
__name(getActorsFromConfig, "getActorsFromConfig");
|
|
240
|
+
function getDefaultActors() {
|
|
241
|
+
return [
|
|
242
|
+
"api",
|
|
243
|
+
"producer"
|
|
244
|
+
];
|
|
245
|
+
}
|
|
246
|
+
__name(getDefaultActors, "getDefaultActors");
|
|
247
|
+
async function startActor(name, locator, orchestrator) {
|
|
248
|
+
switch (name) {
|
|
249
|
+
case "api": {
|
|
250
|
+
const config2 = ApiConfigZod2.parse(locator.context.config);
|
|
251
|
+
const actor = await getApiActor2(config2, locator);
|
|
252
|
+
await orchestrator.registerActor(actor);
|
|
253
|
+
await orchestrator.start();
|
|
254
|
+
await waitForHostPort(config2.host, config2.port);
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
case "bridge": {
|
|
258
|
+
const config2 = BridgeConfigZod2.parse(locator.context.config);
|
|
259
|
+
const actor = await getBridgeActor(config2, locator);
|
|
260
|
+
await orchestrator.registerActor(actor);
|
|
261
|
+
await orchestrator.start();
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
case "mempool": {
|
|
265
|
+
const config2 = MempoolConfigZod3.parse(locator.context.config);
|
|
266
|
+
const actor = await getMempoolActor2(config2, locator);
|
|
267
|
+
await orchestrator.registerActor(actor);
|
|
268
|
+
await orchestrator.start();
|
|
269
|
+
await waitForHostPort(config2.host, config2.port);
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
case "producer": {
|
|
273
|
+
const config2 = ProducerConfigZod2.parse(locator.context.config);
|
|
274
|
+
await runProducer2(config2, orchestrator, locator);
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
case "rewardRedemption": {
|
|
278
|
+
const config2 = RewardRedemptionConfigZod2.parse(locator.context.config);
|
|
279
|
+
const actor = await getRewardRedemptionActor(config2, locator);
|
|
280
|
+
await orchestrator.registerActor(actor);
|
|
281
|
+
await orchestrator.start();
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
case "validator": {
|
|
285
|
+
const config2 = ValidatorConfigZod2.parse(locator.context.config);
|
|
286
|
+
const actor = await getValidatorActor(config2, locator);
|
|
287
|
+
await orchestrator.registerActor(actor);
|
|
288
|
+
await orchestrator.start();
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
default: {
|
|
292
|
+
throw new Error(`Unknown actor: ${name}`);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
__name(startActor, "startActor");
|
|
297
|
+
function startCommand(getConfiguration2, getLocatorsFromConfig2) {
|
|
298
|
+
return {
|
|
299
|
+
command: [
|
|
300
|
+
"start [actors..]",
|
|
301
|
+
"$0"
|
|
302
|
+
],
|
|
303
|
+
describe: "Run a full XL1 Node",
|
|
304
|
+
builder: /* @__PURE__ */ __name((yargs2) => {
|
|
305
|
+
return yargs2.positional("actors", {
|
|
306
|
+
type: "string",
|
|
307
|
+
array: true,
|
|
308
|
+
choices: KNOWN_ACTORS,
|
|
309
|
+
description: "Actors to start (e.g. xl1 start api producer or xl1 start api,producer)",
|
|
310
|
+
coerce: /* @__PURE__ */ __name((values) => values.flatMap((v) => v.split(",")), "coerce")
|
|
311
|
+
}).option("actors", {
|
|
312
|
+
type: "array",
|
|
313
|
+
string: true,
|
|
314
|
+
choices: KNOWN_ACTORS,
|
|
315
|
+
description: "List of actors to start (e.g. --actors api producer mempool). Defaults to api, producer, and mempool if enabled."
|
|
316
|
+
});
|
|
317
|
+
}, "builder"),
|
|
318
|
+
handler: /* @__PURE__ */ __name(async (argv) => {
|
|
319
|
+
const configuration2 = getConfiguration2();
|
|
320
|
+
const requestedActors = argv.actors !== void 0 && argv.actors.length > 0 ? argv.actors : getActorsFromConfig(configuration2) ?? getDefaultActors();
|
|
321
|
+
const { locators, orchestrator } = await getLocatorsFromConfig2(requestedActors, configuration2);
|
|
322
|
+
for (const name of requestedActors) {
|
|
323
|
+
await startActor(name, locators[name], orchestrator);
|
|
324
|
+
}
|
|
325
|
+
}, "handler")
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
__name(startCommand, "startCommand");
|
|
329
|
+
|
|
330
|
+
// src/commands/withDeprecationWarning.ts
|
|
331
|
+
import { delay } from "@xylabs/sdk-js";
|
|
332
|
+
function withDeprecationWarning(module) {
|
|
333
|
+
const { deprecated, handler } = module;
|
|
334
|
+
if (typeof deprecated === "string") {
|
|
335
|
+
return {
|
|
336
|
+
...module,
|
|
337
|
+
handler: /* @__PURE__ */ __name(async (argv) => {
|
|
338
|
+
console.warn(`[deprecated] ${deprecated}`);
|
|
339
|
+
await delay(3e3);
|
|
340
|
+
return handler(argv);
|
|
341
|
+
}, "handler")
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
return module;
|
|
345
|
+
}
|
|
346
|
+
__name(withDeprecationWarning, "withDeprecationWarning");
|
|
347
|
+
|
|
348
|
+
// src/configMiddleware.ts
|
|
349
|
+
import { createDeepMerge } from "@xylabs/sdk-js";
|
|
350
|
+
import { tryParseConfig } from "@xyo-network/chain-orchestration";
|
|
351
|
+
import { ConfigZod, isZodError, resolveConfig } from "@xyo-network/xl1-sdk";
|
|
352
|
+
var deepMerge = createDeepMerge({
|
|
353
|
+
arrayStrategy: "concat"
|
|
354
|
+
});
|
|
355
|
+
async function configMiddleware(argv, setConfiguration) {
|
|
356
|
+
try {
|
|
357
|
+
const configPath = argv.config;
|
|
358
|
+
const parsedConfigFile = await tryParseConfig({
|
|
359
|
+
configPath
|
|
360
|
+
});
|
|
361
|
+
const parsedConfigArgs = ConfigZod.safeParse(argv).data ?? {};
|
|
362
|
+
const parseResult = ConfigZod.safeParse(deepMerge(parsedConfigFile, parsedConfigArgs));
|
|
363
|
+
if (!parseResult.success) {
|
|
364
|
+
throw parseResult.error;
|
|
365
|
+
}
|
|
366
|
+
const mergedConfig = parseResult.data;
|
|
367
|
+
const validatedMergedConfigResult = ConfigZod.safeParse(mergedConfig);
|
|
368
|
+
if (!validatedMergedConfigResult.success) {
|
|
369
|
+
throw validatedMergedConfigResult.error;
|
|
370
|
+
}
|
|
371
|
+
const resolvedConfig = resolveConfig(validatedMergedConfigResult.data);
|
|
372
|
+
const validatedConfigResult = ConfigZod.safeParse(resolvedConfig);
|
|
373
|
+
if (!validatedConfigResult.success) {
|
|
374
|
+
throw validatedConfigResult.error;
|
|
375
|
+
}
|
|
376
|
+
setConfiguration(validatedConfigResult.data);
|
|
377
|
+
if (argv["dump-config"]) {
|
|
378
|
+
console.log(JSON.stringify(validatedConfigResult.data, null, 2));
|
|
379
|
+
process.exit(0);
|
|
380
|
+
}
|
|
381
|
+
} catch (err) {
|
|
382
|
+
if (isZodError(err)) {
|
|
383
|
+
console.error(`Zod error: ${err.message}`);
|
|
384
|
+
} else {
|
|
385
|
+
console.error(`Error parsing configuration: ${err}`);
|
|
386
|
+
}
|
|
387
|
+
console.error(`Stack: ${err instanceof Error ? err.stack : "N/A"}`);
|
|
388
|
+
throw new Error("Invalid configuration");
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
__name(configMiddleware, "configMiddleware");
|
|
91
392
|
|
|
92
393
|
// src/images.ts
|
|
93
394
|
var XL1LogoColorizedAscii = `\x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;118;111;144m_\x1B[0m
|
|
@@ -144,52 +445,30 @@ var optionsFromGlobalZodRegistry = /* @__PURE__ */ __name(() => {
|
|
|
144
445
|
return opts;
|
|
145
446
|
}, "optionsFromGlobalZodRegistry");
|
|
146
447
|
|
|
147
|
-
// src/waitForHostPort.ts
|
|
148
|
-
import net from "net";
|
|
149
|
-
var waitForHostPort = /* @__PURE__ */ __name((host, port) => {
|
|
150
|
-
return new Promise((resolve) => {
|
|
151
|
-
const tryConnect = /* @__PURE__ */ __name(() => {
|
|
152
|
-
const socket = new net.Socket();
|
|
153
|
-
socket.setTimeout(1e3).once("error", () => {
|
|
154
|
-
socket.destroy();
|
|
155
|
-
setTimeout(tryConnect, 500);
|
|
156
|
-
}).once("timeout", () => {
|
|
157
|
-
socket.destroy();
|
|
158
|
-
setTimeout(tryConnect, 500);
|
|
159
|
-
}).connect(port, host, () => {
|
|
160
|
-
socket.end();
|
|
161
|
-
resolve();
|
|
162
|
-
});
|
|
163
|
-
}, "tryConnect");
|
|
164
|
-
tryConnect();
|
|
165
|
-
});
|
|
166
|
-
}, "waitForHostPort");
|
|
167
|
-
|
|
168
448
|
// src/runCLI.ts
|
|
169
449
|
var configuration;
|
|
170
|
-
var version = isDefined2("1.20.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
450
|
+
var version = isDefined2("1.20.8") ? "1.20.8" : "unknown";
|
|
451
|
+
function getConfiguration() {
|
|
452
|
+
return configuration;
|
|
453
|
+
}
|
|
454
|
+
__name(getConfiguration, "getConfiguration");
|
|
174
455
|
async function getLocatorsFromConfig(actors, configuration2) {
|
|
175
456
|
const actorConfigs = [];
|
|
176
457
|
for (const actorName of actors) {
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
458
|
+
const existingConfig = configuration2.actors.find((actor) => actor.name === actorName);
|
|
459
|
+
if (existingConfig) {
|
|
460
|
+
actorConfigs.push(existingConfig);
|
|
461
|
+
} else {
|
|
462
|
+
const actorConfig = ActorConfigZod.loose().parse({
|
|
463
|
+
name: actorName
|
|
464
|
+
});
|
|
465
|
+
actorConfigs.push(actorConfig);
|
|
466
|
+
}
|
|
182
467
|
}
|
|
183
|
-
const config2 =
|
|
468
|
+
const config2 = ConfigZod2.parse({
|
|
469
|
+
...configuration2,
|
|
184
470
|
actors: actorConfigs
|
|
185
|
-
})
|
|
186
|
-
const actorList = [
|
|
187
|
-
.../* @__PURE__ */ new Set([
|
|
188
|
-
...config2.actors.map((actor) => actor.name),
|
|
189
|
-
...actorConfigs.map((actor) => actor.name)
|
|
190
|
-
])
|
|
191
|
-
];
|
|
192
|
-
config2.actors = actorList.map((actorName) => ActorConfigZod.loose().parse(deepMerge(config2.actors.find((actor) => actor.name === actorName) ?? {}, actorConfigs.find((actor) => actor.name === actorName) ?? {})));
|
|
471
|
+
});
|
|
193
472
|
const logger = initLogger(configuration2);
|
|
194
473
|
const orchestrator = await Orchestrator.create({
|
|
195
474
|
logger
|
|
@@ -228,115 +507,10 @@ $0 <command> [options]`).parserConfiguration({
|
|
|
228
507
|
"parse-numbers": false,
|
|
229
508
|
"populate--": true
|
|
230
509
|
}).env("XL1").scriptName("xl1").middleware(async (argv2) => {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
const parsedConfigFile = await tryParseConfig({
|
|
234
|
-
configPath
|
|
235
|
-
});
|
|
236
|
-
const parsedConfigArgs = ConfigZod.safeParse(argv2).data ?? {};
|
|
237
|
-
const parseResult = ConfigZod.safeParse(deepMerge(parsedConfigFile, parsedConfigArgs));
|
|
238
|
-
if (!parseResult.success) {
|
|
239
|
-
throw parseResult.error;
|
|
240
|
-
}
|
|
241
|
-
const mergedConfig = parseResult.data;
|
|
242
|
-
const validatedMergedConfigResult = ConfigZod.safeParse(mergedConfig);
|
|
243
|
-
if (!validatedMergedConfigResult.success) {
|
|
244
|
-
throw validatedMergedConfigResult.error;
|
|
245
|
-
}
|
|
246
|
-
const resolvedConfig = resolveConfig(validatedMergedConfigResult.data);
|
|
247
|
-
const validatedConfigResult = ConfigZod.safeParse(resolvedConfig);
|
|
248
|
-
if (!validatedConfigResult.success) {
|
|
249
|
-
throw validatedConfigResult.error;
|
|
250
|
-
}
|
|
251
|
-
configuration = validatedConfigResult.data;
|
|
252
|
-
if (argv2["dump-config"]) {
|
|
253
|
-
console.log(JSON.stringify(configuration, null, 2));
|
|
254
|
-
process.exit(0);
|
|
255
|
-
}
|
|
256
|
-
} catch (err) {
|
|
257
|
-
if (isZodError(err)) {
|
|
258
|
-
console.error(`Zod error: ${err.message}`);
|
|
259
|
-
} else {
|
|
260
|
-
console.error(`Error parsing configuration: ${err}`);
|
|
261
|
-
}
|
|
262
|
-
console.error(`Stack: ${err instanceof Error ? err.stack : "N/A"}`);
|
|
263
|
-
throw new Error("Invalid configuration");
|
|
264
|
-
}
|
|
265
|
-
}).options(optionsFromGlobalZodRegistry()).wrap(y.terminalWidth()).command("api", "Run a XL1 API Node", (yargs2) => {
|
|
266
|
-
return yargs2.command("$0", "Run a XL1 API Node", () => {
|
|
267
|
-
}, async () => {
|
|
268
|
-
const { locators, orchestrator } = await getLocatorsFromConfig([
|
|
269
|
-
"api",
|
|
270
|
-
"mempool",
|
|
271
|
-
"validator"
|
|
272
|
-
], configuration);
|
|
273
|
-
const actors = await Promise.all([
|
|
274
|
-
getApiActor(ApiConfigZod.parse(locators["api"].context.config), locators["api"]),
|
|
275
|
-
getMempoolActor(MempoolConfigZod.parse(locators["mempool"].context.config), locators["mempool"]),
|
|
276
|
-
getValidatorActor(ValidatorConfigZod.parse(locators["validator"].context.config), locators["validator"])
|
|
277
|
-
]);
|
|
278
|
-
for (const actor of actors) {
|
|
279
|
-
await orchestrator.registerActor(actor);
|
|
280
|
-
}
|
|
281
|
-
await orchestrator.start();
|
|
510
|
+
await configMiddleware(argv2, (config2) => {
|
|
511
|
+
configuration = config2;
|
|
282
512
|
});
|
|
283
|
-
}).command(
|
|
284
|
-
return yargs2.command("$0", "Run a XL1 Bridge Node", () => {
|
|
285
|
-
}, async () => {
|
|
286
|
-
const { locators, orchestrator } = await getLocatorsFromConfig([
|
|
287
|
-
"bridge"
|
|
288
|
-
], configuration);
|
|
289
|
-
await runBridge(BridgeConfigZod.parse(locators["bridge"].context.config), orchestrator, locators["bridge"]);
|
|
290
|
-
});
|
|
291
|
-
}).command("mempool", "Run a XL1 Mempool Node", (yargs2) => {
|
|
292
|
-
return yargs2.command("$0", "Run a XL1 Mempool Node", () => {
|
|
293
|
-
}, async () => {
|
|
294
|
-
const { locators, orchestrator } = await getLocatorsFromConfig([
|
|
295
|
-
"mempool"
|
|
296
|
-
], configuration);
|
|
297
|
-
await runMempool(MempoolConfigZod.parse(locators["mempool"].context.config), orchestrator, locators["mempool"]);
|
|
298
|
-
});
|
|
299
|
-
}).command("producer", "Run a XL1 Producer Node", (yargs2) => {
|
|
300
|
-
return yargs2.command("$0", "Run a XL1 Producer Node", () => {
|
|
301
|
-
}, async () => {
|
|
302
|
-
const { locators, orchestrator } = await getLocatorsFromConfig([
|
|
303
|
-
"producer"
|
|
304
|
-
], configuration);
|
|
305
|
-
await runProducer(ProducerConfigZod.parse(locators["producer"].context.config), orchestrator, locators["producer"]);
|
|
306
|
-
});
|
|
307
|
-
}).command("reward-redemption-api", "Run a XL1 Rewards Redemption API Node", (yargs2) => {
|
|
308
|
-
return yargs2.command("$0", "Run a XL1 Rewards Redemption API Node", () => {
|
|
309
|
-
}, async () => {
|
|
310
|
-
const { locators, orchestrator } = await getLocatorsFromConfig([
|
|
311
|
-
"rewardRedemption"
|
|
312
|
-
], configuration);
|
|
313
|
-
await runRewardRedemptionApi(RewardRedemptionConfigZod.parse(locators["rewardRedemption"].context.config), orchestrator, locators["rewardRedemption"]);
|
|
314
|
-
});
|
|
315
|
-
}).command("$0", "Run a full XL1 Node", () => {
|
|
316
|
-
}, async () => {
|
|
317
|
-
const actors = [
|
|
318
|
-
"producer",
|
|
319
|
-
"api"
|
|
320
|
-
];
|
|
321
|
-
const mempoolEnabled = configuration.actors.find((actor) => actor.name === "mempool")?.enabled;
|
|
322
|
-
if (mempoolEnabled) {
|
|
323
|
-
actors.push("mempool");
|
|
324
|
-
}
|
|
325
|
-
const { locators, orchestrator } = await getLocatorsFromConfig([
|
|
326
|
-
"api",
|
|
327
|
-
"producer"
|
|
328
|
-
], configuration);
|
|
329
|
-
if (mempoolEnabled) {
|
|
330
|
-
const mempoolConfig = MempoolConfigZod.parse(locators["mempool"].context.config);
|
|
331
|
-
await runMempool(mempoolConfig, orchestrator, locators["mempool"]);
|
|
332
|
-
await waitForHostPort(mempoolConfig.host, mempoolConfig.port);
|
|
333
|
-
}
|
|
334
|
-
const apiConfig = ApiConfigZod.parse(locators["api"].context.config);
|
|
335
|
-
await runApi(apiConfig, orchestrator, locators["api"]);
|
|
336
|
-
await waitForHostPort(apiConfig.host, apiConfig.port);
|
|
337
|
-
const producerConfig = ProducerConfigZod.parse(locators["producer"].context.config);
|
|
338
|
-
await runProducer(producerConfig, orchestrator, locators["producer"]);
|
|
339
|
-
}).options({
|
|
513
|
+
}).options(optionsFromGlobalZodRegistry()).wrap(y.terminalWidth()).command(withDeprecationWarning(apiCommand(getConfiguration, getLocatorsFromConfig))).command(withDeprecationWarning(bridgeCommand(getConfiguration, getLocatorsFromConfig))).command(withDeprecationWarning(mempoolCommand(getConfiguration, getLocatorsFromConfig))).command(withDeprecationWarning(producerCommand(getConfiguration, getLocatorsFromConfig))).command(withDeprecationWarning(rewardRedemptionCommand(getConfiguration, getLocatorsFromConfig))).command(startCommand(getConfiguration, getLocatorsFromConfig)).options({
|
|
340
514
|
"config": {
|
|
341
515
|
type: "string",
|
|
342
516
|
description: "Path to a config file to use instead of the default search.",
|