@xyo-network/chain-mempool 1.16.3

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 (95) hide show
  1. package/LICENSE +165 -0
  2. package/README.md +96 -0
  3. package/dist/node/helpers/index.d.ts +2 -0
  4. package/dist/node/helpers/index.d.ts.map +1 -0
  5. package/dist/node/helpers/initChainId.d.ts +4 -0
  6. package/dist/node/helpers/initChainId.d.ts.map +1 -0
  7. package/dist/node/index.d.ts +2 -0
  8. package/dist/node/index.d.ts.map +1 -0
  9. package/dist/node/index.mjs +618 -0
  10. package/dist/node/index.mjs.map +1 -0
  11. package/dist/node/manifest/getLocator.d.ts +14 -0
  12. package/dist/node/manifest/getLocator.d.ts.map +1 -0
  13. package/dist/node/manifest/getNode.d.ts +15 -0
  14. package/dist/node/manifest/getNode.d.ts.map +1 -0
  15. package/dist/node/manifest/index.d.ts +6 -0
  16. package/dist/node/manifest/index.d.ts.map +1 -0
  17. package/dist/node/manifest/nodeManifest.d.ts +6 -0
  18. package/dist/node/manifest/nodeManifest.d.ts.map +1 -0
  19. package/dist/node/manifest/private/index.d.ts +5 -0
  20. package/dist/node/manifest/private/index.d.ts.map +1 -0
  21. package/dist/node/manifest/public/index.d.ts +14 -0
  22. package/dist/node/manifest/public/index.d.ts.map +1 -0
  23. package/dist/node/manifest/public/spec/Node.spec.d.ts +2 -0
  24. package/dist/node/manifest/public/spec/Node.spec.d.ts.map +1 -0
  25. package/dist/node/server/app.d.ts +4 -0
  26. package/dist/node/server/app.d.ts.map +1 -0
  27. package/dist/node/server/index.d.ts +11 -0
  28. package/dist/node/server/index.d.ts.map +1 -0
  29. package/dist/node/server/instrumentation.d.ts +9 -0
  30. package/dist/node/server/instrumentation.d.ts.map +1 -0
  31. package/dist/node/server/routes/addRoutes.d.ts +3 -0
  32. package/dist/node/server/routes/addRoutes.d.ts.map +1 -0
  33. package/dist/node/server/routes/address/AddressPathParams.d.ts +4 -0
  34. package/dist/node/server/routes/address/AddressPathParams.d.ts.map +1 -0
  35. package/dist/node/server/routes/address/addNodeRoutes.d.ts +3 -0
  36. package/dist/node/server/routes/address/addNodeRoutes.d.ts.map +1 -0
  37. package/dist/node/server/routes/address/get/get.d.ts +4 -0
  38. package/dist/node/server/routes/address/get/get.d.ts.map +1 -0
  39. package/dist/node/server/routes/address/get/index.d.ts +2 -0
  40. package/dist/node/server/routes/address/get/index.d.ts.map +1 -0
  41. package/dist/node/server/routes/address/index.d.ts +2 -0
  42. package/dist/node/server/routes/address/index.d.ts.map +1 -0
  43. package/dist/node/server/routes/address/post/getQueryConfig.d.ts +6 -0
  44. package/dist/node/server/routes/address/post/getQueryConfig.d.ts.map +1 -0
  45. package/dist/node/server/routes/address/post/index.d.ts +2 -0
  46. package/dist/node/server/routes/address/post/index.d.ts.map +1 -0
  47. package/dist/node/server/routes/address/post/post.d.ts +8 -0
  48. package/dist/node/server/routes/address/post/post.d.ts.map +1 -0
  49. package/dist/node/server/routes/dataLake/addDataLakeRoutes.d.ts +3 -0
  50. package/dist/node/server/routes/dataLake/addDataLakeRoutes.d.ts.map +1 -0
  51. package/dist/node/server/routes/dataLake/archivistMiddleware.d.ts +10 -0
  52. package/dist/node/server/routes/dataLake/archivistMiddleware.d.ts.map +1 -0
  53. package/dist/node/server/routes/dataLake/index.d.ts +2 -0
  54. package/dist/node/server/routes/dataLake/index.d.ts.map +1 -0
  55. package/dist/node/server/routes/healthz/addHealthRoutes.d.ts +3 -0
  56. package/dist/node/server/routes/healthz/addHealthRoutes.d.ts.map +1 -0
  57. package/dist/node/server/routes/healthz/index.d.ts +2 -0
  58. package/dist/node/server/routes/healthz/index.d.ts.map +1 -0
  59. package/dist/node/server/routes/index.d.ts +4 -0
  60. package/dist/node/server/routes/index.d.ts.map +1 -0
  61. package/dist/node/server/server.d.ts +11 -0
  62. package/dist/node/server/server.d.ts.map +1 -0
  63. package/package.json +118 -0
  64. package/src/helpers/index.ts +1 -0
  65. package/src/helpers/initChainId.ts +20 -0
  66. package/src/index.ts +1 -0
  67. package/src/manifest/getLocator.ts +85 -0
  68. package/src/manifest/getNode.ts +32 -0
  69. package/src/manifest/index.ts +5 -0
  70. package/src/manifest/node.json +17 -0
  71. package/src/manifest/nodeManifest.ts +8 -0
  72. package/src/manifest/private/index.ts +4 -0
  73. package/src/manifest/public/Chain.json +101 -0
  74. package/src/manifest/public/Pending.json +35 -0
  75. package/src/manifest/public/index.ts +20 -0
  76. package/src/manifest/public/spec/Node.spec.ts +32 -0
  77. package/src/server/app.ts +36 -0
  78. package/src/server/index.ts +13 -0
  79. package/src/server/instrumentation.ts +15 -0
  80. package/src/server/routes/addRoutes.ts +11 -0
  81. package/src/server/routes/address/AddressPathParams.ts +3 -0
  82. package/src/server/routes/address/addNodeRoutes.ts +21 -0
  83. package/src/server/routes/address/get/get.ts +31 -0
  84. package/src/server/routes/address/get/index.ts +1 -0
  85. package/src/server/routes/address/index.ts +1 -0
  86. package/src/server/routes/address/post/getQueryConfig.ts +23 -0
  87. package/src/server/routes/address/post/index.ts +1 -0
  88. package/src/server/routes/address/post/post.ts +77 -0
  89. package/src/server/routes/dataLake/addDataLakeRoutes.ts +9 -0
  90. package/src/server/routes/dataLake/archivistMiddleware.ts +86 -0
  91. package/src/server/routes/dataLake/index.ts +1 -0
  92. package/src/server/routes/healthz/addHealthRoutes.ts +14 -0
  93. package/src/server/routes/healthz/index.ts +1 -0
  94. package/src/server/routes/index.ts +3 -0
  95. package/src/server/server.ts +63 -0
@@ -0,0 +1,618 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/server/app.ts
5
+ import { customPoweredByHeader, disableCaseSensitiveRouting, disableExpressDefaultPoweredByHeader, getJsonBodyParser, getJsonBodyParserOptions, responseProfiler, standardErrors, standardResponses } from "@xylabs/express";
6
+ import compression from "compression";
7
+ import cors from "cors";
8
+ import express2 from "express";
9
+
10
+ // src/server/instrumentation.ts
11
+ import { registerInstrumentations } from "@opentelemetry/instrumentation";
12
+ import { ExpressInstrumentation } from "@opentelemetry/instrumentation-express";
13
+ import { HttpInstrumentation } from "@opentelemetry/instrumentation-http";
14
+ var addInstrumentation = /* @__PURE__ */ __name(() => {
15
+ const instrumentations = [
16
+ new HttpInstrumentation(),
17
+ new ExpressInstrumentation()
18
+ ];
19
+ registerInstrumentations({
20
+ instrumentations
21
+ });
22
+ }, "addInstrumentation");
23
+
24
+ // src/server/routes/address/addNodeRoutes.ts
25
+ import { StatusCodes as StatusCodes3 } from "http-status-codes";
26
+
27
+ // src/server/routes/address/get/get.ts
28
+ import { asyncHandler } from "@xylabs/express";
29
+ import { asAddress } from "@xylabs/hex";
30
+ import { isDefined } from "@xylabs/typeof";
31
+ import { isModuleName } from "@xyo-network/module-model";
32
+ import { StatusCodes } from "http-status-codes";
33
+ var handler = /* @__PURE__ */ __name(async (req, res, next) => {
34
+ const { address: moduleIdentifier } = req.params;
35
+ const { node } = req.app;
36
+ const address = asAddress(moduleIdentifier);
37
+ if (isDefined(address)) {
38
+ let mod = node.address === address ? node : await node.resolve(address, {
39
+ direction: "down"
40
+ });
41
+ if (mod) {
42
+ res.json(await mod.state());
43
+ return;
44
+ }
45
+ }
46
+ if (isModuleName(moduleIdentifier)) {
47
+ const mod = await node.resolve(moduleIdentifier, {
48
+ direction: "down"
49
+ });
50
+ if (mod) {
51
+ res.redirect(StatusCodes.MOVED_TEMPORARILY, `/${mod.address}`);
52
+ return;
53
+ }
54
+ }
55
+ next("route");
56
+ }, "handler");
57
+ var getAddress = asyncHandler(handler);
58
+
59
+ // src/server/routes/address/post/post.ts
60
+ import { assertEx } from "@xylabs/assert";
61
+ import { asyncHandler as asyncHandler2 } from "@xylabs/express";
62
+ import { asAddress as asAddress2, isAddress, toAddress } from "@xylabs/hex";
63
+ import { isQueryBoundWitness } from "@xyo-network/boundwitness-model";
64
+ import { ModuleErrorBuilder } from "@xyo-network/module-abstract";
65
+ import { StatusCodes as StatusCodes2 } from "http-status-codes";
66
+
67
+ // src/server/routes/address/post/getQueryConfig.ts
68
+ import { BoundWitnessSchema } from "@xyo-network/boundwitness-model";
69
+ import { ModuleConfigSchema } from "@xyo-network/module-model";
70
+ var DEFAULT_DEPTH = 5;
71
+ var getQueryConfig = /* @__PURE__ */ __name((mod, req, bw, payloads) => {
72
+ const nestedBwAddresses = payloads?.flat(DEFAULT_DEPTH).filter((payload) => payload?.schema === BoundWitnessSchema).map((bw2) => bw2.addresses) ?? [];
73
+ const addresses = [
74
+ bw.addresses,
75
+ ...nestedBwAddresses
76
+ ].filter((address) => address.length > 0);
77
+ const allowed = addresses.length > 0 ? Object.fromEntries(mod.queries.map((schema) => [
78
+ schema,
79
+ addresses
80
+ ])) : {};
81
+ const security = {
82
+ allowed
83
+ };
84
+ return {
85
+ schema: ModuleConfigSchema,
86
+ security
87
+ };
88
+ }, "getQueryConfig");
89
+
90
+ // src/server/routes/address/post/post.ts
91
+ var handler2 = /* @__PURE__ */ __name(async (req, res, next) => {
92
+ const returnError = /* @__PURE__ */ __name((code, message = "An error occurred", details) => {
93
+ const error = new ModuleErrorBuilder().message(message).details(details).build();
94
+ res.locals.rawResponse = false;
95
+ res.status(code).json(error);
96
+ next();
97
+ }, "returnError");
98
+ const { address } = req.params;
99
+ const { node } = req.app;
100
+ const [bw, payloads] = Array.isArray(req.body) ? req.body : [];
101
+ if (!isAddress(address)) {
102
+ return returnError(StatusCodes2.BAD_REQUEST, "Missing address");
103
+ }
104
+ if (!bw) {
105
+ return returnError(StatusCodes2.BAD_REQUEST, "Missing boundwitness");
106
+ }
107
+ if (!isQueryBoundWitness(bw)) {
108
+ return returnError(StatusCodes2.BAD_REQUEST, "Invalid query boundwitness");
109
+ }
110
+ let modules = [];
111
+ const normalizedAddress = toAddress(address);
112
+ if (node.address === normalizedAddress) modules = [
113
+ node
114
+ ];
115
+ else {
116
+ const typedAddress = asAddress2(address);
117
+ const byAddress = typedAddress === void 0 ? void 0 : await node.resolve(typedAddress, {
118
+ maxDepth: 10
119
+ });
120
+ if (byAddress) modules = [
121
+ byAddress
122
+ ];
123
+ else {
124
+ const byName = await node.resolve(address, {
125
+ direction: "down"
126
+ });
127
+ if (byName) {
128
+ const moduleAddress = assertEx(byName?.address, () => "Error redirecting to module by address");
129
+ res.redirect(StatusCodes2.TEMPORARY_REDIRECT, `/${moduleAddress}`);
130
+ return;
131
+ } else {
132
+ return returnError(StatusCodes2.NOT_FOUND, "Module not found", {
133
+ address
134
+ });
135
+ }
136
+ }
137
+ }
138
+ if (modules.length > 0) {
139
+ const mod = modules[0];
140
+ const queryConfig = getQueryConfig(mod, req, bw, payloads);
141
+ try {
142
+ const queryResult = await mod.query(bw, payloads, queryConfig);
143
+ res.json(queryResult);
144
+ } catch (ex) {
145
+ return returnError(StatusCodes2.INTERNAL_SERVER_ERROR, "Query Failed", {
146
+ message: ex?.message ?? "Unknown Error"
147
+ });
148
+ }
149
+ } else {
150
+ return returnError(StatusCodes2.NOT_FOUND, "Module not found", {
151
+ address
152
+ });
153
+ }
154
+ }, "handler");
155
+ var postAddress = asyncHandler2(handler2);
156
+
157
+ // src/server/routes/address/addNodeRoutes.ts
158
+ var addNodeRoutes = /* @__PURE__ */ __name((app) => {
159
+ const defaultModule = app.node;
160
+ const address = defaultModule.address;
161
+ const defaultModuleEndpoint = `/${address}`;
162
+ app.get("/", (_req, res) => res.redirect(StatusCodes3.MOVED_TEMPORARILY, defaultModuleEndpoint));
163
+ app.post("/", (_req, res) => res.redirect(StatusCodes3.TEMPORARY_REDIRECT, defaultModuleEndpoint));
164
+ app.get("/:address", getAddress);
165
+ app.post("/:address", postAddress);
166
+ app.get("/:hash", (_req, res) => {
167
+ res.sendStatus(StatusCodes3.NOT_FOUND);
168
+ });
169
+ app.post("/:hash", (_req, res) => {
170
+ res.sendStatus(StatusCodes3.NOT_FOUND);
171
+ });
172
+ }, "addNodeRoutes");
173
+
174
+ // src/server/routes/dataLake/archivistMiddleware.ts
175
+ import { setRawResponseFormat } from "@xylabs/express";
176
+ import { asHash } from "@xylabs/hex";
177
+ import { isDefined as isDefined2 } from "@xylabs/typeof";
178
+ import { asArchivistInstance } from "@xyo-network/archivist-model";
179
+ import { PayloadBuilder } from "@xyo-network/payload-builder";
180
+ import { isAnyPayload, isSequence } from "@xyo-network/payload-model";
181
+ import express from "express";
182
+ var resolveArchivist = /* @__PURE__ */ __name(async (node, archivistModuleIdentifier) => {
183
+ const mod = await node.resolve(archivistModuleIdentifier);
184
+ return asArchivistInstance(mod, {
185
+ required: true
186
+ });
187
+ }, "resolveArchivist");
188
+ var archivistInstance;
189
+ var getArchivist = /* @__PURE__ */ __name(async (node, archivistModuleIdentifier) => {
190
+ if (isDefined2(archivistInstance)) return archivistInstance;
191
+ archivistInstance = await resolveArchivist(node, archivistModuleIdentifier);
192
+ return archivistInstance;
193
+ }, "getArchivist");
194
+ var archivistMiddleware = /* @__PURE__ */ __name((options) => {
195
+ const { node, archivistModuleIdentifier } = options;
196
+ const router = express.Router({
197
+ mergeParams: true
198
+ });
199
+ router.post("/insert", async (req, res) => {
200
+ setRawResponseFormat(res);
201
+ const body = Array.isArray(req.body) ? req.body : [
202
+ req.body
203
+ ];
204
+ const payloads = (await PayloadBuilder.hashPairs(body)).map((p) => p[0]);
205
+ const archivist = await getArchivist(node, archivistModuleIdentifier);
206
+ const result = await archivist.insert(payloads);
207
+ res.status(200).json(result);
208
+ });
209
+ router.get("/next", async (req, res) => {
210
+ setRawResponseFormat(res);
211
+ const cursor = isSequence(req.query.cursor) ? req.query.cursor : void 0;
212
+ const limit = isDefined2(req.query.limit) ? Number(req.query.limit) : void 0;
213
+ const open = isDefined2(req.query.open) ? Boolean(req.query.open) : void 0;
214
+ const order = req.query.order === "asc" ? "asc" : "desc";
215
+ const options2 = {
216
+ limit,
217
+ open,
218
+ order,
219
+ cursor
220
+ };
221
+ const archivist = await getArchivist(node, archivistModuleIdentifier);
222
+ const result = await archivist.next(options2);
223
+ res.status(200).json(result);
224
+ });
225
+ router.post("/next", async (req, res) => {
226
+ setRawResponseFormat(res);
227
+ const options2 = req.body;
228
+ const archivist = await getArchivist(node, archivistModuleIdentifier);
229
+ const result = await (isDefined2(options2) ? archivist.next(options2) : archivist.next());
230
+ res.status(200).json(result);
231
+ });
232
+ router.get("/get/:hash", async (req, res) => {
233
+ setRawResponseFormat(res);
234
+ const { hash: rawHash } = req.params;
235
+ const hash = asHash(rawHash);
236
+ if (isDefined2(hash)) {
237
+ const archivist = await getArchivist(node, archivistModuleIdentifier);
238
+ const [payload] = await archivist.get([
239
+ hash
240
+ ]);
241
+ if (isAnyPayload(payload)) {
242
+ res.json(payload);
243
+ return;
244
+ }
245
+ }
246
+ res.status(400).send();
247
+ });
248
+ return router;
249
+ }, "archivistMiddleware");
250
+
251
+ // src/server/routes/dataLake/addDataLakeRoutes.ts
252
+ var addDataLakeRoutes = /* @__PURE__ */ __name((app) => {
253
+ const { node } = app;
254
+ const archivistModuleIdentifier = "Chain:Finalized";
255
+ app.use("/chain", archivistMiddleware({
256
+ node,
257
+ archivistModuleIdentifier
258
+ }));
259
+ }, "addDataLakeRoutes");
260
+
261
+ // src/server/routes/healthz/addHealthRoutes.ts
262
+ import { StatusCodes as StatusCodes4 } from "http-status-codes";
263
+ var addHealthRoutes = /* @__PURE__ */ __name((app) => {
264
+ app.get("/healthz", (_req, res) => {
265
+ res.status(StatusCodes4.OK).send();
266
+ });
267
+ app.get("/livez", (_req, res) => {
268
+ res.status(StatusCodes4.OK).send();
269
+ });
270
+ app.get("/readyz", (_req, res) => {
271
+ res.status(StatusCodes4.OK).send();
272
+ });
273
+ }, "addHealthRoutes");
274
+
275
+ // src/server/routes/addRoutes.ts
276
+ var addRoutes = /* @__PURE__ */ __name((app) => {
277
+ addHealthRoutes(app);
278
+ addDataLakeRoutes(app);
279
+ addNodeRoutes(app);
280
+ }, "addRoutes");
281
+
282
+ // src/server/app.ts
283
+ var getApp = /* @__PURE__ */ __name((node) => {
284
+ addInstrumentation();
285
+ const app = express2();
286
+ app.set("etag", false);
287
+ app.use(cors());
288
+ app.use(compression());
289
+ app.use(responseProfiler);
290
+ app.use(getJsonBodyParser(getJsonBodyParserOptions({
291
+ limit: "1mb"
292
+ })));
293
+ app.use(standardResponses);
294
+ disableExpressDefaultPoweredByHeader(app);
295
+ app.use(customPoweredByHeader);
296
+ disableCaseSensitiveRouting(app);
297
+ app.node = node;
298
+ addRoutes(app);
299
+ app.use(standardErrors);
300
+ return app;
301
+ }, "getApp");
302
+
303
+ // src/server/server.ts
304
+ import { assertEx as assertEx3 } from "@xylabs/assert";
305
+ import { isDefined as isDefined4, isString } from "@xylabs/typeof";
306
+ import { boot } from "@xyo-network/bios";
307
+ import { HDWallet } from "@xyo-network/wallet";
308
+
309
+ // src/manifest/getLocator.ts
310
+ import { assertEx as assertEx2 } from "@xylabs/assert";
311
+ import { asAddress as asAddress3, ZERO_ADDRESS } from "@xylabs/hex";
312
+ import { isDefined as isDefined3 } from "@xylabs/typeof";
313
+ import { MemoryArchivist } from "@xyo-network/archivist-memory";
314
+ import { MongoDBArchivistV2 } from "@xyo-network/archivist-mongodb";
315
+ import { ViewArchivist } from "@xyo-network/archivist-view";
316
+ import { HeadValidationDiviner } from "@xyo-network/chain-modules";
317
+ import { initTelemetry } from "@xyo-network/chain-telemetry";
318
+ import { AbstractModule, LoggerModuleStatusReporter } from "@xyo-network/module-abstract";
319
+ import { ModuleFactoryLocator } from "@xyo-network/module-factory-locator";
320
+ import { MemorySentinel } from "@xyo-network/sentinel-memory";
321
+ import { hasMongoConfig } from "@xyo-network/xl1-protocol-sdk";
322
+ var getLocator = /* @__PURE__ */ __name(async (context) => {
323
+ const { config, logger } = context;
324
+ const { otlpEndpoint } = config.telemetry?.otel ?? {};
325
+ const { traceProvider, meterProvider } = await initTelemetry({
326
+ attributes: {
327
+ serviceName: "xl1-api",
328
+ serviceVersion: "1.0.0"
329
+ },
330
+ otlpEndpoint,
331
+ metricsConfig: {
332
+ endpoint: "/metrics",
333
+ port: 9465
334
+ }
335
+ });
336
+ if (isDefined3(logger)) AbstractModule.defaultLogger = logger;
337
+ const statusReporter = logger ? new LoggerModuleStatusReporter(logger) : void 0;
338
+ const locator = new ModuleFactoryLocator();
339
+ const mongoConfig = config.storage?.mongo;
340
+ if (hasMongoConfig(mongoConfig)) {
341
+ const { connectionString: dbConnectionString, database: dbName, domain: dbDomain, password: dbPassword, username: dbUserName } = mongoConfig;
342
+ const payloadSdkConfig = {
343
+ dbConnectionString,
344
+ dbDomain,
345
+ dbName,
346
+ dbPassword,
347
+ dbUserName
348
+ };
349
+ const params = {
350
+ meterProvider,
351
+ payloadSdkConfig,
352
+ statusReporter,
353
+ traceProvider
354
+ };
355
+ locator.register(MongoDBArchivistV2.factory(params), void 0, true);
356
+ }
357
+ const chainId = isDefined3(config.chain.id) ? assertEx2(asAddress3(config.chain.id), () => "chain.id must be an Address") : ZERO_ADDRESS;
358
+ locator.register(HeadValidationDiviner.factory({
359
+ traceProvider,
360
+ meterProvider,
361
+ statusReporter,
362
+ chainId,
363
+ allowedProducers: config.producer.allowlist
364
+ }));
365
+ locator.register(MemoryArchivist.factory({
366
+ traceProvider,
367
+ meterProvider,
368
+ statusReporter
369
+ }));
370
+ locator.register(MemorySentinel.factory({
371
+ traceProvider,
372
+ meterProvider,
373
+ statusReporter
374
+ }));
375
+ locator.register(ViewArchivist.factory({
376
+ traceProvider,
377
+ meterProvider,
378
+ statusReporter
379
+ }));
380
+ return locator;
381
+ }, "getLocator");
382
+
383
+ // src/manifest/getNode.ts
384
+ import { ManifestWrapper } from "@xyo-network/manifest-wrapper";
385
+
386
+ // src/manifest/node.json
387
+ var node_default = {
388
+ $schema: "https://raw.githubusercontent.com/XYOracleNetwork/sdk-xyo-client-js/main/packages/manifest/src/schema.json",
389
+ nodes: [
390
+ {
391
+ config: {
392
+ accountPath: "44'/60'/1",
393
+ name: "XYOChain",
394
+ schema: "network.xyo.node.config"
395
+ },
396
+ modules: {
397
+ private: [],
398
+ public: []
399
+ }
400
+ }
401
+ ],
402
+ schema: "network.xyo.manifest"
403
+ };
404
+
405
+ // src/manifest/nodeManifest.ts
406
+ var NodeManifest = node_default;
407
+
408
+ // src/manifest/private/index.ts
409
+ var PrivateChildManifests = [];
410
+
411
+ // src/manifest/public/Chain.json
412
+ var Chain_default = {
413
+ $schema: "https://raw.githubusercontent.com/XYOracleNetwork/sdk-xyo-client-js/main/packages/manifest/src/schema.json",
414
+ nodes: [
415
+ {
416
+ config: {
417
+ accountPath: "1",
418
+ name: "Chain",
419
+ schema: "network.xyo.node.config"
420
+ },
421
+ modules: {
422
+ private: [
423
+ {
424
+ config: {
425
+ accountPath: "1/1'/1'",
426
+ name: "Validated",
427
+ getCache: {
428
+ enabled: true,
429
+ maxEntries: 5e3
430
+ },
431
+ payloadSdkConfig: {
432
+ collection: "chain_validated"
433
+ },
434
+ schema: "network.xyo.archivist.config"
435
+ }
436
+ },
437
+ {
438
+ config: {
439
+ accountPath: "1/1'/2'",
440
+ schema: "network.xyo.diviner.chain.head.validation.config",
441
+ eventSubscriptions: [
442
+ {
443
+ sourceEvent: "inserted",
444
+ sourceModule: "Submissions",
445
+ targetModuleFunction: "divine"
446
+ }
447
+ ],
448
+ inArchivist: "Submissions",
449
+ outArchivist: "Validated",
450
+ name: "HeadValidationDiviner"
451
+ }
452
+ },
453
+ {
454
+ config: {
455
+ accountPath: "1/1'/3'",
456
+ automations: [
457
+ {
458
+ frequency: 1e3,
459
+ frequencyUnits: "millis",
460
+ schema: "network.xyo.automation.interval",
461
+ type: "interval"
462
+ }
463
+ ],
464
+ name: "ChainValidationSentinel",
465
+ schema: "network.xyo.sentinel.config",
466
+ synchronous: true,
467
+ tasks: [
468
+ {
469
+ mod: "HeadValidationDiviner",
470
+ endPoint: "divine"
471
+ }
472
+ ]
473
+ }
474
+ }
475
+ ],
476
+ public: [
477
+ {
478
+ config: {
479
+ accountPath: "1/1/1",
480
+ name: "Submissions",
481
+ getCache: {
482
+ enabled: true,
483
+ maxEntries: 5e3
484
+ },
485
+ payloadSdkConfig: {
486
+ collection: "chain_submissions"
487
+ },
488
+ schema: "network.xyo.archivist.config"
489
+ }
490
+ },
491
+ {
492
+ config: {
493
+ accountPath: "1/1/2",
494
+ name: "Finalized",
495
+ allowedQueries: [
496
+ "network.xyo.query.archivist.get",
497
+ "network.xyo.query.archivist.next"
498
+ ],
499
+ getCache: {
500
+ enabled: true,
501
+ maxEntries: 5e4
502
+ },
503
+ originArchivist: "Validated",
504
+ schema: "network.xyo.archivist.view.config"
505
+ }
506
+ }
507
+ ]
508
+ }
509
+ }
510
+ ],
511
+ schema: "network.xyo.manifest"
512
+ };
513
+
514
+ // src/manifest/public/Pending.json
515
+ var Pending_default = {
516
+ $schema: "https://raw.githubusercontent.com/XYOracleNetwork/sdk-xyo-client-js/main/packages/manifest/src/schema.json",
517
+ nodes: [
518
+ {
519
+ config: {
520
+ accountPath: "2",
521
+ name: "Pending",
522
+ schema: "network.xyo.node.config"
523
+ },
524
+ modules: {
525
+ private: [],
526
+ public: [
527
+ {
528
+ config: {
529
+ accountPath: "2/1/1",
530
+ name: "PendingTransactions",
531
+ getCache: {
532
+ enabled: true,
533
+ maxEntries: 5e3
534
+ },
535
+ labels: {
536
+ "network.xyo.storage.class": "mongodb"
537
+ },
538
+ payloadSdkConfig: {
539
+ collection: "pending_bundles"
540
+ },
541
+ schema: "network.xyo.archivist.config"
542
+ }
543
+ }
544
+ ]
545
+ }
546
+ }
547
+ ],
548
+ schema: "network.xyo.manifest"
549
+ };
550
+
551
+ // src/manifest/public/index.ts
552
+ var ChainNodeManifest = Chain_default;
553
+ var PendingNodeManifest = Pending_default;
554
+ var PublicChildManifests = [
555
+ ...ChainNodeManifest.nodes,
556
+ ...PendingNodeManifest.nodes
557
+ ];
558
+
559
+ // src/manifest/getNode.ts
560
+ var getNode = /* @__PURE__ */ __name(async (context) => {
561
+ const { wallet } = context;
562
+ const locator = await getLocator(context);
563
+ const wrapper = new ManifestWrapper(NodeManifest, wallet, locator, PublicChildManifests, PrivateChildManifests);
564
+ const [node, ...childNodes] = await wrapper.loadNodes();
565
+ if (childNodes?.length > 0) {
566
+ await Promise.all(childNodes.map((childNode) => node.register(childNode)));
567
+ await Promise.all(childNodes.map((childNode) => node.attach(childNode.address, true)));
568
+ }
569
+ return node;
570
+ }, "getNode");
571
+
572
+ // src/server/server.ts
573
+ var hostname = "::";
574
+ var getSeedPhrase = /* @__PURE__ */ __name(async (bios, config, logger) => {
575
+ const storedSeedPhrase = await bios.seedPhraseStore.get("os");
576
+ logger?.debug(`[API] Stored mnemonic: ${storedSeedPhrase}`);
577
+ const { mnemonic } = config.api;
578
+ if (isString(storedSeedPhrase) && isString(mnemonic)) {
579
+ logger?.warn("[API] Stored mnemonic does not match supplied. Updating stored mnemonic to supplied.");
580
+ await bios.seedPhraseStore.set("os", mnemonic);
581
+ } else {
582
+ let seedPhrase;
583
+ if (isString(mnemonic)) {
584
+ seedPhrase = mnemonic;
585
+ } else {
586
+ seedPhrase = HDWallet.generateMnemonic();
587
+ logger?.log("[API] No mnemonic provided, using random mnemonic. This is not recommended for production use.");
588
+ logger?.log(`[API] Mnemonic: ${seedPhrase}`);
589
+ }
590
+ await bios.seedPhraseStore.set("os", seedPhrase);
591
+ }
592
+ return assertEx3(await bios.seedPhraseStore.get("os"), () => "Unable to acquire mnemonic from bios");
593
+ }, "getSeedPhrase");
594
+ var getServer = /* @__PURE__ */ __name(async (context) => {
595
+ const { config, logger, node } = context;
596
+ const { mnemonic, port } = context.config.mempool;
597
+ const bios = await boot();
598
+ const seedPhrase = isDefined4(mnemonic) ? mnemonic : await getSeedPhrase(bios, config, logger);
599
+ const wallet = await HDWallet.fromPhrase(seedPhrase);
600
+ const nodeContext = {
601
+ wallet,
602
+ logger,
603
+ config
604
+ };
605
+ const resolvedNode = node ?? await getNode(nodeContext);
606
+ const mods = await resolvedNode.resolve("*");
607
+ const startResults = await Promise.all(mods.map((mod) => mod.start?.() ?? true));
608
+ assertEx3(startResults.every((r) => r === true), () => "[Mempool] Not all modules started successfully");
609
+ const app = getApp(resolvedNode);
610
+ const server = app.listen(port, hostname, () => logger?.log(`[Mempool] Server listening at http://${hostname}:${port}`));
611
+ server.setTimeout(2e4);
612
+ return server;
613
+ }, "getServer");
614
+ export {
615
+ getApp,
616
+ getServer
617
+ };
618
+ //# sourceMappingURL=index.mjs.map