@xyo-network/xl1-cli-lib 1.20.5 → 1.20.8

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