@xyo-network/xl1-protocol-sdk 2.0.10 → 2.0.12
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/README.md +3 -6
- package/dist/neutral/ChainContextHelpers.d.ts.map +1 -1
- package/dist/neutral/CreatableProvider/AbstractCreatableProvider.d.ts +8 -1
- package/dist/neutral/CreatableProvider/AbstractCreatableProvider.d.ts.map +1 -1
- package/dist/neutral/config/Actor.d.ts +48 -6
- package/dist/neutral/config/Actor.d.ts.map +1 -1
- package/dist/neutral/config/Actors.d.ts +8 -1
- package/dist/neutral/config/Actors.d.ts.map +1 -1
- package/dist/neutral/config/Base.d.ts +8 -1
- package/dist/neutral/config/Base.d.ts.map +1 -1
- package/dist/neutral/config/Config.d.ts +32 -4
- package/dist/neutral/config/Config.d.ts.map +1 -1
- package/dist/neutral/config/HostActor.d.ts +48 -6
- package/dist/neutral/config/HostActor.d.ts.map +1 -1
- package/dist/neutral/config/Log.d.ts +1 -1
- package/dist/neutral/config/index.d.ts +1 -1
- package/dist/neutral/config/index.d.ts.map +1 -1
- package/dist/neutral/config/storage/Storage.d.ts +7 -0
- package/dist/neutral/config/storage/Storage.d.ts.map +1 -1
- package/dist/neutral/config/storage/driver/R2.d.ts +25 -0
- package/dist/neutral/config/storage/driver/R2.d.ts.map +1 -0
- package/dist/neutral/config/storage/driver/index.d.ts +1 -0
- package/dist/neutral/config/storage/driver/index.d.ts.map +1 -1
- package/dist/neutral/context/Actor.d.ts +48 -6
- package/dist/neutral/context/Actor.d.ts.map +1 -1
- package/dist/neutral/context/HostActor.d.ts +48 -6
- package/dist/neutral/context/HostActor.d.ts.map +1 -1
- package/dist/neutral/getFileConfig.d.ts +16 -2
- package/dist/neutral/getFileConfig.d.ts.map +1 -1
- package/dist/neutral/getFileConfig.mjs +76 -44
- package/dist/neutral/getFileConfig.mjs.map +4 -4
- package/dist/neutral/index.d.ts +2 -1
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +820 -358
- package/dist/neutral/index.mjs.map +4 -4
- package/dist/neutral/model/CreatableProviderContext.zod.d.ts +48 -6
- package/dist/neutral/model/CreatableProviderContext.zod.d.ts.map +1 -1
- package/dist/neutral/simple/block/SimpleBlockViewer.d.ts +13 -2
- package/dist/neutral/simple/block/SimpleBlockViewer.d.ts.map +1 -1
- package/dist/neutral/simple/mempool/SimpleMempoolRunner.d.ts.map +1 -1
- package/dist/neutral/simple/windowedBlock/SimpleWindowedBlockViewer.d.ts +33 -0
- package/dist/neutral/simple/windowedBlock/SimpleWindowedBlockViewer.d.ts.map +1 -1
- package/dist/neutral/summary/model/BlocksStepSummary.d.ts +26 -0
- package/dist/neutral/summary/model/BlocksStepSummary.d.ts.map +1 -0
- package/dist/neutral/summary/model/index.d.ts +1 -0
- package/dist/neutral/summary/model/index.d.ts.map +1 -1
- package/dist/neutral/summary/primitives/blocks/blocksMaxStep.d.ts +13 -0
- package/dist/neutral/summary/primitives/blocks/blocksMaxStep.d.ts.map +1 -0
- package/dist/neutral/summary/primitives/blocks/blocksStepSummaryFromRange.d.ts +13 -0
- package/dist/neutral/summary/primitives/blocks/blocksStepSummaryFromRange.d.ts.map +1 -0
- package/dist/neutral/summary/primitives/blocks/index.d.ts +3 -0
- package/dist/neutral/summary/primitives/blocks/index.d.ts.map +1 -0
- package/dist/neutral/summary/primitives/index.d.ts +1 -0
- package/dist/neutral/summary/primitives/index.d.ts.map +1 -1
- package/dist/neutral/test/index.d.ts +1 -0
- package/dist/neutral/test/index.d.ts.map +1 -1
- package/dist/neutral/test/index.mjs +1164 -1044
- package/dist/neutral/test/index.mjs.map +4 -4
- package/package.json +19 -20
- package/dist/neutral/driver/cache/LruCacheMap.d.ts +0 -15
- package/dist/neutral/driver/cache/LruCacheMap.d.ts.map +0 -1
- package/dist/neutral/driver/cache/index.d.ts +0 -2
- package/dist/neutral/driver/cache/index.d.ts.map +0 -1
- package/dist/neutral/driver/index.d.ts +0 -3
- package/dist/neutral/driver/index.d.ts.map +0 -1
- package/dist/neutral/driver/memory/MemoryMap.d.ts +0 -14
- package/dist/neutral/driver/memory/MemoryMap.d.ts.map +0 -1
- package/dist/neutral/driver/memory/index.d.ts +0 -2
- package/dist/neutral/driver/memory/index.d.ts.map +0 -1
package/dist/neutral/index.mjs
CHANGED
|
@@ -674,7 +674,7 @@ var tryHydrateBlock = async (archivist, hash, maxDepth = 1) => {
|
|
|
674
674
|
// src/block/primitives/blockFromBlockNumber.ts
|
|
675
675
|
import {
|
|
676
676
|
asHash,
|
|
677
|
-
isDefined as
|
|
677
|
+
isDefined as isDefined3,
|
|
678
678
|
spanAsync
|
|
679
679
|
} from "@xylabs/sdk-js";
|
|
680
680
|
import { toSafeJsonString } from "@xylabs/sdk-js";
|
|
@@ -686,91 +686,12 @@ import {
|
|
|
686
686
|
|
|
687
687
|
// src/ChainContextHelpers.ts
|
|
688
688
|
import {
|
|
689
|
-
isDefined as
|
|
689
|
+
isDefined as isDefined2,
|
|
690
690
|
isObject,
|
|
691
691
|
isUndefined as isUndefined4,
|
|
692
692
|
timeBudget
|
|
693
693
|
} from "@xylabs/sdk-js";
|
|
694
|
-
|
|
695
|
-
// src/driver/cache/LruCacheMap.ts
|
|
696
|
-
import { LRUCache as LRUCache2 } from "lru-cache";
|
|
697
|
-
var LruCacheMap = class {
|
|
698
|
-
lruCache;
|
|
699
|
-
constructor(options) {
|
|
700
|
-
this.lruCache = new LRUCache2(options ?? { max: 5e3 });
|
|
701
|
-
}
|
|
702
|
-
clear() {
|
|
703
|
-
this.lruCache.clear();
|
|
704
|
-
}
|
|
705
|
-
delete(id) {
|
|
706
|
-
return this.lruCache.delete(id);
|
|
707
|
-
}
|
|
708
|
-
get(id) {
|
|
709
|
-
return this.lruCache.get(id);
|
|
710
|
-
}
|
|
711
|
-
getMany(id) {
|
|
712
|
-
const results = [];
|
|
713
|
-
for (const key of id) {
|
|
714
|
-
const value = this.lruCache.get(key);
|
|
715
|
-
if (value !== void 0) {
|
|
716
|
-
results.push(value);
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
return results;
|
|
720
|
-
}
|
|
721
|
-
has(id) {
|
|
722
|
-
return this.lruCache.has(id);
|
|
723
|
-
}
|
|
724
|
-
set(id, data) {
|
|
725
|
-
this.lruCache.set(id, data);
|
|
726
|
-
}
|
|
727
|
-
setMany(entries) {
|
|
728
|
-
for (const [key, value] of entries) {
|
|
729
|
-
this.lruCache.set(key, value);
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
};
|
|
733
|
-
|
|
734
|
-
// src/driver/memory/MemoryMap.ts
|
|
735
|
-
import { isDefined as isDefined2 } from "@xylabs/sdk-js";
|
|
736
|
-
var MemoryMap = class {
|
|
737
|
-
map;
|
|
738
|
-
constructor() {
|
|
739
|
-
this.map = /* @__PURE__ */ new Map();
|
|
740
|
-
}
|
|
741
|
-
clear() {
|
|
742
|
-
this.map.clear();
|
|
743
|
-
}
|
|
744
|
-
delete(id) {
|
|
745
|
-
return this.map.delete(id);
|
|
746
|
-
}
|
|
747
|
-
get(id) {
|
|
748
|
-
return this.map.get(id);
|
|
749
|
-
}
|
|
750
|
-
getMany(ids) {
|
|
751
|
-
const results = [];
|
|
752
|
-
for (const id of ids) {
|
|
753
|
-
const data = this.map.get(id);
|
|
754
|
-
if (isDefined2(data)) {
|
|
755
|
-
results.push(data);
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
return results;
|
|
759
|
-
}
|
|
760
|
-
has(id) {
|
|
761
|
-
return this.map.has(id);
|
|
762
|
-
}
|
|
763
|
-
set(id, data) {
|
|
764
|
-
this.map.set(id, data);
|
|
765
|
-
}
|
|
766
|
-
setMany(entries) {
|
|
767
|
-
for (const [key, value] of entries) {
|
|
768
|
-
this.map.set(key, value);
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
};
|
|
772
|
-
|
|
773
|
-
// src/ChainContextHelpers.ts
|
|
694
|
+
import { LruCacheMap, MemoryMap } from "@xyo-network/xl1-driver-memory";
|
|
774
695
|
function contextCache(context, name, create) {
|
|
775
696
|
if (!isObject(context.caches)) {
|
|
776
697
|
throw new Error("Context does not have an appropriate caches property");
|
|
@@ -788,7 +709,7 @@ async function withContextCacheResponse(context, name, key, func, { max = 1e4 }
|
|
|
788
709
|
);
|
|
789
710
|
const { timeBudgetLimit = 0 } = context;
|
|
790
711
|
const cacheResult = await cache.get(key);
|
|
791
|
-
if (
|
|
712
|
+
if (isDefined2(cacheResult)) {
|
|
792
713
|
return cacheResult;
|
|
793
714
|
}
|
|
794
715
|
const result = timeBudgetLimit > 0 ? timeBudget(name, context.logger, func, timeBudgetLimit) : func();
|
|
@@ -803,7 +724,7 @@ async function blockFromBlockNumber(context, blockNumber) {
|
|
|
803
724
|
const { chainMap, head } = context;
|
|
804
725
|
return await withContextCacheResponse(context, "blockFromBlockNumber", cacheKey, async () => {
|
|
805
726
|
const [result] = await chainMap.get([head._hash]);
|
|
806
|
-
if (!
|
|
727
|
+
if (!isDefined3(result)) {
|
|
807
728
|
throw new Error(`Head block not found for hash: ${head._hash}`);
|
|
808
729
|
}
|
|
809
730
|
let currentBlock = asSignedBlockBoundWitnessWithStorageMeta(
|
|
@@ -816,8 +737,8 @@ async function blockFromBlockNumber(context, blockNumber) {
|
|
|
816
737
|
while (currentBlock.block > blockNumber) {
|
|
817
738
|
let jumpHash = currentBlock.previous;
|
|
818
739
|
let jumpBlockNumber = currentBlock.block - 1;
|
|
819
|
-
for (const [step,
|
|
820
|
-
const possibleJumpBlockNumber = currentBlock.block - currentBlock.block %
|
|
740
|
+
for (const [step, stepSize4] of StepSizes.entries()) {
|
|
741
|
+
const possibleJumpBlockNumber = currentBlock.block - currentBlock.block % stepSize4 - 1;
|
|
821
742
|
if (possibleJumpBlockNumber >= blockNumber && possibleJumpBlockNumber <= jumpBlockNumber) {
|
|
822
743
|
jumpBlockNumber = possibleJumpBlockNumber;
|
|
823
744
|
jumpHash = asHash(currentBlock.step_hashes?.at(step), () => `Step hash not found for step ${step} in block ${currentBlock.block}`);
|
|
@@ -826,7 +747,7 @@ async function blockFromBlockNumber(context, blockNumber) {
|
|
|
826
747
|
const [newBlock] = await chainMap.get([
|
|
827
748
|
asHash(jumpHash, () => `Jump hash not found for block number [${blockNumber}]: ${jumpBlockNumber} ${toSafeJsonString(currentBlock, 10)}`)
|
|
828
749
|
]);
|
|
829
|
-
if (!
|
|
750
|
+
if (!isDefined3(newBlock)) {
|
|
830
751
|
throw new Error(`Block not found for jump hash: ${jumpHash}`);
|
|
831
752
|
}
|
|
832
753
|
currentBlock = asSignedBlockBoundWitnessWithStorageMeta(
|
|
@@ -1241,10 +1162,10 @@ import {
|
|
|
1241
1162
|
zodIsFactory as zodIsFactory2,
|
|
1242
1163
|
zodToFactory as zodToFactory2
|
|
1243
1164
|
} from "@xylabs/sdk-js";
|
|
1244
|
-
import { globalRegistry as
|
|
1165
|
+
import { globalRegistry as globalRegistry13, z as z18 } from "zod/mini";
|
|
1245
1166
|
|
|
1246
1167
|
// src/config/Base.ts
|
|
1247
|
-
import { z as
|
|
1168
|
+
import { z as z17 } from "zod/mini";
|
|
1248
1169
|
|
|
1249
1170
|
// src/config/Chain.ts
|
|
1250
1171
|
import { HexZod } from "@xylabs/sdk-js";
|
|
@@ -1414,11 +1335,11 @@ var RpcRemoteConfigZod = z11.union([HttpRpcRemoteConfigZod, PostMessageRpcRemote
|
|
|
1414
1335
|
var RemoteConfigZod = z11.object({ rpc: RpcRemoteConfigZod.optional() }).describe("Configuration for remote connections, including RPC");
|
|
1415
1336
|
|
|
1416
1337
|
// src/config/storage/driver/Mongo.ts
|
|
1417
|
-
import { isDefined as
|
|
1338
|
+
import { isDefined as isDefined4, isUndefined as isUndefined5 } from "@xylabs/sdk-js";
|
|
1418
1339
|
import { globalRegistry as globalRegistry8, z as z12 } from "zod";
|
|
1419
1340
|
var hasMongoConfig = (config) => {
|
|
1420
1341
|
if (isUndefined5(config)) return false;
|
|
1421
|
-
return
|
|
1342
|
+
return isDefined4(config.connectionString) && isDefined4(config.database) && isDefined4(config.domain);
|
|
1422
1343
|
};
|
|
1423
1344
|
var MongoConfigZod = z12.object({
|
|
1424
1345
|
// TODO: Create from other arguments
|
|
@@ -1449,11 +1370,47 @@ var MongoConfigZod = z12.object({
|
|
|
1449
1370
|
})
|
|
1450
1371
|
});
|
|
1451
1372
|
|
|
1452
|
-
// src/config/storage/
|
|
1373
|
+
// src/config/storage/driver/R2.ts
|
|
1374
|
+
import { isDefined as isDefined5, isUndefined as isUndefined6 } from "@xylabs/sdk-js";
|
|
1453
1375
|
import { globalRegistry as globalRegistry9, z as z13 } from "zod";
|
|
1454
|
-
var
|
|
1376
|
+
var hasR2Config = (config) => {
|
|
1377
|
+
if (isUndefined6(config)) return false;
|
|
1378
|
+
return isDefined5(config.accountId) && isDefined5(config.accessKeyId) && isDefined5(config.secretAccessKey) && isDefined5(config.bucket);
|
|
1379
|
+
};
|
|
1380
|
+
var R2ConfigZod = z13.object({
|
|
1381
|
+
accessKeyId: z13.string().nonempty().optional().register(globalRegistry9, {
|
|
1382
|
+
description: "Cloudflare R2 access key id (from an R2 API token)",
|
|
1383
|
+
title: "storage.r2.accessKeyId",
|
|
1384
|
+
type: "string"
|
|
1385
|
+
}),
|
|
1386
|
+
accountId: z13.string().nonempty().optional().register(globalRegistry9, {
|
|
1387
|
+
description: "Cloudflare account id; determines the R2 endpoint https://<accountId>.r2.cloudflarestorage.com",
|
|
1388
|
+
title: "storage.r2.accountId",
|
|
1389
|
+
type: "string"
|
|
1390
|
+
}),
|
|
1391
|
+
bucket: z13.string().nonempty().optional().register(globalRegistry9, {
|
|
1392
|
+
description: "Cloudflare R2 bucket name",
|
|
1393
|
+
title: "storage.r2.bucket",
|
|
1394
|
+
type: "string"
|
|
1395
|
+
}),
|
|
1396
|
+
prefix: z13.string().nonempty().optional().register(globalRegistry9, {
|
|
1397
|
+
description: "Optional key prefix namespacing this store within the bucket",
|
|
1398
|
+
title: "storage.r2.prefix",
|
|
1399
|
+
type: "string"
|
|
1400
|
+
}),
|
|
1401
|
+
secretAccessKey: z13.string().nonempty().optional().register(globalRegistry9, {
|
|
1402
|
+
description: "Cloudflare R2 secret access key (from an R2 API token)",
|
|
1403
|
+
title: "storage.r2.secretAccessKey",
|
|
1404
|
+
type: "string"
|
|
1405
|
+
})
|
|
1406
|
+
});
|
|
1407
|
+
|
|
1408
|
+
// src/config/storage/Storage.ts
|
|
1409
|
+
import { globalRegistry as globalRegistry10, z as z14 } from "zod";
|
|
1410
|
+
var StorageConfigZod = z14.object({
|
|
1455
1411
|
mongo: MongoConfigZod.optional().describe("Configuration for the MongoD storage driver"),
|
|
1456
|
-
|
|
1412
|
+
r2: R2ConfigZod.optional().describe("Configuration for the Cloudflare R2 storage driver"),
|
|
1413
|
+
root: z14.string().optional().register(globalRegistry10, {
|
|
1457
1414
|
description: "Root directory for local storage",
|
|
1458
1415
|
title: "storage.root",
|
|
1459
1416
|
type: "string"
|
|
@@ -1461,7 +1418,7 @@ var StorageConfigZod = z13.object({
|
|
|
1461
1418
|
}).describe("Storage configuration options");
|
|
1462
1419
|
|
|
1463
1420
|
// src/config/Telemetry.ts
|
|
1464
|
-
import { globalRegistry as
|
|
1421
|
+
import { globalRegistry as globalRegistry11, z as z15 } from "zod";
|
|
1465
1422
|
var DefaultMetricsScrapePorts = {
|
|
1466
1423
|
api: 9465,
|
|
1467
1424
|
bridge: 9468,
|
|
@@ -1469,29 +1426,29 @@ var DefaultMetricsScrapePorts = {
|
|
|
1469
1426
|
producer: 9464,
|
|
1470
1427
|
rewardRedemptionApi: 9467
|
|
1471
1428
|
};
|
|
1472
|
-
var MetricsScrapeConfigZod =
|
|
1473
|
-
path:
|
|
1429
|
+
var MetricsScrapeConfigZod = z15.object({
|
|
1430
|
+
path: z15.string().default("/metrics").register(globalRegistry11, {
|
|
1474
1431
|
default: "/metrics",
|
|
1475
1432
|
description: "Path for the metrics scrape endpoint",
|
|
1476
1433
|
title: "telemetry.metrics.scrape.path",
|
|
1477
1434
|
type: "string"
|
|
1478
1435
|
}),
|
|
1479
|
-
port:
|
|
1436
|
+
port: z15.coerce.number().int().positive().optional().register(globalRegistry11, {
|
|
1480
1437
|
description: "Port for the metrics scrape endpoint",
|
|
1481
1438
|
title: "telemetry.metrics.scrape.port",
|
|
1482
1439
|
type: "number"
|
|
1483
1440
|
})
|
|
1484
1441
|
}).describe("Metrics scrape configuration");
|
|
1485
|
-
var MetricsConfigZod =
|
|
1486
|
-
var OpenTelemetryConfigZod =
|
|
1442
|
+
var MetricsConfigZod = z15.object({ scrape: MetricsScrapeConfigZod }).describe("Metrics configuration options");
|
|
1443
|
+
var OpenTelemetryConfigZod = z15.object({
|
|
1487
1444
|
// OpenTelemetry options
|
|
1488
|
-
otlpEndpoint:
|
|
1445
|
+
otlpEndpoint: z15.url().optional().register(globalRegistry11, {
|
|
1489
1446
|
description: "OTLP endpoint for exporting telemetry data",
|
|
1490
1447
|
title: "telemetry.otel.otlpEndpoint",
|
|
1491
1448
|
type: "string"
|
|
1492
1449
|
})
|
|
1493
1450
|
});
|
|
1494
|
-
var TelemetryConfigZod =
|
|
1451
|
+
var TelemetryConfigZod = z15.object({
|
|
1495
1452
|
// Metrics configuration
|
|
1496
1453
|
metrics: MetricsConfigZod.optional().describe("Metrics configuration"),
|
|
1497
1454
|
// OpenTelemetry configuration
|
|
@@ -1500,20 +1457,20 @@ var TelemetryConfigZod = z14.object({
|
|
|
1500
1457
|
|
|
1501
1458
|
// src/config/Validation.ts
|
|
1502
1459
|
import { XyoAddressZod as XyoAddressZod2 } from "@xyo-network/address";
|
|
1503
|
-
import { globalRegistry as
|
|
1460
|
+
import { globalRegistry as globalRegistry12, z as z16 } from "zod";
|
|
1504
1461
|
|
|
1505
1462
|
// src/primitives/block/range/blockRangeSteps.ts
|
|
1506
1463
|
import { asXL1BlockNumber as asXL1BlockNumber2, StepSizes as StepSizes3 } from "@xyo-network/xl1-protocol-lib";
|
|
1507
1464
|
function blockRangeSteps(range, steps) {
|
|
1508
1465
|
const result = [];
|
|
1509
1466
|
for (const step of steps) {
|
|
1510
|
-
const
|
|
1511
|
-
const startOfFirstStepCandidate = range[0] - range[0] %
|
|
1467
|
+
const stepSize4 = StepSizes3[step];
|
|
1468
|
+
const startOfFirstStepCandidate = range[0] - range[0] % stepSize4 + stepSize4;
|
|
1512
1469
|
const startOfFirstStep = asXL1BlockNumber2(
|
|
1513
1470
|
startOfFirstStepCandidate,
|
|
1514
1471
|
{ name: "blockRangeSteps" }
|
|
1515
1472
|
);
|
|
1516
|
-
for (let block = startOfFirstStep; block <= range[1]; block = asXL1BlockNumber2(block +
|
|
1473
|
+
for (let block = startOfFirstStep; block <= range[1]; block = asXL1BlockNumber2(block + stepSize4, { name: "blockRangeSteps" })) {
|
|
1517
1474
|
result.push({ step, block });
|
|
1518
1475
|
}
|
|
1519
1476
|
}
|
|
@@ -1771,9 +1728,9 @@ function mergeTransfers(transfers) {
|
|
|
1771
1728
|
// src/primitives/step/stepBlockRange.ts
|
|
1772
1729
|
import { asXL1BlockRange as asXL1BlockRange4, StepSizes as StepSizes5 } from "@xyo-network/xl1-protocol-lib";
|
|
1773
1730
|
function stepBlockRange({ block, step }) {
|
|
1774
|
-
const
|
|
1775
|
-
const start = block -
|
|
1776
|
-
return asXL1BlockRange4([start, start +
|
|
1731
|
+
const stepSize4 = StepSizes5[step];
|
|
1732
|
+
const start = block - stepSize4;
|
|
1733
|
+
return asXL1BlockRange4([start, start + stepSize4 - 1], { name: "stepBlockRange" });
|
|
1777
1734
|
}
|
|
1778
1735
|
|
|
1779
1736
|
// src/primitives/step/stepTransferIndex.ts
|
|
@@ -1783,9 +1740,9 @@ function stepTransferIndex(block, step) {
|
|
|
1783
1740
|
let rewardTransferCount = 0;
|
|
1784
1741
|
let rewardTransferIndex = -1;
|
|
1785
1742
|
for (let i = 3; i < StepSizes6.length; i++) {
|
|
1786
|
-
const
|
|
1787
|
-
if (block %
|
|
1788
|
-
if (
|
|
1743
|
+
const stepSize4 = StepSizes6[i];
|
|
1744
|
+
if (block % stepSize4 === 0) {
|
|
1745
|
+
if (stepSize4 === StepSizes6[step]) {
|
|
1789
1746
|
rewardTransferIndex = rewardTransferCount;
|
|
1790
1747
|
}
|
|
1791
1748
|
rewardTransferCount++;
|
|
@@ -2134,7 +2091,7 @@ async function activeStakeAtTimeByAddress(chain, staked, time, staker) {
|
|
|
2134
2091
|
}
|
|
2135
2092
|
|
|
2136
2093
|
// src/primitives/stake/activeStakeAtTimeByPosition.ts
|
|
2137
|
-
import { isUndefined as
|
|
2094
|
+
import { isUndefined as isUndefined7 } from "@xylabs/sdk-js";
|
|
2138
2095
|
|
|
2139
2096
|
// src/primitives/stake/mergedAddRemoveStakeEventsByPosition.ts
|
|
2140
2097
|
async function mergedAddRemoveStakeEventsByPosition(chainEvents, range, position) {
|
|
@@ -2152,7 +2109,7 @@ async function activeStakeAtTimeByPosition(chainStakeEvents, externalTime, posit
|
|
|
2152
2109
|
let result = 0n;
|
|
2153
2110
|
for (const event of stakeEvents) {
|
|
2154
2111
|
if (event.time > externalTime) break;
|
|
2155
|
-
if (
|
|
2112
|
+
if (isUndefined7(position) || position === Number(event.args.id)) {
|
|
2156
2113
|
if (event.name === "StakeAdded") {
|
|
2157
2114
|
result += event.args.amount;
|
|
2158
2115
|
} else if (event.name === "StakeRemoved") {
|
|
@@ -2384,11 +2341,11 @@ function toValidUncle(_context, finalizedWindowedChain, possibleUncle) {
|
|
|
2384
2341
|
}
|
|
2385
2342
|
const allUncleTransactions = prunedPossibleUncle.flatMap((b) => b[1]).filter(isTransactionBoundWitness2);
|
|
2386
2343
|
const allFinalizedTransactions = finalizedWindowedChain.flatMap((b) => b[1]).filter(isTransactionBoundWitness2);
|
|
2387
|
-
const txPossiblyBeforeWindow = allUncleTransactions.
|
|
2344
|
+
const txPossiblyBeforeWindow = allUncleTransactions.some((tx) => tx.nbf < finalizedWindowStartBlockNumber);
|
|
2388
2345
|
if (txPossiblyBeforeWindow) {
|
|
2389
2346
|
return;
|
|
2390
2347
|
}
|
|
2391
|
-
const txExistsInWindow = allUncleTransactions.
|
|
2348
|
+
const txExistsInWindow = allUncleTransactions.some((tx) => allFinalizedTransactions.some((finalTx) => finalTx._hash === tx._hash));
|
|
2392
2349
|
if (txExistsInWindow) {
|
|
2393
2350
|
return;
|
|
2394
2351
|
}
|
|
@@ -2399,24 +2356,24 @@ function findUncles(context, finalizedWindowedChain, blocks) {
|
|
|
2399
2356
|
}
|
|
2400
2357
|
|
|
2401
2358
|
// src/config/Validation.ts
|
|
2402
|
-
var ValidationConfigZod =
|
|
2403
|
-
allowedRewardRedeemers:
|
|
2359
|
+
var ValidationConfigZod = z16.object({
|
|
2360
|
+
allowedRewardRedeemers: z16.array(XyoAddressZod2).optional().register(globalRegistry12, {
|
|
2404
2361
|
description: "List of allowed reward redeemer addresses, if undefined anyone can participate",
|
|
2405
2362
|
title: "allowedRewardRedeemers",
|
|
2406
2363
|
type: "array"
|
|
2407
2364
|
}),
|
|
2408
|
-
allowedRewardEscrowAccountSigners:
|
|
2365
|
+
allowedRewardEscrowAccountSigners: z16.array(XyoAddressZod2).optional().register(globalRegistry12, {
|
|
2409
2366
|
description: "List of allowed reward escrow account signer addresses, if undefined anyone can participate",
|
|
2410
2367
|
title: "allowedRewardEscrowAccountSigners",
|
|
2411
2368
|
type: "array"
|
|
2412
2369
|
}),
|
|
2413
|
-
minCandidates:
|
|
2370
|
+
minCandidates: z16.coerce.number().default(DEFAULT_MIN_CANDIDATES).register(globalRegistry12, {
|
|
2414
2371
|
default: DEFAULT_MIN_CANDIDATES,
|
|
2415
2372
|
description: "Minimum number of uncle candidates before selecting the best uncle",
|
|
2416
2373
|
title: "validation.minCandidates",
|
|
2417
2374
|
type: "number"
|
|
2418
2375
|
}),
|
|
2419
|
-
backoffMs:
|
|
2376
|
+
backoffMs: z16.coerce.number().default(DEFAULT_BACKOFF_MS).register(globalRegistry12, {
|
|
2420
2377
|
default: DEFAULT_BACKOFF_MS,
|
|
2421
2378
|
description: "Back-off timeout in ms. If head age exceeds this, minCandidates is ignored",
|
|
2422
2379
|
title: "validation.backoffMs",
|
|
@@ -2425,26 +2382,26 @@ var ValidationConfigZod = z15.object({
|
|
|
2425
2382
|
});
|
|
2426
2383
|
|
|
2427
2384
|
// src/config/Base.ts
|
|
2428
|
-
var BaseConfigZod =
|
|
2429
|
-
chain:
|
|
2430
|
-
dataLake:
|
|
2431
|
-
evm:
|
|
2432
|
-
log:
|
|
2433
|
-
providers:
|
|
2434
|
-
remote:
|
|
2435
|
-
storage:
|
|
2436
|
-
telemetry:
|
|
2437
|
-
validation:
|
|
2385
|
+
var BaseConfigZod = z17.object({
|
|
2386
|
+
chain: z17._default(ChainConfigZod, ChainConfigZod.parse({})).check(z17.describe("Configuration for the chain")),
|
|
2387
|
+
dataLake: z17.optional(DataLakeConfigZod).check(z17.describe("Configuration for data lakes")),
|
|
2388
|
+
evm: z17._default(EvmConfigZod, EvmConfigZod.parse({})).check(z17.describe("Configuration for EVM-backed services")),
|
|
2389
|
+
log: z17._default(LogConfigZod, LogConfigZod.parse({})).check(z17.describe("Configuration for logging")),
|
|
2390
|
+
providers: z17._default(ProvidersConfigZod, ProvidersConfigZod.parse([])).check(z17.describe("Configuration for providers")),
|
|
2391
|
+
remote: z17._default(RemoteConfigZod, RemoteConfigZod.parse({})).check(z17.describe("Configuration for remote services")),
|
|
2392
|
+
storage: z17._default(StorageConfigZod, StorageConfigZod.parse({})).check(z17.describe("Configuration for the storage")),
|
|
2393
|
+
telemetry: z17._default(TelemetryConfigZod, TelemetryConfigZod.parse({})).check(z17.describe("Configuration for telemetry")),
|
|
2394
|
+
validation: z17._default(ValidationConfigZod, ValidationConfigZod.parse({})).check(z17.describe("Configuration for validation"))
|
|
2438
2395
|
});
|
|
2439
2396
|
|
|
2440
2397
|
// src/config/Actor.ts
|
|
2441
|
-
var AccountPathZod =
|
|
2398
|
+
var AccountPathZod = z18.string().check(z18.regex(
|
|
2442
2399
|
/^(m(\/\d+'?)+|\d+'?(\/\d+'?)*)$/,
|
|
2443
2400
|
`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".`
|
|
2444
2401
|
));
|
|
2445
|
-
var ActorConfigZod =
|
|
2446
|
-
name:
|
|
2447
|
-
accountPath:
|
|
2402
|
+
var ActorConfigZod = z18.extend(BaseConfigZod, {
|
|
2403
|
+
name: z18.string(),
|
|
2404
|
+
accountPath: z18.optional(AccountPathZod).register(globalRegistry13, {
|
|
2448
2405
|
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.',
|
|
2449
2406
|
title: "accountPath",
|
|
2450
2407
|
type: "string"
|
|
@@ -2455,22 +2412,22 @@ var asActorConfig = zodAsFactory3(ActorConfigZod, "asActorConfig");
|
|
|
2455
2412
|
var toActorConfig = zodToFactory2(ActorConfigZod, "toActorConfig");
|
|
2456
2413
|
|
|
2457
2414
|
// src/config/Actors.ts
|
|
2458
|
-
import { z as
|
|
2459
|
-
var ActorsConfigZod =
|
|
2460
|
-
|
|
2415
|
+
import { z as z19 } from "zod/mini";
|
|
2416
|
+
var ActorsConfigZod = z19._default(
|
|
2417
|
+
z19.array(z19.looseObject(ActorConfigZod.shape)).check(z19.describe("Actor-specific configurations that override the base configuration when the actor is running")),
|
|
2461
2418
|
[]
|
|
2462
2419
|
);
|
|
2463
2420
|
|
|
2464
2421
|
// src/config/Config.ts
|
|
2465
|
-
import { globalRegistry as
|
|
2466
|
-
var ConfigZod =
|
|
2422
|
+
import { globalRegistry as globalRegistry14, z as z20 } from "zod/mini";
|
|
2423
|
+
var ConfigZod = z20.extend(BaseConfigZod, {
|
|
2467
2424
|
actors: ActorsConfigZod,
|
|
2468
|
-
healthCheckPort:
|
|
2425
|
+
healthCheckPort: z20.optional(z20.coerce.number()).register(globalRegistry14, {
|
|
2469
2426
|
description: "Port for the system-wide health, readiness, and liveness endpoints (/healthz, /livez, /readyz). Set to 0 to disable.",
|
|
2470
2427
|
title: "healthCheckPort",
|
|
2471
2428
|
type: "number"
|
|
2472
2429
|
})
|
|
2473
|
-
}).check(
|
|
2430
|
+
}).check(z20.describe("The complete configuration for the protocol, including global settings and actor-specific overrides"));
|
|
2474
2431
|
function resolveConfig(config) {
|
|
2475
2432
|
const parsedConfig = ConfigZod.parse(config);
|
|
2476
2433
|
const {
|
|
@@ -2479,7 +2436,7 @@ function resolveConfig(config) {
|
|
|
2479
2436
|
...rootConfig
|
|
2480
2437
|
} = parsedConfig;
|
|
2481
2438
|
parsedConfig.actors = actors.map((actorConfig) => {
|
|
2482
|
-
return
|
|
2439
|
+
return z20.looseObject(ActorConfigZod.shape).parse({ ...rootConfig, ...actorConfig });
|
|
2483
2440
|
});
|
|
2484
2441
|
return parsedConfig;
|
|
2485
2442
|
}
|
|
@@ -2490,15 +2447,15 @@ import {
|
|
|
2490
2447
|
zodIsFactory as zodIsFactory3,
|
|
2491
2448
|
zodToFactory as zodToFactory3
|
|
2492
2449
|
} from "@xylabs/sdk-js";
|
|
2493
|
-
import { globalRegistry as
|
|
2494
|
-
var HostActorConfigZod =
|
|
2495
|
-
host:
|
|
2450
|
+
import { globalRegistry as globalRegistry15, z as z21 } from "zod/mini";
|
|
2451
|
+
var HostActorConfigZod = z21.extend(ActorConfigZod, {
|
|
2452
|
+
host: z21._default(z21.string(), "localhost").register(globalRegistry15, {
|
|
2496
2453
|
default: "localhost",
|
|
2497
2454
|
description: "Host for the Actor",
|
|
2498
2455
|
title: "host",
|
|
2499
2456
|
type: "string"
|
|
2500
2457
|
}),
|
|
2501
|
-
port:
|
|
2458
|
+
port: z21._default(z21.coerce.number(), 8080).register(globalRegistry15, {
|
|
2502
2459
|
default: 8080,
|
|
2503
2460
|
description: "Port for the Actor",
|
|
2504
2461
|
title: "port",
|
|
@@ -2510,30 +2467,30 @@ var asHostActorConfig = zodAsFactory4(HostActorConfigZod, "asHostActorConfig");
|
|
|
2510
2467
|
var toHostActorConfig = zodToFactory3(HostActorConfigZod, "toHostActorConfig");
|
|
2511
2468
|
|
|
2512
2469
|
// src/config/UsageMeta.ts
|
|
2513
|
-
import { z as
|
|
2514
|
-
var DescriptionSchema =
|
|
2515
|
-
var TitleSchema =
|
|
2516
|
-
var JSONSchemaMetaSchema =
|
|
2517
|
-
id:
|
|
2470
|
+
import { z as z22 } from "zod";
|
|
2471
|
+
var DescriptionSchema = z22.string();
|
|
2472
|
+
var TitleSchema = z22.string();
|
|
2473
|
+
var JSONSchemaMetaSchema = z22.object({
|
|
2474
|
+
id: z22.string().optional(),
|
|
2518
2475
|
title: TitleSchema.optional(),
|
|
2519
2476
|
description: DescriptionSchema.optional(),
|
|
2520
|
-
deprecated:
|
|
2521
|
-
}).catchall(
|
|
2477
|
+
deprecated: z22.boolean().optional()
|
|
2478
|
+
}).catchall(z22.unknown());
|
|
2522
2479
|
var GlobalMetaSchema = JSONSchemaMetaSchema.extend({});
|
|
2523
|
-
var ChoicesSchema =
|
|
2480
|
+
var ChoicesSchema = z22.array(z22.union([z22.string(), z22.number(), z22.literal(true), z22.undefined()])).readonly();
|
|
2524
2481
|
var UsageMetaSchema = GlobalMetaSchema.extend({
|
|
2525
2482
|
choices: ChoicesSchema.optional(),
|
|
2526
|
-
default:
|
|
2483
|
+
default: z22.unknown().optional(),
|
|
2527
2484
|
description: DescriptionSchema,
|
|
2528
|
-
group:
|
|
2529
|
-
hidden:
|
|
2485
|
+
group: z22.string().optional(),
|
|
2486
|
+
hidden: z22.boolean().optional(),
|
|
2530
2487
|
title: TitleSchema,
|
|
2531
|
-
type:
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2488
|
+
type: z22.union([
|
|
2489
|
+
z22.literal("array"),
|
|
2490
|
+
z22.literal("count"),
|
|
2491
|
+
z22.literal("boolean"),
|
|
2492
|
+
z22.literal("number"),
|
|
2493
|
+
z22.literal("string")
|
|
2537
2494
|
])
|
|
2538
2495
|
});
|
|
2539
2496
|
function isUsageMeta(v) {
|
|
@@ -2546,7 +2503,7 @@ import {
|
|
|
2546
2503
|
zodIsFactory as zodIsFactory5,
|
|
2547
2504
|
zodToFactory as zodToFactory5
|
|
2548
2505
|
} from "@xylabs/sdk-js";
|
|
2549
|
-
import { z as
|
|
2506
|
+
import { z as z24 } from "zod/mini";
|
|
2550
2507
|
|
|
2551
2508
|
// src/model/CreatableProviderContext.zod.ts
|
|
2552
2509
|
import {
|
|
@@ -2555,17 +2512,17 @@ import {
|
|
|
2555
2512
|
zodToFactory as zodToFactory4
|
|
2556
2513
|
} from "@xylabs/sdk-js";
|
|
2557
2514
|
import { CachingContextZod } from "@xyo-network/xl1-protocol-lib";
|
|
2558
|
-
import { z as
|
|
2559
|
-
var RuntimeStatusMonitorZod =
|
|
2560
|
-
var ProviderFactoryLocatorZod =
|
|
2561
|
-
var BaseConfigContextZod =
|
|
2562
|
-
config:
|
|
2563
|
-
locator:
|
|
2515
|
+
import { z as z23 } from "zod/mini";
|
|
2516
|
+
var RuntimeStatusMonitorZod = z23.custom((val) => val && typeof val === "object");
|
|
2517
|
+
var ProviderFactoryLocatorZod = z23.lazy(() => z23.custom((val) => val && typeof val === "object" && "context" in val && "registry" in val));
|
|
2518
|
+
var BaseConfigContextZod = z23.extend(CachingContextZod, {
|
|
2519
|
+
config: z23.looseObject(BaseConfigZod.shape),
|
|
2520
|
+
locator: z23.optional(ProviderFactoryLocatorZod)
|
|
2564
2521
|
});
|
|
2565
|
-
var CreatableProviderContextZod =
|
|
2566
|
-
_id:
|
|
2522
|
+
var CreatableProviderContextZod = z23.lazy(() => z23.extend(BaseConfigContextZod, {
|
|
2523
|
+
_id: z23.optional(z23.string()),
|
|
2567
2524
|
locator: ProviderFactoryLocatorZod,
|
|
2568
|
-
statusReporter:
|
|
2525
|
+
statusReporter: z23.optional(RuntimeStatusMonitorZod)
|
|
2569
2526
|
}));
|
|
2570
2527
|
var isBaseConfigContext = zodIsFactory4(BaseConfigContextZod);
|
|
2571
2528
|
var asBaseConfigContext = zodAsFactory5(BaseConfigContextZod, "asBaseConfigContext");
|
|
@@ -3023,7 +2980,7 @@ var bundle2 = (root, transaction) => {
|
|
|
3023
2980
|
};
|
|
3024
2981
|
|
|
3025
2982
|
// src/context/Actor.ts
|
|
3026
|
-
var ActorConfigContext =
|
|
2983
|
+
var ActorConfigContext = z24.extend(BaseConfigContextZod, { config: ActorConfigZod });
|
|
3027
2984
|
var isActorConfigContext = zodIsFactory5(ActorConfigContext);
|
|
3028
2985
|
var asActorConfigContext = zodAsFactory6(ActorConfigContext, "asActorConfigContext");
|
|
3029
2986
|
var toActorConfigContext = zodToFactory5(ActorConfigContext, "toActorConfigContext");
|
|
@@ -3413,8 +3370,8 @@ import {
|
|
|
3413
3370
|
zodIsFactory as zodIsFactory6,
|
|
3414
3371
|
zodToFactory as zodToFactory6
|
|
3415
3372
|
} from "@xylabs/sdk-js";
|
|
3416
|
-
import { z as
|
|
3417
|
-
var HostActorConfigContext =
|
|
3373
|
+
import { z as z25 } from "zod/mini";
|
|
3374
|
+
var HostActorConfigContext = z25.extend(BaseConfigContextZod, { config: HostActorConfigZod });
|
|
3418
3375
|
var isHostActorConfigContext = zodIsFactory6(HostActorConfigContext);
|
|
3419
3376
|
var asHostActorConfigContext = zodAsFactory7(HostActorConfigContext, "asHostActorConfigContext");
|
|
3420
3377
|
var toHostActorConfigContext = zodToFactory6(HostActorConfigContext, "toHostActorConfigContext");
|
|
@@ -3455,26 +3412,26 @@ import {
|
|
|
3455
3412
|
asSchema as asSchema2,
|
|
3456
3413
|
isPayloadOfZodType
|
|
3457
3414
|
} from "@xyo-network/sdk-js";
|
|
3458
|
-
import { z as
|
|
3415
|
+
import { z as z27 } from "zod";
|
|
3459
3416
|
|
|
3460
3417
|
// src/eip-712/Types.ts
|
|
3461
|
-
import { z as
|
|
3462
|
-
var TypedDataDomainZod =
|
|
3463
|
-
name:
|
|
3464
|
-
version:
|
|
3465
|
-
chainId:
|
|
3466
|
-
verifyingContract:
|
|
3467
|
-
salt:
|
|
3418
|
+
import { z as z26 } from "zod";
|
|
3419
|
+
var TypedDataDomainZod = z26.object({
|
|
3420
|
+
name: z26.string().nullable().optional(),
|
|
3421
|
+
version: z26.string().nullable().optional(),
|
|
3422
|
+
chainId: z26.union([z26.string(), z26.number(), z26.bigint()]).nullable().optional(),
|
|
3423
|
+
verifyingContract: z26.string().nullable().optional(),
|
|
3424
|
+
salt: z26.union([z26.string(), z26.instanceof(Uint8Array)]).nullable().optional()
|
|
3468
3425
|
});
|
|
3469
|
-
var TypedDataFieldZod =
|
|
3470
|
-
name:
|
|
3471
|
-
type:
|
|
3426
|
+
var TypedDataFieldZod = z26.object({
|
|
3427
|
+
name: z26.string(),
|
|
3428
|
+
type: z26.string()
|
|
3472
3429
|
});
|
|
3473
|
-
var TypedDataTypesZod =
|
|
3474
|
-
var TypedDataValueZod =
|
|
3430
|
+
var TypedDataTypesZod = z26.record(z26.string(), z26.array(TypedDataFieldZod));
|
|
3431
|
+
var TypedDataValueZod = z26.record(z26.string(), z26.any());
|
|
3475
3432
|
|
|
3476
3433
|
// src/eip-712/Payloads/EIP712Data.ts
|
|
3477
|
-
var EIP712DataPayloadFieldsZod =
|
|
3434
|
+
var EIP712DataPayloadFieldsZod = z27.object({
|
|
3478
3435
|
domain: TypedDataDomainZod,
|
|
3479
3436
|
types: TypedDataTypesZod,
|
|
3480
3437
|
values: TypedDataValueZod
|
|
@@ -3492,11 +3449,11 @@ import {
|
|
|
3492
3449
|
asSchema as asSchema3,
|
|
3493
3450
|
isPayloadOfZodType as isPayloadOfZodType2
|
|
3494
3451
|
} from "@xyo-network/sdk-js";
|
|
3495
|
-
import { z as
|
|
3496
|
-
var EIP712SignaturePayloadFieldsZod =
|
|
3497
|
-
address:
|
|
3452
|
+
import { z as z28 } from "zod";
|
|
3453
|
+
var EIP712SignaturePayloadFieldsZod = z28.object({
|
|
3454
|
+
address: z28.string(),
|
|
3498
3455
|
hash: HashZod,
|
|
3499
|
-
signature:
|
|
3456
|
+
signature: z28.string()
|
|
3500
3457
|
});
|
|
3501
3458
|
var EIP712SignaturePayloadSchema = asSchema3("network.xyo.chains.ethereum.eip712.signature", true);
|
|
3502
3459
|
var isEIP712SignaturePayload = isPayloadOfZodType2(
|
|
@@ -3525,7 +3482,7 @@ var signEIP712Message = async (signer, data) => {
|
|
|
3525
3482
|
};
|
|
3526
3483
|
|
|
3527
3484
|
// src/eip-712/verify.ts
|
|
3528
|
-
import { asHash as asHash3, isUndefined as
|
|
3485
|
+
import { asHash as asHash3, isUndefined as isUndefined8 } from "@xylabs/sdk-js";
|
|
3529
3486
|
import { PayloadBuilder as PayloadBuilder16 } from "@xyo-network/sdk-js";
|
|
3530
3487
|
import { verifyTypedData } from "ethers";
|
|
3531
3488
|
var verifyEIP712Message = async (data, sig) => {
|
|
@@ -3536,7 +3493,7 @@ var verifyEIP712Message = async (data, sig) => {
|
|
|
3536
3493
|
} = sig;
|
|
3537
3494
|
const { schema, ...fields } = data;
|
|
3538
3495
|
const signedHash = asHash3(hash);
|
|
3539
|
-
if (
|
|
3496
|
+
if (isUndefined8(signedHash) || signedHash !== await PayloadBuilder16.hash(data)) return false;
|
|
3540
3497
|
const recoveredAddress = verifyTypedData(fields.domain, fields.types, fields.values, signature);
|
|
3541
3498
|
return recoveredAddress.toLowerCase() === address.toLowerCase();
|
|
3542
3499
|
};
|
|
@@ -3605,7 +3562,7 @@ var toPositiveBigInt = (value) => {
|
|
|
3605
3562
|
// src/simple/accountBalance/SimpleAccountBalanceViewer.ts
|
|
3606
3563
|
import {
|
|
3607
3564
|
asHash as asHash4,
|
|
3608
|
-
assertEx as
|
|
3565
|
+
assertEx as assertEx33,
|
|
3609
3566
|
exists as exists3,
|
|
3610
3567
|
isDefined as isDefined17,
|
|
3611
3568
|
ZERO_ADDRESS
|
|
@@ -3613,13 +3570,13 @@ import {
|
|
|
3613
3570
|
import {
|
|
3614
3571
|
AccountBalanceViewerMoniker,
|
|
3615
3572
|
asRange,
|
|
3616
|
-
asXL1BlockNumber as
|
|
3573
|
+
asXL1BlockNumber as asXL1BlockNumber8,
|
|
3617
3574
|
asXL1BlockRange as asXL1BlockRange10,
|
|
3618
3575
|
AttoXL1 as AttoXL13,
|
|
3619
3576
|
BlockViewerMoniker,
|
|
3620
3577
|
isChainQualifiedHeadConfig as isChainQualifiedHeadConfig4,
|
|
3621
3578
|
isChainQualifiedRangeConfig as isChainQualifiedRangeConfig4,
|
|
3622
|
-
StepSizes as
|
|
3579
|
+
StepSizes as StepSizes13,
|
|
3623
3580
|
TransferSchema as TransferSchema2
|
|
3624
3581
|
} from "@xyo-network/xl1-protocol-lib";
|
|
3625
3582
|
import { Semaphore } from "async-mutex";
|
|
@@ -3639,41 +3596,56 @@ var isBalancesStepSummaryWithStorageMeta = (value) => {
|
|
|
3639
3596
|
};
|
|
3640
3597
|
var asBalancesStepSummaryWithStorageMeta = AsObjectFactory5.create(isBalancesStepSummaryWithStorageMeta);
|
|
3641
3598
|
|
|
3642
|
-
// src/summary/model/
|
|
3599
|
+
// src/summary/model/BlocksStepSummary.ts
|
|
3643
3600
|
import { AsObjectFactory as AsObjectFactory6 } from "@xylabs/sdk-js";
|
|
3644
3601
|
import {
|
|
3645
3602
|
asSchema as asSchema6,
|
|
3646
3603
|
isPayloadOfSchemaType as isPayloadOfSchemaType4,
|
|
3647
3604
|
isStorageMeta as isStorageMeta3
|
|
3648
3605
|
} from "@xyo-network/sdk-js";
|
|
3649
|
-
var
|
|
3650
|
-
var
|
|
3651
|
-
var
|
|
3606
|
+
var BlocksStepSummarySchema = asSchema6("network.xyo.step.summary.blocks", true);
|
|
3607
|
+
var isBlocksStepSummary = isPayloadOfSchemaType4(BlocksStepSummarySchema);
|
|
3608
|
+
var asBlocksStepSummary = AsObjectFactory6.create(isBlocksStepSummary);
|
|
3609
|
+
var isBlocksStepSummaryWithStorageMeta = (value) => {
|
|
3610
|
+
return isBlocksStepSummary(value) && isStorageMeta3(value);
|
|
3611
|
+
};
|
|
3612
|
+
var asBlocksStepSummaryWithStorageMeta = AsObjectFactory6.create(isBlocksStepSummaryWithStorageMeta);
|
|
3613
|
+
|
|
3614
|
+
// src/summary/model/SchemasStepSummary.ts
|
|
3615
|
+
import { AsObjectFactory as AsObjectFactory7 } from "@xylabs/sdk-js";
|
|
3616
|
+
import {
|
|
3617
|
+
asSchema as asSchema7,
|
|
3618
|
+
isPayloadOfSchemaType as isPayloadOfSchemaType5,
|
|
3619
|
+
isStorageMeta as isStorageMeta4
|
|
3620
|
+
} from "@xyo-network/sdk-js";
|
|
3621
|
+
var SchemasStepSummarySchema = asSchema7("network.xyo.step.summary.schemas", true);
|
|
3622
|
+
var isSchemasStepSummary = isPayloadOfSchemaType5(SchemasStepSummarySchema);
|
|
3623
|
+
var asSchemasStepSummary = AsObjectFactory7.create(isSchemasStepSummary);
|
|
3652
3624
|
var isSchemasStepSummaryWithStorageMeta = (value) => {
|
|
3653
|
-
return isSchemasStepSummary(value) &&
|
|
3625
|
+
return isSchemasStepSummary(value) && isStorageMeta4(value);
|
|
3654
3626
|
};
|
|
3655
|
-
var asSchemasStepSummaryWithStorageMeta =
|
|
3627
|
+
var asSchemasStepSummaryWithStorageMeta = AsObjectFactory7.create(isSchemasStepSummaryWithStorageMeta);
|
|
3656
3628
|
|
|
3657
3629
|
// src/summary/model/StepSummary.ts
|
|
3658
3630
|
import {
|
|
3659
|
-
asSchema as
|
|
3631
|
+
asSchema as asSchema8
|
|
3660
3632
|
} from "@xyo-network/sdk-js";
|
|
3661
|
-
var StepSummarySchema =
|
|
3633
|
+
var StepSummarySchema = asSchema8("network.xyo.step.summary", true);
|
|
3662
3634
|
|
|
3663
3635
|
// src/summary/model/TransfersSummary.ts
|
|
3664
|
-
import { AsObjectFactory as
|
|
3636
|
+
import { AsObjectFactory as AsObjectFactory8 } from "@xylabs/sdk-js";
|
|
3665
3637
|
import {
|
|
3666
|
-
asSchema as
|
|
3667
|
-
isPayloadOfSchemaType as
|
|
3668
|
-
isStorageMeta as
|
|
3638
|
+
asSchema as asSchema9,
|
|
3639
|
+
isPayloadOfSchemaType as isPayloadOfSchemaType6,
|
|
3640
|
+
isStorageMeta as isStorageMeta5
|
|
3669
3641
|
} from "@xyo-network/sdk-js";
|
|
3670
|
-
var TransfersStepSummarySchema =
|
|
3671
|
-
var isTransfersStepSummary =
|
|
3672
|
-
var asTransfersStepSummary =
|
|
3642
|
+
var TransfersStepSummarySchema = asSchema9("network.xyo.step.summary.transfer", true);
|
|
3643
|
+
var isTransfersStepSummary = isPayloadOfSchemaType6(TransfersStepSummarySchema);
|
|
3644
|
+
var asTransfersStepSummary = AsObjectFactory8.create(isTransfersStepSummary);
|
|
3673
3645
|
var isTransfersStepSummaryWithStorageMeta = (value) => {
|
|
3674
|
-
return isTransfersStepSummary(value) &&
|
|
3646
|
+
return isTransfersStepSummary(value) && isStorageMeta5(value);
|
|
3675
3647
|
};
|
|
3676
|
-
var asTransfersStepSummaryWithStorageMeta =
|
|
3648
|
+
var asTransfersStepSummaryWithStorageMeta = AsObjectFactory8.create(isTransfersStepSummaryWithStorageMeta);
|
|
3677
3649
|
|
|
3678
3650
|
// src/summary/primitives/balances/balancesMaxStep.ts
|
|
3679
3651
|
var balancesMaxStep = 5;
|
|
@@ -3777,25 +3749,89 @@ async function balancesSummary(context, semaphores, blockViewer, summaryMap, con
|
|
|
3777
3749
|
}, { ...context, timeBudgetLimit: 500 });
|
|
3778
3750
|
}
|
|
3779
3751
|
|
|
3752
|
+
// src/summary/primitives/blocks/blocksMaxStep.ts
|
|
3753
|
+
var blocksMaxStep = 3;
|
|
3754
|
+
|
|
3755
|
+
// src/summary/primitives/blocks/blocksStepSummaryFromRange.ts
|
|
3756
|
+
import { assertEx as assertEx28, spanRootAsync as spanRootAsync4 } from "@xylabs/sdk-js";
|
|
3757
|
+
import { isAnyPayload as isAnyPayload4 } from "@xyo-network/sdk-js";
|
|
3758
|
+
import { asXL1BlockNumber as asXL1BlockNumber6, StepSizes as StepSizes9 } from "@xyo-network/xl1-protocol-lib";
|
|
3759
|
+
function blocksStepSummaryKey(frameHeadHash, frameSize) {
|
|
3760
|
+
return `${frameHeadHash}|${frameSize}`;
|
|
3761
|
+
}
|
|
3762
|
+
async function blocksStepSummaryFromRange(context, semaphores, blockViewer, summaryMap, range) {
|
|
3763
|
+
const cacheKey = `${range[0]}|${range[1]}`;
|
|
3764
|
+
return await withContextCacheResponse(context, "blocksStepSummaryFromRange", cacheKey, async () => {
|
|
3765
|
+
return await spanRootAsync4("blocksStepSummaryFromRange", async () => {
|
|
3766
|
+
const frameHead = assertEx28(
|
|
3767
|
+
await blockViewer.blockByNumber(range[1]),
|
|
3768
|
+
() => `Block not found for number: ${range[1]}`
|
|
3769
|
+
);
|
|
3770
|
+
const frameHeadHash = frameHead[0]._hash;
|
|
3771
|
+
const frameSize = range[1] - range[0] + 1;
|
|
3772
|
+
let result;
|
|
3773
|
+
if (frameSize === 1) {
|
|
3774
|
+
result = {
|
|
3775
|
+
schema: BlocksStepSummarySchema,
|
|
3776
|
+
hash: frameHeadHash,
|
|
3777
|
+
stepSize: -1,
|
|
3778
|
+
blocks: [frameHead]
|
|
3779
|
+
};
|
|
3780
|
+
} else {
|
|
3781
|
+
const step = StepSizes9.indexOf(asXL1BlockNumber6(frameSize, true));
|
|
3782
|
+
assertEx28(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes9.join(", ")}`);
|
|
3783
|
+
const key = blocksStepSummaryKey(frameHeadHash, frameSize);
|
|
3784
|
+
const summaryResult = await summaryMap.get(key);
|
|
3785
|
+
if (isAnyPayload4(summaryResult)) {
|
|
3786
|
+
result = asBlocksStepSummary(summaryResult, { required: true });
|
|
3787
|
+
} else {
|
|
3788
|
+
await semaphores[step].acquire();
|
|
3789
|
+
try {
|
|
3790
|
+
const subRanges = deepCalculateFramesFromRange(range, step - 1);
|
|
3791
|
+
const subResults = await Promise.all(subRanges.map((subRange) => blocksStepSummaryFromRange(
|
|
3792
|
+
context,
|
|
3793
|
+
semaphores,
|
|
3794
|
+
blockViewer,
|
|
3795
|
+
summaryMap,
|
|
3796
|
+
subRange
|
|
3797
|
+
)));
|
|
3798
|
+
const blocks = subResults.flatMap((subResult) => subResult.blocks);
|
|
3799
|
+
result = {
|
|
3800
|
+
schema: BlocksStepSummarySchema,
|
|
3801
|
+
hash: frameHeadHash,
|
|
3802
|
+
stepSize: frameSize,
|
|
3803
|
+
blocks
|
|
3804
|
+
};
|
|
3805
|
+
await summaryMap.set(key, result);
|
|
3806
|
+
} finally {
|
|
3807
|
+
semaphores[step].release();
|
|
3808
|
+
}
|
|
3809
|
+
}
|
|
3810
|
+
}
|
|
3811
|
+
return result;
|
|
3812
|
+
}, { ...context, timeBudgetLimit: 500 });
|
|
3813
|
+
}, { max: 1e5 });
|
|
3814
|
+
}
|
|
3815
|
+
|
|
3780
3816
|
// src/summary/primitives/schemas/schemasMaxStep.ts
|
|
3781
|
-
import { StepSizes as
|
|
3782
|
-
var schemasMaxStep =
|
|
3817
|
+
import { StepSizes as StepSizes10 } from "@xyo-network/xl1-protocol-lib";
|
|
3818
|
+
var schemasMaxStep = StepSizes10.length - 1;
|
|
3783
3819
|
|
|
3784
3820
|
// src/summary/primitives/schemas/schemasStepSummaryFromRange.ts
|
|
3785
|
-
import { assertEx as
|
|
3821
|
+
import { assertEx as assertEx29 } from "@xylabs/sdk-js";
|
|
3786
3822
|
import {
|
|
3787
|
-
isAnyPayload as
|
|
3823
|
+
isAnyPayload as isAnyPayload5,
|
|
3788
3824
|
isBoundWitness as isBoundWitness2,
|
|
3789
3825
|
isHashMeta,
|
|
3790
3826
|
PayloadBuilder as PayloadBuilder17
|
|
3791
3827
|
} from "@xyo-network/sdk-js";
|
|
3792
|
-
import { StepSizes as
|
|
3828
|
+
import { StepSizes as StepSizes11 } from "@xyo-network/xl1-protocol-lib";
|
|
3793
3829
|
async function schemasStepSummaryFromRange(context, semaphores, blockViewer, summaryMap, range) {
|
|
3794
|
-
const [frameHead] =
|
|
3830
|
+
const [frameHead] = assertEx29(await blockViewer.blockByNumber(range[1]), () => `Block not found for number: ${range[1]}`);
|
|
3795
3831
|
const frameSize = range[1] - range[0] + 1;
|
|
3796
3832
|
let result;
|
|
3797
3833
|
if (frameSize === 1) {
|
|
3798
|
-
const [block, payloads] =
|
|
3834
|
+
const [block, payloads] = assertEx29(await blockViewer.blockByNumber(range[0]), () => `Block not found for number: ${range[0]}`);
|
|
3799
3835
|
const boundWitnesses = [block, ...payloads.filter((x) => isBoundWitness2(x) && isHashMeta(x))];
|
|
3800
3836
|
const schemas = {};
|
|
3801
3837
|
for (const bw of boundWitnesses) {
|
|
@@ -3811,10 +3847,10 @@ async function schemasStepSummaryFromRange(context, semaphores, blockViewer, sum
|
|
|
3811
3847
|
schemas
|
|
3812
3848
|
});
|
|
3813
3849
|
} else {
|
|
3814
|
-
const step =
|
|
3815
|
-
|
|
3850
|
+
const step = StepSizes11.indexOf(frameSize);
|
|
3851
|
+
assertEx29(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes11.join(", ")}`);
|
|
3816
3852
|
const summaryResult = await summaryMap.get(`${frameHead._hash}|${frameSize}`);
|
|
3817
|
-
if (
|
|
3853
|
+
if (isAnyPayload5(summaryResult)) {
|
|
3818
3854
|
result = summaryResult;
|
|
3819
3855
|
} else {
|
|
3820
3856
|
await semaphores[step].acquire();
|
|
@@ -3851,7 +3887,7 @@ async function schemasStepSummaryFromRange(context, semaphores, blockViewer, sum
|
|
|
3851
3887
|
}
|
|
3852
3888
|
|
|
3853
3889
|
// src/summary/primitives/schemas/schemasSummary.ts
|
|
3854
|
-
import { assertEx as
|
|
3890
|
+
import { assertEx as assertEx30, spanRootAsync as spanRootAsync5 } from "@xylabs/sdk-js";
|
|
3855
3891
|
import {
|
|
3856
3892
|
asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta4,
|
|
3857
3893
|
asXL1BlockRange as asXL1BlockRange8,
|
|
@@ -3859,9 +3895,9 @@ import {
|
|
|
3859
3895
|
isChainQualifiedRangeConfig as isChainQualifiedRangeConfig2
|
|
3860
3896
|
} from "@xyo-network/xl1-protocol-lib";
|
|
3861
3897
|
async function schemasSummary(context, semaphores, blockViewer, summaryMap, config) {
|
|
3862
|
-
return await
|
|
3898
|
+
return await spanRootAsync5("schemasSummary", async () => {
|
|
3863
3899
|
const headHash = isChainQualifiedHeadConfig2(config) ? config.head : await blockViewer.currentBlockHash();
|
|
3864
|
-
const [head] =
|
|
3900
|
+
const [head] = assertEx30(await blockViewer.blockByHash(headHash), () => `Block not found for hash: ${headHash}`);
|
|
3865
3901
|
const headBoundWitness = asBlockBoundWitnessWithStorageMeta4(head, () => `Found Block not a BlockWithHashMeta: ${headHash}`);
|
|
3866
3902
|
const range = isChainQualifiedRangeConfig2(config) ? config.range : asXL1BlockRange8([0, headBoundWitness.block], true);
|
|
3867
3903
|
const ranges = deepCalculateFramesFromRange(asXL1BlockRange8(
|
|
@@ -3884,21 +3920,21 @@ async function schemasSummary(context, semaphores, blockViewer, summaryMap, conf
|
|
|
3884
3920
|
var transfersMaxStep = 4;
|
|
3885
3921
|
|
|
3886
3922
|
// src/summary/primitives/transfers/transfersStepSummaryFromRange.ts
|
|
3887
|
-
import { assertEx as
|
|
3888
|
-
import { isAnyPayload as
|
|
3889
|
-
import { asXL1BlockNumber as
|
|
3923
|
+
import { assertEx as assertEx31, spanRootAsync as spanRootAsync6 } from "@xylabs/sdk-js";
|
|
3924
|
+
import { isAnyPayload as isAnyPayload6 } from "@xyo-network/sdk-js";
|
|
3925
|
+
import { asXL1BlockNumber as asXL1BlockNumber7, StepSizes as StepSizes12 } from "@xyo-network/xl1-protocol-lib";
|
|
3890
3926
|
function transfersSummaryKey(frameHeadHash, frameSize) {
|
|
3891
3927
|
return `${frameHeadHash}|${frameSize}`;
|
|
3892
3928
|
}
|
|
3893
3929
|
async function transfersStepSummaryFromRange(context, semaphores, blockViewer, summaryMap, range) {
|
|
3894
3930
|
const cacheKey = `${range[0]}|${range[1]}`;
|
|
3895
3931
|
return await withContextCacheResponse(context, "transfersStepSummaryFromRange", cacheKey, async () => {
|
|
3896
|
-
return await
|
|
3897
|
-
const [frameHead] =
|
|
3932
|
+
return await spanRootAsync6("transfersStepSummaryFromRange", async () => {
|
|
3933
|
+
const [frameHead] = assertEx31(await blockViewer.blockByNumber(range[1]), () => `Block not found for number: ${range[1]}`);
|
|
3898
3934
|
const frameSize = range[1] - range[0] + 1;
|
|
3899
3935
|
let result;
|
|
3900
3936
|
if (frameSize === 1) {
|
|
3901
|
-
const [, payloads] =
|
|
3937
|
+
const [, payloads] = assertEx31(await blockViewer.blockByNumber(range[0]), () => `Block not found for number: ${range[0]}`);
|
|
3902
3938
|
const transfers = {};
|
|
3903
3939
|
for (const [from, toMap] of Object.entries(netTransfersForPayloads(context, payloads))) {
|
|
3904
3940
|
transfers[from] = transfers[from] ?? {};
|
|
@@ -3913,11 +3949,11 @@ async function transfersStepSummaryFromRange(context, semaphores, blockViewer, s
|
|
|
3913
3949
|
transfers
|
|
3914
3950
|
};
|
|
3915
3951
|
} else {
|
|
3916
|
-
const step =
|
|
3917
|
-
|
|
3952
|
+
const step = StepSizes12.indexOf(asXL1BlockNumber7(frameSize, true));
|
|
3953
|
+
assertEx31(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes12.join(", ")}`);
|
|
3918
3954
|
const key = transfersSummaryKey(frameHead._hash, frameSize);
|
|
3919
3955
|
const summaryResult = await summaryMap.get(key);
|
|
3920
|
-
if (
|
|
3956
|
+
if (isAnyPayload6(summaryResult)) {
|
|
3921
3957
|
result = asTransfersStepSummary(summaryResult, { required: true });
|
|
3922
3958
|
} else {
|
|
3923
3959
|
await semaphores[step].acquire();
|
|
@@ -3965,7 +4001,7 @@ async function transfersStepSummaryFromRange(context, semaphores, blockViewer, s
|
|
|
3965
4001
|
}
|
|
3966
4002
|
|
|
3967
4003
|
// src/summary/primitives/transfers/transfersSummary.ts
|
|
3968
|
-
import { assertEx as
|
|
4004
|
+
import { assertEx as assertEx32, spanRootAsync as spanRootAsync7 } from "@xylabs/sdk-js";
|
|
3969
4005
|
import { asXyoAddress as asXyoAddress2 } from "@xyo-network/address";
|
|
3970
4006
|
import {
|
|
3971
4007
|
asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta5,
|
|
@@ -3974,9 +4010,9 @@ import {
|
|
|
3974
4010
|
isChainQualifiedRangeConfig as isChainQualifiedRangeConfig3
|
|
3975
4011
|
} from "@xyo-network/xl1-protocol-lib";
|
|
3976
4012
|
async function transfersSummary(context, semaphores, blockViewer, summaryMap, config) {
|
|
3977
|
-
return await
|
|
4013
|
+
return await spanRootAsync7("transferSummary", async () => {
|
|
3978
4014
|
const headHash = isChainQualifiedHeadConfig3(config) ? config.head : await blockViewer.currentBlockHash();
|
|
3979
|
-
const [head] =
|
|
4015
|
+
const [head] = assertEx32(await blockViewer.blockByHash(headHash), () => `Block not found for hash: ${headHash}`);
|
|
3980
4016
|
const headBoundWitness = asBlockBoundWitnessWithStorageMeta5(head, () => `Found Block not a BlockWithHashMeta: ${headHash}`);
|
|
3981
4017
|
const range = isChainQualifiedRangeConfig3(config) ? config.range : asXL1BlockRange9([0, headBoundWitness.block], true);
|
|
3982
4018
|
const ranges = deepCalculateFramesFromRange(asXL1BlockRange9(
|
|
@@ -4002,9 +4038,9 @@ async function transfersSummary(context, semaphores, blockViewer, summaryMap, co
|
|
|
4002
4038
|
// src/simple/accountBalance/SimpleAccountBalanceViewer.ts
|
|
4003
4039
|
var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
4004
4040
|
moniker = SimpleAccountBalanceViewer.defaultMoniker;
|
|
4005
|
-
_balanceStepSemaphores =
|
|
4041
|
+
_balanceStepSemaphores = StepSizes13.map(() => new Semaphore(20));
|
|
4006
4042
|
_blockViewer;
|
|
4007
|
-
_transferStepSemaphores =
|
|
4043
|
+
_transferStepSemaphores = StepSizes13.map(() => new Semaphore(20));
|
|
4008
4044
|
get balancesSummaryMap() {
|
|
4009
4045
|
return this.params.balancesSummaryMap;
|
|
4010
4046
|
}
|
|
@@ -4017,8 +4053,8 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
4017
4053
|
static async paramsHandler(params = {}) {
|
|
4018
4054
|
return {
|
|
4019
4055
|
...await super.paramsHandler(params),
|
|
4020
|
-
balancesSummaryMap:
|
|
4021
|
-
transfersSummaryMap:
|
|
4056
|
+
balancesSummaryMap: assertEx33(params.balancesSummaryMap, () => "balancesSummaryMap is required"),
|
|
4057
|
+
transfersSummaryMap: assertEx33(params.transfersSummaryMap, () => "transfersSummaryMap is required")
|
|
4022
4058
|
};
|
|
4023
4059
|
}
|
|
4024
4060
|
async accountBalance(address, config) {
|
|
@@ -4039,7 +4075,7 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
4039
4075
|
const transferIndexes = block[0].payload_schemas.map((schema, index) => schema === TransferSchema2 ? index : void 0).filter(exists3);
|
|
4040
4076
|
const transfers = transferIndexes.map((index) => {
|
|
4041
4077
|
const hash = block[0].payload_hashes[index];
|
|
4042
|
-
return
|
|
4078
|
+
return assertEx33(
|
|
4043
4079
|
block[1].find((p) => p._hash === hash),
|
|
4044
4080
|
() => `Error: Could not find Transfer with hash ${hash} in block ${block[0]._hash}`
|
|
4045
4081
|
);
|
|
@@ -4072,7 +4108,7 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
4072
4108
|
const head = isChainQualifiedHeadConfig4(config) ? config.head : await this.blockViewer.currentBlockHash();
|
|
4073
4109
|
const range = isChainQualifiedRangeConfig4(config) ? config.range : asXL1BlockRange10([
|
|
4074
4110
|
0,
|
|
4075
|
-
|
|
4111
|
+
assertEx33(
|
|
4076
4112
|
await this.blockViewer.blockByHash(head),
|
|
4077
4113
|
() => `Error: Could not find block with hash ${head}`
|
|
4078
4114
|
)[0].block
|
|
@@ -4087,11 +4123,11 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
4087
4123
|
const qualifiedRange = qualifiedEntries[0][1][1].range;
|
|
4088
4124
|
const qualifiedHeadHash = qualifiedEntries[0][1][1].head;
|
|
4089
4125
|
for (const [_, [__, { range: range2, head: head2 }]] of qualifiedEntries) {
|
|
4090
|
-
|
|
4126
|
+
assertEx33(
|
|
4091
4127
|
range2[0] === qualifiedRange[0] && range2[1] === qualifiedRange[1],
|
|
4092
4128
|
() => "Inconsistent ranges in qualifiedAccountBalanceHistories"
|
|
4093
4129
|
);
|
|
4094
|
-
|
|
4130
|
+
assertEx33(
|
|
4095
4131
|
head2 === qualifiedHeadHash,
|
|
4096
4132
|
() => "Inconsistent head hashes in qualifiedAccountBalanceHistories"
|
|
4097
4133
|
);
|
|
@@ -4125,8 +4161,8 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
4125
4161
|
}
|
|
4126
4162
|
async distillTransferHistory(address, range, max = 50) {
|
|
4127
4163
|
return await this.spanAsync("distillTransferHistory", async () => {
|
|
4128
|
-
if (range[1] - range[0] <=
|
|
4129
|
-
return Array.from({ length: range[1] - range[0] + 1 }, (_, i) => range[1] - i).slice(0, max).map((n) =>
|
|
4164
|
+
if (range[1] - range[0] <= StepSizes13[0] || max <= 1) {
|
|
4165
|
+
return Array.from({ length: range[1] - range[0] + 1 }, (_, i) => range[1] - i).slice(0, max).map((n) => asXL1BlockNumber8(n, true));
|
|
4130
4166
|
}
|
|
4131
4167
|
const frames = deepCalculateFramesFromRange(asXL1BlockRange10(range, true), transfersMaxStep);
|
|
4132
4168
|
const transferSummaryPairs = await Promise.all(frames.map(
|
|
@@ -4140,7 +4176,7 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
4140
4176
|
});
|
|
4141
4177
|
const resultBlockNumbers = /* @__PURE__ */ new Set();
|
|
4142
4178
|
for (const [frame] of sortedTransferSummaryPairs) {
|
|
4143
|
-
if (frame[1] - frame[0] + 1 >
|
|
4179
|
+
if (frame[1] - frame[0] + 1 > StepSizes13[0]) {
|
|
4144
4180
|
const values = await this.distillTransferHistory(address, asXL1BlockRange10([frame[0], frame[1] - 1], true), max - resultBlockNumbers.size);
|
|
4145
4181
|
for (const value of values) {
|
|
4146
4182
|
resultBlockNumbers.add(value);
|
|
@@ -4162,7 +4198,7 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
4162
4198
|
return await this.spanAsync("qualifiedAccountBalanceHistory", async () => {
|
|
4163
4199
|
const range = asRange(headOrRange);
|
|
4164
4200
|
const headHash = asHash4(headOrRange);
|
|
4165
|
-
const [head] =
|
|
4201
|
+
const [head] = assertEx33(isDefined17(headHash) ? await this.blockViewer.blockByHash(headHash) : await this.blockViewer.currentBlock(), () => "Could not resolve head block");
|
|
4166
4202
|
const startingRange = asXL1BlockRange10(range ?? [0, head.block], true);
|
|
4167
4203
|
const blockNumbers = await this.distillTransferHistory(address, startingRange);
|
|
4168
4204
|
const blocks = (await Promise.all(blockNumbers.map(async (bn) => await this.blockViewer.blockByNumber(bn)))).filter(exists3);
|
|
@@ -4171,7 +4207,7 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
4171
4207
|
const transferIndexes = block[0].payload_schemas.map((schema, index) => schema === TransferSchema2 ? index : void 0).filter(exists3);
|
|
4172
4208
|
const transfers = transferIndexes.map((index) => {
|
|
4173
4209
|
const hash = block[0].payload_hashes[index];
|
|
4174
|
-
return
|
|
4210
|
+
return assertEx33(
|
|
4175
4211
|
block[1].find((p) => p._hash === hash),
|
|
4176
4212
|
() => `Error: Could not find Transfer with hash ${hash} in block ${block[0]._hash}`
|
|
4177
4213
|
);
|
|
@@ -4201,20 +4237,25 @@ SimpleAccountBalanceViewer = __decorateClass([
|
|
|
4201
4237
|
|
|
4202
4238
|
// src/simple/block/SimpleBlockViewer.ts
|
|
4203
4239
|
import {
|
|
4204
|
-
assertEx as
|
|
4240
|
+
assertEx as assertEx34,
|
|
4205
4241
|
exists as exists4,
|
|
4206
|
-
isUndefined as
|
|
4242
|
+
isUndefined as isUndefined9
|
|
4207
4243
|
} from "@xylabs/sdk-js";
|
|
4244
|
+
import { LruCacheMap as LruCacheMap2 } from "@xyo-network/xl1-driver-memory";
|
|
4208
4245
|
import {
|
|
4209
4246
|
asSignedHydratedBlockWithHashMeta,
|
|
4210
4247
|
asSignedHydratedBlockWithStorageMeta,
|
|
4211
|
-
asXL1BlockNumber as
|
|
4248
|
+
asXL1BlockNumber as asXL1BlockNumber9,
|
|
4249
|
+
asXL1BlockRange as asXL1BlockRange11,
|
|
4212
4250
|
BlockViewerMoniker as BlockViewerMoniker2,
|
|
4213
|
-
FinalizationViewerMoniker
|
|
4251
|
+
FinalizationViewerMoniker,
|
|
4252
|
+
stepSize as stepSize2,
|
|
4253
|
+
StepSizes as StepSizes14
|
|
4214
4254
|
} from "@xyo-network/xl1-protocol-lib";
|
|
4255
|
+
import { Semaphore as Semaphore2 } from "async-mutex";
|
|
4215
4256
|
|
|
4216
4257
|
// src/utils/HydratedCache.ts
|
|
4217
|
-
import { LRUCache as
|
|
4258
|
+
import { LRUCache as LRUCache2 } from "lru-cache";
|
|
4218
4259
|
var HydratedCache = class {
|
|
4219
4260
|
cache;
|
|
4220
4261
|
context;
|
|
@@ -4222,7 +4263,7 @@ var HydratedCache = class {
|
|
|
4222
4263
|
constructor(context, hydrateFunction, maxCount = 2e3, ttl = Number.MAX_SAFE_INTEGER) {
|
|
4223
4264
|
this.context = context;
|
|
4224
4265
|
this.hydrateFunction = hydrateFunction;
|
|
4225
|
-
this.cache = new
|
|
4266
|
+
this.cache = new LRUCache2({ max: maxCount, ttl });
|
|
4226
4267
|
}
|
|
4227
4268
|
async get(hash) {
|
|
4228
4269
|
const existing = this.cache.get(hash);
|
|
@@ -4237,12 +4278,12 @@ var HydratedCache = class {
|
|
|
4237
4278
|
};
|
|
4238
4279
|
|
|
4239
4280
|
// src/utils/isZodError.ts
|
|
4240
|
-
import { z as
|
|
4281
|
+
import { z as z29 } from "zod";
|
|
4241
4282
|
var isZodError = (error) => {
|
|
4242
|
-
return error instanceof
|
|
4283
|
+
return error instanceof z29.ZodError;
|
|
4243
4284
|
};
|
|
4244
4285
|
var prettifyZodError = (error) => {
|
|
4245
|
-
return
|
|
4286
|
+
return z29.prettifyError(error);
|
|
4246
4287
|
};
|
|
4247
4288
|
|
|
4248
4289
|
// src/simple/block/SimpleBlockViewer.ts
|
|
@@ -4251,8 +4292,10 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
4251
4292
|
moniker = SimpleBlockViewer.defaultMoniker;
|
|
4252
4293
|
_store;
|
|
4253
4294
|
finalizationViewer;
|
|
4254
|
-
payloadCache = new
|
|
4255
|
-
signedHydratedBlockWithHashMetaCache = new
|
|
4295
|
+
payloadCache = new LruCacheMap2({ max: 1e4 });
|
|
4296
|
+
signedHydratedBlockWithHashMetaCache = new LruCacheMap2({ max: 2e3, ttl: 1e3 * 60 * 60 });
|
|
4297
|
+
_blockStepSemaphores = StepSizes14.map(() => new Semaphore2(20));
|
|
4298
|
+
_blocksSummaryMap;
|
|
4256
4299
|
_headPollHash;
|
|
4257
4300
|
_headPollInProgress = false;
|
|
4258
4301
|
_headPollTimer = null;
|
|
@@ -4260,6 +4303,10 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
4260
4303
|
get finalizedArchivist() {
|
|
4261
4304
|
return this.params.finalizedArchivist;
|
|
4262
4305
|
}
|
|
4306
|
+
get blocksSummaryMap() {
|
|
4307
|
+
this._blocksSummaryMap ??= this.params.blocksSummaryMap ?? new LruCacheMap2({ max: 32 });
|
|
4308
|
+
return this._blocksSummaryMap;
|
|
4309
|
+
}
|
|
4263
4310
|
get headPollIntervalMs() {
|
|
4264
4311
|
return this.params.headPollIntervalMs;
|
|
4265
4312
|
}
|
|
@@ -4278,11 +4325,12 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
4278
4325
|
static async paramsHandler(params) {
|
|
4279
4326
|
const headPollIntervalMs = params.headPollIntervalMs;
|
|
4280
4327
|
if (headPollIntervalMs !== void 0) {
|
|
4281
|
-
|
|
4328
|
+
assertEx34(headPollIntervalMs >= MIN_HEAD_POLL_INTERVAL_MS, () => `headPollIntervalMs must be at least ${MIN_HEAD_POLL_INTERVAL_MS}ms`);
|
|
4282
4329
|
}
|
|
4283
4330
|
return {
|
|
4284
4331
|
...await super.paramsHandler(params),
|
|
4285
|
-
|
|
4332
|
+
blocksSummaryMap: params.blocksSummaryMap,
|
|
4333
|
+
finalizedArchivist: assertEx34(params.finalizedArchivist, () => "finalizedArchivist is required"),
|
|
4286
4334
|
headPollIntervalMs
|
|
4287
4335
|
};
|
|
4288
4336
|
}
|
|
@@ -4303,7 +4351,7 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
4303
4351
|
async blockByNumber(blockNumber) {
|
|
4304
4352
|
return await this.spanAsync("blockByNumber", async () => {
|
|
4305
4353
|
const chainContext = await this.getChainContextRead();
|
|
4306
|
-
if (
|
|
4354
|
+
if (isUndefined9(chainContext.head)) {
|
|
4307
4355
|
return null;
|
|
4308
4356
|
}
|
|
4309
4357
|
return await this.blockByNumberWithContext(chainContext, blockNumber);
|
|
@@ -4311,8 +4359,8 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
4311
4359
|
}
|
|
4312
4360
|
async blocksByHash(hash, limit = 50) {
|
|
4313
4361
|
return await this.spanAsync("blocksByHash", async () => {
|
|
4314
|
-
|
|
4315
|
-
|
|
4362
|
+
assertEx34(limit > 0, () => "limit must be greater than 0");
|
|
4363
|
+
assertEx34(limit <= 100, () => "limit must be less than 100");
|
|
4316
4364
|
const blocks = [];
|
|
4317
4365
|
let current = await this.blockByHash(hash);
|
|
4318
4366
|
while (current && blocks.length < limit) {
|
|
@@ -4326,10 +4374,10 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
4326
4374
|
}
|
|
4327
4375
|
async blocksByNumber(blockNumber, limit = 50) {
|
|
4328
4376
|
return await this.spanAsync("blocksByNumber", async () => {
|
|
4329
|
-
|
|
4330
|
-
|
|
4377
|
+
assertEx34(limit > 0, () => "limit must be greater than 0");
|
|
4378
|
+
assertEx34(limit <= 100, () => "limit must be less than 100");
|
|
4331
4379
|
const chainContext = await this.getChainContextRead();
|
|
4332
|
-
if (
|
|
4380
|
+
if (isUndefined9(chainContext.head)) {
|
|
4333
4381
|
return [];
|
|
4334
4382
|
}
|
|
4335
4383
|
const blocks = [];
|
|
@@ -4337,15 +4385,39 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
4337
4385
|
while (current && blocks.length < limit) {
|
|
4338
4386
|
blocks.push(current);
|
|
4339
4387
|
if (current[0].block === 0) break;
|
|
4340
|
-
const previousNumber =
|
|
4388
|
+
const previousNumber = asXL1BlockNumber9(current[0].block - 1, true);
|
|
4341
4389
|
current = await this.blockByNumberWithContext(chainContext, previousNumber);
|
|
4342
4390
|
}
|
|
4343
4391
|
return blocks.map((b) => asSignedHydratedBlockWithHashMeta(b, true));
|
|
4344
4392
|
}, this.context);
|
|
4345
4393
|
}
|
|
4394
|
+
async blocksByStep(stepLevel, stepIndex) {
|
|
4395
|
+
return await this.spanAsync("blocksByStep", async () => {
|
|
4396
|
+
assertEx34(Number.isInteger(stepIndex) && stepIndex >= 0, () => "stepIndex must be a non-negative integer");
|
|
4397
|
+
const size = stepSize2(stepLevel);
|
|
4398
|
+
assertEx34(
|
|
4399
|
+
stepLevel <= blocksMaxStep,
|
|
4400
|
+
() => `blocksByStep does not support step levels above ${blocksMaxStep} (requested ${stepLevel})`
|
|
4401
|
+
);
|
|
4402
|
+
const chainContext = await this.getChainContextRead();
|
|
4403
|
+
if (isUndefined9(chainContext.head)) {
|
|
4404
|
+
return [];
|
|
4405
|
+
}
|
|
4406
|
+
const start = stepIndex * size;
|
|
4407
|
+
const end = Math.min(start + size - 1, chainContext.head.block);
|
|
4408
|
+
if (end < start) {
|
|
4409
|
+
return [];
|
|
4410
|
+
}
|
|
4411
|
+
const range = asXL1BlockRange11([start, end], { name: "blocksByStep" });
|
|
4412
|
+
const frames = deepCalculateFramesFromRange(range, blocksMaxStep);
|
|
4413
|
+
const summaries = await Promise.all(frames.map((frame) => blocksStepSummaryFromRange(this.context, this._blockStepSemaphores, this, this.blocksSummaryMap, frame)));
|
|
4414
|
+
const blocks = summaries.flatMap((summary) => summary.blocks);
|
|
4415
|
+
return blocks.map((b) => asSignedHydratedBlockWithHashMeta(b, true)).toReversed();
|
|
4416
|
+
}, this.context);
|
|
4417
|
+
}
|
|
4346
4418
|
async chainId(blockNumber = "latest") {
|
|
4347
4419
|
return await this.spanAsync("chainId", async () => {
|
|
4348
|
-
return blockNumber === "latest" ? (await this.finalizationViewer.headBlock()).chain :
|
|
4420
|
+
return blockNumber === "latest" ? (await this.finalizationViewer.headBlock()).chain : assertEx34(await this.blockByNumber(blockNumber), () => `Block not found [${blockNumber}]`)[0].chain;
|
|
4349
4421
|
}, this.context);
|
|
4350
4422
|
}
|
|
4351
4423
|
async createHandler() {
|
|
@@ -4373,9 +4445,9 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
4373
4445
|
remainingHashes = remainingHashes.filter((h) => !cachedHashes.has(h));
|
|
4374
4446
|
const finalizedPayloads = remainingHashes.length > 0 ? await this.finalizedArchivist.get(remainingHashes) : [];
|
|
4375
4447
|
const resultPayloads = [...cachedPayloads, ...finalizedPayloads.filter(exists4)];
|
|
4376
|
-
|
|
4448
|
+
for (const payload of resultPayloads) {
|
|
4377
4449
|
this.payloadCache.set(payload._hash, payload);
|
|
4378
|
-
}
|
|
4450
|
+
}
|
|
4379
4451
|
return resultPayloads;
|
|
4380
4452
|
}
|
|
4381
4453
|
async rate(range, timeUnit) {
|
|
@@ -4474,11 +4546,11 @@ SimpleBlockRewardViewer = __decorateClass([
|
|
|
4474
4546
|
], SimpleBlockRewardViewer);
|
|
4475
4547
|
|
|
4476
4548
|
// src/simple/blockValidation/SimpleBlockValidationViewer.ts
|
|
4477
|
-
import { assertEx as
|
|
4549
|
+
import { assertEx as assertEx35 } from "@xylabs/sdk-js";
|
|
4478
4550
|
import { PayloadBuilder as PayloadBuilder18 } from "@xyo-network/sdk-js";
|
|
4479
4551
|
import {
|
|
4480
4552
|
AccountBalanceViewerMoniker as AccountBalanceViewerMoniker2,
|
|
4481
|
-
asXL1BlockRange as
|
|
4553
|
+
asXL1BlockRange as asXL1BlockRange12,
|
|
4482
4554
|
BlockValidationViewerMoniker,
|
|
4483
4555
|
BlockViewerMoniker as BlockViewerMoniker3,
|
|
4484
4556
|
ChainContractViewerMoniker,
|
|
@@ -4527,7 +4599,7 @@ var SimpleBlockValidationViewer = class extends AbstractCreatableProvider {
|
|
|
4527
4599
|
head: void 0
|
|
4528
4600
|
};
|
|
4529
4601
|
const blocksWithMeta = await Promise.all(blocks.map((b) => Promise.all([PayloadBuilder18.addHashMeta(b[0]), PayloadBuilder18.addHashMeta(b[1])])));
|
|
4530
|
-
const head = isChainQualifiedHeadConfig5(config) ?
|
|
4602
|
+
const head = isChainQualifiedHeadConfig5(config) ? assertEx35(
|
|
4531
4603
|
(await this.blockViewer.blockByHash(config.head))?.[0],
|
|
4532
4604
|
() => `Specified a head that is not in the chain [${config.head}]`
|
|
4533
4605
|
) : void 0;
|
|
@@ -4535,7 +4607,7 @@ var SimpleBlockValidationViewer = class extends AbstractCreatableProvider {
|
|
|
4535
4607
|
const validateProtocol = value ? this.doValidateProtocol.bind(this) : void 0;
|
|
4536
4608
|
const validateState = state ? this.doValidateState.bind(this) : void 0;
|
|
4537
4609
|
const chainIdAtBlockNumber = (blockNumber) => this.chainContractViewer.chainIdAtBlockNumber(blockNumber);
|
|
4538
|
-
const qualification = { head: headBlock._hash, range:
|
|
4610
|
+
const qualification = { head: headBlock._hash, range: asXL1BlockRange12([0, headBlock.block], true) };
|
|
4539
4611
|
const [protocolResults, stateResults] = await Promise.all([
|
|
4540
4612
|
validateProtocol?.(blocksWithMeta, chainIdAtBlockNumber),
|
|
4541
4613
|
validateState?.(blocksWithMeta, chainIdAtBlockNumber)
|
|
@@ -4608,7 +4680,7 @@ SimpleBlockValidationViewer = __decorateClass([
|
|
|
4608
4680
|
], SimpleBlockValidationViewer);
|
|
4609
4681
|
|
|
4610
4682
|
// src/simple/chainContractViewer/SimpleChainContractViewer.ts
|
|
4611
|
-
import { assertEx as
|
|
4683
|
+
import { assertEx as assertEx36 } from "@xylabs/sdk-js";
|
|
4612
4684
|
import { ChainContractViewerMoniker as ChainContractViewerMoniker2, FinalizationViewerMoniker as FinalizationViewerMoniker2 } from "@xyo-network/xl1-protocol-lib";
|
|
4613
4685
|
var SimpleChainContractViewer = class extends AbstractCreatableProvider {
|
|
4614
4686
|
moniker = SimpleChainContractViewer.defaultMoniker;
|
|
@@ -4625,7 +4697,7 @@ var SimpleChainContractViewer = class extends AbstractCreatableProvider {
|
|
|
4625
4697
|
let contractViewer = this;
|
|
4626
4698
|
let forkedAtBlockNumber = await contractViewer.forkedAtBlockNumber();
|
|
4627
4699
|
while (forkedAtBlockNumber !== null && blockNumber <= forkedAtBlockNumber) {
|
|
4628
|
-
contractViewer =
|
|
4700
|
+
contractViewer = assertEx36(await contractViewer.forkedChainContractViewer());
|
|
4629
4701
|
forkedAtBlockNumber = await contractViewer.forkedAtBlockNumber();
|
|
4630
4702
|
chainId = await contractViewer.chainId();
|
|
4631
4703
|
}
|
|
@@ -4678,17 +4750,17 @@ var SimpleXyoClient = class {
|
|
|
4678
4750
|
};
|
|
4679
4751
|
|
|
4680
4752
|
// src/simple/datalake/RestDataLakeRunner.ts
|
|
4681
|
-
import { assertEx as
|
|
4682
|
-
import { isAnyPayload as
|
|
4753
|
+
import { assertEx as assertEx37, exists as exists6 } from "@xylabs/sdk-js";
|
|
4754
|
+
import { isAnyPayload as isAnyPayload8, PayloadZodLoose } from "@xyo-network/sdk-js";
|
|
4683
4755
|
import { DataLakeRunnerMoniker } from "@xyo-network/xl1-protocol-lib";
|
|
4684
|
-
import { z as
|
|
4756
|
+
import { z as z30 } from "zod/mini";
|
|
4685
4757
|
|
|
4686
4758
|
// src/simple/datalake/AbstractRestDataLake.ts
|
|
4687
4759
|
import { FetchClientError, FetchJsonClient } from "@xylabs/sdk-js";
|
|
4688
4760
|
import {
|
|
4689
4761
|
exists as exists5
|
|
4690
4762
|
} from "@xylabs/sdk-js";
|
|
4691
|
-
import { asAnyPayload as asAnyPayload4, isAnyPayload as
|
|
4763
|
+
import { asAnyPayload as asAnyPayload4, isAnyPayload as isAnyPayload7 } from "@xyo-network/sdk-js";
|
|
4692
4764
|
var AbstractRestDataLake = class extends AbstractCreatableProvider {
|
|
4693
4765
|
get allowedSchemas() {
|
|
4694
4766
|
return this.params.allowedSchemas;
|
|
@@ -4719,7 +4791,7 @@ var AbstractRestDataLake = class extends AbstractCreatableProvider {
|
|
|
4719
4791
|
}
|
|
4720
4792
|
}
|
|
4721
4793
|
isAllowed(value) {
|
|
4722
|
-
if (
|
|
4794
|
+
if (isAnyPayload7(value)) {
|
|
4723
4795
|
return this.isAllowedSchema(value.schema);
|
|
4724
4796
|
}
|
|
4725
4797
|
return false;
|
|
@@ -4746,15 +4818,15 @@ var RestDataLakeRunner = class extends AbstractRestDataLake {
|
|
|
4746
4818
|
}
|
|
4747
4819
|
async insert(items) {
|
|
4748
4820
|
const allowedItems = items.map((item) => {
|
|
4749
|
-
if (
|
|
4750
|
-
|
|
4821
|
+
if (isAnyPayload8(item) && this.isAllowed(item)) {
|
|
4822
|
+
assertEx37(typeof item === "object" && item !== null, () => "Data must be an object");
|
|
4751
4823
|
return item;
|
|
4752
4824
|
}
|
|
4753
4825
|
return null;
|
|
4754
4826
|
}).filter(exists6);
|
|
4755
4827
|
if (allowedItems.length > 0) {
|
|
4756
4828
|
const result = await this.client.post(`${this.params.endpoint}/insert`, allowedItems);
|
|
4757
|
-
return
|
|
4829
|
+
return z30.array(PayloadZodLoose).parse(result.data);
|
|
4758
4830
|
} else {
|
|
4759
4831
|
return [];
|
|
4760
4832
|
}
|
|
@@ -4781,11 +4853,11 @@ RestDataLakeViewer = __decorateClass([
|
|
|
4781
4853
|
|
|
4782
4854
|
// src/simple/datalake/SimpleDataLakeRunner.ts
|
|
4783
4855
|
import { exists as exists7 } from "@xylabs/sdk-js";
|
|
4784
|
-
import { isAnyPayload as
|
|
4856
|
+
import { isAnyPayload as isAnyPayload10, PayloadBuilder as PayloadBuilder19 } from "@xyo-network/sdk-js";
|
|
4785
4857
|
import { DataLakeRunnerMoniker as DataLakeRunnerMoniker2 } from "@xyo-network/xl1-protocol-lib";
|
|
4786
4858
|
|
|
4787
4859
|
// src/simple/datalake/AbstractSimpleDataLake.ts
|
|
4788
|
-
import { isAnyPayload as
|
|
4860
|
+
import { isAnyPayload as isAnyPayload9 } from "@xyo-network/sdk-js";
|
|
4789
4861
|
var AbstractSimpleDataLake = class extends AbstractCreatableProvider {
|
|
4790
4862
|
get allowedSchemas() {
|
|
4791
4863
|
return this.params.allowedSchemas;
|
|
@@ -4804,7 +4876,7 @@ var AbstractSimpleDataLake = class extends AbstractCreatableProvider {
|
|
|
4804
4876
|
throw new Error("Method not implemented.");
|
|
4805
4877
|
}
|
|
4806
4878
|
isAllowed(value) {
|
|
4807
|
-
if (
|
|
4879
|
+
if (isAnyPayload9(value)) {
|
|
4808
4880
|
return this.isAllowedSchema(value.schema);
|
|
4809
4881
|
}
|
|
4810
4882
|
return true;
|
|
@@ -4833,7 +4905,7 @@ var SimpleDataLakeRunner = class extends AbstractSimpleDataLake {
|
|
|
4833
4905
|
}))).filter(exists7);
|
|
4834
4906
|
}
|
|
4835
4907
|
async insert(items) {
|
|
4836
|
-
const payloads = items.filter(
|
|
4908
|
+
const payloads = items.filter(isAnyPayload10).filter((i) => this.isAllowed(i));
|
|
4837
4909
|
const hashPairs = await PayloadBuilder19.hashPairs(payloads);
|
|
4838
4910
|
for (const [payload, hash] of hashPairs) {
|
|
4839
4911
|
await this.map.set(hash, payload);
|
|
@@ -4890,7 +4962,7 @@ SimpleFinalizationRunner = __decorateClass([
|
|
|
4890
4962
|
], SimpleFinalizationRunner);
|
|
4891
4963
|
|
|
4892
4964
|
// src/simple/finalization/SimpleFinalizationViewer.ts
|
|
4893
|
-
import { assertEx as
|
|
4965
|
+
import { assertEx as assertEx38 } from "@xylabs/sdk-js";
|
|
4894
4966
|
import {
|
|
4895
4967
|
asSignedHydratedBlockWithStorageMeta as asSignedHydratedBlockWithStorageMeta2,
|
|
4896
4968
|
ChainContractViewerMoniker as ChainContractViewerMoniker3,
|
|
@@ -4919,7 +4991,7 @@ var SimpleFinalizationViewer = class extends AbstractCreatableProvider {
|
|
|
4919
4991
|
static async paramsHandler(params) {
|
|
4920
4992
|
return {
|
|
4921
4993
|
...await super.paramsHandler(params),
|
|
4922
|
-
finalizedArchivist:
|
|
4994
|
+
finalizedArchivist: assertEx38(params.finalizedArchivist, () => "finalizedArchivist is required")
|
|
4923
4995
|
};
|
|
4924
4996
|
}
|
|
4925
4997
|
chainId() {
|
|
@@ -4927,18 +4999,18 @@ var SimpleFinalizationViewer = class extends AbstractCreatableProvider {
|
|
|
4927
4999
|
}
|
|
4928
5000
|
async createHandler() {
|
|
4929
5001
|
await super.createHandler();
|
|
4930
|
-
this._chainId =
|
|
5002
|
+
this._chainId = assertEx38(this.config.chain.id ?? (await findMostRecentBlock(this.params.finalizedArchivist))?.chain, () => "chain.id is required if empty archivist");
|
|
4931
5003
|
this._store = { chainMap: this.params.finalizedArchivist };
|
|
4932
5004
|
}
|
|
4933
5005
|
async head() {
|
|
4934
5006
|
return await this.spanAsync("head", async () => {
|
|
4935
|
-
const currentHead =
|
|
5007
|
+
const currentHead = assertEx38(await this.getCurrentHead(), () => "Could not find most recent block [currentBlock]");
|
|
4936
5008
|
const cache = this.hydratedBlockCache;
|
|
4937
5009
|
const block = await cache.get(currentHead._hash);
|
|
4938
5010
|
if (!block) {
|
|
4939
5011
|
this.logger?.error(`Could not find current block with hash ${currentHead._hash}`);
|
|
4940
5012
|
}
|
|
4941
|
-
return
|
|
5013
|
+
return assertEx38(block, () => "Could not find current block");
|
|
4942
5014
|
}, this.context);
|
|
4943
5015
|
}
|
|
4944
5016
|
async headBlock() {
|
|
@@ -4964,8 +5036,8 @@ var SimpleFinalizationViewer = class extends AbstractCreatableProvider {
|
|
|
4964
5036
|
}
|
|
4965
5037
|
async getCurrentHead() {
|
|
4966
5038
|
const chainArchivist = this.finalizedArchivist;
|
|
4967
|
-
const result =
|
|
4968
|
-
|
|
5039
|
+
const result = assertEx38(await findMostRecentBlock(chainArchivist), () => "Could not find most recent block [getCurrentHead]");
|
|
5040
|
+
assertEx38(result?.chain === this._chainId, () => "Chain ID does not match head block chain ID");
|
|
4969
5041
|
return result;
|
|
4970
5042
|
}
|
|
4971
5043
|
};
|
|
@@ -4995,13 +5067,13 @@ var SimpleXyoGateway = class _SimpleXyoGateway extends AbstractCreatableProvider
|
|
|
4995
5067
|
|
|
4996
5068
|
// src/simple/gateway/SimpleXyoGatewayRunner.ts
|
|
4997
5069
|
import {
|
|
4998
|
-
assertEx as
|
|
5070
|
+
assertEx as assertEx39,
|
|
4999
5071
|
BigIntToJsonZod,
|
|
5000
5072
|
isDefined as isDefined18
|
|
5001
5073
|
} from "@xylabs/sdk-js";
|
|
5002
5074
|
import { PayloadBuilder as PayloadBuilder20 } from "@xyo-network/sdk-js";
|
|
5003
5075
|
import {
|
|
5004
|
-
asXL1BlockNumber as
|
|
5076
|
+
asXL1BlockNumber as asXL1BlockNumber10,
|
|
5005
5077
|
DataLakeRunnerMoniker as DataLakeRunnerMoniker3,
|
|
5006
5078
|
isSignedHydratedTransaction,
|
|
5007
5079
|
TransferSchema as TransferSchema3,
|
|
@@ -5028,7 +5100,7 @@ var SimpleXyoGatewayRunner = class _SimpleXyoGatewayRunner extends AbstractCreat
|
|
|
5028
5100
|
return this._signer;
|
|
5029
5101
|
}
|
|
5030
5102
|
async addPayloadsToChain(onChain, offChain, options) {
|
|
5031
|
-
const viewer =
|
|
5103
|
+
const viewer = assertEx39(this.connection.viewer, () => "No viewer available on connection");
|
|
5032
5104
|
const {
|
|
5033
5105
|
nbf,
|
|
5034
5106
|
exp,
|
|
@@ -5036,15 +5108,15 @@ var SimpleXyoGatewayRunner = class _SimpleXyoGatewayRunner extends AbstractCreat
|
|
|
5036
5108
|
fees
|
|
5037
5109
|
} = options ?? {};
|
|
5038
5110
|
const resolvedChainId = isDefined18(chain) ? chain : await viewer.chainId();
|
|
5039
|
-
const resolvedNbf =
|
|
5040
|
-
const resolvedExp =
|
|
5111
|
+
const resolvedNbf = asXL1BlockNumber10(isDefined18(nbf) ? nbf : await viewer.currentBlockNumber(), true);
|
|
5112
|
+
const resolvedExp = asXL1BlockNumber10(isDefined18(exp) ? exp : resolvedNbf + 10, true);
|
|
5041
5113
|
const tx = await buildUnsignedTransaction(resolvedChainId, onChain, offChain, resolvedNbf, resolvedExp, await this.signer.address(), fees);
|
|
5042
5114
|
return await this.addTransactionToChain(tx, await PayloadBuilder20.addHashMeta(offChain));
|
|
5043
5115
|
}
|
|
5044
5116
|
async addTransactionToChain(tx, offChain = []) {
|
|
5045
5117
|
const connection = this.connection;
|
|
5046
5118
|
const signer = this.signer;
|
|
5047
|
-
const runner =
|
|
5119
|
+
const runner = assertEx39(connection.runner, () => "No runner available on connection");
|
|
5048
5120
|
let signedTx;
|
|
5049
5121
|
if (isSignedHydratedTransaction(tx)) {
|
|
5050
5122
|
const [bw, payloads] = tx;
|
|
@@ -5059,7 +5131,7 @@ var SimpleXyoGatewayRunner = class _SimpleXyoGatewayRunner extends AbstractCreat
|
|
|
5059
5131
|
}
|
|
5060
5132
|
async confirmSubmittedTransaction(txHash, options) {
|
|
5061
5133
|
return await confirmSubmittedTransaction(
|
|
5062
|
-
|
|
5134
|
+
assertEx39(this.connection.viewer, () => "Connection viewer is undefined"),
|
|
5063
5135
|
txHash,
|
|
5064
5136
|
options
|
|
5065
5137
|
);
|
|
@@ -5096,7 +5168,7 @@ var SimpleXyoGatewayRunner = class _SimpleXyoGatewayRunner extends AbstractCreat
|
|
|
5096
5168
|
|
|
5097
5169
|
// src/simple/mempool/SimpleMempoolRunner.ts
|
|
5098
5170
|
import {
|
|
5099
|
-
assertEx as
|
|
5171
|
+
assertEx as assertEx40,
|
|
5100
5172
|
exists as exists8
|
|
5101
5173
|
} from "@xylabs/sdk-js";
|
|
5102
5174
|
import { isPayloadBundle, PayloadBuilder as PayloadBuilder21 } from "@xyo-network/sdk-js";
|
|
@@ -5105,6 +5177,7 @@ import {
|
|
|
5105
5177
|
ChainContractViewerMoniker as ChainContractViewerMoniker4,
|
|
5106
5178
|
DeadLetterQueueRunnerMoniker,
|
|
5107
5179
|
DEFAULT_MAX_EXP_AHEAD,
|
|
5180
|
+
elevatedTransaction,
|
|
5108
5181
|
FinalizationViewerMoniker as FinalizationViewerMoniker4,
|
|
5109
5182
|
isSignedHydratedBlockWithHashMeta,
|
|
5110
5183
|
isSignedHydratedTransactionWithHashMeta,
|
|
@@ -5171,8 +5244,8 @@ var SimpleMempoolRunner = class extends AbstractCreatableProvider {
|
|
|
5171
5244
|
static async paramsHandler(params) {
|
|
5172
5245
|
return {
|
|
5173
5246
|
...await super.paramsHandler(params),
|
|
5174
|
-
pendingBlocksArchivist:
|
|
5175
|
-
pendingTransactionsArchivist:
|
|
5247
|
+
pendingBlocksArchivist: assertEx40(params?.pendingBlocksArchivist, () => "pendingBlocksArchivist is required"),
|
|
5248
|
+
pendingTransactionsArchivist: assertEx40(params?.pendingTransactionsArchivist, () => "pendingTransactionsArchivist is required")
|
|
5176
5249
|
};
|
|
5177
5250
|
}
|
|
5178
5251
|
async createHandler() {
|
|
@@ -5210,7 +5283,7 @@ var SimpleMempoolRunner = class extends AbstractCreatableProvider {
|
|
|
5210
5283
|
return b;
|
|
5211
5284
|
}
|
|
5212
5285
|
}).filter(exists8);
|
|
5213
|
-
|
|
5286
|
+
assertEx40(
|
|
5214
5287
|
remainingBlockMap.length === remainingBlocks.length,
|
|
5215
5288
|
() => `remainingBlockMap length should match remainingBlocks length [${remainingBlockMap.length}/${remainingBlocks.length}]`
|
|
5216
5289
|
);
|
|
@@ -5272,7 +5345,7 @@ var SimpleMempoolRunner = class extends AbstractCreatableProvider {
|
|
|
5272
5345
|
return t;
|
|
5273
5346
|
}
|
|
5274
5347
|
}).filter(exists8);
|
|
5275
|
-
|
|
5348
|
+
assertEx40(
|
|
5276
5349
|
remainingTransactionMap.length === remainingTransactions.length,
|
|
5277
5350
|
() => `remainingTransactionMap length should match remainingTransactions length [${remainingTransactionMap.length}/${remainingTransactions.length}]`
|
|
5278
5351
|
);
|
|
@@ -5335,14 +5408,15 @@ var SimpleMempoolRunner = class extends AbstractCreatableProvider {
|
|
|
5335
5408
|
await PayloadBuilder21.addHashMeta(payloads)
|
|
5336
5409
|
])
|
|
5337
5410
|
);
|
|
5411
|
+
const elevatedTransactions = hashedTransactions.map((tx) => elevatedTransaction(tx));
|
|
5338
5412
|
if (this.validateOnSubmit) {
|
|
5339
5413
|
const validationResults = await Promise.all(
|
|
5340
|
-
|
|
5414
|
+
elevatedTransactions.map(async (tx) => this.transactionValidationViewer.validateTransaction(tx, { value: true, state: true }))
|
|
5341
5415
|
);
|
|
5342
5416
|
const failures = [];
|
|
5343
5417
|
for (const [i, result] of validationResults.entries()) {
|
|
5344
5418
|
if (!isSignedHydratedTransactionWithHashMeta(result)) {
|
|
5345
|
-
failures.push({ tx:
|
|
5419
|
+
failures.push({ tx: elevatedTransactions[i], errors: result });
|
|
5346
5420
|
}
|
|
5347
5421
|
}
|
|
5348
5422
|
if (failures.length > 0) {
|
|
@@ -5351,7 +5425,7 @@ var SimpleMempoolRunner = class extends AbstractCreatableProvider {
|
|
|
5351
5425
|
throw new Error(`SimpleMempoolRunner: rejected ${failures.length} transaction(s) at admission: ${detail}`);
|
|
5352
5426
|
}
|
|
5353
5427
|
}
|
|
5354
|
-
const bundles =
|
|
5428
|
+
const bundles = elevatedTransactions.map((tx) => hydratedTransactionToPayloadBundle(tx));
|
|
5355
5429
|
const inserted = await this.pendingTransactionsArchivist.insert(bundles);
|
|
5356
5430
|
await this.enforceCap();
|
|
5357
5431
|
return inserted.map((p) => p._hash);
|
|
@@ -5738,7 +5812,7 @@ function deduplicateWithBundleBySigner(items) {
|
|
|
5738
5812
|
}
|
|
5739
5813
|
|
|
5740
5814
|
// src/simple/network/SimpleXyoNetwork.ts
|
|
5741
|
-
import { fetchJsonGet, isUndefined as
|
|
5815
|
+
import { fetchJsonGet, isUndefined as isUndefined10 } from "@xylabs/sdk-js";
|
|
5742
5816
|
import { isNetworkStatus } from "@xyo-network/xl1-protocol-lib";
|
|
5743
5817
|
|
|
5744
5818
|
// src/simple/network/lib/FailedNetworkStatusPayloads.ts
|
|
@@ -5786,7 +5860,7 @@ var SimpleXyoNetwork = class {
|
|
|
5786
5860
|
}
|
|
5787
5861
|
async status() {
|
|
5788
5862
|
const statusNetwork = StatusNetworks[this._networkId];
|
|
5789
|
-
if (
|
|
5863
|
+
if (isUndefined10(statusNetwork)) {
|
|
5790
5864
|
throw new Error(`Unknown status network ID: ${this._networkId}`);
|
|
5791
5865
|
}
|
|
5792
5866
|
return await this.makeRequest(statusNetwork.statusUrl);
|
|
@@ -5811,7 +5885,7 @@ var SimpleXyoNetwork = class {
|
|
|
5811
5885
|
};
|
|
5812
5886
|
|
|
5813
5887
|
// src/simple/permissions/SimpleXyoPermissions.ts
|
|
5814
|
-
import { assertEx as
|
|
5888
|
+
import { assertEx as assertEx41 } from "@xylabs/sdk-js";
|
|
5815
5889
|
var SimpleXyoPermissions = class {
|
|
5816
5890
|
invoker;
|
|
5817
5891
|
_store;
|
|
@@ -5820,7 +5894,7 @@ var SimpleXyoPermissions = class {
|
|
|
5820
5894
|
this.invoker = store.invoker;
|
|
5821
5895
|
}
|
|
5822
5896
|
get store() {
|
|
5823
|
-
return
|
|
5897
|
+
return assertEx41(this._store, () => "Store must be defined to get permissions");
|
|
5824
5898
|
}
|
|
5825
5899
|
async getPermissions() {
|
|
5826
5900
|
return await this.store.getPermissions();
|
|
@@ -5873,7 +5947,7 @@ var SimpleXyoPermissions = class {
|
|
|
5873
5947
|
};
|
|
5874
5948
|
|
|
5875
5949
|
// src/simple/permissions/store/MemoryPermissions.ts
|
|
5876
|
-
import { assertEx as
|
|
5950
|
+
import { assertEx as assertEx42 } from "@xylabs/sdk-js";
|
|
5877
5951
|
var MemoryPermissionsStore = class {
|
|
5878
5952
|
_invoker;
|
|
5879
5953
|
permissions = [];
|
|
@@ -5881,7 +5955,7 @@ var MemoryPermissionsStore = class {
|
|
|
5881
5955
|
this._invoker = invoker;
|
|
5882
5956
|
}
|
|
5883
5957
|
get invoker() {
|
|
5884
|
-
return
|
|
5958
|
+
return assertEx42(this._invoker, () => "Invoker must be defined to get permissions");
|
|
5885
5959
|
}
|
|
5886
5960
|
async getPermissions() {
|
|
5887
5961
|
await Promise.resolve();
|
|
@@ -6047,7 +6121,7 @@ SimpleStakeEventsViewer = __decorateClass([
|
|
|
6047
6121
|
], SimpleStakeEventsViewer);
|
|
6048
6122
|
|
|
6049
6123
|
// src/simple/StakeTotalsViewer/SimpleStakeTotalsViewer.ts
|
|
6050
|
-
import { assertEx as
|
|
6124
|
+
import { assertEx as assertEx43 } from "@xylabs/sdk-js";
|
|
6051
6125
|
import { asXyoAddress as asXyoAddress3 } from "@xyo-network/address";
|
|
6052
6126
|
import {
|
|
6053
6127
|
StakeTotalsViewerMoniker,
|
|
@@ -6091,7 +6165,7 @@ var SimpleStakeTotalsViewer = class extends AbstractCreatableProvider {
|
|
|
6091
6165
|
}
|
|
6092
6166
|
async createHandler() {
|
|
6093
6167
|
await super.createHandler();
|
|
6094
|
-
this._stakeViewer =
|
|
6168
|
+
this._stakeViewer = assertEx43(
|
|
6095
6169
|
await this.locateAndCreate(StakeViewerMoniker),
|
|
6096
6170
|
() => "Failed to create StakeViewer"
|
|
6097
6171
|
);
|
|
@@ -6145,14 +6219,14 @@ SimpleStakeTotalsViewer = __decorateClass([
|
|
|
6145
6219
|
], SimpleStakeTotalsViewer);
|
|
6146
6220
|
|
|
6147
6221
|
// src/simple/StakeViewer/SimpleStakeViewer.ts
|
|
6148
|
-
import { assertEx as
|
|
6222
|
+
import { assertEx as assertEx44, toAddress } from "@xylabs/sdk-js";
|
|
6149
6223
|
import { asXyoAddress as asXyoAddress4 } from "@xyo-network/address";
|
|
6150
6224
|
import { StakeEventsViewerMoniker as StakeEventsViewerMoniker2, StakeViewerMoniker as StakeViewerMoniker2 } from "@xyo-network/xl1-protocol-lib";
|
|
6151
6225
|
var SimpleStakeViewer = class extends AbstractCreatableProvider {
|
|
6152
6226
|
moniker = SimpleStakeViewer.defaultMoniker;
|
|
6153
6227
|
_chainStakeEventsViewer;
|
|
6154
6228
|
get stakeEvents() {
|
|
6155
|
-
return
|
|
6229
|
+
return assertEx44(this._chainStakeEventsViewer, () => "Stake events viewer not set");
|
|
6156
6230
|
}
|
|
6157
6231
|
get positions() {
|
|
6158
6232
|
return this.params.positions;
|
|
@@ -6192,7 +6266,7 @@ var SimpleStakeViewer = class extends AbstractCreatableProvider {
|
|
|
6192
6266
|
}
|
|
6193
6267
|
async createHandler() {
|
|
6194
6268
|
await super.createHandler();
|
|
6195
|
-
this._chainStakeEventsViewer =
|
|
6269
|
+
this._chainStakeEventsViewer = assertEx44(
|
|
6196
6270
|
await this.locateAndCreate(StakeEventsViewerMoniker2),
|
|
6197
6271
|
() => "Failed to create StakeEventsViewer"
|
|
6198
6272
|
);
|
|
@@ -6227,7 +6301,7 @@ var SimpleStakeViewer = class extends AbstractCreatableProvider {
|
|
|
6227
6301
|
return toAddress(toAddress(1n));
|
|
6228
6302
|
}
|
|
6229
6303
|
stakeById(id) {
|
|
6230
|
-
return
|
|
6304
|
+
return assertEx44(this.positions[id], () => new Error(`Stake with id ${id} not found`));
|
|
6231
6305
|
}
|
|
6232
6306
|
stakeByStaker(staker, slot) {
|
|
6233
6307
|
return this.positions.filter((s) => asXyoAddress4(s.staker) === asXyoAddress4(staker))[slot];
|
|
@@ -6329,12 +6403,12 @@ RestSyncViewer = __decorateClass([
|
|
|
6329
6403
|
// src/simple/timeSync2/SimpleTimeSyncViewer.ts
|
|
6330
6404
|
import {
|
|
6331
6405
|
asHash as asHash5,
|
|
6332
|
-
assertEx as
|
|
6406
|
+
assertEx as assertEx45,
|
|
6333
6407
|
isDefined as isDefined21
|
|
6334
6408
|
} from "@xylabs/sdk-js";
|
|
6335
6409
|
import {
|
|
6336
6410
|
asTimePayload as asTimePayload2,
|
|
6337
|
-
asXL1BlockNumber as
|
|
6411
|
+
asXL1BlockNumber as asXL1BlockNumber11,
|
|
6338
6412
|
BlockViewerMoniker as BlockViewerMoniker4,
|
|
6339
6413
|
TimeSchema,
|
|
6340
6414
|
TimeSyncViewerMoniker
|
|
@@ -6351,7 +6425,7 @@ var SimpleTimeSyncViewer = class extends AbstractCreatableProvider {
|
|
|
6351
6425
|
async convertTime(fromDomain, toDomain, from) {
|
|
6352
6426
|
switch (fromDomain) {
|
|
6353
6427
|
case "xl1": {
|
|
6354
|
-
const [block, payloads] =
|
|
6428
|
+
const [block, payloads] = assertEx45(await this.blockViewer.blockByNumber(asXL1BlockNumber11(from, true)), () => "Block not found");
|
|
6355
6429
|
const timeSchemaIndex = block.payload_schemas.indexOf(TimeSchema);
|
|
6356
6430
|
const hash = timeSchemaIndex === -1 ? void 0 : block.payload_hashes[timeSchemaIndex];
|
|
6357
6431
|
const timePayload = asTimePayload2(isDefined21(hash) ? payloads.find((p) => p._hash === hash) : void 0);
|
|
@@ -6406,10 +6480,10 @@ var SimpleTimeSyncViewer = class extends AbstractCreatableProvider {
|
|
|
6406
6480
|
return [Date.now(), null];
|
|
6407
6481
|
}
|
|
6408
6482
|
case "ethereum": {
|
|
6409
|
-
const provider =
|
|
6483
|
+
const provider = assertEx45(this.ethProvider, () => "Ethereum provider not configured");
|
|
6410
6484
|
const blockNumber = await provider.getBlockNumber() ?? 0;
|
|
6411
6485
|
const block = await provider.getBlock(blockNumber);
|
|
6412
|
-
const blockHash = asHash5(
|
|
6486
|
+
const blockHash = asHash5(assertEx45(block?.hash, () => "Block hash not found"), true);
|
|
6413
6487
|
return [blockNumber, blockHash];
|
|
6414
6488
|
}
|
|
6415
6489
|
default: {
|
|
@@ -6424,7 +6498,7 @@ var SimpleTimeSyncViewer = class extends AbstractCreatableProvider {
|
|
|
6424
6498
|
// this is for the previous block
|
|
6425
6499
|
xl1,
|
|
6426
6500
|
// this is for the previous block
|
|
6427
|
-
xl1Hash:
|
|
6501
|
+
xl1Hash: assertEx45(xl1Hash, () => "No xl1 hash available from time sync service"),
|
|
6428
6502
|
epoch: Date.now()
|
|
6429
6503
|
};
|
|
6430
6504
|
if (isDefined21(this.ethProvider)) {
|
|
@@ -6444,11 +6518,11 @@ SimpleTimeSyncViewer = __decorateClass([
|
|
|
6444
6518
|
], SimpleTimeSyncViewer);
|
|
6445
6519
|
|
|
6446
6520
|
// src/simple/transactionValidation/SimpleTransactionValidationViewer.ts
|
|
6447
|
-
import { assertEx as
|
|
6521
|
+
import { assertEx as assertEx46 } from "@xylabs/sdk-js";
|
|
6448
6522
|
import { PayloadBuilder as PayloadBuilder24 } from "@xyo-network/sdk-js";
|
|
6449
6523
|
import {
|
|
6450
6524
|
AccountBalanceViewerMoniker as AccountBalanceViewerMoniker3,
|
|
6451
|
-
asXL1BlockRange as
|
|
6525
|
+
asXL1BlockRange as asXL1BlockRange13,
|
|
6452
6526
|
BlockViewerMoniker as BlockViewerMoniker5,
|
|
6453
6527
|
ChainContractViewerMoniker as ChainContractViewerMoniker5,
|
|
6454
6528
|
isChainQualifiedHeadConfig as isChainQualifiedHeadConfig6,
|
|
@@ -6495,7 +6569,7 @@ var SimpleTransactionValidationViewer = class extends AbstractCreatableProvider
|
|
|
6495
6569
|
head: void 0
|
|
6496
6570
|
};
|
|
6497
6571
|
const transactionsWithMeta = await Promise.all(transactions.map((b) => Promise.all([PayloadBuilder24.addHashMeta(b[0]), PayloadBuilder24.addHashMeta(b[1])])));
|
|
6498
|
-
const head = isChainQualifiedHeadConfig6(config) ?
|
|
6572
|
+
const head = isChainQualifiedHeadConfig6(config) ? assertEx46(
|
|
6499
6573
|
(await this.blockViewer.blockByHash(config.head))?.[0],
|
|
6500
6574
|
() => `Specified a head that is not in the chain [${config.head}]`
|
|
6501
6575
|
) : void 0;
|
|
@@ -6503,7 +6577,7 @@ var SimpleTransactionValidationViewer = class extends AbstractCreatableProvider
|
|
|
6503
6577
|
const validateProtocol = value ? this.doValidateProtocol.bind(this) : void 0;
|
|
6504
6578
|
const validateState = state ? this.doValidateState.bind(this) : void 0;
|
|
6505
6579
|
const chainId = headBlock.chain;
|
|
6506
|
-
const qualification = { head: headBlock._hash, range:
|
|
6580
|
+
const qualification = { head: headBlock._hash, range: asXL1BlockRange13([0, headBlock.block], true) };
|
|
6507
6581
|
const [protocolResults, stateResults] = await Promise.all([
|
|
6508
6582
|
validateProtocol?.(transactionsWithMeta, chainId),
|
|
6509
6583
|
validateState?.(transactionsWithMeta, chainId)
|
|
@@ -6561,7 +6635,7 @@ SimpleTransactionValidationViewer = __decorateClass([
|
|
|
6561
6635
|
], SimpleTransactionValidationViewer);
|
|
6562
6636
|
|
|
6563
6637
|
// src/simple/TransactionViewer/SimpleTransactionViewer.ts
|
|
6564
|
-
import { assertEx as
|
|
6638
|
+
import { assertEx as assertEx47, exists as exists10 } from "@xylabs/sdk-js";
|
|
6565
6639
|
import { BoundWitnessSchema } from "@xyo-network/sdk-js";
|
|
6566
6640
|
import {
|
|
6567
6641
|
asSignedHydratedTransactionWithHashMeta,
|
|
@@ -6578,7 +6652,7 @@ var SimpleTransactionViewer = class extends AbstractCreatableProvider {
|
|
|
6578
6652
|
}
|
|
6579
6653
|
async byBlockHashAndIndex(blockHash, transactionIndex) {
|
|
6580
6654
|
return await this.spanAsync("byBlockHashAndIndex", async () => {
|
|
6581
|
-
|
|
6655
|
+
assertEx47(transactionIndex >= 0, () => "transactionIndex must be greater than or equal to 0");
|
|
6582
6656
|
try {
|
|
6583
6657
|
const block = await this.blockViewer.blockByHash(blockHash);
|
|
6584
6658
|
if (!block) return null;
|
|
@@ -6642,13 +6716,15 @@ SimpleTransactionViewer = __decorateClass([
|
|
|
6642
6716
|
|
|
6643
6717
|
// src/simple/windowedBlock/SimpleWindowedBlockViewer.ts
|
|
6644
6718
|
import {
|
|
6645
|
-
assertEx as
|
|
6719
|
+
assertEx as assertEx48,
|
|
6646
6720
|
exists as exists11,
|
|
6647
6721
|
isNull as isNull2
|
|
6648
6722
|
} from "@xylabs/sdk-js";
|
|
6723
|
+
import { MemoryMap as MemoryMap2 } from "@xyo-network/xl1-driver-memory";
|
|
6649
6724
|
import {
|
|
6650
|
-
asXL1BlockNumber as
|
|
6725
|
+
asXL1BlockNumber as asXL1BlockNumber12,
|
|
6651
6726
|
BlockViewerMoniker as BlockViewerMoniker7,
|
|
6727
|
+
stepSize as stepSize3,
|
|
6652
6728
|
WindowedBlockViewerMoniker as WindowedBlockViewerMoniker2
|
|
6653
6729
|
} from "@xyo-network/xl1-protocol-lib";
|
|
6654
6730
|
import { Mutex as Mutex2 } from "async-mutex";
|
|
@@ -6700,11 +6776,20 @@ var SimpleWindowedBlockViewer = class extends AbstractCreatableProvider {
|
|
|
6700
6776
|
let block = this._blockNumberMap.get(blockNumber);
|
|
6701
6777
|
while (block && (limit === void 0 || result.length < limit)) {
|
|
6702
6778
|
result.unshift(block);
|
|
6703
|
-
const previousBlockNumber =
|
|
6779
|
+
const previousBlockNumber = asXL1BlockNumber12(block[0].block - 1, true);
|
|
6704
6780
|
block = previousBlockNumber >= 0 ? this._blockNumberMap.get(previousBlockNumber) : void 0;
|
|
6705
6781
|
}
|
|
6706
6782
|
return result;
|
|
6707
6783
|
}
|
|
6784
|
+
blocksByStep(stepLevel, stepIndex) {
|
|
6785
|
+
const size = stepSize3(stepLevel);
|
|
6786
|
+
const start = stepIndex * size;
|
|
6787
|
+
const end = start + size - 1;
|
|
6788
|
+
return this._chain.filter((block) => {
|
|
6789
|
+
const blockNumber = block[0].block;
|
|
6790
|
+
return blockNumber >= start && blockNumber <= end;
|
|
6791
|
+
}).toReversed();
|
|
6792
|
+
}
|
|
6708
6793
|
blocksByTransactionHashes(hashes) {
|
|
6709
6794
|
return hashes.map((hash) => this._transactionHashMap.get(hash)).filter(exists11);
|
|
6710
6795
|
}
|
|
@@ -6713,22 +6798,22 @@ var SimpleWindowedBlockViewer = class extends AbstractCreatableProvider {
|
|
|
6713
6798
|
}
|
|
6714
6799
|
async createHandler() {
|
|
6715
6800
|
await super.createHandler();
|
|
6716
|
-
this._blockViewer =
|
|
6801
|
+
this._blockViewer = assertEx48(
|
|
6717
6802
|
this.params.blockViewer ?? await this.locator.getInstance(BlockViewerMoniker7),
|
|
6718
6803
|
() => "BlockViewer instance is required"
|
|
6719
6804
|
);
|
|
6720
|
-
this._blockHashMap = new
|
|
6721
|
-
this._blockNumberMap = new
|
|
6722
|
-
this._transactionHashMap = new
|
|
6805
|
+
this._blockHashMap = new MemoryMap2();
|
|
6806
|
+
this._blockNumberMap = new MemoryMap2();
|
|
6807
|
+
this._transactionHashMap = new MemoryMap2();
|
|
6723
6808
|
}
|
|
6724
6809
|
currentBlock() {
|
|
6725
|
-
return
|
|
6810
|
+
return assertEx48(this._chain.at(-1));
|
|
6726
6811
|
}
|
|
6727
6812
|
currentBlockHash() {
|
|
6728
|
-
return
|
|
6813
|
+
return assertEx48(this._chain.at(-1)?.[0]._hash);
|
|
6729
6814
|
}
|
|
6730
6815
|
currentBlockNumber() {
|
|
6731
|
-
return
|
|
6816
|
+
return assertEx48(this._chain.at(-1)?.[0].block);
|
|
6732
6817
|
}
|
|
6733
6818
|
async payloadByHash(hash) {
|
|
6734
6819
|
const payloads = await this.payloadsByHash([hash]);
|
|
@@ -6886,14 +6971,375 @@ var RuntimeStatusMonitor = class extends LoggerStatusReporter {
|
|
|
6886
6971
|
}
|
|
6887
6972
|
};
|
|
6888
6973
|
|
|
6974
|
+
// src/test/buildRandomChain.ts
|
|
6975
|
+
import { asAddress as asAddress2, assertEx as assertEx51 } from "@xylabs/sdk-js";
|
|
6976
|
+
import {
|
|
6977
|
+
Account as Account4,
|
|
6978
|
+
asSchema as asSchema11,
|
|
6979
|
+
IdSchema as IdSchema2,
|
|
6980
|
+
MemoryArchivist,
|
|
6981
|
+
PayloadBuilder as PayloadBuilder29
|
|
6982
|
+
} from "@xyo-network/sdk-js";
|
|
6983
|
+
import {
|
|
6984
|
+
asXL1BlockNumber as asXL1BlockNumber17
|
|
6985
|
+
} from "@xyo-network/xl1-protocol-lib";
|
|
6986
|
+
|
|
6987
|
+
// src/test/buildNextBlock.ts
|
|
6988
|
+
import {
|
|
6989
|
+
AttoXL1 as AttoXL15,
|
|
6990
|
+
XYO_STEP_REWARD_ADDRESS as XYO_STEP_REWARD_ADDRESS4
|
|
6991
|
+
} from "@xyo-network/xl1-protocol-lib";
|
|
6992
|
+
|
|
6993
|
+
// src/test/buildBlock.ts
|
|
6994
|
+
import { assertEx as assertEx49, isDefined as isDefined22 } from "@xylabs/sdk-js";
|
|
6995
|
+
import {
|
|
6996
|
+
asAnyPayload as asAnyPayload5,
|
|
6997
|
+
BoundWitnessBuilder as BoundWitnessBuilder3,
|
|
6998
|
+
PayloadBuilder as PayloadBuilder25
|
|
6999
|
+
} from "@xyo-network/sdk-js";
|
|
7000
|
+
import {
|
|
7001
|
+
asXL1BlockNumber as asXL1BlockNumber13,
|
|
7002
|
+
AttoXL1 as AttoXL14,
|
|
7003
|
+
isBlockBoundWitness,
|
|
7004
|
+
rewardAddressFromStepIdentity,
|
|
7005
|
+
StepRewardFractions,
|
|
7006
|
+
StepSizes as StepSizes15,
|
|
7007
|
+
XL1_PROTOCOL_VERSION,
|
|
7008
|
+
XYO_STEP_REWARD_ADDRESS as XYO_STEP_REWARD_ADDRESS3,
|
|
7009
|
+
XYO_ZERO_ADDRESS as XYO_ZERO_ADDRESS2
|
|
7010
|
+
} from "@xyo-network/xl1-protocol-lib";
|
|
7011
|
+
|
|
7012
|
+
// src/test/BuildBlockOptions.ts
|
|
7013
|
+
import {
|
|
7014
|
+
isAddress,
|
|
7015
|
+
isArray as isArray2,
|
|
7016
|
+
isHash as isHash3,
|
|
7017
|
+
isNumber as isNumber2,
|
|
7018
|
+
isObject as isObject3
|
|
7019
|
+
} from "@xylabs/sdk-js";
|
|
7020
|
+
var isBaseBuildBlockOptions = (value) => {
|
|
7021
|
+
if (!isObject3(value)) {
|
|
7022
|
+
return false;
|
|
7023
|
+
}
|
|
7024
|
+
const typedValue = value;
|
|
7025
|
+
if (!isArray2(typedValue.blockPayloads) || !isAddress(typedValue.chainId) || !isArray2(typedValue.signers) || !isArray2(typedValue.txs)) {
|
|
7026
|
+
return false;
|
|
7027
|
+
}
|
|
7028
|
+
return true;
|
|
7029
|
+
};
|
|
7030
|
+
var isBuildGenesisBlockOptions = (value) => {
|
|
7031
|
+
if (!isBaseBuildBlockOptions(value)) {
|
|
7032
|
+
return false;
|
|
7033
|
+
}
|
|
7034
|
+
const typedValue = value;
|
|
7035
|
+
if (typedValue.previousBlockHash !== null) {
|
|
7036
|
+
return false;
|
|
7037
|
+
}
|
|
7038
|
+
if (typedValue.previousBlockNumber !== void 0) {
|
|
7039
|
+
return false;
|
|
7040
|
+
}
|
|
7041
|
+
return true;
|
|
7042
|
+
};
|
|
7043
|
+
var isBuildNextBlockOptions = (value) => {
|
|
7044
|
+
if (!isBaseBuildBlockOptions(value)) {
|
|
7045
|
+
return false;
|
|
7046
|
+
}
|
|
7047
|
+
const typedValue = value;
|
|
7048
|
+
if (!isHash3(typedValue.previousBlockHash)) {
|
|
7049
|
+
return false;
|
|
7050
|
+
}
|
|
7051
|
+
if (!isNumber2(typedValue.previousBlockNumber)) {
|
|
7052
|
+
return false;
|
|
7053
|
+
}
|
|
7054
|
+
if (!isArray2(typedValue.previousStepHashes)) {
|
|
7055
|
+
return false;
|
|
7056
|
+
}
|
|
7057
|
+
return true;
|
|
7058
|
+
};
|
|
7059
|
+
|
|
7060
|
+
// src/test/buildBlock.ts
|
|
7061
|
+
function calculateCompletedStepReward(step, balance) {
|
|
7062
|
+
return AttoXL14(StepRewardFractions[step][0] * balance / StepRewardFractions[step][1]);
|
|
7063
|
+
}
|
|
7064
|
+
async function buildBlock(options) {
|
|
7065
|
+
const previousBlockNumber = isBuildGenesisBlockOptions(options) ? -1 : options.previousBlockNumber;
|
|
7066
|
+
const blockNumber = asXL1BlockNumber13(previousBlockNumber + 1, true);
|
|
7067
|
+
const inStepHashes = isBuildNextBlockOptions(options) ? options.previousStepHashes : [];
|
|
7068
|
+
const previousBlockHash = isBuildNextBlockOptions(options) ? options.previousBlockHash : void 0;
|
|
7069
|
+
const stepRewardPoolBalance = isBuildNextBlockOptions(options) ? options.stepRewardPoolBalance : AttoXL14(0n);
|
|
7070
|
+
const {
|
|
7071
|
+
chainId,
|
|
7072
|
+
txs,
|
|
7073
|
+
chainStepRewardAddress: chainStepRewardAddress2 = XYO_STEP_REWARD_ADDRESS3,
|
|
7074
|
+
blockPayloads,
|
|
7075
|
+
protocol = XL1_PROTOCOL_VERSION,
|
|
7076
|
+
signers
|
|
7077
|
+
} = options;
|
|
7078
|
+
const step_hashes = [];
|
|
7079
|
+
for (const [tx] of txs) {
|
|
7080
|
+
if (tx.nbf > blockNumber) {
|
|
7081
|
+
throw new Error(`Transaction ${await PayloadBuilder25.hash(tx)} not valid for block ${blockNumber} - NBF is ${tx.nbf}`);
|
|
7082
|
+
}
|
|
7083
|
+
if (tx.exp < blockNumber) {
|
|
7084
|
+
throw new Error(`Transaction ${await PayloadBuilder25.hash(tx)} not valid for block ${blockNumber} - EXP is ${tx.exp}`);
|
|
7085
|
+
}
|
|
7086
|
+
}
|
|
7087
|
+
const completedStepRewardTransfers = [];
|
|
7088
|
+
for (const [i, step] of StepSizes15.entries()) {
|
|
7089
|
+
if (blockNumber < step) {
|
|
7090
|
+
break;
|
|
7091
|
+
}
|
|
7092
|
+
if (blockNumber % step === 0) {
|
|
7093
|
+
if (StepRewardFractions[i][0] > 0 && chainStepRewardAddress2 !== XYO_ZERO_ADDRESS2) {
|
|
7094
|
+
const completedStepRewardHolderAddress = rewardAddressFromStepIdentity({ block: blockNumber, step });
|
|
7095
|
+
const completedStepReward = calculateCompletedStepReward(i, stepRewardPoolBalance);
|
|
7096
|
+
completedStepRewardTransfers.push(createTransferPayload(chainStepRewardAddress2, { [completedStepRewardHolderAddress]: completedStepReward }));
|
|
7097
|
+
}
|
|
7098
|
+
step_hashes.push(assertEx49(previousBlockHash, () => `Previous block hash is required for step ${step} at block ${blockNumber}`));
|
|
7099
|
+
} else {
|
|
7100
|
+
if (isDefined22(inStepHashes.at(i))) {
|
|
7101
|
+
step_hashes.push(inStepHashes[i]);
|
|
7102
|
+
}
|
|
7103
|
+
}
|
|
7104
|
+
}
|
|
7105
|
+
const previous = previousBlockHash ?? null;
|
|
7106
|
+
const block = blockNumber;
|
|
7107
|
+
const txElevatedPayloads = await validateTransactionsOpcodes(txs);
|
|
7108
|
+
const payloads = [
|
|
7109
|
+
...txs.map(([tx]) => tx),
|
|
7110
|
+
...blockPayloads,
|
|
7111
|
+
...txElevatedPayloads,
|
|
7112
|
+
...completedStepRewardTransfers
|
|
7113
|
+
];
|
|
7114
|
+
const [bw, txPayloads] = await new BoundWitnessBuilder3().fields({
|
|
7115
|
+
block,
|
|
7116
|
+
chain: chainId,
|
|
7117
|
+
previous,
|
|
7118
|
+
step_hashes,
|
|
7119
|
+
protocol
|
|
7120
|
+
}).meta({ $epoch: Date.now(), $signatures: [] }).signers(signers).payloads(await PayloadBuilder25.addStorageMeta(payloads)).build();
|
|
7121
|
+
assertEx49(isBlockBoundWitness(bw), () => "Build of BlockBoundWitness failed");
|
|
7122
|
+
return [await PayloadBuilder25.addStorageMeta(bw), txPayloads.map((p) => asAnyPayload5(p, true))];
|
|
7123
|
+
}
|
|
7124
|
+
|
|
7125
|
+
// src/test/buildNextBlock.ts
|
|
7126
|
+
async function buildNextBlock(previousBlock, txs, blockPayloads, signers, chainStepRewardAddress2 = XYO_STEP_REWARD_ADDRESS4, stepRewardPoolBalance = AttoXL15(0n), protocol, chainId) {
|
|
7127
|
+
return await buildBlock({
|
|
7128
|
+
chainId: chainId ?? previousBlock.chain,
|
|
7129
|
+
previousBlockNumber: previousBlock.block,
|
|
7130
|
+
previousStepHashes: previousBlock.step_hashes ?? [],
|
|
7131
|
+
previousBlockHash: previousBlock._hash,
|
|
7132
|
+
txs,
|
|
7133
|
+
blockPayloads,
|
|
7134
|
+
signers,
|
|
7135
|
+
protocol,
|
|
7136
|
+
chainStepRewardAddress: chainStepRewardAddress2,
|
|
7137
|
+
stepRewardPoolBalance
|
|
7138
|
+
});
|
|
7139
|
+
}
|
|
7140
|
+
|
|
7141
|
+
// src/test/buildRandomGenesisBlock.ts
|
|
7142
|
+
import { asAddress, assertEx as assertEx50 } from "@xylabs/sdk-js";
|
|
7143
|
+
import {
|
|
7144
|
+
Account as Account3,
|
|
7145
|
+
asAnyPayload as asAnyPayload6,
|
|
7146
|
+
asSchema as asSchema10,
|
|
7147
|
+
IdSchema,
|
|
7148
|
+
PayloadBuilder as PayloadBuilder26
|
|
7149
|
+
} from "@xyo-network/sdk-js";
|
|
7150
|
+
import {
|
|
7151
|
+
asXL1BlockNumber as asXL1BlockNumber15
|
|
7152
|
+
} from "@xyo-network/xl1-protocol-lib";
|
|
7153
|
+
|
|
7154
|
+
// src/test/buildGenesisBlock.ts
|
|
7155
|
+
import { XYO_ZERO_ADDRESS as XYO_ZERO_ADDRESS3 } from "@xyo-network/xl1-protocol-lib";
|
|
7156
|
+
async function buildGenesisBlock(chainId, txs, blockPayloads, signers, chainStepRewardAddress2 = XYO_ZERO_ADDRESS3, protocol) {
|
|
7157
|
+
return await buildBlock({
|
|
7158
|
+
previousBlockHash: null,
|
|
7159
|
+
chainId,
|
|
7160
|
+
txs,
|
|
7161
|
+
blockPayloads,
|
|
7162
|
+
signers,
|
|
7163
|
+
chainStepRewardAddress: chainStepRewardAddress2,
|
|
7164
|
+
protocol
|
|
7165
|
+
});
|
|
7166
|
+
}
|
|
7167
|
+
|
|
7168
|
+
// src/test/buildRandomTransaction.ts
|
|
7169
|
+
import { Account as Account2 } from "@xyo-network/sdk-js";
|
|
7170
|
+
import { asXL1BlockNumber as asXL1BlockNumber14, isAllowedBlockPayload as isAllowedBlockPayload3 } from "@xyo-network/xl1-protocol-lib";
|
|
7171
|
+
var buildRandomTransaction = async (chain, payloads, account, nbf = asXL1BlockNumber14(0, true), exp = asXL1BlockNumber14(nbf + 1e3, true), privatePayloadSchemas = [], receiverAddress) => {
|
|
7172
|
+
const elevatedPayloads = (payloads ?? []).filter(isAllowedBlockPayload3);
|
|
7173
|
+
const additionalPayloads = (payloads ?? []).filter((payload) => !isAllowedBlockPayload3(payload));
|
|
7174
|
+
const sender = account ?? await Account2.random();
|
|
7175
|
+
if (elevatedPayloads.length === 0) {
|
|
7176
|
+
const receiver = receiverAddress ?? (await Account2.random()).address;
|
|
7177
|
+
const transferPayload = createTransferPayload(sender.address, { [receiver]: 1n });
|
|
7178
|
+
elevatedPayloads.push(transferPayload);
|
|
7179
|
+
}
|
|
7180
|
+
const hydratedTransaction = await buildTransaction(chain, elevatedPayloads, additionalPayloads, sender, nbf, exp);
|
|
7181
|
+
return [hydratedTransaction[0], hydratedTransaction[1].filter((payload) => !privatePayloadSchemas.includes(payload.schema))];
|
|
7182
|
+
};
|
|
7183
|
+
|
|
7184
|
+
// src/test/buildRandomGenesisBlock.ts
|
|
7185
|
+
var TestChainId = assertEx50(asAddress("c5fe2e6F6841Cbab12d8C0618Be2DF8C6156cC44"));
|
|
7186
|
+
|
|
7187
|
+
// src/test/createGenesisBlock.ts
|
|
7188
|
+
import { PayloadBuilder as PayloadBuilder28 } from "@xyo-network/sdk-js";
|
|
7189
|
+
import {
|
|
7190
|
+
BlockBoundWitnessSchemaPayload,
|
|
7191
|
+
BlockBoundWitnessWithStorageMetaSchemaPayload,
|
|
7192
|
+
ChainStakeIntentPayloadJsonSchemaPayload,
|
|
7193
|
+
HashPayloadJsonSchemaPayload,
|
|
7194
|
+
TransactionBoundWitnessSchemaPayload,
|
|
7195
|
+
TransactionBoundWitnessWithStorageMetaSchemaPayload,
|
|
7196
|
+
TransferPayloadJsonSchemaPayload
|
|
7197
|
+
} from "@xyo-network/xl1-schema";
|
|
7198
|
+
|
|
7199
|
+
// src/test/createProducerChainStakeIntentTransaction.ts
|
|
7200
|
+
import { PayloadBuilder as PayloadBuilder27 } from "@xyo-network/sdk-js";
|
|
7201
|
+
import {
|
|
7202
|
+
asXL1BlockNumber as asXL1BlockNumber16,
|
|
7203
|
+
ChainStakeIntentSchema as ChainStakeIntentSchema2,
|
|
7204
|
+
defaultTransactionFees as defaultTransactionFees4
|
|
7205
|
+
} from "@xyo-network/xl1-protocol-lib";
|
|
7206
|
+
async function createProducerChainStakeIntent(from, exp, nbf = 0) {
|
|
7207
|
+
return await PayloadBuilder27.addHashMeta(new PayloadBuilder27({ schema: ChainStakeIntentSchema2 }).fields({
|
|
7208
|
+
from,
|
|
7209
|
+
exp,
|
|
7210
|
+
nbf,
|
|
7211
|
+
intent: "producer"
|
|
7212
|
+
}).build());
|
|
7213
|
+
}
|
|
7214
|
+
|
|
7215
|
+
// src/test/createGenesisBlock.ts
|
|
7216
|
+
var createGenesisBlock = async (initialBlockProducer, nextContractAddress, genesisBlockRewardAmount, genesisBlockRewardAddress) => {
|
|
7217
|
+
const blockPayloads = await PayloadBuilder28.addHashMeta([
|
|
7218
|
+
TransferPayloadJsonSchemaPayload,
|
|
7219
|
+
BlockBoundWitnessSchemaPayload,
|
|
7220
|
+
BlockBoundWitnessWithStorageMetaSchemaPayload,
|
|
7221
|
+
TransactionBoundWitnessSchemaPayload,
|
|
7222
|
+
TransactionBoundWitnessWithStorageMetaSchemaPayload,
|
|
7223
|
+
ChainStakeIntentPayloadJsonSchemaPayload,
|
|
7224
|
+
HashPayloadJsonSchemaPayload
|
|
7225
|
+
]);
|
|
7226
|
+
const intentPayload = await createProducerChainStakeIntent(initialBlockProducer.address, 1, 0);
|
|
7227
|
+
blockPayloads.push(intentPayload);
|
|
7228
|
+
if (genesisBlockRewardAmount > 0n) {
|
|
7229
|
+
blockPayloads.push(await PayloadBuilder28.addHashMeta(createTransferPayload(
|
|
7230
|
+
nextContractAddress,
|
|
7231
|
+
{ [genesisBlockRewardAddress]: genesisBlockRewardAmount }
|
|
7232
|
+
)));
|
|
7233
|
+
}
|
|
7234
|
+
return await buildGenesisBlock(nextContractAddress, [], blockPayloads, [initialBlockProducer]);
|
|
7235
|
+
};
|
|
7236
|
+
|
|
7237
|
+
// src/test/buildRandomChain.ts
|
|
7238
|
+
var TestGenesisBlockRewardAddress = assertEx51(asAddress2("fa7f0bb865a4bfff3d5e2c726d3e063297014da9"));
|
|
7239
|
+
var buildRandomChain = async (blockProducer, count = 10, previousBlock, chainId, transactionAccount, receiverAddresses) => {
|
|
7240
|
+
const chainIdToUse = chainId ?? TestChainId;
|
|
7241
|
+
const blocks = [];
|
|
7242
|
+
let remaining = count;
|
|
7243
|
+
let lastBlock = previousBlock;
|
|
7244
|
+
const transactionAccountToUse = transactionAccount ?? await Account4.random();
|
|
7245
|
+
if (!lastBlock) {
|
|
7246
|
+
const block = await createGenesisBlock(
|
|
7247
|
+
blockProducer,
|
|
7248
|
+
chainIdToUse,
|
|
7249
|
+
1000000000n * 10n ** 18n,
|
|
7250
|
+
transactionAccountToUse.address
|
|
7251
|
+
);
|
|
7252
|
+
blocks.push(block);
|
|
7253
|
+
remaining = remaining - 1;
|
|
7254
|
+
lastBlock = block;
|
|
7255
|
+
}
|
|
7256
|
+
const resolvedReceiverAddresses = receiverAddresses ?? [(await Account4.random()).address];
|
|
7257
|
+
let saltCounter = 0;
|
|
7258
|
+
while (remaining > 0) {
|
|
7259
|
+
saltCounter += 1;
|
|
7260
|
+
const payloads = [new PayloadBuilder29({ schema: IdSchema2 }).fields({ salt: `${Date.now()}-${saltCounter}` }).build()];
|
|
7261
|
+
saltCounter += 1;
|
|
7262
|
+
const additionalPrivatePayloads = remaining % 2 === 0 ? [new PayloadBuilder29({ schema: asSchema11("network.xyo.private", true) }).fields({ salt: `${Date.now()}-${saltCounter}` }).build()] : [];
|
|
7263
|
+
const txs = [];
|
|
7264
|
+
for (const receiverAddress of resolvedReceiverAddresses) {
|
|
7265
|
+
txs.push(await buildRandomTransaction(
|
|
7266
|
+
chainIdToUse,
|
|
7267
|
+
[...payloads, ...additionalPrivatePayloads],
|
|
7268
|
+
transactionAccountToUse,
|
|
7269
|
+
asXL1BlockNumber17(Math.max(count - remaining - 1e3, 0), true),
|
|
7270
|
+
asXL1BlockNumber17(count - remaining + 1e3, true),
|
|
7271
|
+
[asSchema11("network.xyo.private", true)],
|
|
7272
|
+
receiverAddress
|
|
7273
|
+
));
|
|
7274
|
+
}
|
|
7275
|
+
const previousBlock2 = assertEx51(lastBlock?.[0], () => new Error("No last block"));
|
|
7276
|
+
const block = await buildNextBlock(previousBlock2, txs, [], [blockProducer], transactionAccountToUse.address);
|
|
7277
|
+
blocks.push(block);
|
|
7278
|
+
remaining = remaining - 1;
|
|
7279
|
+
lastBlock = block;
|
|
7280
|
+
}
|
|
7281
|
+
return blocks;
|
|
7282
|
+
};
|
|
7283
|
+
async function buildRandomChainArchivist(count = 20) {
|
|
7284
|
+
const producerAccount = await Account4.random();
|
|
7285
|
+
const blocks = await buildRandomChain(producerAccount, count);
|
|
7286
|
+
const archivist = await MemoryArchivist.create();
|
|
7287
|
+
const payloads = flattenHydratedBlocks(blocks);
|
|
7288
|
+
await archivist.insert(payloads);
|
|
7289
|
+
return archivist;
|
|
7290
|
+
}
|
|
7291
|
+
|
|
7292
|
+
// src/test/getSimpleBlockViewerLocator.ts
|
|
7293
|
+
import { XYO_ZERO_ADDRESS as XYO_ZERO_ADDRESS4 } from "@xyo-network/xl1-protocol-lib";
|
|
7294
|
+
|
|
7295
|
+
// src/_internal/context/getTestProviderContext.ts
|
|
7296
|
+
function getTestProviderContext(config) {
|
|
7297
|
+
const singletons = {};
|
|
7298
|
+
const caches = {};
|
|
7299
|
+
const locator = new ProviderFactoryLocator({
|
|
7300
|
+
config,
|
|
7301
|
+
singletons,
|
|
7302
|
+
caches,
|
|
7303
|
+
logger: console
|
|
7304
|
+
});
|
|
7305
|
+
return locator.context;
|
|
7306
|
+
}
|
|
7307
|
+
|
|
7308
|
+
// src/test/getSimpleBlockViewerLocator.ts
|
|
7309
|
+
async function getTestSimpleBlockViewerLocator({
|
|
7310
|
+
minWithdrawalBlocks = 10,
|
|
7311
|
+
config = ConfigZod.parse({}),
|
|
7312
|
+
finalizedArchivist: finalizedArchivistIn,
|
|
7313
|
+
rewardsContract = XYO_ZERO_ADDRESS4,
|
|
7314
|
+
stakingTokenAddress = XYO_ZERO_ADDRESS4
|
|
7315
|
+
}) {
|
|
7316
|
+
const finalizedArchivist = finalizedArchivistIn ?? await buildRandomChainArchivist();
|
|
7317
|
+
const context = getTestProviderContext(config);
|
|
7318
|
+
context.locator.registerMany([
|
|
7319
|
+
SimpleChainContractViewer.factory(SimpleChainContractViewer.dependencies, {
|
|
7320
|
+
minWithdrawalBlocks,
|
|
7321
|
+
rewardsContract,
|
|
7322
|
+
stakingTokenAddress
|
|
7323
|
+
}),
|
|
7324
|
+
SimpleFinalizationViewer.factory(SimpleFinalizationViewer.dependencies, { finalizedArchivist }),
|
|
7325
|
+
SimpleBlockViewer.factory(SimpleBlockViewer.dependencies, { finalizedArchivist })
|
|
7326
|
+
]);
|
|
7327
|
+
return context.locator;
|
|
7328
|
+
}
|
|
7329
|
+
|
|
7330
|
+
// src/test/getTestProviderContext.ts
|
|
7331
|
+
function getTestProviderContext2(config) {
|
|
7332
|
+
return getTestProviderContext(config);
|
|
7333
|
+
}
|
|
7334
|
+
|
|
6889
7335
|
// src/time/primitives/xl1BlockNumberToEthBlockNumber.ts
|
|
6890
|
-
import { assertEx as
|
|
7336
|
+
import { assertEx as assertEx52 } from "@xylabs/sdk-js";
|
|
6891
7337
|
import { asTimePayload as asTimePayload3, TimeSchema as TimeSchema2 } from "@xyo-network/xl1-protocol-lib";
|
|
6892
7338
|
async function xl1BlockNumberToEthBlockNumber(context, xl1BlockNumber) {
|
|
6893
7339
|
const blockHash = await hashFromBlockNumber(context, xl1BlockNumber);
|
|
6894
7340
|
const hydratedBlock = await hydrateBlock(context, blockHash);
|
|
6895
7341
|
const timePayload = asTimePayload3(hydratedBlock[1].find((p) => p.schema === TimeSchema2), { required: true });
|
|
6896
|
-
return
|
|
7342
|
+
return assertEx52(timePayload.ethereum, () => "No ethereum timestamp found on block");
|
|
6897
7343
|
}
|
|
6898
7344
|
|
|
6899
7345
|
// src/validation/lib/isLocalhost.ts
|
|
@@ -6911,8 +7357,8 @@ var getUrl = (host, port) => {
|
|
|
6911
7357
|
var TODO = true;
|
|
6912
7358
|
|
|
6913
7359
|
// src/validation/schema/Mnemonic.ts
|
|
6914
|
-
import { z as
|
|
6915
|
-
var MnemonicStringZod =
|
|
7360
|
+
import { z as z31 } from "zod";
|
|
7361
|
+
var MnemonicStringZod = z31.string().transform((s) => s.trim().replaceAll(/\s+/g, " ")).refine(
|
|
6916
7362
|
(s) => [12, 15, 18, 21, 24].includes(s.split(" ").length),
|
|
6917
7363
|
{ message: "Mnemonic must contain 12, 15, 18, 21, or 24 words." }
|
|
6918
7364
|
).describe("BIP-39 mnemonic string");
|
|
@@ -6933,6 +7379,9 @@ var generateXyoBaseWalletFromPhrase = (walletPhrase) => {
|
|
|
6933
7379
|
const wallet = HDWallet.fromPhrase(walletPhrase, DEFAULT_WALLET_PATH);
|
|
6934
7380
|
return wallet;
|
|
6935
7381
|
};
|
|
7382
|
+
|
|
7383
|
+
// src/index.ts
|
|
7384
|
+
export * from "@xyo-network/xl1-driver-memory";
|
|
6936
7385
|
export {
|
|
6937
7386
|
ACCOUNT_TYPE,
|
|
6938
7387
|
ADDRESS_INDEX,
|
|
@@ -6945,6 +7394,7 @@ export {
|
|
|
6945
7394
|
BalancesStepSummarySchema,
|
|
6946
7395
|
BaseConfigContextZod,
|
|
6947
7396
|
BaseConfigZod,
|
|
7397
|
+
BlocksStepSummarySchema,
|
|
6948
7398
|
BoundWitnessHydrator,
|
|
6949
7399
|
BoundWitnessWithStorageMetaZod,
|
|
6950
7400
|
CHANGE_ADDRESS,
|
|
@@ -6972,8 +7422,6 @@ export {
|
|
|
6972
7422
|
HydratedCache,
|
|
6973
7423
|
JSONSchemaMetaSchema,
|
|
6974
7424
|
LoggerStatusReporter,
|
|
6975
|
-
LruCacheMap,
|
|
6976
|
-
MemoryMap,
|
|
6977
7425
|
MemoryPermissionsStore,
|
|
6978
7426
|
MissingCapabilityError,
|
|
6979
7427
|
MnemonicStringZod,
|
|
@@ -7025,6 +7473,7 @@ export {
|
|
|
7025
7473
|
SimpleXyoSigner,
|
|
7026
7474
|
StepSummarySchema,
|
|
7027
7475
|
TODO,
|
|
7476
|
+
TestGenesisBlockRewardAddress,
|
|
7028
7477
|
TransactionBuilder,
|
|
7029
7478
|
TransfersStepSummarySchema,
|
|
7030
7479
|
TypedDataDomainZod,
|
|
@@ -7053,6 +7502,8 @@ export {
|
|
|
7053
7502
|
asBalancesStepSummary,
|
|
7054
7503
|
asBalancesStepSummaryWithStorageMeta,
|
|
7055
7504
|
asBaseConfigContext,
|
|
7505
|
+
asBlocksStepSummary,
|
|
7506
|
+
asBlocksStepSummaryWithStorageMeta,
|
|
7056
7507
|
asBoundWitnessWithStorageMeta,
|
|
7057
7508
|
asChainIndexingServiceState,
|
|
7058
7509
|
asChainIndexingServiceStateWithStorageMeta,
|
|
@@ -7077,6 +7528,12 @@ export {
|
|
|
7077
7528
|
blockPayloadsFromHydratedBlock,
|
|
7078
7529
|
blockRangeSteps,
|
|
7079
7530
|
blockRate,
|
|
7531
|
+
blocksMaxStep,
|
|
7532
|
+
blocksStepSummaryFromRange,
|
|
7533
|
+
blocksStepSummaryKey,
|
|
7534
|
+
buildRandomChain,
|
|
7535
|
+
buildRandomChainArchivist,
|
|
7536
|
+
buildRandomTransaction,
|
|
7080
7537
|
buildTransaction,
|
|
7081
7538
|
buildUnsignedTransaction,
|
|
7082
7539
|
bundledPayloadToHydratedBlock,
|
|
@@ -7115,11 +7572,14 @@ export {
|
|
|
7115
7572
|
getEmptyContext,
|
|
7116
7573
|
getEmptyProviderContext,
|
|
7117
7574
|
getProducerKey,
|
|
7575
|
+
getTestProviderContext2 as getTestProviderContext,
|
|
7576
|
+
getTestSimpleBlockViewerLocator,
|
|
7118
7577
|
getTimeConfigInMilliseconds,
|
|
7119
7578
|
getUrl,
|
|
7120
7579
|
getWindowedChain,
|
|
7121
7580
|
hasLabels,
|
|
7122
7581
|
hasMongoConfig,
|
|
7582
|
+
hasR2Config,
|
|
7123
7583
|
hashFromBlockNumber,
|
|
7124
7584
|
hydrateBlock,
|
|
7125
7585
|
hydrateElevatedTransaction,
|
|
@@ -7133,6 +7593,8 @@ export {
|
|
|
7133
7593
|
isBalancesStepSummary,
|
|
7134
7594
|
isBalancesStepSummaryWithStorageMeta,
|
|
7135
7595
|
isBaseConfigContext,
|
|
7596
|
+
isBlocksStepSummary,
|
|
7597
|
+
isBlocksStepSummaryWithStorageMeta,
|
|
7136
7598
|
isChainIndexingServiceState,
|
|
7137
7599
|
isChainIndexingServiceStateWithStorageMeta,
|
|
7138
7600
|
isCreatableProviderContext,
|