@xyo-network/xl1-protocol-sdk 1.30.3 → 2.0.0
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/neutral/block/hydrate/BoundWitnessHydrator.d.ts +8 -12
- package/dist/neutral/block/hydrate/BoundWitnessHydrator.d.ts.map +1 -1
- package/dist/neutral/block/hydrate/createBoundWitnessHydrator.d.ts +30 -30
- package/dist/neutral/block/hydrate/createBoundWitnessHydrator.d.ts.map +1 -1
- package/dist/neutral/config/Actor.d.ts +50 -56
- package/dist/neutral/config/Actor.d.ts.map +1 -1
- package/dist/neutral/config/Actors.d.ts +65 -66
- package/dist/neutral/config/Actors.d.ts.map +1 -1
- package/dist/neutral/config/Base.d.ts +47 -47
- package/dist/neutral/config/Base.d.ts.map +1 -1
- package/dist/neutral/config/Chain.d.ts +4 -4
- package/dist/neutral/config/Chain.d.ts.map +1 -1
- package/dist/neutral/config/Config.d.ts +96 -98
- package/dist/neutral/config/Config.d.ts.map +1 -1
- package/dist/neutral/config/HostActor.d.ts +51 -57
- package/dist/neutral/config/HostActor.d.ts.map +1 -1
- package/dist/neutral/config/Validation.d.ts +2 -2
- package/dist/neutral/context/Actor.d.ts +51 -57
- package/dist/neutral/context/Actor.d.ts.map +1 -1
- package/dist/neutral/context/HostActor.d.ts +53 -59
- package/dist/neutral/context/HostActor.d.ts.map +1 -1
- package/dist/neutral/eip-712/Payloads/EIP712Signature.d.ts +1 -1
- package/dist/neutral/getFileConfig.d.ts +0 -1
- package/dist/neutral/getFileConfig.d.ts.map +1 -1
- package/dist/neutral/getFileConfig.mjs +29 -35
- package/dist/neutral/getFileConfig.mjs.map +3 -3
- package/dist/neutral/index.mjs +443 -424
- package/dist/neutral/index.mjs.map +4 -4
- package/dist/neutral/model/CreatableProviderContext.zod.d.ts +52 -52
- package/dist/neutral/model/CreatableProviderContext.zod.d.ts.map +1 -1
- package/dist/neutral/primitives/datalake/NamedDataLake.d.ts +7 -0
- package/dist/neutral/primitives/datalake/NamedDataLake.d.ts.map +1 -0
- package/dist/neutral/primitives/datalake/PayloadLocator.d.ts +55 -0
- package/dist/neutral/primitives/datalake/PayloadLocator.d.ts.map +1 -0
- package/dist/neutral/primitives/datalake/index.d.ts +2 -0
- package/dist/neutral/primitives/datalake/index.d.ts.map +1 -1
- package/dist/neutral/simple/StakeEventsViewer/SimpleStakeEventsViewer.d.ts +3 -2
- package/dist/neutral/simple/StakeEventsViewer/SimpleStakeEventsViewer.d.ts.map +1 -1
- package/dist/neutral/simple/StakeTotalsViewer/SimpleStakeTotalsViewer.d.ts +3 -2
- package/dist/neutral/simple/StakeTotalsViewer/SimpleStakeTotalsViewer.d.ts.map +1 -1
- package/dist/neutral/simple/StakeViewer/SimpleStakeViewer.d.ts +4 -3
- package/dist/neutral/simple/StakeViewer/SimpleStakeViewer.d.ts.map +1 -1
- package/dist/neutral/simple/TransactionViewer/SimpleTransactionViewer.d.ts +4 -3
- package/dist/neutral/simple/TransactionViewer/SimpleTransactionViewer.d.ts.map +1 -1
- package/dist/neutral/simple/block/SimpleBlockViewer.d.ts +2 -2
- package/dist/neutral/simple/block/SimpleBlockViewer.d.ts.map +1 -1
- package/dist/neutral/simple/blockInvalidation/SimpleBlockInvalidationViewer.d.ts +1 -1
- package/dist/neutral/simple/blockInvalidation/SimpleBlockInvalidationViewer.d.ts.map +1 -1
- package/dist/neutral/simple/blockReward/SimpleBlockRewardViewer.d.ts +4 -3
- package/dist/neutral/simple/blockReward/SimpleBlockRewardViewer.d.ts.map +1 -1
- package/dist/neutral/simple/blockValidation/SimpleBlockValidationViewer.d.ts +2 -1
- package/dist/neutral/simple/blockValidation/SimpleBlockValidationViewer.d.ts.map +1 -1
- package/dist/neutral/simple/chainContractViewer/SimpleChainContractViewer.d.ts +3 -2
- package/dist/neutral/simple/chainContractViewer/SimpleChainContractViewer.d.ts.map +1 -1
- package/dist/neutral/simple/datalake/RestDataLakeRunner.d.ts +3 -3
- package/dist/neutral/simple/datalake/RestDataLakeRunner.d.ts.map +1 -1
- package/dist/neutral/simple/datalake/RestDataLakeViewer.d.ts +3 -2
- package/dist/neutral/simple/datalake/RestDataLakeViewer.d.ts.map +1 -1
- package/dist/neutral/simple/datalake/SimpleDataLakeRunner.d.ts +2 -2
- package/dist/neutral/simple/datalake/SimpleDataLakeRunner.d.ts.map +1 -1
- package/dist/neutral/simple/datalake/SimpleDataLakeViewer.d.ts +3 -2
- package/dist/neutral/simple/datalake/SimpleDataLakeViewer.d.ts.map +1 -1
- package/dist/neutral/simple/finalization/SimpleFinalizationRunner.d.ts +4 -4
- package/dist/neutral/simple/finalization/SimpleFinalizationRunner.d.ts.map +1 -1
- package/dist/neutral/simple/finalization/SimpleFinalizationViewer.d.ts +5 -4
- package/dist/neutral/simple/finalization/SimpleFinalizationViewer.d.ts.map +1 -1
- package/dist/neutral/simple/mempool/SimpleMempoolRunner.d.ts +4 -4
- package/dist/neutral/simple/mempool/SimpleMempoolRunner.d.ts.map +1 -1
- package/dist/neutral/simple/mempool/SimpleMempoolViewer.d.ts +3 -2
- package/dist/neutral/simple/mempool/SimpleMempoolViewer.d.ts.map +1 -1
- package/dist/neutral/simple/runner/SimpleXyoRunner.d.ts +1 -1
- package/dist/neutral/simple/runner/SimpleXyoRunner.d.ts.map +1 -1
- package/dist/neutral/simple/transactionInvalidation/SimpleTransactionInvalidationViewer.d.ts +1 -1
- package/dist/neutral/simple/transactionInvalidation/SimpleTransactionInvalidationViewer.d.ts.map +1 -1
- package/dist/neutral/simple/transactionValidation/SimpleTransactionValidationViewer.d.ts +1 -1
- package/dist/neutral/simple/transactionValidation/SimpleTransactionValidationViewer.d.ts.map +1 -1
- package/dist/neutral/test/index.mjs +29 -41
- package/dist/neutral/test/index.mjs.map +2 -2
- package/package.json +58 -58
package/dist/neutral/index.mjs
CHANGED
|
@@ -201,37 +201,132 @@ var blockPayloadsFromHydratedBlock = (block) => {
|
|
|
201
201
|
};
|
|
202
202
|
|
|
203
203
|
// src/block/hydrate/BoundWitnessHydrator.ts
|
|
204
|
-
import { assertEx as assertEx3 } from "@xylabs/sdk-js";
|
|
205
204
|
import {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
} from "@
|
|
205
|
+
assertEx as assertEx4,
|
|
206
|
+
isDefined,
|
|
207
|
+
isUndefined as isUndefined3
|
|
208
|
+
} from "@xylabs/sdk-js";
|
|
209
|
+
import { isBoundWitness, PayloadBuilder as PayloadBuilder2 } from "@xyo-network/sdk-js";
|
|
210
210
|
import { LRUCache } from "lru-cache";
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
211
|
+
|
|
212
|
+
// src/primitives/datalake/addDataLakePayloadsToPayloads.ts
|
|
213
|
+
import { isUndefined } from "@xylabs/sdk-js";
|
|
214
|
+
import { isAnyPayload, PayloadBuilder } from "@xyo-network/sdk-js";
|
|
215
|
+
async function addDataLakePayloadsToPayloads(hashes, payloads, dataLakeViewer) {
|
|
216
|
+
if (isUndefined(dataLakeViewer)) return [payloads, []];
|
|
217
|
+
const missingPayloadHashes = hashes.filter((hash) => !payloads.some((p) => p._hash === hash));
|
|
218
|
+
const payloadsFromDataLake = await PayloadBuilder.addHashMeta(
|
|
219
|
+
await PayloadBuilder.addHashMeta((await dataLakeViewer.get(missingPayloadHashes)).filter(isAnyPayload))
|
|
220
|
+
);
|
|
221
|
+
return [[...payloads, ...payloadsFromDataLake], payloadsFromDataLake.map((p) => p._hash)];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// src/primitives/datalake/addDataLakePayloads.ts
|
|
225
|
+
async function addDataLakePayloads([boundWitness, payloads], dataLakeViewer) {
|
|
226
|
+
const [updatedPayloads, foundHashes] = await addDataLakePayloadsToPayloads(boundWitness.payload_hashes, payloads, dataLakeViewer);
|
|
227
|
+
return [
|
|
228
|
+
[
|
|
229
|
+
boundWitness,
|
|
230
|
+
updatedPayloads
|
|
231
|
+
],
|
|
232
|
+
foundHashes
|
|
233
|
+
];
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// src/primitives/datalake/PayloadLocator.ts
|
|
237
|
+
import { assertEx as assertEx3, isUndefined as isUndefined2 } from "@xylabs/sdk-js";
|
|
238
|
+
import { isAnyPayload as isAnyPayload2 } from "@xyo-network/sdk-js";
|
|
239
|
+
var PayloadLocator = class {
|
|
216
240
|
datalakes;
|
|
217
|
-
isNestedBoundWitness;
|
|
218
|
-
payloadCache;
|
|
219
|
-
sourceCache;
|
|
220
241
|
/**
|
|
221
242
|
* @throws if `params.datalakes` is empty. Required at construction to fail fast on misconfig.
|
|
222
|
-
* The only zero-datalake
|
|
223
|
-
*
|
|
224
|
-
* If lifecycle ordering ever requires construction before sources are wired, prefer adding
|
|
225
|
-
* an `addDatalake()` mutator over removing this assertion.
|
|
243
|
+
* The only zero-datalake calls that wouldn't already throw are degenerate (no hashes input),
|
|
244
|
+
* not load-bearing enough to justify loosening the guard.
|
|
226
245
|
*/
|
|
227
246
|
constructor(params) {
|
|
228
|
-
assertEx3(params.datalakes.length > 0, () => "
|
|
247
|
+
assertEx3(params.datalakes.length > 0, () => "PayloadLocator requires at least one datalake");
|
|
229
248
|
const seen = /* @__PURE__ */ new Set();
|
|
230
249
|
for (const dl of params.datalakes) {
|
|
231
250
|
assertEx3(!seen.has(dl.name), () => `Duplicate datalake name: ${dl.name}`);
|
|
232
251
|
seen.add(dl.name);
|
|
233
252
|
}
|
|
234
253
|
this.datalakes = params.datalakes;
|
|
254
|
+
}
|
|
255
|
+
async findAll(input) {
|
|
256
|
+
if (typeof input === "string") {
|
|
257
|
+
const m = await this.findAllBatch([input]);
|
|
258
|
+
return m.get(input) ?? [];
|
|
259
|
+
}
|
|
260
|
+
return await this.findAllBatch(input);
|
|
261
|
+
}
|
|
262
|
+
async findFirst(input) {
|
|
263
|
+
if (typeof input === "string") {
|
|
264
|
+
const m = await this.findFirstBatch([input]);
|
|
265
|
+
return m.get(input);
|
|
266
|
+
}
|
|
267
|
+
return await this.findFirstBatch(input);
|
|
268
|
+
}
|
|
269
|
+
/** Fetch a single hash from a single datalake, filtering non-Payload entries. */
|
|
270
|
+
async fetchOne(dl, hash) {
|
|
271
|
+
const arr = await dl.viewer.get([hash]);
|
|
272
|
+
for (const item of arr) {
|
|
273
|
+
if (isAnyPayload2(item)) return item;
|
|
274
|
+
}
|
|
275
|
+
return void 0;
|
|
276
|
+
}
|
|
277
|
+
async findAllBatch(hashes) {
|
|
278
|
+
const result = /* @__PURE__ */ new Map();
|
|
279
|
+
if (hashes.length === 0) return result;
|
|
280
|
+
const buckets = hashes.map(() => []);
|
|
281
|
+
for (const dl of this.datalakes) {
|
|
282
|
+
const fetched = await Promise.all(hashes.map(async (h) => await this.fetchOne(dl, h)));
|
|
283
|
+
for (const [i, p] of fetched.entries()) {
|
|
284
|
+
if (isUndefined2(p)) continue;
|
|
285
|
+
buckets[i].push({ payload: p, source: dl.name });
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
for (const [i, h] of hashes.entries()) result.set(h, buckets[i]);
|
|
289
|
+
return result;
|
|
290
|
+
}
|
|
291
|
+
async findFirstBatch(hashes) {
|
|
292
|
+
const result = /* @__PURE__ */ new Map();
|
|
293
|
+
if (hashes.length === 0) return result;
|
|
294
|
+
const remaining = new Set(hashes);
|
|
295
|
+
for (const dl of this.datalakes) {
|
|
296
|
+
if (remaining.size === 0) break;
|
|
297
|
+
const needHashes = [];
|
|
298
|
+
for (const h of hashes) if (remaining.has(h)) needHashes.push(h);
|
|
299
|
+
const fetched = await Promise.all(needHashes.map(async (h) => await this.fetchOne(dl, h)));
|
|
300
|
+
for (const [i, h] of needHashes.entries()) {
|
|
301
|
+
const p = fetched[i];
|
|
302
|
+
if (isUndefined2(p)) continue;
|
|
303
|
+
result.set(h, { payload: p, source: dl.name });
|
|
304
|
+
remaining.delete(h);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return result;
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
// src/block/hydrate/BoundWitnessHydrator.ts
|
|
312
|
+
var DEFAULT_CACHE_MAX = 5e3;
|
|
313
|
+
var DEFAULT_CACHE_TTL = Number.MAX_SAFE_INTEGER;
|
|
314
|
+
var BoundWitnessHydrator = class {
|
|
315
|
+
asBoundWitness;
|
|
316
|
+
asHydrated;
|
|
317
|
+
isNestedBoundWitness;
|
|
318
|
+
locator;
|
|
319
|
+
payloadCache;
|
|
320
|
+
sourceCache;
|
|
321
|
+
/**
|
|
322
|
+
* @throws if `params.datalakes` is empty (propagated from PayloadLocator). Required at construction
|
|
323
|
+
* to fail fast on misconfig. The only zero-datalake hydrate calls that would succeed anyway are
|
|
324
|
+
* degenerate (maxDepth=0 or a BW with empty payload_hashes) — not load-bearing enough to justify
|
|
325
|
+
* loosening the guard. If lifecycle ordering ever requires construction before sources are wired,
|
|
326
|
+
* prefer adding an `addDatalake()` mutator over removing this assertion.
|
|
327
|
+
*/
|
|
328
|
+
constructor(params) {
|
|
329
|
+
this.locator = new PayloadLocator({ datalakes: params.datalakes });
|
|
235
330
|
this.asBoundWitness = params.asBoundWitness;
|
|
236
331
|
this.asHydrated = params.asHydrated;
|
|
237
332
|
this.isNestedBoundWitness = params.isNestedBoundWitness ?? isBoundWitness;
|
|
@@ -269,11 +364,11 @@ var BoundWitnessHydrator = class {
|
|
|
269
364
|
const fetched = await this.fetchByHashes(bw.payload_hashes, sources);
|
|
270
365
|
if (minDepth >= 1) {
|
|
271
366
|
const missing = bw.payload_hashes.filter((h) => !fetched.has(h));
|
|
272
|
-
|
|
367
|
+
assertEx4(missing.length === 0, () => `Unable to find all payloads for BoundWitness: missing ${missing.join(", ")}`);
|
|
273
368
|
}
|
|
274
369
|
for (const h of bw.payload_hashes) {
|
|
275
370
|
const p = fetched.get(h);
|
|
276
|
-
if (p
|
|
371
|
+
if (isUndefined3(p) || orderedHashes.has(h)) continue;
|
|
277
372
|
orderedHashes.add(h);
|
|
278
373
|
orderedPayloads.push(p);
|
|
279
374
|
}
|
|
@@ -289,73 +384,56 @@ var BoundWitnessHydrator = class {
|
|
|
289
384
|
const fetched = await this.fetchByHashes(nestedHashes, sources);
|
|
290
385
|
if (minDepth >= 2) {
|
|
291
386
|
const missing = nestedHashes.filter((h) => !fetched.has(h));
|
|
292
|
-
|
|
387
|
+
assertEx4(missing.length === 0, () => `Unable to find all nested payloads for BoundWitness: missing ${missing.join(", ")}`);
|
|
293
388
|
}
|
|
294
389
|
for (const h of nestedHashes) {
|
|
295
390
|
const p = fetched.get(h);
|
|
296
|
-
if (p
|
|
391
|
+
if (isUndefined3(p) || orderedHashes.has(h)) continue;
|
|
297
392
|
orderedHashes.add(h);
|
|
298
393
|
orderedPayloads.push(p);
|
|
299
394
|
}
|
|
300
395
|
}
|
|
301
396
|
async fetchByHash(hash, sources) {
|
|
302
397
|
const cached = this.payloadCache.get(hash);
|
|
303
|
-
if (cached
|
|
398
|
+
if (isDefined(cached)) {
|
|
304
399
|
const cachedSource = this.sourceCache.get(hash);
|
|
305
|
-
if (cachedSource
|
|
400
|
+
if (isDefined(cachedSource)) sources.set(hash, cachedSource);
|
|
306
401
|
return cached;
|
|
307
402
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
sources.set(hash, dl.name);
|
|
315
|
-
return data;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
return void 0;
|
|
403
|
+
const located = await this.locator.findFirst(hash);
|
|
404
|
+
if (isUndefined3(located)) return void 0;
|
|
405
|
+
this.payloadCache.set(hash, located.payload);
|
|
406
|
+
this.sourceCache.set(hash, located.source);
|
|
407
|
+
sources.set(hash, located.source);
|
|
408
|
+
return located.payload;
|
|
319
409
|
}
|
|
320
410
|
async fetchByHashes(hashes, sources) {
|
|
321
411
|
const result = /* @__PURE__ */ new Map();
|
|
322
|
-
const remaining =
|
|
412
|
+
const remaining = [];
|
|
323
413
|
for (const h of hashes) {
|
|
324
414
|
const cached = this.payloadCache.get(h);
|
|
325
|
-
if (cached
|
|
326
|
-
remaining.
|
|
415
|
+
if (isUndefined3(cached)) {
|
|
416
|
+
remaining.push(h);
|
|
327
417
|
continue;
|
|
328
418
|
}
|
|
329
419
|
result.set(h, cached);
|
|
330
420
|
const cachedSource = this.sourceCache.get(h);
|
|
331
|
-
if (cachedSource
|
|
421
|
+
if (isDefined(cachedSource)) sources.set(h, cachedSource);
|
|
332
422
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
}
|
|
341
|
-
return void 0;
|
|
342
|
-
}));
|
|
343
|
-
for (const [i, h] of needHashes.entries()) {
|
|
344
|
-
const p = fetched[i];
|
|
345
|
-
if (p === void 0) continue;
|
|
346
|
-
result.set(h, p);
|
|
347
|
-
this.payloadCache.set(h, p);
|
|
348
|
-
this.sourceCache.set(h, dl.name);
|
|
349
|
-
sources.set(h, dl.name);
|
|
350
|
-
remaining.delete(h);
|
|
351
|
-
}
|
|
423
|
+
if (remaining.length === 0) return result;
|
|
424
|
+
const located = await this.locator.findFirst(remaining);
|
|
425
|
+
for (const [h, { payload, source }] of located) {
|
|
426
|
+
result.set(h, payload);
|
|
427
|
+
this.payloadCache.set(h, payload);
|
|
428
|
+
this.sourceCache.set(h, source);
|
|
429
|
+
sources.set(h, source);
|
|
352
430
|
}
|
|
353
431
|
return result;
|
|
354
432
|
}
|
|
355
433
|
async hydrateInternal(input, maxDepth, minDepth) {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
434
|
+
assertEx4(maxDepth >= 0 && maxDepth <= 2, () => `maxDepth must be 0, 1, or 2 (got ${maxDepth})`);
|
|
435
|
+
assertEx4(minDepth >= 0 && minDepth <= 2, () => `minDepth must be 0, 1, or 2 (got ${minDepth})`);
|
|
436
|
+
assertEx4(maxDepth >= minDepth, () => `maxDepth (${maxDepth}) must be >= minDepth (${minDepth})`);
|
|
359
437
|
const sources = /* @__PURE__ */ new Map();
|
|
360
438
|
const bw = await this.resolveBoundWitness(input, sources);
|
|
361
439
|
if (maxDepth === 0) {
|
|
@@ -371,13 +449,13 @@ var BoundWitnessHydrator = class {
|
|
|
371
449
|
}
|
|
372
450
|
async resolveBoundWitness(input, sources) {
|
|
373
451
|
if (typeof input === "string") {
|
|
374
|
-
const fetched =
|
|
452
|
+
const fetched = assertEx4(
|
|
375
453
|
await this.fetchByHash(input, sources),
|
|
376
454
|
() => `BoundWitness ${input} not found in any datalake`
|
|
377
455
|
);
|
|
378
456
|
return this.asBoundWitness(fetched, true);
|
|
379
457
|
}
|
|
380
|
-
const withMeta = "_hash" in input ? input : await
|
|
458
|
+
const withMeta = "_hash" in input ? input : await PayloadBuilder2.addStorageMeta(input);
|
|
381
459
|
return this.asBoundWitness(withMeta, true);
|
|
382
460
|
}
|
|
383
461
|
};
|
|
@@ -399,12 +477,12 @@ import {
|
|
|
399
477
|
PayloadZod,
|
|
400
478
|
WithStorageMetaZod
|
|
401
479
|
} from "@xyo-network/sdk-js";
|
|
402
|
-
import { z } from "zod";
|
|
480
|
+
import { z } from "zod/mini";
|
|
403
481
|
var BoundWitnessWithStorageMetaZod = WithStorageMetaZod(BoundWitnessZod);
|
|
404
482
|
var asBoundWitnessWithStorageMeta = zodAsFactory(BoundWitnessWithStorageMetaZod, "asBoundWitnessWithStorageMeta");
|
|
405
483
|
var HydratedBoundWitnessWithStorageMetaZod = z.tuple([
|
|
406
484
|
BoundWitnessWithStorageMetaZod,
|
|
407
|
-
z.array(WithStorageMetaZod(PayloadZod).
|
|
485
|
+
z.array(z.looseObject(WithStorageMetaZod(PayloadZod).shape))
|
|
408
486
|
]);
|
|
409
487
|
var asHydratedBoundWitnessWithStorageMeta = zodAsFactory(
|
|
410
488
|
HydratedBoundWitnessWithStorageMetaZod,
|
|
@@ -445,30 +523,30 @@ var unflattenHydratedBlock = (flattened) => toHydratedBlock(tryUnflattenHydrated
|
|
|
445
523
|
var flattenHydratedBlocks = (hydratedBlocks) => hydratedBlocks.flatMap((blk) => flattenHydratedBlock(blk));
|
|
446
524
|
|
|
447
525
|
// src/block/hydrate/hydrateBlock.ts
|
|
448
|
-
import { assertEx as
|
|
526
|
+
import { assertEx as assertEx5 } from "@xylabs/sdk-js";
|
|
449
527
|
import { asAnyPayload } from "@xyo-network/sdk-js";
|
|
450
528
|
import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta2, isTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol-lib";
|
|
451
529
|
var hydrateBlock = async (context, hash, maxDepth = 1, minDepth = maxDepth) => {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
530
|
+
assertEx5(maxDepth >= 0, () => "maxDepth must be greater than or equal to 0");
|
|
531
|
+
assertEx5(minDepth >= 0, () => "minDepth must be greater than or equal to 0");
|
|
532
|
+
assertEx5(maxDepth >= minDepth, () => "maxDepth must be greater than or equal to minDepth");
|
|
455
533
|
const { chainMap } = context;
|
|
456
534
|
const [block] = await chainMap.get([hash]);
|
|
457
|
-
const bw =
|
|
458
|
-
|
|
535
|
+
const bw = assertEx5(asBlockBoundWitnessWithStorageMeta2(
|
|
536
|
+
assertEx5(block, () => `block ${hash} not found`)
|
|
459
537
|
), () => `hash ${hash} is not a BlockBoundWitness`);
|
|
460
538
|
if (maxDepth === 0) return [bw, []];
|
|
461
539
|
const blkPayloads = (await chainMap.get(bw.payload_hashes)).map((p) => asAnyPayload(p, true));
|
|
462
|
-
if (minDepth === 1)
|
|
540
|
+
if (minDepth === 1) assertEx5(allHashesPresent(bw.payload_hashes, blkPayloads), () => `Unable to find all payloads for block ${hash}`);
|
|
463
541
|
if (maxDepth === 1) return [bw, blkPayloads];
|
|
464
542
|
const transactions = blkPayloads.filter(isTransactionBoundWitnessWithStorageMeta);
|
|
465
543
|
const transactionsPayloadHashes = transactions.flatMap((tx) => tx.payload_hashes);
|
|
466
544
|
const transactionsPayloads = (await chainMap.get(transactionsPayloadHashes)).map((p) => asAnyPayload(p, true));
|
|
467
|
-
|
|
545
|
+
assertEx5(allHashesPresent(transactionsPayloadHashes, transactionsPayloads), () => `Unable to find all payloads for transactions in block ${hash}`);
|
|
468
546
|
const allPayloadsHashes = new Set([...blkPayloads, ...transactionsPayloads].flatMap((p) => p._hash));
|
|
469
547
|
const allPayloads = (await chainMap.get([...allPayloadsHashes])).map((p) => asAnyPayload(p, true));
|
|
470
548
|
const allPayloadsFiltered = allPayloads.filter((p) => allPayloadsHashes.has(p._hash));
|
|
471
|
-
if (maxDepth === 2)
|
|
549
|
+
if (maxDepth === 2) assertEx5(allHashesPresent(
|
|
472
550
|
[...allPayloadsHashes],
|
|
473
551
|
allPayloadsFiltered
|
|
474
552
|
), () => `Unable to find all payloads for transactions in block ${hash}`);
|
|
@@ -482,10 +560,10 @@ var transactionsFromHydratedBlock = (block) => {
|
|
|
482
560
|
};
|
|
483
561
|
|
|
484
562
|
// src/block/hydrate/tryHydrateBlock.ts
|
|
485
|
-
import { assertEx as
|
|
563
|
+
import { assertEx as assertEx6 } from "@xylabs/sdk-js";
|
|
486
564
|
import { isBlockBoundWitnessWithStorageMeta, isTransactionBoundWitnessWithStorageMeta as isTransactionBoundWitnessWithStorageMeta2 } from "@xyo-network/xl1-protocol-lib";
|
|
487
565
|
var tryHydrateBlock = async (archivist, hash, maxDepth = 1) => {
|
|
488
|
-
|
|
566
|
+
assertEx6(maxDepth >= 0, () => "maxDepth must be greater than or equal to 0");
|
|
489
567
|
const bw = (await archivist.get([hash])).find(isBlockBoundWitnessWithStorageMeta);
|
|
490
568
|
if (!bw) return void 0;
|
|
491
569
|
if (maxDepth === 0) return [bw, []];
|
|
@@ -503,7 +581,7 @@ var tryHydrateBlock = async (archivist, hash, maxDepth = 1) => {
|
|
|
503
581
|
// src/block/primitives/blockFromBlockNumber.ts
|
|
504
582
|
import {
|
|
505
583
|
asHash,
|
|
506
|
-
isDefined as
|
|
584
|
+
isDefined as isDefined4,
|
|
507
585
|
spanAsync
|
|
508
586
|
} from "@xylabs/sdk-js";
|
|
509
587
|
import { toSafeJsonString } from "@xylabs/sdk-js";
|
|
@@ -515,9 +593,9 @@ import {
|
|
|
515
593
|
|
|
516
594
|
// src/ChainContextHelpers.ts
|
|
517
595
|
import {
|
|
518
|
-
isDefined as
|
|
596
|
+
isDefined as isDefined3,
|
|
519
597
|
isObject,
|
|
520
|
-
isUndefined,
|
|
598
|
+
isUndefined as isUndefined4,
|
|
521
599
|
timeBudget
|
|
522
600
|
} from "@xylabs/sdk-js";
|
|
523
601
|
|
|
@@ -561,7 +639,7 @@ var LruCacheMap = class {
|
|
|
561
639
|
};
|
|
562
640
|
|
|
563
641
|
// src/driver/memory/MemoryMap.ts
|
|
564
|
-
import { isDefined } from "@xylabs/sdk-js";
|
|
642
|
+
import { isDefined as isDefined2 } from "@xylabs/sdk-js";
|
|
565
643
|
var MemoryMap = class {
|
|
566
644
|
map;
|
|
567
645
|
constructor() {
|
|
@@ -580,7 +658,7 @@ var MemoryMap = class {
|
|
|
580
658
|
const results = [];
|
|
581
659
|
for (const id of ids) {
|
|
582
660
|
const data = this.map.get(id);
|
|
583
|
-
if (
|
|
661
|
+
if (isDefined2(data)) {
|
|
584
662
|
results.push(data);
|
|
585
663
|
}
|
|
586
664
|
}
|
|
@@ -604,7 +682,7 @@ function contextCache(context, name, create) {
|
|
|
604
682
|
if (!isObject(context.caches)) {
|
|
605
683
|
throw new Error("Context does not have an appropriate caches property");
|
|
606
684
|
}
|
|
607
|
-
if (
|
|
685
|
+
if (isUndefined4(context.caches[name])) {
|
|
608
686
|
context.caches[name] = create?.() ?? new MemoryMap();
|
|
609
687
|
}
|
|
610
688
|
return context.caches[name];
|
|
@@ -617,7 +695,7 @@ async function withContextCacheResponse(context, name, key, func, { max = 1e4 }
|
|
|
617
695
|
);
|
|
618
696
|
const { timeBudgetLimit = 0 } = context;
|
|
619
697
|
const cacheResult = await cache.get(key);
|
|
620
|
-
if (
|
|
698
|
+
if (isDefined3(cacheResult)) {
|
|
621
699
|
return cacheResult;
|
|
622
700
|
}
|
|
623
701
|
const result = timeBudgetLimit > 0 ? timeBudget(name, context.logger, func, timeBudgetLimit) : func();
|
|
@@ -632,7 +710,7 @@ async function blockFromBlockNumber(context, blockNumber) {
|
|
|
632
710
|
const { chainMap, head } = context;
|
|
633
711
|
return await withContextCacheResponse(context, "blockFromBlockNumber", cacheKey, async () => {
|
|
634
712
|
const [result] = await chainMap.get([head._hash]);
|
|
635
|
-
if (!
|
|
713
|
+
if (!isDefined4(result)) {
|
|
636
714
|
throw new Error(`Head block not found for hash: ${head._hash}`);
|
|
637
715
|
}
|
|
638
716
|
let currentBlock = asSignedBlockBoundWitnessWithStorageMeta(
|
|
@@ -655,7 +733,7 @@ async function blockFromBlockNumber(context, blockNumber) {
|
|
|
655
733
|
const [newBlock] = await chainMap.get([
|
|
656
734
|
asHash(jumpHash, () => `Jump hash not found for block number [${blockNumber}]: ${jumpBlockNumber} ${toSafeJsonString(currentBlock, 10)}`)
|
|
657
735
|
]);
|
|
658
|
-
if (!
|
|
736
|
+
if (!isDefined4(newBlock)) {
|
|
659
737
|
throw new Error(`Block not found for jump hash: ${jumpHash}`);
|
|
660
738
|
}
|
|
661
739
|
currentBlock = asSignedBlockBoundWitnessWithStorageMeta(
|
|
@@ -746,12 +824,12 @@ function toStepIdentityString({ block, step }) {
|
|
|
746
824
|
|
|
747
825
|
// src/block/primitives/validateTransactionOpcodes.ts
|
|
748
826
|
import {
|
|
749
|
-
assertEx as
|
|
827
|
+
assertEx as assertEx7,
|
|
750
828
|
isHash,
|
|
751
829
|
toSafeJsonString as toSafeJsonString2
|
|
752
830
|
} from "@xylabs/sdk-js";
|
|
753
831
|
import {
|
|
754
|
-
PayloadBuilder as
|
|
832
|
+
PayloadBuilder as PayloadBuilder3
|
|
755
833
|
} from "@xyo-network/sdk-js";
|
|
756
834
|
import { isExecutable } from "@xyo-network/xl1-protocol-lib";
|
|
757
835
|
async function validateTransactionsOpcodes(txs) {
|
|
@@ -763,14 +841,14 @@ async function validateTransactionsOpcodes(txs) {
|
|
|
763
841
|
switch (opCode) {
|
|
764
842
|
case "elevate": {
|
|
765
843
|
const [hash, ...rest] = args;
|
|
766
|
-
const txPayloadsWithStorageMeta = await
|
|
767
|
-
|
|
844
|
+
const txPayloadsWithStorageMeta = await PayloadBuilder3.addStorageMeta(txPayloads);
|
|
845
|
+
assertEx7(rest.length === 0, () => `Invalid elevate operation ${opCode} ${args.join(", ")} - Too many Arguments`);
|
|
768
846
|
if (isHash(hash)) {
|
|
769
|
-
|
|
847
|
+
assertEx7(
|
|
770
848
|
txBw.payload_hashes.includes(hash),
|
|
771
849
|
() => `Invalid elevate operation ${opCode} ${args.join(", ")} - Hash not in payload hashes => ${toSafeJsonString2(txBw, 20)}`
|
|
772
850
|
);
|
|
773
|
-
const txPayload =
|
|
851
|
+
const txPayload = assertEx7(
|
|
774
852
|
txPayloadsWithStorageMeta.find((p) => p._hash === hash),
|
|
775
853
|
() => `Invalid elevate operation ${opCode} ${args.join(", ")} - Payload not found`
|
|
776
854
|
);
|
|
@@ -1069,21 +1147,21 @@ import {
|
|
|
1069
1147
|
zodIsFactory as zodIsFactory2,
|
|
1070
1148
|
zodToFactory as zodToFactory2
|
|
1071
1149
|
} from "@xylabs/sdk-js";
|
|
1072
|
-
import { globalRegistry as globalRegistry12, z as z17 } from "zod";
|
|
1150
|
+
import { globalRegistry as globalRegistry12, z as z17 } from "zod/mini";
|
|
1073
1151
|
|
|
1074
1152
|
// src/config/Base.ts
|
|
1075
|
-
import { z as z16 } from "zod";
|
|
1153
|
+
import { z as z16 } from "zod/mini";
|
|
1076
1154
|
|
|
1077
1155
|
// src/config/Chain.ts
|
|
1078
1156
|
import { AddressZod, HexZod } from "@xylabs/sdk-js";
|
|
1079
|
-
import { globalRegistry, z as z2 } from "zod";
|
|
1157
|
+
import { globalRegistry, z as z2 } from "zod/mini";
|
|
1080
1158
|
var ChainConfigZod = z2.object({
|
|
1081
|
-
id:
|
|
1159
|
+
id: z2.optional(HexZod).register(globalRegistry, {
|
|
1082
1160
|
description: "The unique identifier for the chain. Should be the staking contract address for contract-backed chains.",
|
|
1083
1161
|
title: "chain.id",
|
|
1084
1162
|
type: "string"
|
|
1085
1163
|
}),
|
|
1086
|
-
genesisRewardAddress:
|
|
1164
|
+
genesisRewardAddress: z2.optional(AddressZod).register(globalRegistry, {
|
|
1087
1165
|
description: "Address to send the initial genesis rewards to, if a new chain is being created.",
|
|
1088
1166
|
title: "chain.genesisRewardAddress",
|
|
1089
1167
|
type: "Address"
|
|
@@ -1241,11 +1319,11 @@ var RpcRemoteConfigZod = z11.union([HttpRpcRemoteConfigZod, PostMessageRpcRemote
|
|
|
1241
1319
|
var RemoteConfigZod = z11.object({ rpc: RpcRemoteConfigZod.optional() }).describe("Configuration for remote connections, including RPC");
|
|
1242
1320
|
|
|
1243
1321
|
// src/config/storage/driver/Mongo.ts
|
|
1244
|
-
import { isDefined as
|
|
1322
|
+
import { isDefined as isDefined5, isUndefined as isUndefined5 } from "@xylabs/sdk-js";
|
|
1245
1323
|
import { globalRegistry as globalRegistry8, z as z12 } from "zod";
|
|
1246
1324
|
var hasMongoConfig = (config) => {
|
|
1247
|
-
if (
|
|
1248
|
-
return
|
|
1325
|
+
if (isUndefined5(config)) return false;
|
|
1326
|
+
return isDefined5(config.connectionString) && isDefined5(config.database) && isDefined5(config.domain);
|
|
1249
1327
|
};
|
|
1250
1328
|
var MongoConfigZod = z12.object({
|
|
1251
1329
|
// TODO: Create from other arguments
|
|
@@ -1348,11 +1426,11 @@ function blockRangeSteps(range, steps) {
|
|
|
1348
1426
|
}
|
|
1349
1427
|
|
|
1350
1428
|
// src/primitives/block/rate/blockRate.ts
|
|
1351
|
-
import { isDefined as
|
|
1429
|
+
import { isDefined as isDefined7, isFalsy } from "@xylabs/sdk-js";
|
|
1352
1430
|
import { asXL1BlockRange } from "@xyo-network/xl1-protocol-lib";
|
|
1353
1431
|
|
|
1354
1432
|
// src/primitives/block/rate/timeHelpers.ts
|
|
1355
|
-
import { assertEx as
|
|
1433
|
+
import { assertEx as assertEx8, isDefined as isDefined6 } from "@xylabs/sdk-js";
|
|
1356
1434
|
var rateMultipliers = {
|
|
1357
1435
|
millis: 1,
|
|
1358
1436
|
seconds: 1e3,
|
|
@@ -1370,7 +1448,7 @@ var timeDurations = (timeInMs) => ({
|
|
|
1370
1448
|
weeks: timeInMs / (1e3 * 60 * 60 * 24 * 7)
|
|
1371
1449
|
});
|
|
1372
1450
|
var getTimeConfigInMilliseconds = (timeConfig) => {
|
|
1373
|
-
const assertedTimeConfig =
|
|
1451
|
+
const assertedTimeConfig = assertEx8(isDefined6(timeConfig) ? timeConfig : void 0, () => "Time configuration must be provided");
|
|
1374
1452
|
let totalMilliseconds = 0;
|
|
1375
1453
|
if ("years" in assertedTimeConfig) {
|
|
1376
1454
|
totalMilliseconds += assertedTimeConfig.years * 31536e6;
|
|
@@ -1409,13 +1487,13 @@ var blockRate = (startBlock, endBlock, timeUnit) => {
|
|
|
1409
1487
|
throw new Error("Time difference must be greater than 0");
|
|
1410
1488
|
}
|
|
1411
1489
|
const rate = heightDifference / timeDifference;
|
|
1412
|
-
const timeUnitValue =
|
|
1413
|
-
const returnedTimeDifference =
|
|
1490
|
+
const timeUnitValue = isDefined7(timeUnit) ? timeUnit : "millis";
|
|
1491
|
+
const returnedTimeDifference = isDefined7(timeUnit) ? timeDurations(timeDifference)[timeUnit] : timeDifference;
|
|
1414
1492
|
const timePerBlock = returnedTimeDifference / heightDifference;
|
|
1415
1493
|
return {
|
|
1416
1494
|
range: asXL1BlockRange([startingBlock.block, endingBlock.block], true),
|
|
1417
1495
|
span: heightDifference,
|
|
1418
|
-
rate:
|
|
1496
|
+
rate: isDefined7(timeUnit) ? rate * rateMultipliers[timeUnit] : rate,
|
|
1419
1497
|
timeUnit: timeUnitValue,
|
|
1420
1498
|
timeDifference: returnedTimeDifference,
|
|
1421
1499
|
timePerBlock
|
|
@@ -1443,7 +1521,7 @@ var calculateBlockRate = async (viewer, range, timeUnit) => {
|
|
|
1443
1521
|
};
|
|
1444
1522
|
|
|
1445
1523
|
// src/primitives/block/rate/stepRate.ts
|
|
1446
|
-
import { assertEx as
|
|
1524
|
+
import { assertEx as assertEx9 } from "@xylabs/sdk-js";
|
|
1447
1525
|
import {
|
|
1448
1526
|
asXL1BlockRange as asXL1BlockRange2,
|
|
1449
1527
|
isValidStep,
|
|
@@ -1455,26 +1533,26 @@ var stepRate = async (viewer, start, step, count = 1, timeUnit) => {
|
|
|
1455
1533
|
return await calculateBlockRate(viewer, range, timeUnit);
|
|
1456
1534
|
};
|
|
1457
1535
|
var calculateStepSizeRate = async (viewer, start, stepIndex, count = 1, timeUnit) => {
|
|
1458
|
-
|
|
1536
|
+
assertEx9(isValidStep(stepIndex), () => `Invalid step index: ${stepIndex}`);
|
|
1459
1537
|
const step = StepSizes4[stepIndex];
|
|
1460
1538
|
return await stepRate(viewer, start, step, count, timeUnit);
|
|
1461
1539
|
};
|
|
1462
1540
|
|
|
1463
1541
|
// src/primitives/block/rate/timeRate.ts
|
|
1464
1542
|
import {
|
|
1465
|
-
assertEx as
|
|
1466
|
-
isDefined as
|
|
1543
|
+
assertEx as assertEx10,
|
|
1544
|
+
isDefined as isDefined8,
|
|
1467
1545
|
isDefinedNotNull
|
|
1468
1546
|
} from "@xylabs/sdk-js";
|
|
1469
1547
|
import { asXL1BlockNumber as asXL1BlockNumber3, asXL1BlockRange as asXL1BlockRange3 } from "@xyo-network/xl1-protocol-lib";
|
|
1470
1548
|
var DEFAULT_TOLERANCE_MS = 3e4;
|
|
1471
1549
|
var DEFAULT_MAX_ATTEMPTS = 10;
|
|
1472
1550
|
var calculateTimeRate = async (viewer, timeConfig, startBlockNumber, timeUnit, toleranceMs = DEFAULT_TOLERANCE_MS, maxAttempts = DEFAULT_MAX_ATTEMPTS) => {
|
|
1473
|
-
|
|
1551
|
+
assertEx10(Object.keys(timeConfig ?? {}).length === 1, () => "Only one time unit should be specified in timeConfig");
|
|
1474
1552
|
const startBlock = isDefinedNotNull(startBlockNumber) ? await viewer.blockByNumber(startBlockNumber) : null;
|
|
1475
1553
|
const resolvedStartBlock = isDefinedNotNull(startBlock) ? startBlock[0] : (await viewer.currentBlock())[0];
|
|
1476
1554
|
const timeInMilliseconds = getTimeConfigInMilliseconds(timeConfig);
|
|
1477
|
-
|
|
1555
|
+
assertEx10(timeInMilliseconds > 0, () => "Time duration must be greater than zero");
|
|
1478
1556
|
const blocksPerMillisecondRate = 1 / (12 * 1e3);
|
|
1479
1557
|
const initialBlocksInDuration = Math.floor(blocksPerMillisecondRate * timeInMilliseconds);
|
|
1480
1558
|
const endBlockNumber = await findEndBlockRecursive(
|
|
@@ -1492,15 +1570,15 @@ var calculateTimeRate = async (viewer, timeConfig, startBlockNumber, timeUnit, t
|
|
|
1492
1570
|
);
|
|
1493
1571
|
};
|
|
1494
1572
|
var findEndBlockRecursive = async (viewer, startBlock, targetTimeMs, estimatedBlocksBack, toleranceMs, attemptsRemaining) => {
|
|
1495
|
-
|
|
1573
|
+
assertEx10(attemptsRemaining >= 0, () => "Maximum attempts reached while searching for end block");
|
|
1496
1574
|
const startBlockEpoch = startBlock.$epoch;
|
|
1497
1575
|
const estimatedEndBlockNumber = asXL1BlockNumber3(startBlock.block - estimatedBlocksBack, true);
|
|
1498
1576
|
if (estimatedEndBlockNumber < 0) {
|
|
1499
1577
|
throw new Error("Estimated end block number is less than zero");
|
|
1500
1578
|
}
|
|
1501
1579
|
const endBlock = await viewer.blockByNumber(estimatedEndBlockNumber);
|
|
1502
|
-
const resolvedEndBlock =
|
|
1503
|
-
|
|
1580
|
+
const resolvedEndBlock = assertEx10(
|
|
1581
|
+
isDefined8(endBlock?.[0]) ? endBlock[0] : void 0,
|
|
1504
1582
|
() => `Could not retrieve block ${estimatedEndBlockNumber} for time rate calculation`
|
|
1505
1583
|
);
|
|
1506
1584
|
const endBlockEpoch = resolvedEndBlock.$epoch;
|
|
@@ -1536,8 +1614,8 @@ var findEndBlockRecursive = async (viewer, startBlock, targetTimeMs, estimatedBl
|
|
|
1536
1614
|
|
|
1537
1615
|
// src/primitives/chain/getWindowedChain.ts
|
|
1538
1616
|
import {
|
|
1539
|
-
assertEx as
|
|
1540
|
-
isDefined as
|
|
1617
|
+
assertEx as assertEx11,
|
|
1618
|
+
isDefined as isDefined9,
|
|
1541
1619
|
isNull,
|
|
1542
1620
|
spanRootAsync
|
|
1543
1621
|
} from "@xylabs/sdk-js";
|
|
@@ -1551,14 +1629,14 @@ async function getWindowedChain(context, blockViewer, maxWindowSize, previousCha
|
|
|
1551
1629
|
while (currentBlock !== null && newChain.length < maxWindowSize) {
|
|
1552
1630
|
const currentBlockNumber = currentBlock[0].block;
|
|
1553
1631
|
const nextBlock = newChain[0];
|
|
1554
|
-
if (
|
|
1632
|
+
if (isDefined9(nextBlock)) {
|
|
1555
1633
|
const nextBlockNumber = nextBlock[0].block;
|
|
1556
|
-
|
|
1634
|
+
assertEx11(
|
|
1557
1635
|
currentBlockNumber === nextBlockNumber - 1,
|
|
1558
1636
|
() => `[getWindowedChain] Non-monotonic block sequence detected: current=${currentBlockNumber}, next=${nextBlockNumber}`
|
|
1559
1637
|
);
|
|
1560
1638
|
}
|
|
1561
|
-
|
|
1639
|
+
assertEx11(
|
|
1562
1640
|
currentBlockNumber <= head[0].block,
|
|
1563
1641
|
() => `[getWindowedChain] Current block number (${currentBlockNumber}) exceeds head block number (${head[0].block})`
|
|
1564
1642
|
);
|
|
@@ -1573,7 +1651,7 @@ async function getWindowedChain(context, blockViewer, maxWindowSize, previousCha
|
|
|
1573
1651
|
|
|
1574
1652
|
// src/primitives/chain/step/chainStepRewardAddress.ts
|
|
1575
1653
|
import {
|
|
1576
|
-
assertEx as
|
|
1654
|
+
assertEx as assertEx14,
|
|
1577
1655
|
exists,
|
|
1578
1656
|
toAddress as toAddress2
|
|
1579
1657
|
} from "@xylabs/sdk-js";
|
|
@@ -1606,7 +1684,7 @@ function stepBlockRange({ block, step }) {
|
|
|
1606
1684
|
}
|
|
1607
1685
|
|
|
1608
1686
|
// src/primitives/step/stepTransferIndex.ts
|
|
1609
|
-
import { assertEx as
|
|
1687
|
+
import { assertEx as assertEx12 } from "@xylabs/sdk-js";
|
|
1610
1688
|
import { StepSizes as StepSizes6 } from "@xyo-network/xl1-protocol-lib";
|
|
1611
1689
|
function stepTransferIndex(block, step) {
|
|
1612
1690
|
let rewardTransferCount = 0;
|
|
@@ -1620,16 +1698,16 @@ function stepTransferIndex(block, step) {
|
|
|
1620
1698
|
rewardTransferCount++;
|
|
1621
1699
|
}
|
|
1622
1700
|
}
|
|
1623
|
-
|
|
1701
|
+
assertEx12(rewardTransferIndex >= 0, () => `Could not find step size for step ${step} at block ${block}`);
|
|
1624
1702
|
return [rewardTransferIndex, rewardTransferCount];
|
|
1625
1703
|
}
|
|
1626
1704
|
|
|
1627
1705
|
// src/primitives/chain/step/stepRewardBlock.ts
|
|
1628
|
-
import { assertEx as
|
|
1706
|
+
import { assertEx as assertEx13 } from "@xylabs/sdk-js";
|
|
1629
1707
|
import { StepSizes as StepSizes7 } from "@xyo-network/xl1-protocol-lib";
|
|
1630
1708
|
async function stepRewardBlock(context, blockViewer, { block, step }) {
|
|
1631
|
-
|
|
1632
|
-
return
|
|
1709
|
+
assertEx13(block % StepSizes7[step] === 0, () => `Block must be the first block of the step [${StepSizes7[step]}], got ${block}`);
|
|
1710
|
+
return assertEx13(await blockViewer.blockByNumber(block), () => `Could not find block for block number ${block}`);
|
|
1633
1711
|
}
|
|
1634
1712
|
|
|
1635
1713
|
// src/primitives/chain/step/chainStepRewardAddress.ts
|
|
@@ -1640,7 +1718,7 @@ async function chainStepRewardAddress(context, blockViewer, { block, step }) {
|
|
|
1640
1718
|
const transfersFromPool = payloads.filter(isTransfer).map((p) => asTransfer(p)).filter(exists).filter((t) => t.from === XYO_STEP_REWARD_ADDRESS);
|
|
1641
1719
|
const fromEntries = Object.entries(mergeTransfers(transfersFromPool)[XYO_STEP_REWARD_ADDRESS]);
|
|
1642
1720
|
const sortedTransferAmounts = fromEntries.toSorted(([, a], [, b]) => a > b ? -1 : a < b ? 1 : 0);
|
|
1643
|
-
|
|
1721
|
+
assertEx14(
|
|
1644
1722
|
sortedTransferAmounts.length === transferCount,
|
|
1645
1723
|
() => `Step Transfers mismatch ${block} (${blockBw._hash}) [${sortedTransferAmounts.length} - ${transferCount}]`
|
|
1646
1724
|
);
|
|
@@ -1648,7 +1726,7 @@ async function chainStepRewardAddress(context, blockViewer, { block, step }) {
|
|
|
1648
1726
|
}
|
|
1649
1727
|
|
|
1650
1728
|
// src/primitives/chain/step/stepRewardTotal.ts
|
|
1651
|
-
import { assertEx as
|
|
1729
|
+
import { assertEx as assertEx15, isDefined as isDefined10 } from "@xylabs/sdk-js";
|
|
1652
1730
|
import {
|
|
1653
1731
|
asAttoXL1,
|
|
1654
1732
|
asXL1BlockRange as asXL1BlockRange5,
|
|
@@ -1743,16 +1821,16 @@ function stepInRange(step, range) {
|
|
|
1743
1821
|
return stepRange[0] >= range[0] && stepRange[1] <= range[1];
|
|
1744
1822
|
}
|
|
1745
1823
|
async function stepRewardTotal(context, blockViewer, { block, step }, multipliers) {
|
|
1746
|
-
const cacheKey = `${block}|${step}|${
|
|
1824
|
+
const cacheKey = `${block}|${step}|${isDefined10(multipliers)}`;
|
|
1747
1825
|
return await withContextCacheResponse(context, "stepRewardTotal", cacheKey, async () => {
|
|
1748
1826
|
const [blockBw, payloads] = await stepRewardBlock(context, blockViewer, { block, step });
|
|
1749
|
-
|
|
1827
|
+
assertEx15(blockBw.block === block, () => `Block Mismatch: expected ${block}, got ${blockBw.block}`);
|
|
1750
1828
|
const [transferIndex] = stepTransferIndex(block, step);
|
|
1751
|
-
const stepTransfer =
|
|
1829
|
+
const stepTransfer = assertEx15(
|
|
1752
1830
|
payloads.find((p) => isTransfer5(p) && p.from === XYO_STEP_REWARD_ADDRESS2),
|
|
1753
1831
|
() => `No step transfer found for step ${step} at block ${block} (${blockBw._hash})`
|
|
1754
1832
|
);
|
|
1755
|
-
const rewards =
|
|
1833
|
+
const rewards = assertEx15(
|
|
1756
1834
|
netTransfersForPayloads(context, [stepTransfer])[XYO_STEP_REWARD_ADDRESS2],
|
|
1757
1835
|
() => `No rewards found for step reward address ${XYO_STEP_REWARD_ADDRESS2} at block ${block} (${blockBw._hash})`
|
|
1758
1836
|
);
|
|
@@ -1795,7 +1873,7 @@ async function stepsRewardTotal(context, blockViewer, steps, multipliers) {
|
|
|
1795
1873
|
}
|
|
1796
1874
|
|
|
1797
1875
|
// src/primitives/chain/time/externalBlockNumberFromXL1BlockNumber.ts
|
|
1798
|
-
import { assertEx as
|
|
1876
|
+
import { assertEx as assertEx16, isArray } from "@xylabs/sdk-js";
|
|
1799
1877
|
import {
|
|
1800
1878
|
asBlockNumber,
|
|
1801
1879
|
asTimePayload,
|
|
@@ -1806,7 +1884,7 @@ async function externalBlockNumberFromXL1BlockNumber(context, blockViewer, xl1Bl
|
|
|
1806
1884
|
const cacheKey = `${xl1BlockNumber}-${externalTimeName}-${externalGenesisTime ?? "default"}`;
|
|
1807
1885
|
return await withContextCacheResponse(context, functionName, cacheKey, async () => {
|
|
1808
1886
|
const [, payloads = []] = await blockViewer.blockByNumber(xl1BlockNumber) ?? [];
|
|
1809
|
-
|
|
1887
|
+
assertEx16(isArray(payloads));
|
|
1810
1888
|
const timePayload = asTimePayload(payloads.find(isTimePayload));
|
|
1811
1889
|
return asBlockNumber(
|
|
1812
1890
|
timePayload?.[externalTimeName] ?? externalGenesisTime ?? 23372716,
|
|
@@ -1831,32 +1909,8 @@ async function externalBlockRangeFromStep(context, blockViewer, stepIdentity) {
|
|
|
1831
1909
|
});
|
|
1832
1910
|
}
|
|
1833
1911
|
|
|
1834
|
-
// src/primitives/datalake/addDataLakePayloadsToPayloads.ts
|
|
1835
|
-
import { isUndefined as isUndefined3 } from "@xylabs/sdk-js";
|
|
1836
|
-
import { isAnyPayload as isAnyPayload2, PayloadBuilder as PayloadBuilder3 } from "@xyo-network/sdk-js";
|
|
1837
|
-
async function addDataLakePayloadsToPayloads(hashes, payloads, dataLakeViewer) {
|
|
1838
|
-
if (isUndefined3(dataLakeViewer)) return [payloads, []];
|
|
1839
|
-
const missingPayloadHashes = hashes.filter((hash) => !payloads.some((p) => p._hash === hash));
|
|
1840
|
-
const payloadsFromDataLake = await PayloadBuilder3.addHashMeta(
|
|
1841
|
-
await PayloadBuilder3.addHashMeta((await dataLakeViewer.get(missingPayloadHashes)).filter(isAnyPayload2))
|
|
1842
|
-
);
|
|
1843
|
-
return [[...payloads, ...payloadsFromDataLake], payloadsFromDataLake.map((p) => p._hash)];
|
|
1844
|
-
}
|
|
1845
|
-
|
|
1846
|
-
// src/primitives/datalake/addDataLakePayloads.ts
|
|
1847
|
-
async function addDataLakePayloads([boundWitness, payloads], dataLakeViewer) {
|
|
1848
|
-
const [updatedPayloads, foundHashes] = await addDataLakePayloadsToPayloads(boundWitness.payload_hashes, payloads, dataLakeViewer);
|
|
1849
|
-
return [
|
|
1850
|
-
[
|
|
1851
|
-
boundWitness,
|
|
1852
|
-
updatedPayloads
|
|
1853
|
-
],
|
|
1854
|
-
foundHashes
|
|
1855
|
-
];
|
|
1856
|
-
}
|
|
1857
|
-
|
|
1858
1912
|
// src/primitives/mapToMapType.ts
|
|
1859
|
-
import { isDefined as
|
|
1913
|
+
import { isDefined as isDefined11 } from "@xylabs/sdk-js";
|
|
1860
1914
|
function mapToMapType(map) {
|
|
1861
1915
|
return {
|
|
1862
1916
|
get: (key) => map.get(key),
|
|
@@ -1875,7 +1929,7 @@ function mapToMapType(map) {
|
|
|
1875
1929
|
const result = [];
|
|
1876
1930
|
for (const key of keys) {
|
|
1877
1931
|
const value = map.get(key);
|
|
1878
|
-
if (
|
|
1932
|
+
if (isDefined11(value)) {
|
|
1879
1933
|
result.push(value);
|
|
1880
1934
|
}
|
|
1881
1935
|
}
|
|
@@ -1890,7 +1944,7 @@ function mapToMapType(map) {
|
|
|
1890
1944
|
}
|
|
1891
1945
|
|
|
1892
1946
|
// src/primitives/readPayloadMapFromStore.ts
|
|
1893
|
-
import { isDefined as
|
|
1947
|
+
import { isDefined as isDefined12 } from "@xylabs/sdk-js";
|
|
1894
1948
|
function readPayloadMapFromStore(store) {
|
|
1895
1949
|
if (isReadArchivist(store)) {
|
|
1896
1950
|
return {
|
|
@@ -1901,7 +1955,7 @@ function readPayloadMapFromStore(store) {
|
|
|
1901
1955
|
return await store.get(hashes);
|
|
1902
1956
|
},
|
|
1903
1957
|
has: async (hash) => {
|
|
1904
|
-
return
|
|
1958
|
+
return isDefined12((await store.get([hash]))[0]);
|
|
1905
1959
|
}
|
|
1906
1960
|
};
|
|
1907
1961
|
}
|
|
@@ -1917,7 +1971,7 @@ function payloadMapFromStore(store) {
|
|
|
1917
1971
|
return await store.get(hashes);
|
|
1918
1972
|
},
|
|
1919
1973
|
has: async (hash) => {
|
|
1920
|
-
return
|
|
1974
|
+
return isDefined12((await store.get([hash]))[0]);
|
|
1921
1975
|
},
|
|
1922
1976
|
clear: async () => {
|
|
1923
1977
|
return await store.clear();
|
|
@@ -1963,7 +2017,7 @@ function rewardFromBlockNumber(blockNumber) {
|
|
|
1963
2017
|
import { XYO_NETWORK_STAKING_ADDRESS } from "@xyo-network/xl1-protocol-lib";
|
|
1964
2018
|
|
|
1965
2019
|
// src/primitives/stake/activeStakeAtTimeByAddress.ts
|
|
1966
|
-
import { isDefined as
|
|
2020
|
+
import { isDefined as isDefined13 } from "@xylabs/sdk-js";
|
|
1967
2021
|
|
|
1968
2022
|
// src/primitives/stake/mergedAddRemoveStakeEventsByStaker.ts
|
|
1969
2023
|
async function mergedAddRemoveStakeEventsByStaker(chainEvents, range, staked, staker) {
|
|
@@ -1982,7 +2036,7 @@ async function activeStakeAtTimeByAddress(chain, staked, time, staker) {
|
|
|
1982
2036
|
for (const event of stakeEvents) {
|
|
1983
2037
|
if (event.time > time) break;
|
|
1984
2038
|
if (event.args.staked !== staked) continue;
|
|
1985
|
-
if (
|
|
2039
|
+
if (isDefined13(staker) && event.args.staker !== staker) continue;
|
|
1986
2040
|
if (event.name === "StakeAdded") {
|
|
1987
2041
|
result += event.args.amount;
|
|
1988
2042
|
} else if (event.name === "StakeRemoved") {
|
|
@@ -1993,7 +2047,7 @@ async function activeStakeAtTimeByAddress(chain, staked, time, staker) {
|
|
|
1993
2047
|
}
|
|
1994
2048
|
|
|
1995
2049
|
// src/primitives/stake/activeStakeAtTimeByPosition.ts
|
|
1996
|
-
import { isUndefined as
|
|
2050
|
+
import { isUndefined as isUndefined6 } from "@xylabs/sdk-js";
|
|
1997
2051
|
|
|
1998
2052
|
// src/primitives/stake/mergedAddRemoveStakeEventsByPosition.ts
|
|
1999
2053
|
async function mergedAddRemoveStakeEventsByPosition(chainEvents, range, position) {
|
|
@@ -2011,7 +2065,7 @@ async function activeStakeAtTimeByPosition(chainStakeEvents, externalTime, posit
|
|
|
2011
2065
|
let result = 0n;
|
|
2012
2066
|
for (const event of stakeEvents) {
|
|
2013
2067
|
if (event.time > externalTime) break;
|
|
2014
|
-
if (
|
|
2068
|
+
if (isUndefined6(position) || position === Number(event.args.id)) {
|
|
2015
2069
|
if (event.name === "StakeAdded") {
|
|
2016
2070
|
result += event.args.amount;
|
|
2017
2071
|
} else if (event.name === "StakeRemoved") {
|
|
@@ -2057,13 +2111,13 @@ async function allStakersForStep(context, blockViewer, stakeEventsViewer, stepCo
|
|
|
2057
2111
|
}
|
|
2058
2112
|
|
|
2059
2113
|
// src/primitives/stake/weightedStakeForRangeByPosition.ts
|
|
2060
|
-
import { isDefined as
|
|
2114
|
+
import { isDefined as isDefined14 } from "@xylabs/sdk-js";
|
|
2061
2115
|
import { asBlockNumber as asBlockNumber2 } from "@xyo-network/xl1-protocol-lib";
|
|
2062
2116
|
async function weightedStakeForRangeByPosition(context, blockViewer, stakeEventsViewer, externalRange, staked, positionId) {
|
|
2063
|
-
const cacheKey =
|
|
2117
|
+
const cacheKey = isDefined14(positionId) ? `${externalRange[0]}-${externalRange[1]}-${positionId}` : `${externalRange[0]}-${externalRange[1]}-all`;
|
|
2064
2118
|
return await withContextCacheResponse(context, "weightedStakeForRangeByPosition", cacheKey, async () => {
|
|
2065
2119
|
let weightedStakeSum = 0n;
|
|
2066
|
-
if (
|
|
2120
|
+
if (isDefined14(positionId)) {
|
|
2067
2121
|
const mergedEvents = (await mergedAddRemoveStakeEventsByPosition(
|
|
2068
2122
|
stakeEventsViewer,
|
|
2069
2123
|
[0, externalRange[1]],
|
|
@@ -2071,7 +2125,7 @@ async function weightedStakeForRangeByPosition(context, blockViewer, stakeEvents
|
|
|
2071
2125
|
)).toSorted((a, b) => a.time - b.time);
|
|
2072
2126
|
let currentTime = externalRange[0];
|
|
2073
2127
|
let currentStake = 0n;
|
|
2074
|
-
if (
|
|
2128
|
+
if (isDefined14(staked) && mergedEvents.at(0)?.args.staked !== staked) {
|
|
2075
2129
|
return 0n;
|
|
2076
2130
|
}
|
|
2077
2131
|
for (const event of mergedEvents) {
|
|
@@ -2143,7 +2197,7 @@ var findMostRecentBlock = async (chainArchivist, nextOptions = DEFAULT_NEXT_OPTI
|
|
|
2143
2197
|
};
|
|
2144
2198
|
|
|
2145
2199
|
// src/primitives/state/hydratedBlockByNumber.ts
|
|
2146
|
-
import { assertEx as
|
|
2200
|
+
import { assertEx as assertEx17, spanAsync as spanAsync2 } from "@xylabs/sdk-js";
|
|
2147
2201
|
async function hydratedBlockByNumber(context, blockNumber) {
|
|
2148
2202
|
return await spanAsync2("hydratedBlockByNumber", async () => {
|
|
2149
2203
|
if (blockNumber < 0) throw new Error(`Block number ${blockNumber} is less than 0`);
|
|
@@ -2151,7 +2205,7 @@ async function hydratedBlockByNumber(context, blockNumber) {
|
|
|
2151
2205
|
if (blockNumber % 1 !== 0) throw new Error(`Block number ${blockNumber} is not an integer`);
|
|
2152
2206
|
const cacheKey = `${blockNumber}`;
|
|
2153
2207
|
return await withContextCacheResponse(context, "hydratedBlockByNumber", cacheKey, async () => {
|
|
2154
|
-
const block =
|
|
2208
|
+
const block = assertEx17(
|
|
2155
2209
|
await blockFromBlockNumber(context, blockNumber),
|
|
2156
2210
|
() => `Could not find block for block number ${blockNumber}`
|
|
2157
2211
|
);
|
|
@@ -2202,7 +2256,7 @@ function findBestUncle(finalizedWindowedChain, uncles, options) {
|
|
|
2202
2256
|
|
|
2203
2257
|
// src/primitives/uncle/findUncles.ts
|
|
2204
2258
|
import {
|
|
2205
|
-
assertEx as
|
|
2259
|
+
assertEx as assertEx18,
|
|
2206
2260
|
exists as exists2
|
|
2207
2261
|
} from "@xylabs/sdk-js";
|
|
2208
2262
|
import { isTransactionBoundWitness as isTransactionBoundWitness2 } from "@xyo-network/xl1-protocol-lib";
|
|
@@ -2232,7 +2286,7 @@ function blocksToChains(blocks) {
|
|
|
2232
2286
|
}
|
|
2233
2287
|
function toValidUncle(_context, finalizedWindowedChain, possibleUncle) {
|
|
2234
2288
|
const finalizedWindowStartBlockNumber = finalizedWindowedChain.at(0)?.[0].block ?? -1;
|
|
2235
|
-
const finalizedHead =
|
|
2289
|
+
const finalizedHead = assertEx18(finalizedWindowedChain.at(-1), () => "finalizedWindowedChain is empty");
|
|
2236
2290
|
const prunedPossibleUncle = possibleUncle.filter((b) => b[0].block > finalizedHead[0].block);
|
|
2237
2291
|
if (prunedPossibleUncle.length === 0) {
|
|
2238
2292
|
return;
|
|
@@ -2287,38 +2341,28 @@ var ValidationConfigZod = z15.object({
|
|
|
2287
2341
|
|
|
2288
2342
|
// src/config/Base.ts
|
|
2289
2343
|
var BaseConfigZod = z16.object({
|
|
2290
|
-
chain:
|
|
2291
|
-
dataLake:
|
|
2292
|
-
evm:
|
|
2293
|
-
log:
|
|
2294
|
-
providers:
|
|
2295
|
-
remote:
|
|
2296
|
-
storage:
|
|
2297
|
-
telemetry:
|
|
2298
|
-
validation:
|
|
2344
|
+
chain: z16._default(ChainConfigZod, ChainConfigZod.parse({})).check(z16.describe("Configuration for the chain")),
|
|
2345
|
+
dataLake: z16.optional(DataLakeConfigZod).check(z16.describe("Configuration for data lakes")),
|
|
2346
|
+
evm: z16._default(EvmConfigZod, EvmConfigZod.parse({})).check(z16.describe("Configuration for EVM-backed services")),
|
|
2347
|
+
log: z16._default(LogConfigZod, LogConfigZod.parse({})).check(z16.describe("Configuration for logging")),
|
|
2348
|
+
providers: z16._default(ProvidersConfigZod, ProvidersConfigZod.parse([])).check(z16.describe("Configuration for providers")),
|
|
2349
|
+
remote: z16._default(RemoteConfigZod, RemoteConfigZod.parse({})).check(z16.describe("Configuration for remote services")),
|
|
2350
|
+
storage: z16._default(StorageConfigZod, StorageConfigZod.parse({})).check(z16.describe("Configuration for the storage")),
|
|
2351
|
+
telemetry: z16._default(TelemetryConfigZod, TelemetryConfigZod.parse({})).check(z16.describe("Configuration for telemetry")),
|
|
2352
|
+
validation: z16._default(ValidationConfigZod, ValidationConfigZod.parse({})).check(z16.describe("Configuration for validation"))
|
|
2299
2353
|
});
|
|
2300
2354
|
|
|
2301
2355
|
// src/config/Actor.ts
|
|
2302
|
-
var AccountPathZod = z17.string().regex(
|
|
2356
|
+
var AccountPathZod = z17.string().check(z17.regex(
|
|
2303
2357
|
/^(m(\/\d+'?)+|\d+'?(\/\d+'?)*)$/,
|
|
2304
2358
|
`Invalid BIP-32 derivation path. Use either an absolute path like "m/44'/60'/0'/0/0" or a relative path like "0", "0/1", or "44'/60'/0'/0/0".`
|
|
2305
|
-
);
|
|
2306
|
-
var ActorConfigZod =
|
|
2359
|
+
));
|
|
2360
|
+
var ActorConfigZod = z17.extend(BaseConfigZod, {
|
|
2307
2361
|
name: z17.string(),
|
|
2308
|
-
accountPath:
|
|
2362
|
+
accountPath: z17.optional(AccountPathZod).register(globalRegistry12, {
|
|
2309
2363
|
description: 'BIP-32 derivation path for the actor wallet. Absolute when it starts with "m/"; otherwise relative to the root wallet base path. Each actor must derive to a distinct path.',
|
|
2310
2364
|
title: "accountPath",
|
|
2311
2365
|
type: "string"
|
|
2312
|
-
}),
|
|
2313
|
-
/**
|
|
2314
|
-
* @deprecated Use the top-level `healthCheckPort` on `ConfigZod` instead.
|
|
2315
|
-
* The system-wide health server covers all actors in a single process; per-actor
|
|
2316
|
-
* health ports will be removed in a future major release.
|
|
2317
|
-
*/
|
|
2318
|
-
healthCheckPort: z17.coerce.number().optional().register(globalRegistry12, {
|
|
2319
|
-
description: "[DEPRECATED \u2014 use top-level healthCheckPort] Per-actor health server port.",
|
|
2320
|
-
title: "actor.healthCheckPort",
|
|
2321
|
-
type: "number"
|
|
2322
2366
|
})
|
|
2323
2367
|
});
|
|
2324
2368
|
var isActorConfig = zodIsFactory2(ActorConfigZod);
|
|
@@ -2326,24 +2370,31 @@ var asActorConfig = zodAsFactory3(ActorConfigZod, "asActorConfig");
|
|
|
2326
2370
|
var toActorConfig = zodToFactory2(ActorConfigZod, "toActorConfig");
|
|
2327
2371
|
|
|
2328
2372
|
// src/config/Actors.ts
|
|
2329
|
-
import z18 from "zod";
|
|
2330
|
-
var ActorsConfigZod = z18.
|
|
2373
|
+
import { z as z18 } from "zod/mini";
|
|
2374
|
+
var ActorsConfigZod = z18._default(
|
|
2375
|
+
z18.array(z18.looseObject(ActorConfigZod.shape)).check(z18.describe("Actor-specific configurations that override the base configuration when the actor is running")),
|
|
2376
|
+
[]
|
|
2377
|
+
);
|
|
2331
2378
|
|
|
2332
2379
|
// src/config/Config.ts
|
|
2333
|
-
import { globalRegistry as globalRegistry13, z as z19 } from "zod";
|
|
2334
|
-
var ConfigZod =
|
|
2380
|
+
import { globalRegistry as globalRegistry13, z as z19 } from "zod/mini";
|
|
2381
|
+
var ConfigZod = z19.extend(BaseConfigZod, {
|
|
2335
2382
|
actors: ActorsConfigZod,
|
|
2336
|
-
healthCheckPort: z19.coerce.number()
|
|
2383
|
+
healthCheckPort: z19.optional(z19.coerce.number()).register(globalRegistry13, {
|
|
2337
2384
|
description: "Port for the system-wide health, readiness, and liveness endpoints (/healthz, /livez, /readyz). Set to 0 to disable.",
|
|
2338
2385
|
title: "healthCheckPort",
|
|
2339
2386
|
type: "number"
|
|
2340
2387
|
})
|
|
2341
|
-
}).describe("The complete configuration for the protocol, including global settings and actor-specific overrides");
|
|
2388
|
+
}).check(z19.describe("The complete configuration for the protocol, including global settings and actor-specific overrides"));
|
|
2342
2389
|
function resolveConfig(config) {
|
|
2343
2390
|
const parsedConfig = ConfigZod.parse(config);
|
|
2344
|
-
const {
|
|
2391
|
+
const {
|
|
2392
|
+
actors,
|
|
2393
|
+
healthCheckPort: _healthCheckPort,
|
|
2394
|
+
...rootConfig
|
|
2395
|
+
} = parsedConfig;
|
|
2345
2396
|
parsedConfig.actors = actors.map((actorConfig) => {
|
|
2346
|
-
return ActorConfigZod.
|
|
2397
|
+
return z19.looseObject(ActorConfigZod.shape).parse({ ...rootConfig, ...actorConfig });
|
|
2347
2398
|
});
|
|
2348
2399
|
return parsedConfig;
|
|
2349
2400
|
}
|
|
@@ -2354,15 +2405,15 @@ import {
|
|
|
2354
2405
|
zodIsFactory as zodIsFactory3,
|
|
2355
2406
|
zodToFactory as zodToFactory3
|
|
2356
2407
|
} from "@xylabs/sdk-js";
|
|
2357
|
-
import { globalRegistry as globalRegistry14, z as z20 } from "zod";
|
|
2358
|
-
var HostActorConfigZod =
|
|
2359
|
-
host: z20.string()
|
|
2408
|
+
import { globalRegistry as globalRegistry14, z as z20 } from "zod/mini";
|
|
2409
|
+
var HostActorConfigZod = z20.extend(ActorConfigZod, {
|
|
2410
|
+
host: z20._default(z20.string(), "localhost").register(globalRegistry14, {
|
|
2360
2411
|
default: "localhost",
|
|
2361
2412
|
description: "Host for the Actor",
|
|
2362
2413
|
title: "host",
|
|
2363
2414
|
type: "string"
|
|
2364
2415
|
}),
|
|
2365
|
-
port: z20.coerce.number()
|
|
2416
|
+
port: z20._default(z20.coerce.number(), 8080).register(globalRegistry14, {
|
|
2366
2417
|
default: 8080,
|
|
2367
2418
|
description: "Port for the Actor",
|
|
2368
2419
|
title: "port",
|
|
@@ -2410,6 +2461,7 @@ import {
|
|
|
2410
2461
|
zodIsFactory as zodIsFactory5,
|
|
2411
2462
|
zodToFactory as zodToFactory5
|
|
2412
2463
|
} from "@xylabs/sdk-js";
|
|
2464
|
+
import { z as z23 } from "zod/mini";
|
|
2413
2465
|
|
|
2414
2466
|
// src/model/CreatableProviderContext.zod.ts
|
|
2415
2467
|
import {
|
|
@@ -2418,17 +2470,17 @@ import {
|
|
|
2418
2470
|
zodToFactory as zodToFactory4
|
|
2419
2471
|
} from "@xylabs/sdk-js";
|
|
2420
2472
|
import { CachingContextZod } from "@xyo-network/xl1-protocol-lib";
|
|
2421
|
-
import { z as z22 } from "zod";
|
|
2473
|
+
import { z as z22 } from "zod/mini";
|
|
2422
2474
|
var RuntimeStatusMonitorZod = z22.custom((val) => val && typeof val === "object");
|
|
2423
2475
|
var ProviderFactoryLocatorZod = z22.lazy(() => z22.custom((val) => val && typeof val === "object" && "context" in val && "registry" in val));
|
|
2424
|
-
var BaseConfigContextZod =
|
|
2425
|
-
config: BaseConfigZod.
|
|
2426
|
-
locator:
|
|
2476
|
+
var BaseConfigContextZod = z22.extend(CachingContextZod, {
|
|
2477
|
+
config: z22.looseObject(BaseConfigZod.shape),
|
|
2478
|
+
locator: z22.optional(ProviderFactoryLocatorZod)
|
|
2427
2479
|
});
|
|
2428
|
-
var CreatableProviderContextZod = z22.lazy(() =>
|
|
2429
|
-
_id: z22.
|
|
2480
|
+
var CreatableProviderContextZod = z22.lazy(() => z22.extend(BaseConfigContextZod, {
|
|
2481
|
+
_id: z22.optional(z22.string()),
|
|
2430
2482
|
locator: ProviderFactoryLocatorZod,
|
|
2431
|
-
statusReporter:
|
|
2483
|
+
statusReporter: z22.optional(RuntimeStatusMonitorZod)
|
|
2432
2484
|
}));
|
|
2433
2485
|
var isBaseConfigContext = zodIsFactory4(BaseConfigContextZod);
|
|
2434
2486
|
var asBaseConfigContext = zodAsFactory5(BaseConfigContextZod, "asBaseConfigContext");
|
|
@@ -2476,7 +2528,7 @@ import { PayloadBundleSchema as PayloadBundleSchema2 } from "@xyo-network/sdk-js
|
|
|
2476
2528
|
import { PayloadBuilder as PayloadBuilder12 } from "@xyo-network/sdk-js";
|
|
2477
2529
|
|
|
2478
2530
|
// src/transaction/buildTransaction.ts
|
|
2479
|
-
import { assertEx as
|
|
2531
|
+
import { assertEx as assertEx19, toHex } from "@xylabs/sdk-js";
|
|
2480
2532
|
import {
|
|
2481
2533
|
asAnyPayload as asAnyPayload2,
|
|
2482
2534
|
BoundWitnessBuilder,
|
|
@@ -2505,7 +2557,7 @@ async function buildTransaction(chain, onChainPayloads, offChainPayloads, signer
|
|
|
2505
2557
|
}
|
|
2506
2558
|
const fields = {
|
|
2507
2559
|
...txBoundWitnessFields,
|
|
2508
|
-
from: from ?? (Array.isArray(signer) ?
|
|
2560
|
+
from: from ?? (Array.isArray(signer) ? assertEx19(signer.at(0)?.address) : signer.address)
|
|
2509
2561
|
};
|
|
2510
2562
|
if (script.length > 0) {
|
|
2511
2563
|
fields.script = script;
|
|
@@ -2547,7 +2599,7 @@ async function buildUnsignedTransaction(chain, onChainPayloads, offChainPayloads
|
|
|
2547
2599
|
}
|
|
2548
2600
|
|
|
2549
2601
|
// src/transaction/confirmSubmittedTransaction.ts
|
|
2550
|
-
import { delay, isDefined as
|
|
2602
|
+
import { delay, isDefined as isDefined15 } from "@xylabs/sdk-js";
|
|
2551
2603
|
var DEFAULT_CONFIRMATION_ATTEMPTS = 20;
|
|
2552
2604
|
var DEFAULT_DELAY_BETWEEN_ATTEMPTS = 1e3;
|
|
2553
2605
|
var confirmSubmittedTransaction = async (viewer, txHash, options) => {
|
|
@@ -2556,7 +2608,7 @@ var confirmSubmittedTransaction = async (viewer, txHash, options) => {
|
|
|
2556
2608
|
let attempts = 0;
|
|
2557
2609
|
while (true) {
|
|
2558
2610
|
const tx = await viewer.transaction.byHash(txHash) ?? void 0;
|
|
2559
|
-
if (
|
|
2611
|
+
if (isDefined15(tx)) {
|
|
2560
2612
|
options?.logger?.debug("Transaction confirmed", txHash);
|
|
2561
2613
|
return tx;
|
|
2562
2614
|
} else {
|
|
@@ -2573,7 +2625,7 @@ var confirmSubmittedTransaction = async (viewer, txHash, options) => {
|
|
|
2573
2625
|
};
|
|
2574
2626
|
|
|
2575
2627
|
// src/transaction/hydrateTransaction.ts
|
|
2576
|
-
import { assertEx as
|
|
2628
|
+
import { assertEx as assertEx20 } from "@xylabs/sdk-js";
|
|
2577
2629
|
import {
|
|
2578
2630
|
asAnyPayload as asAnyPayload3,
|
|
2579
2631
|
hydrateTypedBoundWitness,
|
|
@@ -2648,7 +2700,7 @@ var tryHydrateElevatedTransaction = async ({ chainMap }, hash) => {
|
|
|
2648
2700
|
return void 0;
|
|
2649
2701
|
};
|
|
2650
2702
|
var hydrateElevatedTransaction = async (context, hash) => {
|
|
2651
|
-
return
|
|
2703
|
+
return assertEx20(await tryHydrateElevatedTransaction(context, hash), () => "Hydration failed");
|
|
2652
2704
|
};
|
|
2653
2705
|
|
|
2654
2706
|
// src/transaction/primitives/transactionBlockByteCount.ts
|
|
@@ -2701,13 +2753,13 @@ function transactionRequiredGas(hydratedTransaction) {
|
|
|
2701
2753
|
|
|
2702
2754
|
// src/transaction/signTransaction.ts
|
|
2703
2755
|
import {
|
|
2704
|
-
assertEx as
|
|
2756
|
+
assertEx as assertEx21,
|
|
2705
2757
|
hexFromArrayBuffer,
|
|
2706
2758
|
toArrayBuffer
|
|
2707
2759
|
} from "@xylabs/sdk-js";
|
|
2708
2760
|
import { PayloadBuilder as PayloadBuilder10 } from "@xyo-network/sdk-js";
|
|
2709
2761
|
async function signTransaction(tx, account) {
|
|
2710
|
-
|
|
2762
|
+
assertEx21(tx.from === account.address, () => "Signer address does not match transaction from address");
|
|
2711
2763
|
const unsignedTx = structuredClone(tx);
|
|
2712
2764
|
unsignedTx.addresses = [account.address];
|
|
2713
2765
|
unsignedTx.previous_hashes = [account.previousHash ?? null];
|
|
@@ -2722,7 +2774,7 @@ async function signTransaction(tx, account) {
|
|
|
2722
2774
|
}
|
|
2723
2775
|
|
|
2724
2776
|
// src/transaction/TransactionBuilder.ts
|
|
2725
|
-
import { assertEx as
|
|
2777
|
+
import { assertEx as assertEx22, Base } from "@xylabs/sdk-js";
|
|
2726
2778
|
import { PayloadBuilder as PayloadBuilder11 } from "@xyo-network/sdk-js";
|
|
2727
2779
|
import {
|
|
2728
2780
|
asXL1BlockNumber as asXL1BlockNumber4,
|
|
@@ -2742,9 +2794,9 @@ var TransactionBuilder = class extends Base {
|
|
|
2742
2794
|
super(options);
|
|
2743
2795
|
}
|
|
2744
2796
|
async build() {
|
|
2745
|
-
const chain =
|
|
2746
|
-
const fees =
|
|
2747
|
-
const blockRange =
|
|
2797
|
+
const chain = assertEx22(this._chain, () => "Chain must be set before building the transaction");
|
|
2798
|
+
const fees = assertEx22(this._fees, () => "Fees must be set before building the transaction");
|
|
2799
|
+
const blockRange = assertEx22(this._blockRange, () => "Block range must be set before building the transaction");
|
|
2748
2800
|
return await buildTransaction(
|
|
2749
2801
|
chain,
|
|
2750
2802
|
this._elevatedPayloads,
|
|
@@ -2774,7 +2826,7 @@ var TransactionBuilder = class extends Base {
|
|
|
2774
2826
|
}
|
|
2775
2827
|
elevatedPayload(payload) {
|
|
2776
2828
|
const allowedPayload = isAllowedBlockPayload2(payload) ? payload : void 0;
|
|
2777
|
-
const allowPayloadExists =
|
|
2829
|
+
const allowPayloadExists = assertEx22(allowedPayload, () => "Payload must be an AllowedBlockPayload");
|
|
2778
2830
|
this._elevatedPayloads.push(allowPayloadExists);
|
|
2779
2831
|
return this;
|
|
2780
2832
|
}
|
|
@@ -2868,7 +2920,7 @@ var bundle2 = (root, transaction) => {
|
|
|
2868
2920
|
};
|
|
2869
2921
|
|
|
2870
2922
|
// src/context/Actor.ts
|
|
2871
|
-
var ActorConfigContext =
|
|
2923
|
+
var ActorConfigContext = z23.extend(BaseConfigContextZod, { config: ActorConfigZod });
|
|
2872
2924
|
var isActorConfigContext = zodIsFactory5(ActorConfigContext);
|
|
2873
2925
|
var asActorConfigContext = zodAsFactory6(ActorConfigContext, "asActorConfigContext");
|
|
2874
2926
|
var toActorConfigContext = zodToFactory5(ActorConfigContext, "toActorConfigContext");
|
|
@@ -2876,12 +2928,12 @@ var toActorConfigContext = zodToFactory5(ActorConfigContext, "toActorConfigConte
|
|
|
2876
2928
|
// src/CreatableProvider/AbstractCreatableProvider.ts
|
|
2877
2929
|
import {
|
|
2878
2930
|
AbstractCreatable,
|
|
2879
|
-
assertEx as
|
|
2931
|
+
assertEx as assertEx24,
|
|
2880
2932
|
IdLogger
|
|
2881
2933
|
} from "@xylabs/sdk-js";
|
|
2882
2934
|
|
|
2883
2935
|
// src/CreatableProvider/ProviderFactory.ts
|
|
2884
|
-
import { assertEx as
|
|
2936
|
+
import { assertEx as assertEx23 } from "@xylabs/sdk-js";
|
|
2885
2937
|
function providerFactoryDescription(factory, labels) {
|
|
2886
2938
|
return `${factory.providerName}:${factory.defaultMoniker}:${JSON.stringify(labels ?? factory.labels ?? {})}`;
|
|
2887
2939
|
}
|
|
@@ -2902,7 +2954,7 @@ var ProviderFactory = class _ProviderFactory {
|
|
|
2902
2954
|
this.dependencies = dependencies;
|
|
2903
2955
|
this.monikers = creatableProvider2.monikers;
|
|
2904
2956
|
this.scope = scope;
|
|
2905
|
-
|
|
2957
|
+
assertEx23(this.monikers.includes(this.defaultMoniker), () => "defaultMoniker must be in monikers");
|
|
2906
2958
|
this.labels = Object.assign({}, creatableProvider2.labels ?? {}, labels ?? {});
|
|
2907
2959
|
this.providerName = creatableProvider2.name;
|
|
2908
2960
|
this._uniqueId = Symbol(providerFactoryDescription(this));
|
|
@@ -2930,7 +2982,7 @@ var ProviderFactory = class _ProviderFactory {
|
|
|
2930
2982
|
break;
|
|
2931
2983
|
}
|
|
2932
2984
|
case "context": {
|
|
2933
|
-
const context =
|
|
2985
|
+
const context = assertEx23(
|
|
2934
2986
|
params?.context,
|
|
2935
2987
|
() => "Context is required for context-scoped providers"
|
|
2936
2988
|
);
|
|
@@ -2951,7 +3003,7 @@ var ProviderFactory = class _ProviderFactory {
|
|
|
2951
3003
|
scopeObject[this.resolvedMoniker] = resultPromise;
|
|
2952
3004
|
const result = await resultPromise;
|
|
2953
3005
|
if (start) {
|
|
2954
|
-
|
|
3006
|
+
assertEx23(await result.start(), () => `Failed to start provider instance [${this.resolvedMoniker}]`);
|
|
2955
3007
|
}
|
|
2956
3008
|
return result;
|
|
2957
3009
|
}
|
|
@@ -2996,9 +3048,9 @@ var AbstractCreatableProvider = class extends AbstractCreatable {
|
|
|
2996
3048
|
return factory;
|
|
2997
3049
|
}
|
|
2998
3050
|
static async paramsHandler(params = {}) {
|
|
2999
|
-
const context =
|
|
3000
|
-
const config =
|
|
3001
|
-
const locator =
|
|
3051
|
+
const context = assertEx24(params.context, () => new Error("Context is required"));
|
|
3052
|
+
const config = assertEx24(context.config, () => new Error("Context config is required"));
|
|
3053
|
+
const locator = assertEx24(context.locator, () => new Error("Context locator is required"));
|
|
3002
3054
|
return await super.paramsHandler({
|
|
3003
3055
|
...params,
|
|
3004
3056
|
statusReporter: params.statusReporter ?? context.statusReporter,
|
|
@@ -3110,7 +3162,7 @@ function labeledCreatableProviderFactory() {
|
|
|
3110
3162
|
|
|
3111
3163
|
// src/CreatableProvider/ProviderFactoryLocator.ts
|
|
3112
3164
|
import { hasAllLabels } from "@xylabs/sdk-js";
|
|
3113
|
-
import { assertEx as
|
|
3165
|
+
import { assertEx as assertEx25 } from "@xylabs/sdk-js";
|
|
3114
3166
|
var ProviderFactoryLocator = class _ProviderFactoryLocator {
|
|
3115
3167
|
_context;
|
|
3116
3168
|
_registry;
|
|
@@ -3142,7 +3194,7 @@ var ProviderFactoryLocator = class _ProviderFactoryLocator {
|
|
|
3142
3194
|
this._frozen = true;
|
|
3143
3195
|
}
|
|
3144
3196
|
async getInstance(moniker, { start = true, labels } = {}) {
|
|
3145
|
-
return
|
|
3197
|
+
return assertEx25(
|
|
3146
3198
|
await this.tryGetInstance(moniker, { start, labels }),
|
|
3147
3199
|
() => `No provider instance for the supplied config moniker [${moniker}]${labels ? ` & labels [${JSON.stringify(labels)}]` : ""} could be created`
|
|
3148
3200
|
);
|
|
@@ -3157,7 +3209,7 @@ var ProviderFactoryLocator = class _ProviderFactoryLocator {
|
|
|
3157
3209
|
* @returns A provider factory that matches the supplied moniker and labels or throws if one is not found
|
|
3158
3210
|
*/
|
|
3159
3211
|
locate(moniker, labels) {
|
|
3160
|
-
return
|
|
3212
|
+
return assertEx25(
|
|
3161
3213
|
this.tryLocate(moniker, labels),
|
|
3162
3214
|
() => `No module factory for the supplied config moniker [${moniker}]${labels ? ` & labels [${JSON.stringify(labels)}]` : ""} registered`
|
|
3163
3215
|
);
|
|
@@ -3179,10 +3231,10 @@ var ProviderFactoryLocator = class _ProviderFactoryLocator {
|
|
|
3179
3231
|
* @param labels The labels for the module factory
|
|
3180
3232
|
*/
|
|
3181
3233
|
register(factory, labels, primary = false) {
|
|
3182
|
-
|
|
3234
|
+
assertEx25(!this._frozen, () => "Cannot register a module factory after the locator has been frozen");
|
|
3183
3235
|
if (this.validateDepsOnRegister) {
|
|
3184
3236
|
const missingDeps = factory.dependencies.filter((dep) => !this.registered(dep));
|
|
3185
|
-
|
|
3237
|
+
assertEx25(missingDeps.length === 0, () => `Cannot register module factory [${factory.uniqueId.description}] due to missing dependencies: ${missingDeps.join(", ")}`);
|
|
3186
3238
|
}
|
|
3187
3239
|
registerCreatableProviderFactory(this._registry, factory, labels, primary);
|
|
3188
3240
|
return this;
|
|
@@ -3230,7 +3282,7 @@ var ProviderFactoryLocator = class _ProviderFactoryLocator {
|
|
|
3230
3282
|
for (const moniker in this.registry) {
|
|
3231
3283
|
for (const factory of this.registry[moniker] ?? []) {
|
|
3232
3284
|
const missingDeps = factory.dependencies.filter((dep) => !this.registered(dep));
|
|
3233
|
-
|
|
3285
|
+
assertEx25(missingDeps.length === 0, () => `Module factory [${factory.uniqueId.description}] is missing dependencies: ${missingDeps.join(", ")}`);
|
|
3234
3286
|
}
|
|
3235
3287
|
}
|
|
3236
3288
|
}
|
|
@@ -3258,19 +3310,20 @@ import {
|
|
|
3258
3310
|
zodIsFactory as zodIsFactory6,
|
|
3259
3311
|
zodToFactory as zodToFactory6
|
|
3260
3312
|
} from "@xylabs/sdk-js";
|
|
3261
|
-
|
|
3313
|
+
import { z as z24 } from "zod/mini";
|
|
3314
|
+
var HostActorConfigContext = z24.extend(BaseConfigContextZod, { config: HostActorConfigZod });
|
|
3262
3315
|
var isHostActorConfigContext = zodIsFactory6(HostActorConfigContext);
|
|
3263
3316
|
var asHostActorConfigContext = zodAsFactory7(HostActorConfigContext, "asHostActorConfigContext");
|
|
3264
3317
|
var toHostActorConfigContext = zodToFactory6(HostActorConfigContext, "toHostActorConfigContext");
|
|
3265
3318
|
|
|
3266
3319
|
// src/createDeclarationPayload.ts
|
|
3267
|
-
import { isDefined as
|
|
3320
|
+
import { isDefined as isDefined16 } from "@xylabs/sdk-js";
|
|
3268
3321
|
import { PayloadBuilder as PayloadBuilder13 } from "@xyo-network/sdk-js";
|
|
3269
3322
|
import {
|
|
3270
3323
|
ChainStakeIntentSchema
|
|
3271
3324
|
} from "@xyo-network/xl1-protocol-lib";
|
|
3272
3325
|
var createDeclarationIntent = (address, intent, nbf, exp) => {
|
|
3273
|
-
const expiration =
|
|
3326
|
+
const expiration = isDefined16(exp) ? exp : nbf + 1e4;
|
|
3274
3327
|
const redeclarationIntent = new PayloadBuilder13({ schema: ChainStakeIntentSchema }).fields({
|
|
3275
3328
|
from: address,
|
|
3276
3329
|
intent,
|
|
@@ -3299,26 +3352,26 @@ import {
|
|
|
3299
3352
|
asSchema as asSchema2,
|
|
3300
3353
|
isPayloadOfZodType
|
|
3301
3354
|
} from "@xyo-network/sdk-js";
|
|
3302
|
-
import { z as
|
|
3355
|
+
import { z as z26 } from "zod";
|
|
3303
3356
|
|
|
3304
3357
|
// src/eip-712/Types.ts
|
|
3305
|
-
import { z as
|
|
3306
|
-
var TypedDataDomainZod =
|
|
3307
|
-
name:
|
|
3308
|
-
version:
|
|
3309
|
-
chainId:
|
|
3310
|
-
verifyingContract:
|
|
3311
|
-
salt:
|
|
3358
|
+
import { z as z25 } from "zod";
|
|
3359
|
+
var TypedDataDomainZod = z25.object({
|
|
3360
|
+
name: z25.string().nullable().optional(),
|
|
3361
|
+
version: z25.string().nullable().optional(),
|
|
3362
|
+
chainId: z25.union([z25.string(), z25.number(), z25.bigint()]).nullable().optional(),
|
|
3363
|
+
verifyingContract: z25.string().nullable().optional(),
|
|
3364
|
+
salt: z25.union([z25.string(), z25.instanceof(Uint8Array)]).nullable().optional()
|
|
3312
3365
|
});
|
|
3313
|
-
var TypedDataFieldZod =
|
|
3314
|
-
name:
|
|
3315
|
-
type:
|
|
3366
|
+
var TypedDataFieldZod = z25.object({
|
|
3367
|
+
name: z25.string(),
|
|
3368
|
+
type: z25.string()
|
|
3316
3369
|
});
|
|
3317
|
-
var TypedDataTypesZod =
|
|
3318
|
-
var TypedDataValueZod =
|
|
3370
|
+
var TypedDataTypesZod = z25.record(z25.string(), z25.array(TypedDataFieldZod));
|
|
3371
|
+
var TypedDataValueZod = z25.record(z25.string(), z25.any());
|
|
3319
3372
|
|
|
3320
3373
|
// src/eip-712/Payloads/EIP712Data.ts
|
|
3321
|
-
var EIP712DataPayloadFieldsZod =
|
|
3374
|
+
var EIP712DataPayloadFieldsZod = z26.object({
|
|
3322
3375
|
domain: TypedDataDomainZod,
|
|
3323
3376
|
types: TypedDataTypesZod,
|
|
3324
3377
|
values: TypedDataValueZod
|
|
@@ -3336,11 +3389,11 @@ import {
|
|
|
3336
3389
|
asSchema as asSchema3,
|
|
3337
3390
|
isPayloadOfZodType as isPayloadOfZodType2
|
|
3338
3391
|
} from "@xyo-network/sdk-js";
|
|
3339
|
-
import { z as
|
|
3340
|
-
var EIP712SignaturePayloadFieldsZod =
|
|
3341
|
-
address:
|
|
3392
|
+
import { z as z27 } from "zod";
|
|
3393
|
+
var EIP712SignaturePayloadFieldsZod = z27.object({
|
|
3394
|
+
address: z27.string(),
|
|
3342
3395
|
hash: HashZod,
|
|
3343
|
-
signature:
|
|
3396
|
+
signature: z27.string()
|
|
3344
3397
|
});
|
|
3345
3398
|
var EIP712SignaturePayloadSchema = asSchema3("network.xyo.chains.ethereum.eip712.signature", true);
|
|
3346
3399
|
var isEIP712SignaturePayload = isPayloadOfZodType2(
|
|
@@ -3369,7 +3422,7 @@ var signEIP712Message = async (signer, data) => {
|
|
|
3369
3422
|
};
|
|
3370
3423
|
|
|
3371
3424
|
// src/eip-712/verify.ts
|
|
3372
|
-
import { asHash as asHash3, isUndefined as
|
|
3425
|
+
import { asHash as asHash3, isUndefined as isUndefined7 } from "@xylabs/sdk-js";
|
|
3373
3426
|
import { PayloadBuilder as PayloadBuilder16 } from "@xyo-network/sdk-js";
|
|
3374
3427
|
import { verifyTypedData } from "ethers";
|
|
3375
3428
|
var verifyEIP712Message = async (data, sig) => {
|
|
@@ -3380,7 +3433,7 @@ var verifyEIP712Message = async (data, sig) => {
|
|
|
3380
3433
|
} = sig;
|
|
3381
3434
|
const { schema, ...fields } = data;
|
|
3382
3435
|
const signedHash = asHash3(hash);
|
|
3383
|
-
if (
|
|
3436
|
+
if (isUndefined7(signedHash) || signedHash !== await PayloadBuilder16.hash(data)) return false;
|
|
3384
3437
|
const recoveredAddress = verifyTypedData(fields.domain, fields.types, fields.values, signature);
|
|
3385
3438
|
return recoveredAddress.toLowerCase() === address.toLowerCase();
|
|
3386
3439
|
};
|
|
@@ -3449,9 +3502,9 @@ var toPositiveBigInt = (value) => {
|
|
|
3449
3502
|
// src/simple/accountBalance/SimpleAccountBalanceViewer.ts
|
|
3450
3503
|
import {
|
|
3451
3504
|
asHash as asHash4,
|
|
3452
|
-
assertEx as
|
|
3505
|
+
assertEx as assertEx32,
|
|
3453
3506
|
exists as exists3,
|
|
3454
|
-
isDefined as
|
|
3507
|
+
isDefined as isDefined17,
|
|
3455
3508
|
ZERO_ADDRESS
|
|
3456
3509
|
} from "@xylabs/sdk-js";
|
|
3457
3510
|
import {
|
|
@@ -3521,18 +3574,18 @@ var asTransfersStepSummaryWithStorageMeta = AsObjectFactory7.create(isTransfersS
|
|
|
3521
3574
|
|
|
3522
3575
|
// src/summary/primitives/balances/balancesStepSummaryFromRange.ts
|
|
3523
3576
|
import { spanRootAsync as spanRootAsync2 } from "@xylabs/sdk-js";
|
|
3524
|
-
import { assertEx as
|
|
3577
|
+
import { assertEx as assertEx26 } from "@xylabs/sdk-js";
|
|
3525
3578
|
import { isAnyPayload as isAnyPayload3 } from "@xyo-network/sdk-js";
|
|
3526
3579
|
import { asXL1BlockNumber as asXL1BlockNumber5, StepSizes as StepSizes8 } from "@xyo-network/xl1-protocol-lib";
|
|
3527
3580
|
async function balancesStepSummaryFromRange(context, semaphores, blockViewer, summaryMap, range) {
|
|
3528
3581
|
const cacheKey = `${range[0]}|${range[1]}`;
|
|
3529
3582
|
return await withContextCacheResponse(context, "balancesStepSummaryFromRange", cacheKey, async () => {
|
|
3530
3583
|
return await spanRootAsync2("balancesStepSummaryFromRange", async () => {
|
|
3531
|
-
const [frameHead] =
|
|
3584
|
+
const [frameHead] = assertEx26(await blockViewer.blockByNumber(range[1]), () => `Block not found for number: ${range[1]}`);
|
|
3532
3585
|
const frameSize = range[1] - range[0] + 1;
|
|
3533
3586
|
const key = `${frameHead._hash}|${frameSize}`;
|
|
3534
3587
|
return frameSize === 1 ? await spanRootAsync2(`balancesStepSummaryFromRange.frameSize=1[${key}]`, async () => {
|
|
3535
|
-
const [, payloads] =
|
|
3588
|
+
const [, payloads] = assertEx26(await blockViewer.blockByNumber(range[0]), () => `Block not found for number: ${range[0]}`);
|
|
3536
3589
|
const balances = {};
|
|
3537
3590
|
for (const [address, balance] of Object.entries(netBalancesForPayloads(context, payloads))) {
|
|
3538
3591
|
balances[address] = toSignedBigInt(balance);
|
|
@@ -3545,7 +3598,7 @@ async function balancesStepSummaryFromRange(context, semaphores, blockViewer, su
|
|
|
3545
3598
|
};
|
|
3546
3599
|
}, { ...context, timeBudgetLimit: 500 }) : await spanRootAsync2(`balancesStepSummaryFromRange.frameSize>1[${key}]`, async () => {
|
|
3547
3600
|
const step = StepSizes8.indexOf(asXL1BlockNumber5(frameSize, true));
|
|
3548
|
-
|
|
3601
|
+
assertEx26(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes8.join(", ")}`);
|
|
3549
3602
|
const summaryResult = await summaryMap.get(`${frameHead._hash}|${frameSize}`);
|
|
3550
3603
|
if (isAnyPayload3(summaryResult)) {
|
|
3551
3604
|
return summaryResult;
|
|
@@ -3591,7 +3644,7 @@ async function balancesStepSummaryFromRange(context, semaphores, blockViewer, su
|
|
|
3591
3644
|
// src/summary/primitives/balances/balancesSummary.ts
|
|
3592
3645
|
import {
|
|
3593
3646
|
asAddress,
|
|
3594
|
-
assertEx as
|
|
3647
|
+
assertEx as assertEx27,
|
|
3595
3648
|
spanRootAsync as spanRootAsync3
|
|
3596
3649
|
} from "@xylabs/sdk-js";
|
|
3597
3650
|
import {
|
|
@@ -3603,7 +3656,7 @@ import {
|
|
|
3603
3656
|
async function balancesSummary(context, semaphores, blockViewer, summaryMap, config) {
|
|
3604
3657
|
return await spanRootAsync3("balancesSummary", async () => {
|
|
3605
3658
|
const headHash = isChainQualifiedHeadConfig(config) ? config.head : await blockViewer.currentBlockHash();
|
|
3606
|
-
const [head] =
|
|
3659
|
+
const [head] = assertEx27(await blockViewer.blockByHash(headHash), () => `Block not found for hash: ${headHash}`);
|
|
3607
3660
|
const headBoundWitness = asBlockBoundWitnessWithStorageMeta3(head, () => `Found Block not a BlockWithHashMeta: ${headHash}`);
|
|
3608
3661
|
const range = isChainQualifiedRangeConfig(config) ? config.range : asXL1BlockRange7([0, headBoundWitness.block], true);
|
|
3609
3662
|
const ranges = deepCalculateFramesFromRange(asXL1BlockRange7(
|
|
@@ -3623,7 +3676,7 @@ async function balancesSummary(context, semaphores, blockViewer, summaryMap, con
|
|
|
3623
3676
|
}
|
|
3624
3677
|
|
|
3625
3678
|
// src/summary/primitives/schemas/schemasStepSummaryFromRange.ts
|
|
3626
|
-
import { assertEx as
|
|
3679
|
+
import { assertEx as assertEx28 } from "@xylabs/sdk-js";
|
|
3627
3680
|
import {
|
|
3628
3681
|
isAnyPayload as isAnyPayload4,
|
|
3629
3682
|
isBoundWitness as isBoundWitness2,
|
|
@@ -3632,11 +3685,11 @@ import {
|
|
|
3632
3685
|
} from "@xyo-network/sdk-js";
|
|
3633
3686
|
import { StepSizes as StepSizes9 } from "@xyo-network/xl1-protocol-lib";
|
|
3634
3687
|
async function schemasStepSummaryFromRange(context, semaphores, blockViewer, summaryMap, range) {
|
|
3635
|
-
const [frameHead] =
|
|
3688
|
+
const [frameHead] = assertEx28(await blockViewer.blockByNumber(range[1]), () => `Block not found for number: ${range[1]}`);
|
|
3636
3689
|
const frameSize = range[1] - range[0] + 1;
|
|
3637
3690
|
let result;
|
|
3638
3691
|
if (frameSize === 1) {
|
|
3639
|
-
const [block, payloads] =
|
|
3692
|
+
const [block, payloads] = assertEx28(await blockViewer.blockByNumber(range[0]), () => `Block not found for number: ${range[0]}`);
|
|
3640
3693
|
const boundWitnesses = [block, ...payloads.filter((x) => isBoundWitness2(x) && isHashMeta(x))];
|
|
3641
3694
|
const schemas = {};
|
|
3642
3695
|
for (const bw of boundWitnesses) {
|
|
@@ -3653,7 +3706,7 @@ async function schemasStepSummaryFromRange(context, semaphores, blockViewer, sum
|
|
|
3653
3706
|
});
|
|
3654
3707
|
} else {
|
|
3655
3708
|
const step = StepSizes9.indexOf(frameSize);
|
|
3656
|
-
|
|
3709
|
+
assertEx28(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes9.join(", ")}`);
|
|
3657
3710
|
const summaryResult = await summaryMap.get(`${frameHead._hash}|${frameSize}`);
|
|
3658
3711
|
if (isAnyPayload4(summaryResult)) {
|
|
3659
3712
|
result = summaryResult;
|
|
@@ -3692,7 +3745,7 @@ async function schemasStepSummaryFromRange(context, semaphores, blockViewer, sum
|
|
|
3692
3745
|
}
|
|
3693
3746
|
|
|
3694
3747
|
// src/summary/primitives/schemas/schemasSummary.ts
|
|
3695
|
-
import { assertEx as
|
|
3748
|
+
import { assertEx as assertEx29, spanRootAsync as spanRootAsync4 } from "@xylabs/sdk-js";
|
|
3696
3749
|
import {
|
|
3697
3750
|
asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta4,
|
|
3698
3751
|
asXL1BlockRange as asXL1BlockRange8,
|
|
@@ -3702,7 +3755,7 @@ import {
|
|
|
3702
3755
|
async function schemasSummary(context, semaphores, blockViewer, summaryMap, config) {
|
|
3703
3756
|
return await spanRootAsync4("schemasSummary", async () => {
|
|
3704
3757
|
const headHash = isChainQualifiedHeadConfig2(config) ? config.head : await blockViewer.currentBlockHash();
|
|
3705
|
-
const [head] =
|
|
3758
|
+
const [head] = assertEx29(await blockViewer.blockByHash(headHash), () => `Block not found for hash: ${headHash}`);
|
|
3706
3759
|
const headBoundWitness = asBlockBoundWitnessWithStorageMeta4(head, () => `Found Block not a BlockWithHashMeta: ${headHash}`);
|
|
3707
3760
|
const range = isChainQualifiedRangeConfig2(config) ? config.range : asXL1BlockRange8([0, headBoundWitness.block], true);
|
|
3708
3761
|
const ranges = deepCalculateFramesFromRange(asXL1BlockRange8(
|
|
@@ -3722,7 +3775,7 @@ async function schemasSummary(context, semaphores, blockViewer, summaryMap, conf
|
|
|
3722
3775
|
}
|
|
3723
3776
|
|
|
3724
3777
|
// src/summary/primitives/transfers/transfersStepSummaryFromRange.ts
|
|
3725
|
-
import { assertEx as
|
|
3778
|
+
import { assertEx as assertEx30, spanRootAsync as spanRootAsync5 } from "@xylabs/sdk-js";
|
|
3726
3779
|
import { isAnyPayload as isAnyPayload5 } from "@xyo-network/sdk-js";
|
|
3727
3780
|
import { asXL1BlockNumber as asXL1BlockNumber6, StepSizes as StepSizes10 } from "@xyo-network/xl1-protocol-lib";
|
|
3728
3781
|
function transfersSummaryKey(frameHeadHash, frameSize) {
|
|
@@ -3732,11 +3785,11 @@ async function transfersStepSummaryFromRange(context, semaphores, blockViewer, s
|
|
|
3732
3785
|
const cacheKey = `${range[0]}|${range[1]}`;
|
|
3733
3786
|
return await withContextCacheResponse(context, "transfersStepSummaryFromRange", cacheKey, async () => {
|
|
3734
3787
|
return await spanRootAsync5("transfersStepSummaryFromRange", async () => {
|
|
3735
|
-
const [frameHead] =
|
|
3788
|
+
const [frameHead] = assertEx30(await blockViewer.blockByNumber(range[1]), () => `Block not found for number: ${range[1]}`);
|
|
3736
3789
|
const frameSize = range[1] - range[0] + 1;
|
|
3737
3790
|
let result;
|
|
3738
3791
|
if (frameSize === 1) {
|
|
3739
|
-
const [, payloads] =
|
|
3792
|
+
const [, payloads] = assertEx30(await blockViewer.blockByNumber(range[0]), () => `Block not found for number: ${range[0]}`);
|
|
3740
3793
|
const transfers = {};
|
|
3741
3794
|
for (const [from, toMap] of Object.entries(netTransfersForPayloads(context, payloads))) {
|
|
3742
3795
|
transfers[from] = transfers[from] ?? {};
|
|
@@ -3752,7 +3805,7 @@ async function transfersStepSummaryFromRange(context, semaphores, blockViewer, s
|
|
|
3752
3805
|
};
|
|
3753
3806
|
} else {
|
|
3754
3807
|
const step = StepSizes10.indexOf(asXL1BlockNumber6(frameSize, true));
|
|
3755
|
-
|
|
3808
|
+
assertEx30(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes10.join(", ")}`);
|
|
3756
3809
|
const key = transfersSummaryKey(frameHead._hash, frameSize);
|
|
3757
3810
|
const summaryResult = await summaryMap.get(key);
|
|
3758
3811
|
if (isAnyPayload5(summaryResult)) {
|
|
@@ -3805,7 +3858,7 @@ async function transfersStepSummaryFromRange(context, semaphores, blockViewer, s
|
|
|
3805
3858
|
// src/summary/primitives/transfers/transfersSummary.ts
|
|
3806
3859
|
import {
|
|
3807
3860
|
asAddress as asAddress2,
|
|
3808
|
-
assertEx as
|
|
3861
|
+
assertEx as assertEx31,
|
|
3809
3862
|
spanRootAsync as spanRootAsync6
|
|
3810
3863
|
} from "@xylabs/sdk-js";
|
|
3811
3864
|
import {
|
|
@@ -3817,7 +3870,7 @@ import {
|
|
|
3817
3870
|
async function transfersSummary(context, semaphores, blockViewer, summaryMap, config) {
|
|
3818
3871
|
return await spanRootAsync6("transferSummary", async () => {
|
|
3819
3872
|
const headHash = isChainQualifiedHeadConfig3(config) ? config.head : await blockViewer.currentBlockHash();
|
|
3820
|
-
const [head] =
|
|
3873
|
+
const [head] = assertEx31(await blockViewer.blockByHash(headHash), () => `Block not found for hash: ${headHash}`);
|
|
3821
3874
|
const headBoundWitness = asBlockBoundWitnessWithStorageMeta5(head, () => `Found Block not a BlockWithHashMeta: ${headHash}`);
|
|
3822
3875
|
const range = isChainQualifiedRangeConfig3(config) ? config.range : asXL1BlockRange9([0, headBoundWitness.block], true);
|
|
3823
3876
|
const ranges = deepCalculateFramesFromRange(asXL1BlockRange9(
|
|
@@ -3858,8 +3911,8 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
3858
3911
|
static async paramsHandler(params = {}) {
|
|
3859
3912
|
return {
|
|
3860
3913
|
...await super.paramsHandler(params),
|
|
3861
|
-
balancesSummaryMap:
|
|
3862
|
-
transfersSummaryMap:
|
|
3914
|
+
balancesSummaryMap: assertEx32(params.balancesSummaryMap, () => "balancesSummaryMap is required"),
|
|
3915
|
+
transfersSummaryMap: assertEx32(params.transfersSummaryMap, () => "transfersSummaryMap is required")
|
|
3863
3916
|
};
|
|
3864
3917
|
}
|
|
3865
3918
|
async accountBalance(address, config) {
|
|
@@ -3880,11 +3933,11 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
3880
3933
|
const transferIndexes = block[0].payload_schemas.map((schema, index) => schema === TransferSchema2 ? index : void 0).filter(exists3);
|
|
3881
3934
|
const transfers = transferIndexes.map((index) => {
|
|
3882
3935
|
const hash = block[0].payload_hashes[index];
|
|
3883
|
-
return
|
|
3936
|
+
return assertEx32(
|
|
3884
3937
|
block[1].find((p) => p._hash === hash),
|
|
3885
3938
|
() => `Error: Could not find Transfer with hash ${hash} in block ${block[0]._hash}`
|
|
3886
3939
|
);
|
|
3887
|
-
}).filter(exists3).filter((t) => t.from === address ||
|
|
3940
|
+
}).filter(exists3).filter((t) => t.from === address || isDefined17(t.transfers[address]));
|
|
3888
3941
|
if (transfers.length === 0) {
|
|
3889
3942
|
continue;
|
|
3890
3943
|
}
|
|
@@ -3913,7 +3966,7 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
3913
3966
|
const head = isChainQualifiedHeadConfig4(config) ? config.head : await this.blockViewer.currentBlockHash();
|
|
3914
3967
|
const range = isChainQualifiedRangeConfig4(config) ? config.range : asXL1BlockRange10([
|
|
3915
3968
|
0,
|
|
3916
|
-
|
|
3969
|
+
assertEx32(
|
|
3917
3970
|
await this.blockViewer.blockByHash(head),
|
|
3918
3971
|
() => `Error: Could not find block with hash ${head}`
|
|
3919
3972
|
)[0].block
|
|
@@ -3928,11 +3981,11 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
3928
3981
|
const qualifiedRange = qualifiedEntries[0][1][1].range;
|
|
3929
3982
|
const qualifiedHeadHash = qualifiedEntries[0][1][1].head;
|
|
3930
3983
|
for (const [_, [__, { range: range2, head: head2 }]] of qualifiedEntries) {
|
|
3931
|
-
|
|
3984
|
+
assertEx32(
|
|
3932
3985
|
range2[0] === qualifiedRange[0] && range2[1] === qualifiedRange[1],
|
|
3933
3986
|
() => "Inconsistent ranges in qualifiedAccountBalanceHistories"
|
|
3934
3987
|
);
|
|
3935
|
-
|
|
3988
|
+
assertEx32(
|
|
3936
3989
|
head2 === qualifiedHeadHash,
|
|
3937
3990
|
() => "Inconsistent head hashes in qualifiedAccountBalanceHistories"
|
|
3938
3991
|
);
|
|
@@ -4003,7 +4056,7 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
4003
4056
|
return await this.spanAsync("qualifiedAccountBalanceHistory", async () => {
|
|
4004
4057
|
const range = asRange(headOrRange);
|
|
4005
4058
|
const headHash = asHash4(headOrRange);
|
|
4006
|
-
const [head] =
|
|
4059
|
+
const [head] = assertEx32(isDefined17(headHash) ? await this.blockViewer.blockByHash(headHash) : await this.blockViewer.currentBlock(), () => "Could not resolve head block");
|
|
4007
4060
|
const startingRange = asXL1BlockRange10(range ?? [0, head.block], true);
|
|
4008
4061
|
const blockNumbers = await this.distillTransferHistory(address, startingRange);
|
|
4009
4062
|
const blocks = (await Promise.all(blockNumbers.map(async (bn) => await this.blockViewer.blockByNumber(bn)))).filter(exists3);
|
|
@@ -4012,11 +4065,11 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
4012
4065
|
const transferIndexes = block[0].payload_schemas.map((schema, index) => schema === TransferSchema2 ? index : void 0).filter(exists3);
|
|
4013
4066
|
const transfers = transferIndexes.map((index) => {
|
|
4014
4067
|
const hash = block[0].payload_hashes[index];
|
|
4015
|
-
return
|
|
4068
|
+
return assertEx32(
|
|
4016
4069
|
block[1].find((p) => p._hash === hash),
|
|
4017
4070
|
() => `Error: Could not find Transfer with hash ${hash} in block ${block[0]._hash}`
|
|
4018
4071
|
);
|
|
4019
|
-
}).filter(exists3).filter((t) => t.from === address ||
|
|
4072
|
+
}).filter(exists3).filter((t) => t.from === address || isDefined17(t.transfers[address]));
|
|
4020
4073
|
if (transfers.length === 0) {
|
|
4021
4074
|
continue;
|
|
4022
4075
|
}
|
|
@@ -4042,9 +4095,9 @@ SimpleAccountBalanceViewer = __decorateClass([
|
|
|
4042
4095
|
|
|
4043
4096
|
// src/simple/block/SimpleBlockViewer.ts
|
|
4044
4097
|
import {
|
|
4045
|
-
assertEx as
|
|
4098
|
+
assertEx as assertEx33,
|
|
4046
4099
|
exists as exists4,
|
|
4047
|
-
isUndefined as
|
|
4100
|
+
isUndefined as isUndefined8
|
|
4048
4101
|
} from "@xylabs/sdk-js";
|
|
4049
4102
|
import {
|
|
4050
4103
|
asSignedHydratedBlockWithHashMeta,
|
|
@@ -4078,12 +4131,12 @@ var HydratedCache = class {
|
|
|
4078
4131
|
};
|
|
4079
4132
|
|
|
4080
4133
|
// src/utils/isZodError.ts
|
|
4081
|
-
import { z as
|
|
4134
|
+
import { z as z28 } from "zod";
|
|
4082
4135
|
var isZodError = (error) => {
|
|
4083
|
-
return error instanceof
|
|
4136
|
+
return error instanceof z28.ZodError;
|
|
4084
4137
|
};
|
|
4085
4138
|
var prettifyZodError = (error) => {
|
|
4086
|
-
return
|
|
4139
|
+
return z28.prettifyError(error);
|
|
4087
4140
|
};
|
|
4088
4141
|
|
|
4089
4142
|
// src/simple/block/SimpleBlockViewer.ts
|
|
@@ -4119,11 +4172,11 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
4119
4172
|
static async paramsHandler(params) {
|
|
4120
4173
|
const headPollIntervalMs = params.headPollIntervalMs;
|
|
4121
4174
|
if (headPollIntervalMs !== void 0) {
|
|
4122
|
-
|
|
4175
|
+
assertEx33(headPollIntervalMs >= MIN_HEAD_POLL_INTERVAL_MS, () => `headPollIntervalMs must be at least ${MIN_HEAD_POLL_INTERVAL_MS}ms`);
|
|
4123
4176
|
}
|
|
4124
4177
|
return {
|
|
4125
4178
|
...await super.paramsHandler(params),
|
|
4126
|
-
finalizedArchivist:
|
|
4179
|
+
finalizedArchivist: assertEx33(params.finalizedArchivist, () => "finalizedArchivist is required"),
|
|
4127
4180
|
headPollIntervalMs
|
|
4128
4181
|
};
|
|
4129
4182
|
}
|
|
@@ -4144,7 +4197,7 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
4144
4197
|
async blockByNumber(blockNumber) {
|
|
4145
4198
|
return await this.spanAsync("blockByNumber", async () => {
|
|
4146
4199
|
const chainContext = await this.getChainContextRead();
|
|
4147
|
-
if (
|
|
4200
|
+
if (isUndefined8(chainContext.head)) {
|
|
4148
4201
|
return null;
|
|
4149
4202
|
}
|
|
4150
4203
|
return await this.blockByNumberWithContext(chainContext, blockNumber);
|
|
@@ -4152,8 +4205,8 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
4152
4205
|
}
|
|
4153
4206
|
async blocksByHash(hash, limit = 50) {
|
|
4154
4207
|
return await this.spanAsync("blocksByHash", async () => {
|
|
4155
|
-
|
|
4156
|
-
|
|
4208
|
+
assertEx33(limit > 0, () => "limit must be greater than 0");
|
|
4209
|
+
assertEx33(limit <= 100, () => "limit must be less than 100");
|
|
4157
4210
|
const blocks = [];
|
|
4158
4211
|
let current = await this.blockByHash(hash);
|
|
4159
4212
|
while (current && blocks.length < limit) {
|
|
@@ -4167,10 +4220,10 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
4167
4220
|
}
|
|
4168
4221
|
async blocksByNumber(blockNumber, limit = 50) {
|
|
4169
4222
|
return await this.spanAsync("blocksByNumber", async () => {
|
|
4170
|
-
|
|
4171
|
-
|
|
4223
|
+
assertEx33(limit > 0, () => "limit must be greater than 0");
|
|
4224
|
+
assertEx33(limit <= 100, () => "limit must be less than 100");
|
|
4172
4225
|
const chainContext = await this.getChainContextRead();
|
|
4173
|
-
if (
|
|
4226
|
+
if (isUndefined8(chainContext.head)) {
|
|
4174
4227
|
return [];
|
|
4175
4228
|
}
|
|
4176
4229
|
const blocks = [];
|
|
@@ -4186,7 +4239,7 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
4186
4239
|
}
|
|
4187
4240
|
async chainId(blockNumber = "latest") {
|
|
4188
4241
|
return await this.spanAsync("chainId", async () => {
|
|
4189
|
-
return blockNumber === "latest" ? (await this.finalizationViewer.headBlock()).chain :
|
|
4242
|
+
return blockNumber === "latest" ? (await this.finalizationViewer.headBlock()).chain : assertEx33(await this.blockByNumber(blockNumber), () => `Block not found [${blockNumber}]`)[0].chain;
|
|
4190
4243
|
}, this.context);
|
|
4191
4244
|
}
|
|
4192
4245
|
async createHandler() {
|
|
@@ -4298,9 +4351,7 @@ SimpleBlockViewer = __decorateClass([
|
|
|
4298
4351
|
], SimpleBlockViewer);
|
|
4299
4352
|
|
|
4300
4353
|
// src/simple/blockReward/SimpleBlockRewardViewer.ts
|
|
4301
|
-
import {
|
|
4302
|
-
BlockRewardViewerMoniker
|
|
4303
|
-
} from "@xyo-network/xl1-protocol-lib";
|
|
4354
|
+
import { BlockRewardViewerMoniker } from "@xyo-network/xl1-protocol-lib";
|
|
4304
4355
|
var SimpleBlockRewardViewer = class extends AbstractCreatableProvider {
|
|
4305
4356
|
moniker = SimpleBlockRewardViewer.defaultMoniker;
|
|
4306
4357
|
allowedRewardForBlock(block) {
|
|
@@ -4317,7 +4368,7 @@ SimpleBlockRewardViewer = __decorateClass([
|
|
|
4317
4368
|
], SimpleBlockRewardViewer);
|
|
4318
4369
|
|
|
4319
4370
|
// src/simple/blockValidation/SimpleBlockValidationViewer.ts
|
|
4320
|
-
import { assertEx as
|
|
4371
|
+
import { assertEx as assertEx34 } from "@xylabs/sdk-js";
|
|
4321
4372
|
import { PayloadBuilder as PayloadBuilder18 } from "@xyo-network/sdk-js";
|
|
4322
4373
|
import {
|
|
4323
4374
|
AccountBalanceViewerMoniker as AccountBalanceViewerMoniker2,
|
|
@@ -4370,7 +4421,7 @@ var SimpleBlockValidationViewer = class extends AbstractCreatableProvider {
|
|
|
4370
4421
|
head: void 0
|
|
4371
4422
|
};
|
|
4372
4423
|
const blocksWithMeta = await Promise.all(blocks.map((b) => Promise.all([PayloadBuilder18.addHashMeta(b[0]), PayloadBuilder18.addHashMeta(b[1])])));
|
|
4373
|
-
const head = isChainQualifiedHeadConfig5(config) ?
|
|
4424
|
+
const head = isChainQualifiedHeadConfig5(config) ? assertEx34(
|
|
4374
4425
|
(await this.blockViewer.blockByHash(config.head))?.[0],
|
|
4375
4426
|
() => `Specified a head that is not in the chain [${config.head}]`
|
|
4376
4427
|
) : void 0;
|
|
@@ -4452,12 +4503,9 @@ SimpleBlockValidationViewer = __decorateClass([
|
|
|
4452
4503
|
|
|
4453
4504
|
// src/simple/chainContractViewer/SimpleChainContractViewer.ts
|
|
4454
4505
|
import {
|
|
4455
|
-
assertEx as
|
|
4506
|
+
assertEx as assertEx35
|
|
4456
4507
|
} from "@xylabs/sdk-js";
|
|
4457
|
-
import {
|
|
4458
|
-
ChainContractViewerMoniker as ChainContractViewerMoniker2,
|
|
4459
|
-
FinalizationViewerMoniker as FinalizationViewerMoniker2
|
|
4460
|
-
} from "@xyo-network/xl1-protocol-lib";
|
|
4508
|
+
import { ChainContractViewerMoniker as ChainContractViewerMoniker2, FinalizationViewerMoniker as FinalizationViewerMoniker2 } from "@xyo-network/xl1-protocol-lib";
|
|
4461
4509
|
var SimpleChainContractViewer = class extends AbstractCreatableProvider {
|
|
4462
4510
|
moniker = SimpleChainContractViewer.defaultMoniker;
|
|
4463
4511
|
_finalizationViewer;
|
|
@@ -4473,7 +4521,7 @@ var SimpleChainContractViewer = class extends AbstractCreatableProvider {
|
|
|
4473
4521
|
let contractViewer = this;
|
|
4474
4522
|
let forkedAtBlockNumber = await contractViewer.forkedAtBlockNumber();
|
|
4475
4523
|
while (forkedAtBlockNumber !== null && blockNumber <= forkedAtBlockNumber) {
|
|
4476
|
-
contractViewer =
|
|
4524
|
+
contractViewer = assertEx35(await contractViewer.forkedChainContractViewer());
|
|
4477
4525
|
forkedAtBlockNumber = await contractViewer.forkedAtBlockNumber();
|
|
4478
4526
|
chainId = await contractViewer.chainId();
|
|
4479
4527
|
}
|
|
@@ -4526,15 +4574,10 @@ var SimpleXyoClient = class {
|
|
|
4526
4574
|
};
|
|
4527
4575
|
|
|
4528
4576
|
// src/simple/datalake/RestDataLakeRunner.ts
|
|
4529
|
-
import {
|
|
4530
|
-
assertEx as assertEx35,
|
|
4531
|
-
exists as exists6
|
|
4532
|
-
} from "@xylabs/sdk-js";
|
|
4577
|
+
import { assertEx as assertEx36, exists as exists6 } from "@xylabs/sdk-js";
|
|
4533
4578
|
import { isAnyPayload as isAnyPayload7, PayloadZodLoose } from "@xyo-network/sdk-js";
|
|
4534
|
-
import {
|
|
4535
|
-
|
|
4536
|
-
} from "@xyo-network/xl1-protocol-lib";
|
|
4537
|
-
import z27 from "zod";
|
|
4579
|
+
import { DataLakeRunnerMoniker } from "@xyo-network/xl1-protocol-lib";
|
|
4580
|
+
import { z as z29 } from "zod/mini";
|
|
4538
4581
|
|
|
4539
4582
|
// src/simple/datalake/AbstractRestDataLake.ts
|
|
4540
4583
|
import { FetchClientError, FetchJsonClient } from "@xylabs/fetch";
|
|
@@ -4600,14 +4643,14 @@ var RestDataLakeRunner = class extends AbstractRestDataLake {
|
|
|
4600
4643
|
async insert(items) {
|
|
4601
4644
|
const allowedItems = items.map((item) => {
|
|
4602
4645
|
if (isAnyPayload7(item) && this.isAllowed(item)) {
|
|
4603
|
-
|
|
4646
|
+
assertEx36(typeof item === "object" && item !== null, () => "Data must be an object");
|
|
4604
4647
|
return item;
|
|
4605
4648
|
}
|
|
4606
4649
|
return null;
|
|
4607
4650
|
}).filter(exists6);
|
|
4608
4651
|
if (allowedItems.length > 0) {
|
|
4609
4652
|
const result = await this.client.post(`${this.params.endpoint}/insert`, allowedItems);
|
|
4610
|
-
return
|
|
4653
|
+
return z29.array(PayloadZodLoose).parse(result.data);
|
|
4611
4654
|
} else {
|
|
4612
4655
|
return [];
|
|
4613
4656
|
}
|
|
@@ -4621,9 +4664,7 @@ RestDataLakeRunner = __decorateClass([
|
|
|
4621
4664
|
], RestDataLakeRunner);
|
|
4622
4665
|
|
|
4623
4666
|
// src/simple/datalake/RestDataLakeViewer.ts
|
|
4624
|
-
import {
|
|
4625
|
-
DataLakeViewerMoniker
|
|
4626
|
-
} from "@xyo-network/xl1-protocol-lib";
|
|
4667
|
+
import { DataLakeViewerMoniker } from "@xyo-network/xl1-protocol-lib";
|
|
4627
4668
|
var RestDataLakeViewer = class extends AbstractRestDataLake {
|
|
4628
4669
|
moniker = RestDataLakeViewer.defaultMoniker;
|
|
4629
4670
|
};
|
|
@@ -4637,9 +4678,7 @@ RestDataLakeViewer = __decorateClass([
|
|
|
4637
4678
|
// src/simple/datalake/SimpleDataLakeRunner.ts
|
|
4638
4679
|
import { exists as exists7 } from "@xylabs/sdk-js";
|
|
4639
4680
|
import { isAnyPayload as isAnyPayload9, PayloadBuilder as PayloadBuilder19 } from "@xyo-network/sdk-js";
|
|
4640
|
-
import {
|
|
4641
|
-
DataLakeRunnerMoniker as DataLakeRunnerMoniker2
|
|
4642
|
-
} from "@xyo-network/xl1-protocol-lib";
|
|
4681
|
+
import { DataLakeRunnerMoniker as DataLakeRunnerMoniker2 } from "@xyo-network/xl1-protocol-lib";
|
|
4643
4682
|
|
|
4644
4683
|
// src/simple/datalake/AbstractSimpleDataLake.ts
|
|
4645
4684
|
import { isAnyPayload as isAnyPayload8 } from "@xyo-network/sdk-js";
|
|
@@ -4706,9 +4745,7 @@ SimpleDataLakeRunner = __decorateClass([
|
|
|
4706
4745
|
], SimpleDataLakeRunner);
|
|
4707
4746
|
|
|
4708
4747
|
// src/simple/datalake/SimpleDataLakeViewer.ts
|
|
4709
|
-
import {
|
|
4710
|
-
DataLakeViewerMoniker as DataLakeViewerMoniker2
|
|
4711
|
-
} from "@xyo-network/xl1-protocol-lib";
|
|
4748
|
+
import { DataLakeViewerMoniker as DataLakeViewerMoniker2 } from "@xyo-network/xl1-protocol-lib";
|
|
4712
4749
|
var SimpleDataLakeViewer = class extends AbstractSimpleDataLake {
|
|
4713
4750
|
moniker = SimpleDataLakeViewer.defaultMoniker;
|
|
4714
4751
|
};
|
|
@@ -4749,9 +4786,7 @@ SimpleFinalizationRunner = __decorateClass([
|
|
|
4749
4786
|
], SimpleFinalizationRunner);
|
|
4750
4787
|
|
|
4751
4788
|
// src/simple/finalization/SimpleFinalizationViewer.ts
|
|
4752
|
-
import {
|
|
4753
|
-
assertEx as assertEx36
|
|
4754
|
-
} from "@xylabs/sdk-js";
|
|
4789
|
+
import { assertEx as assertEx37 } from "@xylabs/sdk-js";
|
|
4755
4790
|
import {
|
|
4756
4791
|
asSignedHydratedBlockWithStorageMeta as asSignedHydratedBlockWithStorageMeta2,
|
|
4757
4792
|
ChainContractViewerMoniker as ChainContractViewerMoniker3,
|
|
@@ -4780,7 +4815,7 @@ var SimpleFinalizationViewer = class extends AbstractCreatableProvider {
|
|
|
4780
4815
|
static async paramsHandler(params) {
|
|
4781
4816
|
return {
|
|
4782
4817
|
...await super.paramsHandler(params),
|
|
4783
|
-
finalizedArchivist:
|
|
4818
|
+
finalizedArchivist: assertEx37(params.finalizedArchivist, () => "finalizedArchivist is required")
|
|
4784
4819
|
};
|
|
4785
4820
|
}
|
|
4786
4821
|
chainId() {
|
|
@@ -4788,18 +4823,18 @@ var SimpleFinalizationViewer = class extends AbstractCreatableProvider {
|
|
|
4788
4823
|
}
|
|
4789
4824
|
async createHandler() {
|
|
4790
4825
|
await super.createHandler();
|
|
4791
|
-
this._chainId =
|
|
4826
|
+
this._chainId = assertEx37(this.config.chain.id ?? (await findMostRecentBlock(this.params.finalizedArchivist))?.chain, () => "chain.id is required if empty archivist");
|
|
4792
4827
|
this._store = { chainMap: this.params.finalizedArchivist };
|
|
4793
4828
|
}
|
|
4794
4829
|
async head() {
|
|
4795
4830
|
return await this.spanAsync("head", async () => {
|
|
4796
|
-
const currentHead =
|
|
4831
|
+
const currentHead = assertEx37(await this.getCurrentHead(), () => "Could not find most recent block [currentBlock]");
|
|
4797
4832
|
const cache = this.hydratedBlockCache;
|
|
4798
4833
|
const block = await cache.get(currentHead._hash);
|
|
4799
4834
|
if (!block) {
|
|
4800
4835
|
this.logger?.error(`Could not find current block with hash ${currentHead._hash}`);
|
|
4801
4836
|
}
|
|
4802
|
-
return
|
|
4837
|
+
return assertEx37(block, () => "Could not find current block");
|
|
4803
4838
|
}, this.context);
|
|
4804
4839
|
}
|
|
4805
4840
|
async headBlock() {
|
|
@@ -4825,8 +4860,8 @@ var SimpleFinalizationViewer = class extends AbstractCreatableProvider {
|
|
|
4825
4860
|
}
|
|
4826
4861
|
async getCurrentHead() {
|
|
4827
4862
|
const chainArchivist = this.finalizedArchivist;
|
|
4828
|
-
const result =
|
|
4829
|
-
|
|
4863
|
+
const result = assertEx37(await findMostRecentBlock(chainArchivist), () => "Could not find most recent block [getCurrentHead]");
|
|
4864
|
+
assertEx37(result?.chain === this._chainId, () => "Chain ID does not match head block chain ID");
|
|
4830
4865
|
return result;
|
|
4831
4866
|
}
|
|
4832
4867
|
};
|
|
@@ -4856,9 +4891,9 @@ var SimpleXyoGateway = class _SimpleXyoGateway extends AbstractCreatableProvider
|
|
|
4856
4891
|
|
|
4857
4892
|
// src/simple/gateway/SimpleXyoGatewayRunner.ts
|
|
4858
4893
|
import {
|
|
4859
|
-
assertEx as
|
|
4894
|
+
assertEx as assertEx38,
|
|
4860
4895
|
BigIntToJsonZod,
|
|
4861
|
-
isDefined as
|
|
4896
|
+
isDefined as isDefined18
|
|
4862
4897
|
} from "@xylabs/sdk-js";
|
|
4863
4898
|
import { PayloadBuilder as PayloadBuilder20 } from "@xyo-network/sdk-js";
|
|
4864
4899
|
import {
|
|
@@ -4889,23 +4924,23 @@ var SimpleXyoGatewayRunner = class _SimpleXyoGatewayRunner extends AbstractCreat
|
|
|
4889
4924
|
return this._signer;
|
|
4890
4925
|
}
|
|
4891
4926
|
async addPayloadsToChain(onChain, offChain, options) {
|
|
4892
|
-
const viewer =
|
|
4927
|
+
const viewer = assertEx38(this.connection.viewer, () => "No viewer available on connection");
|
|
4893
4928
|
const {
|
|
4894
4929
|
nbf,
|
|
4895
4930
|
exp,
|
|
4896
4931
|
chain,
|
|
4897
4932
|
fees
|
|
4898
4933
|
} = options ?? {};
|
|
4899
|
-
const resolvedChainId =
|
|
4900
|
-
const resolvedNbf = asXL1BlockNumber9(
|
|
4901
|
-
const resolvedExp = asXL1BlockNumber9(
|
|
4934
|
+
const resolvedChainId = isDefined18(chain) ? chain : await viewer.chainId();
|
|
4935
|
+
const resolvedNbf = asXL1BlockNumber9(isDefined18(nbf) ? nbf : await viewer.currentBlockNumber(), true);
|
|
4936
|
+
const resolvedExp = asXL1BlockNumber9(isDefined18(exp) ? exp : resolvedNbf + 10, true);
|
|
4902
4937
|
const tx = await buildUnsignedTransaction(resolvedChainId, onChain, offChain, resolvedNbf, resolvedExp, await this.signer.address(), fees);
|
|
4903
4938
|
return await this.addTransactionToChain(tx, await PayloadBuilder20.addHashMeta(offChain));
|
|
4904
4939
|
}
|
|
4905
4940
|
async addTransactionToChain(tx, offChain = []) {
|
|
4906
4941
|
const connection = this.connection;
|
|
4907
4942
|
const signer = this.signer;
|
|
4908
|
-
const runner =
|
|
4943
|
+
const runner = assertEx38(connection.runner, () => "No runner available on connection");
|
|
4909
4944
|
let signedTx;
|
|
4910
4945
|
if (isSignedHydratedTransaction(tx)) {
|
|
4911
4946
|
const [bw, payloads] = tx;
|
|
@@ -4920,7 +4955,7 @@ var SimpleXyoGatewayRunner = class _SimpleXyoGatewayRunner extends AbstractCreat
|
|
|
4920
4955
|
}
|
|
4921
4956
|
async confirmSubmittedTransaction(txHash, options) {
|
|
4922
4957
|
return await confirmSubmittedTransaction(
|
|
4923
|
-
|
|
4958
|
+
assertEx38(this.connection.viewer, () => "Connection viewer is undefined"),
|
|
4924
4959
|
txHash,
|
|
4925
4960
|
options
|
|
4926
4961
|
);
|
|
@@ -4957,13 +4992,10 @@ var SimpleXyoGatewayRunner = class _SimpleXyoGatewayRunner extends AbstractCreat
|
|
|
4957
4992
|
|
|
4958
4993
|
// src/simple/mempool/SimpleMempoolRunner.ts
|
|
4959
4994
|
import {
|
|
4960
|
-
assertEx as
|
|
4995
|
+
assertEx as assertEx39,
|
|
4961
4996
|
exists as exists8
|
|
4962
4997
|
} from "@xylabs/sdk-js";
|
|
4963
|
-
import {
|
|
4964
|
-
isPayloadBundle,
|
|
4965
|
-
PayloadBuilder as PayloadBuilder21
|
|
4966
|
-
} from "@xyo-network/sdk-js";
|
|
4998
|
+
import { isPayloadBundle, PayloadBuilder as PayloadBuilder21 } from "@xyo-network/sdk-js";
|
|
4967
4999
|
import {
|
|
4968
5000
|
BlockValidationViewerMoniker as BlockValidationViewerMoniker2,
|
|
4969
5001
|
ChainContractViewerMoniker as ChainContractViewerMoniker4,
|
|
@@ -5035,8 +5067,8 @@ var SimpleMempoolRunner = class extends AbstractCreatableProvider {
|
|
|
5035
5067
|
static async paramsHandler(params) {
|
|
5036
5068
|
return {
|
|
5037
5069
|
...await super.paramsHandler(params),
|
|
5038
|
-
pendingBlocksArchivist:
|
|
5039
|
-
pendingTransactionsArchivist:
|
|
5070
|
+
pendingBlocksArchivist: assertEx39(params?.pendingBlocksArchivist, () => "pendingBlocksArchivist is required"),
|
|
5071
|
+
pendingTransactionsArchivist: assertEx39(params?.pendingTransactionsArchivist, () => "pendingTransactionsArchivist is required")
|
|
5040
5072
|
};
|
|
5041
5073
|
}
|
|
5042
5074
|
async createHandler() {
|
|
@@ -5074,7 +5106,7 @@ var SimpleMempoolRunner = class extends AbstractCreatableProvider {
|
|
|
5074
5106
|
return b;
|
|
5075
5107
|
}
|
|
5076
5108
|
}).filter(exists8);
|
|
5077
|
-
|
|
5109
|
+
assertEx39(
|
|
5078
5110
|
remainingBlockMap.length === remainingBlocks.length,
|
|
5079
5111
|
() => `remainingBlockMap length should match remainingBlocks length [${remainingBlockMap.length}/${remainingBlocks.length}]`
|
|
5080
5112
|
);
|
|
@@ -5136,7 +5168,7 @@ var SimpleMempoolRunner = class extends AbstractCreatableProvider {
|
|
|
5136
5168
|
return t;
|
|
5137
5169
|
}
|
|
5138
5170
|
}).filter(exists8);
|
|
5139
|
-
|
|
5171
|
+
assertEx39(
|
|
5140
5172
|
remainingTransactionMap.length === remainingTransactions.length,
|
|
5141
5173
|
() => `remainingTransactionMap length should match remainingTransactions length [${remainingTransactionMap.length}/${remainingTransactions.length}]`
|
|
5142
5174
|
);
|
|
@@ -5387,14 +5419,11 @@ SimpleMempoolRunner = __decorateClass([
|
|
|
5387
5419
|
// src/simple/mempool/SimpleMempoolViewer.ts
|
|
5388
5420
|
import {
|
|
5389
5421
|
exists as exists9,
|
|
5390
|
-
isDefined as
|
|
5422
|
+
isDefined as isDefined19,
|
|
5391
5423
|
isHash as isHash2
|
|
5392
5424
|
} from "@xylabs/sdk-js";
|
|
5393
5425
|
import { isHashMeta as isHashMeta2, isPayloadBundle as isPayloadBundle2 } from "@xyo-network/sdk-js";
|
|
5394
|
-
import {
|
|
5395
|
-
MempoolViewerMoniker as MempoolViewerMoniker2,
|
|
5396
|
-
WindowedBlockViewerMoniker
|
|
5397
|
-
} from "@xyo-network/xl1-protocol-lib";
|
|
5426
|
+
import { MempoolViewerMoniker as MempoolViewerMoniker2, WindowedBlockViewerMoniker } from "@xyo-network/xl1-protocol-lib";
|
|
5398
5427
|
var DEFAULT_MEMPOOL_SELECTION_RATIO = 0.66;
|
|
5399
5428
|
var DEFAULT_DEMOTION_THRESHOLD = 3;
|
|
5400
5429
|
var DEFAULT_HANDOUT_STATS_TTL_BLOCKS = 1e3;
|
|
@@ -5451,7 +5480,7 @@ var SimpleMempoolViewer = class extends AbstractCreatableProvider {
|
|
|
5451
5480
|
let cursor = void 0;
|
|
5452
5481
|
if (isHash2(providedCursor)) {
|
|
5453
5482
|
const [p] = await this.pendingBlocksArchivist.get([providedCursor]);
|
|
5454
|
-
if (
|
|
5483
|
+
if (isDefined19(p)) {
|
|
5455
5484
|
cursor = p._sequence;
|
|
5456
5485
|
}
|
|
5457
5486
|
}
|
|
@@ -5470,7 +5499,7 @@ var SimpleMempoolViewer = class extends AbstractCreatableProvider {
|
|
|
5470
5499
|
let cursor = void 0;
|
|
5471
5500
|
if (isHash2(providedCursor)) {
|
|
5472
5501
|
const [p] = await this.pendingTransactionsArchivist.get([providedCursor]);
|
|
5473
|
-
if (
|
|
5502
|
+
if (isDefined19(p)) {
|
|
5474
5503
|
cursor = p._sequence;
|
|
5475
5504
|
}
|
|
5476
5505
|
}
|
|
@@ -5485,7 +5514,7 @@ var SimpleMempoolViewer = class extends AbstractCreatableProvider {
|
|
|
5485
5514
|
const hydratedWithBundle = (await Promise.all(
|
|
5486
5515
|
filteredBundles.map(async (bundle3) => {
|
|
5487
5516
|
const tx = await bundledPayloadToHydratedTransaction(bundle3);
|
|
5488
|
-
return
|
|
5517
|
+
return isDefined19(tx) ? { bundle: bundle3, tx } : void 0;
|
|
5489
5518
|
})
|
|
5490
5519
|
)).filter(exists9);
|
|
5491
5520
|
const currentBlock = await this.windowedBlockViewer.currentBlock();
|
|
@@ -5606,7 +5635,7 @@ function deduplicateWithBundleBySigner(items) {
|
|
|
5606
5635
|
|
|
5607
5636
|
// src/simple/network/SimpleXyoNetwork.ts
|
|
5608
5637
|
import { fetchJsonGet } from "@xylabs/fetch";
|
|
5609
|
-
import { isUndefined as
|
|
5638
|
+
import { isUndefined as isUndefined9 } from "@xylabs/sdk-js";
|
|
5610
5639
|
import { isNetworkStatus } from "@xyo-network/xl1-protocol-lib";
|
|
5611
5640
|
|
|
5612
5641
|
// src/simple/network/lib/FailedNetworkStatusPayloads.ts
|
|
@@ -5654,7 +5683,7 @@ var SimpleXyoNetwork = class {
|
|
|
5654
5683
|
}
|
|
5655
5684
|
async status() {
|
|
5656
5685
|
const statusNetwork = StatusNetworks[this._networkId];
|
|
5657
|
-
if (
|
|
5686
|
+
if (isUndefined9(statusNetwork)) {
|
|
5658
5687
|
throw new Error(`Unknown status network ID: ${this._networkId}`);
|
|
5659
5688
|
}
|
|
5660
5689
|
return await this.makeRequest(statusNetwork.statusUrl);
|
|
@@ -5679,7 +5708,7 @@ var SimpleXyoNetwork = class {
|
|
|
5679
5708
|
};
|
|
5680
5709
|
|
|
5681
5710
|
// src/simple/permissions/SimpleXyoPermissions.ts
|
|
5682
|
-
import { assertEx as
|
|
5711
|
+
import { assertEx as assertEx40 } from "@xylabs/sdk-js";
|
|
5683
5712
|
var SimpleXyoPermissions = class {
|
|
5684
5713
|
invoker;
|
|
5685
5714
|
_store;
|
|
@@ -5688,7 +5717,7 @@ var SimpleXyoPermissions = class {
|
|
|
5688
5717
|
this.invoker = store.invoker;
|
|
5689
5718
|
}
|
|
5690
5719
|
get store() {
|
|
5691
|
-
return
|
|
5720
|
+
return assertEx40(this._store, () => "Store must be defined to get permissions");
|
|
5692
5721
|
}
|
|
5693
5722
|
async getPermissions() {
|
|
5694
5723
|
return await this.store.getPermissions();
|
|
@@ -5741,7 +5770,7 @@ var SimpleXyoPermissions = class {
|
|
|
5741
5770
|
};
|
|
5742
5771
|
|
|
5743
5772
|
// src/simple/permissions/store/MemoryPermissions.ts
|
|
5744
|
-
import { assertEx as
|
|
5773
|
+
import { assertEx as assertEx41 } from "@xylabs/sdk-js";
|
|
5745
5774
|
var MemoryPermissionsStore = class {
|
|
5746
5775
|
_invoker;
|
|
5747
5776
|
permissions = [];
|
|
@@ -5749,7 +5778,7 @@ var MemoryPermissionsStore = class {
|
|
|
5749
5778
|
this._invoker = invoker;
|
|
5750
5779
|
}
|
|
5751
5780
|
get invoker() {
|
|
5752
|
-
return
|
|
5781
|
+
return assertEx41(this._invoker, () => "Invoker must be defined to get permissions");
|
|
5753
5782
|
}
|
|
5754
5783
|
async getPermissions() {
|
|
5755
5784
|
await Promise.resolve();
|
|
@@ -5763,10 +5792,7 @@ var MemoryPermissionsStore = class {
|
|
|
5763
5792
|
|
|
5764
5793
|
// src/simple/runner/SimpleXyoRunner.ts
|
|
5765
5794
|
import { PayloadBuilder as PayloadBuilder22 } from "@xyo-network/sdk-js";
|
|
5766
|
-
import {
|
|
5767
|
-
MempoolRunnerMoniker as MempoolRunnerMoniker2,
|
|
5768
|
-
XyoRunnerMoniker
|
|
5769
|
-
} from "@xyo-network/xl1-protocol-lib";
|
|
5795
|
+
import { MempoolRunnerMoniker as MempoolRunnerMoniker2, XyoRunnerMoniker } from "@xyo-network/xl1-protocol-lib";
|
|
5770
5796
|
var SimpleXyoRunner = class extends AbstractCreatableProvider {
|
|
5771
5797
|
moniker = SimpleXyoRunner.defaultMoniker;
|
|
5772
5798
|
_mempoolRunner;
|
|
@@ -5840,10 +5866,8 @@ var SimpleXyoSigner = class _SimpleXyoSigner extends AbstractCreatableProvider {
|
|
|
5840
5866
|
};
|
|
5841
5867
|
|
|
5842
5868
|
// src/simple/StakeEventsViewer/SimpleStakeEventsViewer.ts
|
|
5843
|
-
import { isDefined as
|
|
5844
|
-
import {
|
|
5845
|
-
StakeEventsViewerMoniker
|
|
5846
|
-
} from "@xyo-network/xl1-protocol-lib";
|
|
5869
|
+
import { isDefined as isDefined20 } from "@xylabs/sdk-js";
|
|
5870
|
+
import { StakeEventsViewerMoniker } from "@xyo-network/xl1-protocol-lib";
|
|
5847
5871
|
var SimpleStakeEventsViewer = class extends AbstractCreatableProvider {
|
|
5848
5872
|
moniker = SimpleStakeEventsViewer.defaultMoniker;
|
|
5849
5873
|
get positions() {
|
|
@@ -5855,7 +5879,7 @@ var SimpleStakeEventsViewer = class extends AbstractCreatableProvider {
|
|
|
5855
5879
|
stakeEvents(range, { name } = {}) {
|
|
5856
5880
|
const positions = this.positionsFromRange(range);
|
|
5857
5881
|
const events = this.eventsFromPositions(positions);
|
|
5858
|
-
if (
|
|
5882
|
+
if (isDefined20(name)) {
|
|
5859
5883
|
return events.filter((event) => event.name === name);
|
|
5860
5884
|
}
|
|
5861
5885
|
return events;
|
|
@@ -5921,7 +5945,7 @@ SimpleStakeEventsViewer = __decorateClass([
|
|
|
5921
5945
|
|
|
5922
5946
|
// src/simple/StakeTotalsViewer/SimpleStakeTotalsViewer.ts
|
|
5923
5947
|
import { asAddress as asAddress3 } from "@xylabs/sdk-js";
|
|
5924
|
-
import { assertEx as
|
|
5948
|
+
import { assertEx as assertEx42 } from "@xylabs/sdk-js";
|
|
5925
5949
|
import {
|
|
5926
5950
|
StakeTotalsViewerMoniker,
|
|
5927
5951
|
StakeViewerMoniker
|
|
@@ -5964,7 +5988,7 @@ var SimpleStakeTotalsViewer = class extends AbstractCreatableProvider {
|
|
|
5964
5988
|
}
|
|
5965
5989
|
async createHandler() {
|
|
5966
5990
|
await super.createHandler();
|
|
5967
|
-
this._stakeViewer =
|
|
5991
|
+
this._stakeViewer = assertEx42(
|
|
5968
5992
|
await this.locateAndCreate(StakeViewerMoniker),
|
|
5969
5993
|
() => "Failed to create StakeViewer"
|
|
5970
5994
|
);
|
|
@@ -6020,18 +6044,15 @@ SimpleStakeTotalsViewer = __decorateClass([
|
|
|
6020
6044
|
// src/simple/StakeViewer/SimpleStakeViewer.ts
|
|
6021
6045
|
import {
|
|
6022
6046
|
asAddress as asAddress4,
|
|
6047
|
+
assertEx as assertEx43,
|
|
6023
6048
|
toAddress as toAddress6
|
|
6024
6049
|
} from "@xylabs/sdk-js";
|
|
6025
|
-
import {
|
|
6026
|
-
import {
|
|
6027
|
-
StakeEventsViewerMoniker as StakeEventsViewerMoniker2,
|
|
6028
|
-
StakeViewerMoniker as StakeViewerMoniker2
|
|
6029
|
-
} from "@xyo-network/xl1-protocol-lib";
|
|
6050
|
+
import { StakeEventsViewerMoniker as StakeEventsViewerMoniker2, StakeViewerMoniker as StakeViewerMoniker2 } from "@xyo-network/xl1-protocol-lib";
|
|
6030
6051
|
var SimpleStakeViewer = class extends AbstractCreatableProvider {
|
|
6031
6052
|
moniker = SimpleStakeViewer.defaultMoniker;
|
|
6032
6053
|
_chainStakeEventsViewer;
|
|
6033
6054
|
get stakeEvents() {
|
|
6034
|
-
return
|
|
6055
|
+
return assertEx43(this._chainStakeEventsViewer, () => "Stake events viewer not set");
|
|
6035
6056
|
}
|
|
6036
6057
|
get positions() {
|
|
6037
6058
|
return this.params.positions;
|
|
@@ -6071,7 +6092,7 @@ var SimpleStakeViewer = class extends AbstractCreatableProvider {
|
|
|
6071
6092
|
}
|
|
6072
6093
|
async createHandler() {
|
|
6073
6094
|
await super.createHandler();
|
|
6074
|
-
this._chainStakeEventsViewer =
|
|
6095
|
+
this._chainStakeEventsViewer = assertEx43(
|
|
6075
6096
|
await this.locateAndCreate(StakeEventsViewerMoniker2),
|
|
6076
6097
|
() => "Failed to create StakeEventsViewer"
|
|
6077
6098
|
);
|
|
@@ -6106,7 +6127,7 @@ var SimpleStakeViewer = class extends AbstractCreatableProvider {
|
|
|
6106
6127
|
return toAddress6(toAddress6(1n));
|
|
6107
6128
|
}
|
|
6108
6129
|
stakeById(id) {
|
|
6109
|
-
return
|
|
6130
|
+
return assertEx43(this.positions[id], () => new Error(`Stake with id ${id} not found`));
|
|
6110
6131
|
}
|
|
6111
6132
|
stakeByStaker(staker, slot) {
|
|
6112
6133
|
return this.positions.filter((s) => asAddress4(s.staker) === asAddress4(staker))[slot];
|
|
@@ -6156,8 +6177,8 @@ SimpleStakeViewer = __decorateClass([
|
|
|
6156
6177
|
// src/simple/timeSync2/SimpleTimeSyncViewer.ts
|
|
6157
6178
|
import {
|
|
6158
6179
|
asHash as asHash5,
|
|
6159
|
-
assertEx as
|
|
6160
|
-
isDefined as
|
|
6180
|
+
assertEx as assertEx44,
|
|
6181
|
+
isDefined as isDefined21
|
|
6161
6182
|
} from "@xylabs/sdk-js";
|
|
6162
6183
|
import {
|
|
6163
6184
|
asTimePayload as asTimePayload2,
|
|
@@ -6178,10 +6199,10 @@ var SimpleTimeSyncViewer = class extends AbstractCreatableProvider {
|
|
|
6178
6199
|
async convertTime(fromDomain, toDomain, from) {
|
|
6179
6200
|
switch (fromDomain) {
|
|
6180
6201
|
case "xl1": {
|
|
6181
|
-
const [block, payloads] =
|
|
6202
|
+
const [block, payloads] = assertEx44(await this.blockViewer.blockByNumber(asXL1BlockNumber10(from, true)), () => "Block not found");
|
|
6182
6203
|
const timeSchemaIndex = block.payload_schemas.indexOf(TimeSchema);
|
|
6183
6204
|
const hash = timeSchemaIndex === -1 ? void 0 : block.payload_hashes[timeSchemaIndex];
|
|
6184
|
-
const timePayload = asTimePayload2(
|
|
6205
|
+
const timePayload = asTimePayload2(isDefined21(hash) ? payloads.find((p) => p._hash === hash) : void 0);
|
|
6185
6206
|
if (timePayload === void 0) return 0;
|
|
6186
6207
|
switch (toDomain) {
|
|
6187
6208
|
case "xl1": {
|
|
@@ -6233,10 +6254,10 @@ var SimpleTimeSyncViewer = class extends AbstractCreatableProvider {
|
|
|
6233
6254
|
return [Date.now(), null];
|
|
6234
6255
|
}
|
|
6235
6256
|
case "ethereum": {
|
|
6236
|
-
const provider =
|
|
6257
|
+
const provider = assertEx44(this.ethProvider, () => "Ethereum provider not configured");
|
|
6237
6258
|
const blockNumber = await provider.getBlockNumber() ?? 0;
|
|
6238
6259
|
const block = await provider.getBlock(blockNumber);
|
|
6239
|
-
const blockHash = asHash5(
|
|
6260
|
+
const blockHash = asHash5(assertEx44(block?.hash, () => "Block hash not found"), true);
|
|
6240
6261
|
return [blockNumber, blockHash];
|
|
6241
6262
|
}
|
|
6242
6263
|
default: {
|
|
@@ -6251,10 +6272,10 @@ var SimpleTimeSyncViewer = class extends AbstractCreatableProvider {
|
|
|
6251
6272
|
// this is for the previous block
|
|
6252
6273
|
xl1,
|
|
6253
6274
|
// this is for the previous block
|
|
6254
|
-
xl1Hash:
|
|
6275
|
+
xl1Hash: assertEx44(xl1Hash, () => "No xl1 hash available from time sync service"),
|
|
6255
6276
|
epoch: Date.now()
|
|
6256
6277
|
};
|
|
6257
|
-
if (
|
|
6278
|
+
if (isDefined21(this.ethProvider)) {
|
|
6258
6279
|
const [ethereum, ethHashOrNull] = await this.currentTimeAndHash("ethereum");
|
|
6259
6280
|
const ethereumHash = asHash5(ethHashOrNull, () => "No ethereum hash available from time sync service");
|
|
6260
6281
|
timePayload.ethereum = ethereum;
|
|
@@ -6271,7 +6292,7 @@ SimpleTimeSyncViewer = __decorateClass([
|
|
|
6271
6292
|
], SimpleTimeSyncViewer);
|
|
6272
6293
|
|
|
6273
6294
|
// src/simple/transactionValidation/SimpleTransactionValidationViewer.ts
|
|
6274
|
-
import { assertEx as
|
|
6295
|
+
import { assertEx as assertEx45 } from "@xylabs/sdk-js";
|
|
6275
6296
|
import { PayloadBuilder as PayloadBuilder24 } from "@xyo-network/sdk-js";
|
|
6276
6297
|
import {
|
|
6277
6298
|
AccountBalanceViewerMoniker as AccountBalanceViewerMoniker3,
|
|
@@ -6322,7 +6343,7 @@ var SimpleTransactionValidationViewer = class extends AbstractCreatableProvider
|
|
|
6322
6343
|
head: void 0
|
|
6323
6344
|
};
|
|
6324
6345
|
const transactionsWithMeta = await Promise.all(transactions.map((b) => Promise.all([PayloadBuilder24.addHashMeta(b[0]), PayloadBuilder24.addHashMeta(b[1])])));
|
|
6325
|
-
const head = isChainQualifiedHeadConfig6(config) ?
|
|
6346
|
+
const head = isChainQualifiedHeadConfig6(config) ? assertEx45(
|
|
6326
6347
|
(await this.blockViewer.blockByHash(config.head))?.[0],
|
|
6327
6348
|
() => `Specified a head that is not in the chain [${config.head}]`
|
|
6328
6349
|
) : void 0;
|
|
@@ -6388,10 +6409,7 @@ SimpleTransactionValidationViewer = __decorateClass([
|
|
|
6388
6409
|
], SimpleTransactionValidationViewer);
|
|
6389
6410
|
|
|
6390
6411
|
// src/simple/TransactionViewer/SimpleTransactionViewer.ts
|
|
6391
|
-
import {
|
|
6392
|
-
assertEx as assertEx45,
|
|
6393
|
-
exists as exists10
|
|
6394
|
-
} from "@xylabs/sdk-js";
|
|
6412
|
+
import { assertEx as assertEx46, exists as exists10 } from "@xylabs/sdk-js";
|
|
6395
6413
|
import { BoundWitnessSchema } from "@xyo-network/sdk-js";
|
|
6396
6414
|
import {
|
|
6397
6415
|
asSignedHydratedTransactionWithHashMeta,
|
|
@@ -6408,7 +6426,7 @@ var SimpleTransactionViewer = class extends AbstractCreatableProvider {
|
|
|
6408
6426
|
}
|
|
6409
6427
|
async byBlockHashAndIndex(blockHash, transactionIndex) {
|
|
6410
6428
|
return await this.spanAsync("byBlockHashAndIndex", async () => {
|
|
6411
|
-
|
|
6429
|
+
assertEx46(transactionIndex >= 0, () => "transactionIndex must be greater than or equal to 0");
|
|
6412
6430
|
try {
|
|
6413
6431
|
const block = await this.blockViewer.blockByHash(blockHash);
|
|
6414
6432
|
if (!block) return null;
|
|
@@ -6472,7 +6490,7 @@ SimpleTransactionViewer = __decorateClass([
|
|
|
6472
6490
|
|
|
6473
6491
|
// src/simple/windowedBlock/SimpleWindowedBlockViewer.ts
|
|
6474
6492
|
import {
|
|
6475
|
-
assertEx as
|
|
6493
|
+
assertEx as assertEx47,
|
|
6476
6494
|
exists as exists11,
|
|
6477
6495
|
isNull as isNull2
|
|
6478
6496
|
} from "@xylabs/sdk-js";
|
|
@@ -6543,7 +6561,7 @@ var SimpleWindowedBlockViewer = class extends AbstractCreatableProvider {
|
|
|
6543
6561
|
}
|
|
6544
6562
|
async createHandler() {
|
|
6545
6563
|
await super.createHandler();
|
|
6546
|
-
this._blockViewer =
|
|
6564
|
+
this._blockViewer = assertEx47(
|
|
6547
6565
|
this.params.blockViewer ?? await this.locator.getInstance(BlockViewerMoniker7),
|
|
6548
6566
|
() => "BlockViewer instance is required"
|
|
6549
6567
|
);
|
|
@@ -6552,13 +6570,13 @@ var SimpleWindowedBlockViewer = class extends AbstractCreatableProvider {
|
|
|
6552
6570
|
this._transactionHashMap = new MemoryMap();
|
|
6553
6571
|
}
|
|
6554
6572
|
currentBlock() {
|
|
6555
|
-
return
|
|
6573
|
+
return assertEx47(this._chain.at(-1));
|
|
6556
6574
|
}
|
|
6557
6575
|
currentBlockHash() {
|
|
6558
|
-
return
|
|
6576
|
+
return assertEx47(this._chain.at(-1)?.[0]._hash);
|
|
6559
6577
|
}
|
|
6560
6578
|
currentBlockNumber() {
|
|
6561
|
-
return
|
|
6579
|
+
return assertEx47(this._chain.at(-1)?.[0].block);
|
|
6562
6580
|
}
|
|
6563
6581
|
async payloadByHash(hash) {
|
|
6564
6582
|
const payloads = await this.payloadsByHash([hash]);
|
|
@@ -6717,13 +6735,13 @@ var RuntimeStatusMonitor = class extends LoggerStatusReporter {
|
|
|
6717
6735
|
};
|
|
6718
6736
|
|
|
6719
6737
|
// src/time/primitives/xl1BlockNumberToEthBlockNumber.ts
|
|
6720
|
-
import { assertEx as
|
|
6738
|
+
import { assertEx as assertEx48 } from "@xylabs/sdk-js";
|
|
6721
6739
|
import { asTimePayload as asTimePayload3, TimeSchema as TimeSchema2 } from "@xyo-network/xl1-protocol-lib";
|
|
6722
6740
|
async function xl1BlockNumberToEthBlockNumber(context, xl1BlockNumber) {
|
|
6723
6741
|
const blockHash = await hashFromBlockNumber(context, xl1BlockNumber);
|
|
6724
6742
|
const hydratedBlock = await hydrateBlock(context, blockHash);
|
|
6725
6743
|
const timePayload = asTimePayload3(hydratedBlock[1].find((p) => p.schema === TimeSchema2), { required: true });
|
|
6726
|
-
return
|
|
6744
|
+
return assertEx48(timePayload.ethereum, () => "No ethereum timestamp found on block");
|
|
6727
6745
|
}
|
|
6728
6746
|
|
|
6729
6747
|
// src/validation/lib/isLocalhost.ts
|
|
@@ -6741,8 +6759,8 @@ var getUrl = (host, port) => {
|
|
|
6741
6759
|
var TODO = true;
|
|
6742
6760
|
|
|
6743
6761
|
// src/validation/schema/Mnemonic.ts
|
|
6744
|
-
import { z as
|
|
6745
|
-
var MnemonicStringZod =
|
|
6762
|
+
import { z as z30 } from "zod";
|
|
6763
|
+
var MnemonicStringZod = z30.string().transform((s) => s.trim().replaceAll(/\s+/g, " ")).refine(
|
|
6746
6764
|
(s) => [12, 15, 18, 21, 24].includes(s.split(" ").length),
|
|
6747
6765
|
{ message: "Mnemonic must contain 12, 15, 18, 21, or 24 words." }
|
|
6748
6766
|
).describe("BIP-39 mnemonic string");
|
|
@@ -6808,6 +6826,7 @@ export {
|
|
|
6808
6826
|
MissingCapabilityError,
|
|
6809
6827
|
MnemonicStringZod,
|
|
6810
6828
|
PRODUCER_DIVERSITY_BONUS,
|
|
6829
|
+
PayloadLocator,
|
|
6811
6830
|
PostMessageRpcRemoteConfigZod,
|
|
6812
6831
|
ProviderConfigZod,
|
|
6813
6832
|
ProviderFactory,
|