@xyo-network/xl1-protocol-sdk 2.0.9 → 2.0.11
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 +4 -4
- package/dist/neutral/block/hydrate/createBoundWitnessHydrator.d.ts +12 -12
- package/dist/neutral/block/primitives/frames/deepCalculateFramesFromRange.d.ts +7 -1
- package/dist/neutral/block/primitives/frames/deepCalculateFramesFromRange.d.ts.map +1 -1
- package/dist/neutral/config/Actor.d.ts +24 -24
- package/dist/neutral/config/Actors.d.ts +4 -4
- package/dist/neutral/config/Base.d.ts +4 -4
- package/dist/neutral/config/Chain.d.ts +1 -1
- package/dist/neutral/config/Config.d.ts +16 -16
- package/dist/neutral/config/HostActor.d.ts +24 -24
- package/dist/neutral/config/Log.d.ts +1 -1
- package/dist/neutral/config/Validation.d.ts +2 -2
- package/dist/neutral/context/Actor.d.ts +24 -24
- package/dist/neutral/context/HostActor.d.ts +24 -24
- package/dist/neutral/getFileConfig.d.ts +8 -8
- package/dist/neutral/index.d.ts +1 -1
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +377 -305
- package/dist/neutral/index.mjs.map +4 -4
- package/dist/neutral/model/CreatableProviderContext.zod.d.ts +24 -24
- package/dist/neutral/payloads/netBalancesForPayloads.d.ts +1 -1
- package/dist/neutral/payloads/netBalancesForPayloads.d.ts.map +1 -1
- package/dist/neutral/payloads/netSchemasForPayloads.d.ts +1 -1
- package/dist/neutral/payloads/netSchemasForPayloads.d.ts.map +1 -1
- package/dist/neutral/primitives/uncle/findUncles.d.ts +2 -2
- package/dist/neutral/simple/accountBalance/SimpleAccountBalanceViewer.d.ts +8 -8
- package/dist/neutral/simple/accountBalance/SimpleAccountBalanceViewer.d.ts.map +1 -1
- package/dist/neutral/simple/block/SimpleBlockViewer.d.ts +15 -4
- package/dist/neutral/simple/block/SimpleBlockViewer.d.ts.map +1 -1
- package/dist/neutral/simple/chainContractViewer/SimpleChainContractViewer.d.ts +2 -2
- package/dist/neutral/simple/finalization/SimpleFinalizationViewer.d.ts +2 -2
- package/dist/neutral/simple/mempool/SimpleMempoolRunner.d.ts.map +1 -1
- package/dist/neutral/simple/windowedBlock/SimpleWindowedBlockViewer.d.ts +43 -10
- 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/balances/balancesMaxStep.d.ts +9 -0
- package/dist/neutral/summary/primitives/balances/balancesMaxStep.d.ts.map +1 -0
- package/dist/neutral/summary/primitives/balances/balancesSummary.d.ts.map +1 -1
- package/dist/neutral/summary/primitives/balances/index.d.ts +1 -0
- package/dist/neutral/summary/primitives/balances/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/summary/primitives/schemas/index.d.ts +1 -0
- package/dist/neutral/summary/primitives/schemas/index.d.ts.map +1 -1
- package/dist/neutral/summary/primitives/schemas/schemasMaxStep.d.ts +8 -0
- package/dist/neutral/summary/primitives/schemas/schemasMaxStep.d.ts.map +1 -0
- package/dist/neutral/summary/primitives/schemas/schemasSummary.d.ts.map +1 -1
- package/dist/neutral/summary/primitives/transfers/index.d.ts +1 -0
- package/dist/neutral/summary/primitives/transfers/index.d.ts.map +1 -1
- package/dist/neutral/summary/primitives/transfers/transfersMaxStep.d.ts +10 -0
- package/dist/neutral/summary/primitives/transfers/transfersMaxStep.d.ts.map +1 -0
- package/dist/neutral/summary/primitives/transfers/transfersSummary.d.ts.map +1 -1
- package/dist/neutral/test/index.mjs +218 -135
- package/dist/neutral/test/index.mjs.map +4 -4
- package/dist/neutral/transaction/TransactionBuilder.d.ts +6 -6
- package/dist/neutral/transaction/signTransaction.d.ts +3 -3
- 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(
|
|
@@ -873,10 +794,11 @@ function calculateFramesFromRange(range, step) {
|
|
|
873
794
|
}
|
|
874
795
|
|
|
875
796
|
// src/block/primitives/frames/deepCalculateFramesFromRange.ts
|
|
876
|
-
|
|
797
|
+
import { StepSizes as StepSizes2 } from "@xyo-network/xl1-protocol-lib";
|
|
798
|
+
function deepCalculateFramesFromRange(range, startingStep = StepSizes2.length - 1) {
|
|
877
799
|
const fitted = [];
|
|
878
800
|
let remaining = [range];
|
|
879
|
-
const actualStartingStep = Math.min(startingStep,
|
|
801
|
+
const actualStartingStep = Math.min(startingStep, StepSizes2.length - 1);
|
|
880
802
|
for (let step = actualStartingStep; step >= 0; step--) {
|
|
881
803
|
const newRemaining = [];
|
|
882
804
|
for (const range2 of remaining) {
|
|
@@ -1413,11 +1335,11 @@ var RpcRemoteConfigZod = z11.union([HttpRpcRemoteConfigZod, PostMessageRpcRemote
|
|
|
1413
1335
|
var RemoteConfigZod = z11.object({ rpc: RpcRemoteConfigZod.optional() }).describe("Configuration for remote connections, including RPC");
|
|
1414
1336
|
|
|
1415
1337
|
// src/config/storage/driver/Mongo.ts
|
|
1416
|
-
import { isDefined as
|
|
1338
|
+
import { isDefined as isDefined4, isUndefined as isUndefined5 } from "@xylabs/sdk-js";
|
|
1417
1339
|
import { globalRegistry as globalRegistry8, z as z12 } from "zod";
|
|
1418
1340
|
var hasMongoConfig = (config) => {
|
|
1419
1341
|
if (isUndefined5(config)) return false;
|
|
1420
|
-
return
|
|
1342
|
+
return isDefined4(config.connectionString) && isDefined4(config.database) && isDefined4(config.domain);
|
|
1421
1343
|
};
|
|
1422
1344
|
var MongoConfigZod = z12.object({
|
|
1423
1345
|
// TODO: Create from other arguments
|
|
@@ -1502,17 +1424,17 @@ import { XyoAddressZod as XyoAddressZod2 } from "@xyo-network/address";
|
|
|
1502
1424
|
import { globalRegistry as globalRegistry11, z as z15 } from "zod";
|
|
1503
1425
|
|
|
1504
1426
|
// src/primitives/block/range/blockRangeSteps.ts
|
|
1505
|
-
import { asXL1BlockNumber as asXL1BlockNumber2, StepSizes as
|
|
1427
|
+
import { asXL1BlockNumber as asXL1BlockNumber2, StepSizes as StepSizes3 } from "@xyo-network/xl1-protocol-lib";
|
|
1506
1428
|
function blockRangeSteps(range, steps) {
|
|
1507
1429
|
const result = [];
|
|
1508
1430
|
for (const step of steps) {
|
|
1509
|
-
const
|
|
1510
|
-
const startOfFirstStepCandidate = range[0] - range[0] %
|
|
1431
|
+
const stepSize4 = StepSizes3[step];
|
|
1432
|
+
const startOfFirstStepCandidate = range[0] - range[0] % stepSize4 + stepSize4;
|
|
1511
1433
|
const startOfFirstStep = asXL1BlockNumber2(
|
|
1512
1434
|
startOfFirstStepCandidate,
|
|
1513
1435
|
{ name: "blockRangeSteps" }
|
|
1514
1436
|
);
|
|
1515
|
-
for (let block = startOfFirstStep; block <= range[1]; block = asXL1BlockNumber2(block +
|
|
1437
|
+
for (let block = startOfFirstStep; block <= range[1]; block = asXL1BlockNumber2(block + stepSize4, { name: "blockRangeSteps" })) {
|
|
1516
1438
|
result.push({ step, block });
|
|
1517
1439
|
}
|
|
1518
1440
|
}
|
|
@@ -1520,11 +1442,11 @@ function blockRangeSteps(range, steps) {
|
|
|
1520
1442
|
}
|
|
1521
1443
|
|
|
1522
1444
|
// src/primitives/block/rate/blockRate.ts
|
|
1523
|
-
import { isDefined as
|
|
1445
|
+
import { isDefined as isDefined6, isFalsy } from "@xylabs/sdk-js";
|
|
1524
1446
|
import { asXL1BlockRange } from "@xyo-network/xl1-protocol-lib";
|
|
1525
1447
|
|
|
1526
1448
|
// src/primitives/block/rate/timeHelpers.ts
|
|
1527
|
-
import { assertEx as assertEx8, isDefined as
|
|
1449
|
+
import { assertEx as assertEx8, isDefined as isDefined5 } from "@xylabs/sdk-js";
|
|
1528
1450
|
var rateMultipliers = {
|
|
1529
1451
|
millis: 1,
|
|
1530
1452
|
seconds: 1e3,
|
|
@@ -1542,7 +1464,7 @@ var timeDurations = (timeInMs) => ({
|
|
|
1542
1464
|
weeks: timeInMs / (1e3 * 60 * 60 * 24 * 7)
|
|
1543
1465
|
});
|
|
1544
1466
|
var getTimeConfigInMilliseconds = (timeConfig) => {
|
|
1545
|
-
const assertedTimeConfig = assertEx8(
|
|
1467
|
+
const assertedTimeConfig = assertEx8(isDefined5(timeConfig) ? timeConfig : void 0, () => "Time configuration must be provided");
|
|
1546
1468
|
let totalMilliseconds = 0;
|
|
1547
1469
|
if ("years" in assertedTimeConfig) {
|
|
1548
1470
|
totalMilliseconds += assertedTimeConfig.years * 31536e6;
|
|
@@ -1581,13 +1503,13 @@ var blockRate = (startBlock, endBlock, timeUnit) => {
|
|
|
1581
1503
|
throw new Error("Time difference must be greater than 0");
|
|
1582
1504
|
}
|
|
1583
1505
|
const rate = heightDifference / timeDifference;
|
|
1584
|
-
const timeUnitValue =
|
|
1585
|
-
const returnedTimeDifference =
|
|
1506
|
+
const timeUnitValue = isDefined6(timeUnit) ? timeUnit : "millis";
|
|
1507
|
+
const returnedTimeDifference = isDefined6(timeUnit) ? timeDurations(timeDifference)[timeUnit] : timeDifference;
|
|
1586
1508
|
const timePerBlock = returnedTimeDifference / heightDifference;
|
|
1587
1509
|
return {
|
|
1588
1510
|
range: asXL1BlockRange([startingBlock.block, endingBlock.block], true),
|
|
1589
1511
|
span: heightDifference,
|
|
1590
|
-
rate:
|
|
1512
|
+
rate: isDefined6(timeUnit) ? rate * rateMultipliers[timeUnit] : rate,
|
|
1591
1513
|
timeUnit: timeUnitValue,
|
|
1592
1514
|
timeDifference: returnedTimeDifference,
|
|
1593
1515
|
timePerBlock
|
|
@@ -1619,7 +1541,7 @@ import { assertEx as assertEx9 } from "@xylabs/sdk-js";
|
|
|
1619
1541
|
import {
|
|
1620
1542
|
asXL1BlockRange as asXL1BlockRange2,
|
|
1621
1543
|
isValidStep,
|
|
1622
|
-
StepSizes as
|
|
1544
|
+
StepSizes as StepSizes4
|
|
1623
1545
|
} from "@xyo-network/xl1-protocol-lib";
|
|
1624
1546
|
var stepRate = async (viewer, start, step, count = 1, timeUnit) => {
|
|
1625
1547
|
const end = start + step * count;
|
|
@@ -1628,14 +1550,14 @@ var stepRate = async (viewer, start, step, count = 1, timeUnit) => {
|
|
|
1628
1550
|
};
|
|
1629
1551
|
var calculateStepSizeRate = async (viewer, start, stepIndex, count = 1, timeUnit) => {
|
|
1630
1552
|
assertEx9(isValidStep(stepIndex), () => `Invalid step index: ${stepIndex}`);
|
|
1631
|
-
const step =
|
|
1553
|
+
const step = StepSizes4[stepIndex];
|
|
1632
1554
|
return await stepRate(viewer, start, step, count, timeUnit);
|
|
1633
1555
|
};
|
|
1634
1556
|
|
|
1635
1557
|
// src/primitives/block/rate/timeRate.ts
|
|
1636
1558
|
import {
|
|
1637
1559
|
assertEx as assertEx10,
|
|
1638
|
-
isDefined as
|
|
1560
|
+
isDefined as isDefined7,
|
|
1639
1561
|
isDefinedNotNull
|
|
1640
1562
|
} from "@xylabs/sdk-js";
|
|
1641
1563
|
import { asXL1BlockNumber as asXL1BlockNumber3, asXL1BlockRange as asXL1BlockRange3 } from "@xyo-network/xl1-protocol-lib";
|
|
@@ -1672,7 +1594,7 @@ var findEndBlockRecursive = async (viewer, startBlock, targetTimeMs, estimatedBl
|
|
|
1672
1594
|
}
|
|
1673
1595
|
const endBlock = await viewer.blockByNumber(estimatedEndBlockNumber);
|
|
1674
1596
|
const resolvedEndBlock = assertEx10(
|
|
1675
|
-
|
|
1597
|
+
isDefined7(endBlock?.[0]) ? endBlock[0] : void 0,
|
|
1676
1598
|
() => `Could not retrieve block ${estimatedEndBlockNumber} for time rate calculation`
|
|
1677
1599
|
);
|
|
1678
1600
|
const endBlockEpoch = resolvedEndBlock.$epoch;
|
|
@@ -1709,7 +1631,7 @@ var findEndBlockRecursive = async (viewer, startBlock, targetTimeMs, estimatedBl
|
|
|
1709
1631
|
// src/primitives/chain/getWindowedChain.ts
|
|
1710
1632
|
import {
|
|
1711
1633
|
assertEx as assertEx11,
|
|
1712
|
-
isDefined as
|
|
1634
|
+
isDefined as isDefined8,
|
|
1713
1635
|
isNull,
|
|
1714
1636
|
spanRootAsync
|
|
1715
1637
|
} from "@xylabs/sdk-js";
|
|
@@ -1723,7 +1645,7 @@ async function getWindowedChain(context, blockViewer, maxWindowSize, previousCha
|
|
|
1723
1645
|
while (currentBlock !== null && newChain.length < maxWindowSize) {
|
|
1724
1646
|
const currentBlockNumber = currentBlock[0].block;
|
|
1725
1647
|
const nextBlock = newChain[0];
|
|
1726
|
-
if (
|
|
1648
|
+
if (isDefined8(nextBlock)) {
|
|
1727
1649
|
const nextBlockNumber = nextBlock[0].block;
|
|
1728
1650
|
assertEx11(
|
|
1729
1651
|
currentBlockNumber === nextBlockNumber - 1,
|
|
@@ -1768,23 +1690,23 @@ function mergeTransfers(transfers) {
|
|
|
1768
1690
|
}
|
|
1769
1691
|
|
|
1770
1692
|
// src/primitives/step/stepBlockRange.ts
|
|
1771
|
-
import { asXL1BlockRange as asXL1BlockRange4, StepSizes as
|
|
1693
|
+
import { asXL1BlockRange as asXL1BlockRange4, StepSizes as StepSizes5 } from "@xyo-network/xl1-protocol-lib";
|
|
1772
1694
|
function stepBlockRange({ block, step }) {
|
|
1773
|
-
const
|
|
1774
|
-
const start = block -
|
|
1775
|
-
return asXL1BlockRange4([start, start +
|
|
1695
|
+
const stepSize4 = StepSizes5[step];
|
|
1696
|
+
const start = block - stepSize4;
|
|
1697
|
+
return asXL1BlockRange4([start, start + stepSize4 - 1], { name: "stepBlockRange" });
|
|
1776
1698
|
}
|
|
1777
1699
|
|
|
1778
1700
|
// src/primitives/step/stepTransferIndex.ts
|
|
1779
1701
|
import { assertEx as assertEx12 } from "@xylabs/sdk-js";
|
|
1780
|
-
import { StepSizes as
|
|
1702
|
+
import { StepSizes as StepSizes6 } from "@xyo-network/xl1-protocol-lib";
|
|
1781
1703
|
function stepTransferIndex(block, step) {
|
|
1782
1704
|
let rewardTransferCount = 0;
|
|
1783
1705
|
let rewardTransferIndex = -1;
|
|
1784
|
-
for (let i = 3; i <
|
|
1785
|
-
const
|
|
1786
|
-
if (block %
|
|
1787
|
-
if (
|
|
1706
|
+
for (let i = 3; i < StepSizes6.length; i++) {
|
|
1707
|
+
const stepSize4 = StepSizes6[i];
|
|
1708
|
+
if (block % stepSize4 === 0) {
|
|
1709
|
+
if (stepSize4 === StepSizes6[step]) {
|
|
1788
1710
|
rewardTransferIndex = rewardTransferCount;
|
|
1789
1711
|
}
|
|
1790
1712
|
rewardTransferCount++;
|
|
@@ -1796,9 +1718,9 @@ function stepTransferIndex(block, step) {
|
|
|
1796
1718
|
|
|
1797
1719
|
// src/primitives/chain/step/stepRewardBlock.ts
|
|
1798
1720
|
import { assertEx as assertEx13 } from "@xylabs/sdk-js";
|
|
1799
|
-
import { StepSizes as
|
|
1721
|
+
import { StepSizes as StepSizes7 } from "@xyo-network/xl1-protocol-lib";
|
|
1800
1722
|
async function stepRewardBlock(context, blockViewer, { block, step }) {
|
|
1801
|
-
assertEx13(block %
|
|
1723
|
+
assertEx13(block % StepSizes7[step] === 0, () => `Block must be the first block of the step [${StepSizes7[step]}], got ${block}`);
|
|
1802
1724
|
return assertEx13(await blockViewer.blockByNumber(block), () => `Could not find block for block number ${block}`);
|
|
1803
1725
|
}
|
|
1804
1726
|
|
|
@@ -1818,7 +1740,7 @@ async function chainStepRewardAddress(context, blockViewer, { block, step }) {
|
|
|
1818
1740
|
}
|
|
1819
1741
|
|
|
1820
1742
|
// src/primitives/chain/step/stepRewardTotal.ts
|
|
1821
|
-
import { assertEx as assertEx15, isDefined as
|
|
1743
|
+
import { assertEx as assertEx15, isDefined as isDefined9 } from "@xylabs/sdk-js";
|
|
1822
1744
|
import {
|
|
1823
1745
|
asAttoXL1,
|
|
1824
1746
|
asXL1BlockRange as asXL1BlockRange5,
|
|
@@ -1907,7 +1829,7 @@ function stepInRange(step, range) {
|
|
|
1907
1829
|
return stepRange[0] >= range[0] && stepRange[1] <= range[1];
|
|
1908
1830
|
}
|
|
1909
1831
|
async function stepRewardTotal(context, blockViewer, { block, step }, multipliers) {
|
|
1910
|
-
const cacheKey = `${block}|${step}|${
|
|
1832
|
+
const cacheKey = `${block}|${step}|${isDefined9(multipliers)}`;
|
|
1911
1833
|
return await withContextCacheResponse(context, "stepRewardTotal", cacheKey, async () => {
|
|
1912
1834
|
const [blockBw, payloads] = await stepRewardBlock(context, blockViewer, { block, step });
|
|
1913
1835
|
assertEx15(blockBw.block === block, () => `Block Mismatch: expected ${block}, got ${blockBw.block}`);
|
|
@@ -1996,7 +1918,7 @@ async function externalBlockRangeFromStep(context, blockViewer, stepIdentity) {
|
|
|
1996
1918
|
}
|
|
1997
1919
|
|
|
1998
1920
|
// src/primitives/mapToMapType.ts
|
|
1999
|
-
import { isDefined as
|
|
1921
|
+
import { isDefined as isDefined10 } from "@xylabs/sdk-js";
|
|
2000
1922
|
function mapToMapType(map) {
|
|
2001
1923
|
return {
|
|
2002
1924
|
get: (key) => map.get(key),
|
|
@@ -2015,7 +1937,7 @@ function mapToMapType(map) {
|
|
|
2015
1937
|
const result = [];
|
|
2016
1938
|
for (const key of keys) {
|
|
2017
1939
|
const value = map.get(key);
|
|
2018
|
-
if (
|
|
1940
|
+
if (isDefined10(value)) {
|
|
2019
1941
|
result.push(value);
|
|
2020
1942
|
}
|
|
2021
1943
|
}
|
|
@@ -2030,7 +1952,7 @@ function mapToMapType(map) {
|
|
|
2030
1952
|
}
|
|
2031
1953
|
|
|
2032
1954
|
// src/primitives/readPayloadMapFromStore.ts
|
|
2033
|
-
import { isDefined as
|
|
1955
|
+
import { isDefined as isDefined11 } from "@xylabs/sdk-js";
|
|
2034
1956
|
function readPayloadMapFromStore(store) {
|
|
2035
1957
|
if (isReadArchivist(store)) {
|
|
2036
1958
|
return {
|
|
@@ -2041,7 +1963,7 @@ function readPayloadMapFromStore(store) {
|
|
|
2041
1963
|
return await store.get(hashes);
|
|
2042
1964
|
},
|
|
2043
1965
|
has: async (hash) => {
|
|
2044
|
-
return
|
|
1966
|
+
return isDefined11((await store.get([hash]))[0]);
|
|
2045
1967
|
}
|
|
2046
1968
|
};
|
|
2047
1969
|
}
|
|
@@ -2057,7 +1979,7 @@ function payloadMapFromStore(store) {
|
|
|
2057
1979
|
return await store.get(hashes);
|
|
2058
1980
|
},
|
|
2059
1981
|
has: async (hash) => {
|
|
2060
|
-
return
|
|
1982
|
+
return isDefined11((await store.get([hash]))[0]);
|
|
2061
1983
|
},
|
|
2062
1984
|
clear: async () => {
|
|
2063
1985
|
return await store.clear();
|
|
@@ -2103,7 +2025,7 @@ function rewardFromBlockNumber(blockNumber) {
|
|
|
2103
2025
|
import { XYO_NETWORK_STAKING_ADDRESS } from "@xyo-network/xl1-protocol-lib";
|
|
2104
2026
|
|
|
2105
2027
|
// src/primitives/stake/activeStakeAtTimeByAddress.ts
|
|
2106
|
-
import { isDefined as
|
|
2028
|
+
import { isDefined as isDefined12 } from "@xylabs/sdk-js";
|
|
2107
2029
|
|
|
2108
2030
|
// src/primitives/stake/mergedAddRemoveStakeEventsByStaker.ts
|
|
2109
2031
|
async function mergedAddRemoveStakeEventsByStaker(chainEvents, range, staked, staker) {
|
|
@@ -2122,7 +2044,7 @@ async function activeStakeAtTimeByAddress(chain, staked, time, staker) {
|
|
|
2122
2044
|
for (const event of stakeEvents) {
|
|
2123
2045
|
if (event.time > time) break;
|
|
2124
2046
|
if (event.args.staked !== staked) continue;
|
|
2125
|
-
if (
|
|
2047
|
+
if (isDefined12(staker) && event.args.staker !== staker) continue;
|
|
2126
2048
|
if (event.name === "StakeAdded") {
|
|
2127
2049
|
result += event.args.amount;
|
|
2128
2050
|
} else if (event.name === "StakeRemoved") {
|
|
@@ -2195,13 +2117,13 @@ async function allStakersForStep(context, blockViewer, stakeEventsViewer, stepCo
|
|
|
2195
2117
|
}
|
|
2196
2118
|
|
|
2197
2119
|
// src/primitives/stake/weightedStakeForRangeByPosition.ts
|
|
2198
|
-
import { isDefined as
|
|
2120
|
+
import { isDefined as isDefined13 } from "@xylabs/sdk-js";
|
|
2199
2121
|
import { asBlockNumber as asBlockNumber2 } from "@xyo-network/xl1-protocol-lib";
|
|
2200
2122
|
async function weightedStakeForRangeByPosition(context, blockViewer, stakeEventsViewer, externalRange, staked, positionId) {
|
|
2201
|
-
const cacheKey =
|
|
2123
|
+
const cacheKey = isDefined13(positionId) ? `${externalRange[0]}-${externalRange[1]}-${positionId}` : `${externalRange[0]}-${externalRange[1]}-all`;
|
|
2202
2124
|
return await withContextCacheResponse(context, "weightedStakeForRangeByPosition", cacheKey, async () => {
|
|
2203
2125
|
let weightedStakeSum = 0n;
|
|
2204
|
-
if (
|
|
2126
|
+
if (isDefined13(positionId)) {
|
|
2205
2127
|
const mergedEvents = (await mergedAddRemoveStakeEventsByPosition(
|
|
2206
2128
|
stakeEventsViewer,
|
|
2207
2129
|
[0, externalRange[1]],
|
|
@@ -2209,7 +2131,7 @@ async function weightedStakeForRangeByPosition(context, blockViewer, stakeEvents
|
|
|
2209
2131
|
)).toSorted((a, b) => a.time - b.time);
|
|
2210
2132
|
let currentTime = externalRange[0];
|
|
2211
2133
|
let currentStake = 0n;
|
|
2212
|
-
if (
|
|
2134
|
+
if (isDefined13(staked) && mergedEvents.at(0)?.args.staked !== staked) {
|
|
2213
2135
|
return 0n;
|
|
2214
2136
|
}
|
|
2215
2137
|
for (const event of mergedEvents) {
|
|
@@ -2383,11 +2305,11 @@ function toValidUncle(_context, finalizedWindowedChain, possibleUncle) {
|
|
|
2383
2305
|
}
|
|
2384
2306
|
const allUncleTransactions = prunedPossibleUncle.flatMap((b) => b[1]).filter(isTransactionBoundWitness2);
|
|
2385
2307
|
const allFinalizedTransactions = finalizedWindowedChain.flatMap((b) => b[1]).filter(isTransactionBoundWitness2);
|
|
2386
|
-
const txPossiblyBeforeWindow = allUncleTransactions.
|
|
2308
|
+
const txPossiblyBeforeWindow = allUncleTransactions.some((tx) => tx.nbf < finalizedWindowStartBlockNumber);
|
|
2387
2309
|
if (txPossiblyBeforeWindow) {
|
|
2388
2310
|
return;
|
|
2389
2311
|
}
|
|
2390
|
-
const txExistsInWindow = allUncleTransactions.
|
|
2312
|
+
const txExistsInWindow = allUncleTransactions.some((tx) => allFinalizedTransactions.some((finalTx) => finalTx._hash === tx._hash));
|
|
2391
2313
|
if (txExistsInWindow) {
|
|
2392
2314
|
return;
|
|
2393
2315
|
}
|
|
@@ -2685,7 +2607,7 @@ async function buildUnsignedTransaction(chain, onChainPayloads, offChainPayloads
|
|
|
2685
2607
|
// src/transaction/confirmSubmittedTransaction.ts
|
|
2686
2608
|
import {
|
|
2687
2609
|
delay,
|
|
2688
|
-
isDefined as
|
|
2610
|
+
isDefined as isDefined14,
|
|
2689
2611
|
isNumber
|
|
2690
2612
|
} from "@xylabs/sdk-js";
|
|
2691
2613
|
var DEFAULT_CONFIRMATION_ATTEMPTS = 20;
|
|
@@ -2707,7 +2629,7 @@ var confirmSubmittedTransaction = async (viewer, txHash, options) => {
|
|
|
2707
2629
|
let attempts = 0;
|
|
2708
2630
|
while (true) {
|
|
2709
2631
|
const tx = await viewer.transaction.byHash(txHash) ?? void 0;
|
|
2710
|
-
if (
|
|
2632
|
+
if (isDefined14(tx)) {
|
|
2711
2633
|
options?.logger?.debug("Transaction confirmed", txHash);
|
|
2712
2634
|
return tx;
|
|
2713
2635
|
} else {
|
|
@@ -3419,13 +3341,13 @@ var asHostActorConfigContext = zodAsFactory7(HostActorConfigContext, "asHostActo
|
|
|
3419
3341
|
var toHostActorConfigContext = zodToFactory6(HostActorConfigContext, "toHostActorConfigContext");
|
|
3420
3342
|
|
|
3421
3343
|
// src/createDeclarationPayload.ts
|
|
3422
|
-
import { isDefined as
|
|
3344
|
+
import { isDefined as isDefined15 } from "@xylabs/sdk-js";
|
|
3423
3345
|
import { PayloadBuilder as PayloadBuilder13 } from "@xyo-network/sdk-js";
|
|
3424
3346
|
import {
|
|
3425
3347
|
ChainStakeIntentSchema
|
|
3426
3348
|
} from "@xyo-network/xl1-protocol-lib";
|
|
3427
3349
|
var createDeclarationIntent = (address, intent, nbf, exp) => {
|
|
3428
|
-
const expiration =
|
|
3350
|
+
const expiration = isDefined15(exp) ? exp : nbf + 1e4;
|
|
3429
3351
|
const redeclarationIntent = new PayloadBuilder13({ schema: ChainStakeIntentSchema }).fields({
|
|
3430
3352
|
from: address,
|
|
3431
3353
|
intent,
|
|
@@ -3604,21 +3526,21 @@ var toPositiveBigInt = (value) => {
|
|
|
3604
3526
|
// src/simple/accountBalance/SimpleAccountBalanceViewer.ts
|
|
3605
3527
|
import {
|
|
3606
3528
|
asHash as asHash4,
|
|
3607
|
-
assertEx as
|
|
3529
|
+
assertEx as assertEx33,
|
|
3608
3530
|
exists as exists3,
|
|
3609
|
-
isDefined as
|
|
3531
|
+
isDefined as isDefined16,
|
|
3610
3532
|
ZERO_ADDRESS
|
|
3611
3533
|
} from "@xylabs/sdk-js";
|
|
3612
3534
|
import {
|
|
3613
3535
|
AccountBalanceViewerMoniker,
|
|
3614
3536
|
asRange,
|
|
3615
|
-
asXL1BlockNumber as
|
|
3537
|
+
asXL1BlockNumber as asXL1BlockNumber8,
|
|
3616
3538
|
asXL1BlockRange as asXL1BlockRange10,
|
|
3617
3539
|
AttoXL1 as AttoXL13,
|
|
3618
3540
|
BlockViewerMoniker,
|
|
3619
3541
|
isChainQualifiedHeadConfig as isChainQualifiedHeadConfig4,
|
|
3620
3542
|
isChainQualifiedRangeConfig as isChainQualifiedRangeConfig4,
|
|
3621
|
-
StepSizes as
|
|
3543
|
+
StepSizes as StepSizes13,
|
|
3622
3544
|
TransferSchema as TransferSchema2
|
|
3623
3545
|
} from "@xyo-network/xl1-protocol-lib";
|
|
3624
3546
|
import { Semaphore } from "async-mutex";
|
|
@@ -3638,46 +3560,64 @@ var isBalancesStepSummaryWithStorageMeta = (value) => {
|
|
|
3638
3560
|
};
|
|
3639
3561
|
var asBalancesStepSummaryWithStorageMeta = AsObjectFactory5.create(isBalancesStepSummaryWithStorageMeta);
|
|
3640
3562
|
|
|
3641
|
-
// src/summary/model/
|
|
3563
|
+
// src/summary/model/BlocksStepSummary.ts
|
|
3642
3564
|
import { AsObjectFactory as AsObjectFactory6 } from "@xylabs/sdk-js";
|
|
3643
3565
|
import {
|
|
3644
3566
|
asSchema as asSchema6,
|
|
3645
3567
|
isPayloadOfSchemaType as isPayloadOfSchemaType4,
|
|
3646
3568
|
isStorageMeta as isStorageMeta3
|
|
3647
3569
|
} from "@xyo-network/sdk-js";
|
|
3648
|
-
var
|
|
3649
|
-
var
|
|
3650
|
-
var
|
|
3570
|
+
var BlocksStepSummarySchema = asSchema6("network.xyo.step.summary.blocks", true);
|
|
3571
|
+
var isBlocksStepSummary = isPayloadOfSchemaType4(BlocksStepSummarySchema);
|
|
3572
|
+
var asBlocksStepSummary = AsObjectFactory6.create(isBlocksStepSummary);
|
|
3573
|
+
var isBlocksStepSummaryWithStorageMeta = (value) => {
|
|
3574
|
+
return isBlocksStepSummary(value) && isStorageMeta3(value);
|
|
3575
|
+
};
|
|
3576
|
+
var asBlocksStepSummaryWithStorageMeta = AsObjectFactory6.create(isBlocksStepSummaryWithStorageMeta);
|
|
3577
|
+
|
|
3578
|
+
// src/summary/model/SchemasStepSummary.ts
|
|
3579
|
+
import { AsObjectFactory as AsObjectFactory7 } from "@xylabs/sdk-js";
|
|
3580
|
+
import {
|
|
3581
|
+
asSchema as asSchema7,
|
|
3582
|
+
isPayloadOfSchemaType as isPayloadOfSchemaType5,
|
|
3583
|
+
isStorageMeta as isStorageMeta4
|
|
3584
|
+
} from "@xyo-network/sdk-js";
|
|
3585
|
+
var SchemasStepSummarySchema = asSchema7("network.xyo.step.summary.schemas", true);
|
|
3586
|
+
var isSchemasStepSummary = isPayloadOfSchemaType5(SchemasStepSummarySchema);
|
|
3587
|
+
var asSchemasStepSummary = AsObjectFactory7.create(isSchemasStepSummary);
|
|
3651
3588
|
var isSchemasStepSummaryWithStorageMeta = (value) => {
|
|
3652
|
-
return isSchemasStepSummary(value) &&
|
|
3589
|
+
return isSchemasStepSummary(value) && isStorageMeta4(value);
|
|
3653
3590
|
};
|
|
3654
|
-
var asSchemasStepSummaryWithStorageMeta =
|
|
3591
|
+
var asSchemasStepSummaryWithStorageMeta = AsObjectFactory7.create(isSchemasStepSummaryWithStorageMeta);
|
|
3655
3592
|
|
|
3656
3593
|
// src/summary/model/StepSummary.ts
|
|
3657
3594
|
import {
|
|
3658
|
-
asSchema as
|
|
3595
|
+
asSchema as asSchema8
|
|
3659
3596
|
} from "@xyo-network/sdk-js";
|
|
3660
|
-
var StepSummarySchema =
|
|
3597
|
+
var StepSummarySchema = asSchema8("network.xyo.step.summary", true);
|
|
3661
3598
|
|
|
3662
3599
|
// src/summary/model/TransfersSummary.ts
|
|
3663
|
-
import { AsObjectFactory as
|
|
3600
|
+
import { AsObjectFactory as AsObjectFactory8 } from "@xylabs/sdk-js";
|
|
3664
3601
|
import {
|
|
3665
|
-
asSchema as
|
|
3666
|
-
isPayloadOfSchemaType as
|
|
3667
|
-
isStorageMeta as
|
|
3602
|
+
asSchema as asSchema9,
|
|
3603
|
+
isPayloadOfSchemaType as isPayloadOfSchemaType6,
|
|
3604
|
+
isStorageMeta as isStorageMeta5
|
|
3668
3605
|
} from "@xyo-network/sdk-js";
|
|
3669
|
-
var TransfersStepSummarySchema =
|
|
3670
|
-
var isTransfersStepSummary =
|
|
3671
|
-
var asTransfersStepSummary =
|
|
3606
|
+
var TransfersStepSummarySchema = asSchema9("network.xyo.step.summary.transfer", true);
|
|
3607
|
+
var isTransfersStepSummary = isPayloadOfSchemaType6(TransfersStepSummarySchema);
|
|
3608
|
+
var asTransfersStepSummary = AsObjectFactory8.create(isTransfersStepSummary);
|
|
3672
3609
|
var isTransfersStepSummaryWithStorageMeta = (value) => {
|
|
3673
|
-
return isTransfersStepSummary(value) &&
|
|
3610
|
+
return isTransfersStepSummary(value) && isStorageMeta5(value);
|
|
3674
3611
|
};
|
|
3675
|
-
var asTransfersStepSummaryWithStorageMeta =
|
|
3612
|
+
var asTransfersStepSummaryWithStorageMeta = AsObjectFactory8.create(isTransfersStepSummaryWithStorageMeta);
|
|
3613
|
+
|
|
3614
|
+
// src/summary/primitives/balances/balancesMaxStep.ts
|
|
3615
|
+
var balancesMaxStep = 5;
|
|
3676
3616
|
|
|
3677
3617
|
// src/summary/primitives/balances/balancesStepSummaryFromRange.ts
|
|
3678
3618
|
import { assertEx as assertEx26, spanRootAsync as spanRootAsync2 } from "@xylabs/sdk-js";
|
|
3679
3619
|
import { isAnyPayload as isAnyPayload3 } from "@xyo-network/sdk-js";
|
|
3680
|
-
import { asXL1BlockNumber as asXL1BlockNumber5, StepSizes as
|
|
3620
|
+
import { asXL1BlockNumber as asXL1BlockNumber5, StepSizes as StepSizes8 } from "@xyo-network/xl1-protocol-lib";
|
|
3681
3621
|
async function balancesStepSummaryFromRange(context, semaphores, blockViewer, summaryMap, range) {
|
|
3682
3622
|
const cacheKey = `${range[0]}|${range[1]}`;
|
|
3683
3623
|
return await withContextCacheResponse(context, "balancesStepSummaryFromRange", cacheKey, async () => {
|
|
@@ -3698,8 +3638,8 @@ async function balancesStepSummaryFromRange(context, semaphores, blockViewer, su
|
|
|
3698
3638
|
balances
|
|
3699
3639
|
};
|
|
3700
3640
|
}, { ...context, timeBudgetLimit: 500 }) : await spanRootAsync2(`balancesStepSummaryFromRange.frameSize>1[${key}]`, async () => {
|
|
3701
|
-
const step =
|
|
3702
|
-
assertEx26(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${
|
|
3641
|
+
const step = StepSizes8.indexOf(asXL1BlockNumber5(frameSize, true));
|
|
3642
|
+
assertEx26(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes8.join(", ")}`);
|
|
3703
3643
|
const summaryResult = await summaryMap.get(`${frameHead._hash}|${frameSize}`);
|
|
3704
3644
|
if (isAnyPayload3(summaryResult)) {
|
|
3705
3645
|
return summaryResult;
|
|
@@ -3760,7 +3700,7 @@ async function balancesSummary(context, semaphores, blockViewer, summaryMap, con
|
|
|
3760
3700
|
const ranges = deepCalculateFramesFromRange(asXL1BlockRange7(
|
|
3761
3701
|
range,
|
|
3762
3702
|
{ name: "balancesSummary" }
|
|
3763
|
-
));
|
|
3703
|
+
), balancesMaxStep);
|
|
3764
3704
|
const summaries = await Promise.all(ranges.map((range2) => balancesStepSummaryFromRange(context, semaphores, blockViewer, summaryMap, range2)));
|
|
3765
3705
|
const balances = {};
|
|
3766
3706
|
for (const summary of summaries) {
|
|
@@ -3773,21 +3713,89 @@ async function balancesSummary(context, semaphores, blockViewer, summaryMap, con
|
|
|
3773
3713
|
}, { ...context, timeBudgetLimit: 500 });
|
|
3774
3714
|
}
|
|
3775
3715
|
|
|
3716
|
+
// src/summary/primitives/blocks/blocksMaxStep.ts
|
|
3717
|
+
var blocksMaxStep = 3;
|
|
3718
|
+
|
|
3719
|
+
// src/summary/primitives/blocks/blocksStepSummaryFromRange.ts
|
|
3720
|
+
import { assertEx as assertEx28, spanRootAsync as spanRootAsync4 } from "@xylabs/sdk-js";
|
|
3721
|
+
import { isAnyPayload as isAnyPayload4 } from "@xyo-network/sdk-js";
|
|
3722
|
+
import { asXL1BlockNumber as asXL1BlockNumber6, StepSizes as StepSizes9 } from "@xyo-network/xl1-protocol-lib";
|
|
3723
|
+
function blocksStepSummaryKey(frameHeadHash, frameSize) {
|
|
3724
|
+
return `${frameHeadHash}|${frameSize}`;
|
|
3725
|
+
}
|
|
3726
|
+
async function blocksStepSummaryFromRange(context, semaphores, blockViewer, summaryMap, range) {
|
|
3727
|
+
const cacheKey = `${range[0]}|${range[1]}`;
|
|
3728
|
+
return await withContextCacheResponse(context, "blocksStepSummaryFromRange", cacheKey, async () => {
|
|
3729
|
+
return await spanRootAsync4("blocksStepSummaryFromRange", async () => {
|
|
3730
|
+
const frameHead = assertEx28(
|
|
3731
|
+
await blockViewer.blockByNumber(range[1]),
|
|
3732
|
+
() => `Block not found for number: ${range[1]}`
|
|
3733
|
+
);
|
|
3734
|
+
const frameHeadHash = frameHead[0]._hash;
|
|
3735
|
+
const frameSize = range[1] - range[0] + 1;
|
|
3736
|
+
let result;
|
|
3737
|
+
if (frameSize === 1) {
|
|
3738
|
+
result = {
|
|
3739
|
+
schema: BlocksStepSummarySchema,
|
|
3740
|
+
hash: frameHeadHash,
|
|
3741
|
+
stepSize: -1,
|
|
3742
|
+
blocks: [frameHead]
|
|
3743
|
+
};
|
|
3744
|
+
} else {
|
|
3745
|
+
const step = StepSizes9.indexOf(asXL1BlockNumber6(frameSize, true));
|
|
3746
|
+
assertEx28(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes9.join(", ")}`);
|
|
3747
|
+
const key = blocksStepSummaryKey(frameHeadHash, frameSize);
|
|
3748
|
+
const summaryResult = await summaryMap.get(key);
|
|
3749
|
+
if (isAnyPayload4(summaryResult)) {
|
|
3750
|
+
result = asBlocksStepSummary(summaryResult, { required: true });
|
|
3751
|
+
} else {
|
|
3752
|
+
await semaphores[step].acquire();
|
|
3753
|
+
try {
|
|
3754
|
+
const subRanges = deepCalculateFramesFromRange(range, step - 1);
|
|
3755
|
+
const subResults = await Promise.all(subRanges.map((subRange) => blocksStepSummaryFromRange(
|
|
3756
|
+
context,
|
|
3757
|
+
semaphores,
|
|
3758
|
+
blockViewer,
|
|
3759
|
+
summaryMap,
|
|
3760
|
+
subRange
|
|
3761
|
+
)));
|
|
3762
|
+
const blocks = subResults.flatMap((subResult) => subResult.blocks);
|
|
3763
|
+
result = {
|
|
3764
|
+
schema: BlocksStepSummarySchema,
|
|
3765
|
+
hash: frameHeadHash,
|
|
3766
|
+
stepSize: frameSize,
|
|
3767
|
+
blocks
|
|
3768
|
+
};
|
|
3769
|
+
await summaryMap.set(key, result);
|
|
3770
|
+
} finally {
|
|
3771
|
+
semaphores[step].release();
|
|
3772
|
+
}
|
|
3773
|
+
}
|
|
3774
|
+
}
|
|
3775
|
+
return result;
|
|
3776
|
+
}, { ...context, timeBudgetLimit: 500 });
|
|
3777
|
+
}, { max: 1e5 });
|
|
3778
|
+
}
|
|
3779
|
+
|
|
3780
|
+
// src/summary/primitives/schemas/schemasMaxStep.ts
|
|
3781
|
+
import { StepSizes as StepSizes10 } from "@xyo-network/xl1-protocol-lib";
|
|
3782
|
+
var schemasMaxStep = StepSizes10.length - 1;
|
|
3783
|
+
|
|
3776
3784
|
// src/summary/primitives/schemas/schemasStepSummaryFromRange.ts
|
|
3777
|
-
import { assertEx as
|
|
3785
|
+
import { assertEx as assertEx29 } from "@xylabs/sdk-js";
|
|
3778
3786
|
import {
|
|
3779
|
-
isAnyPayload as
|
|
3787
|
+
isAnyPayload as isAnyPayload5,
|
|
3780
3788
|
isBoundWitness as isBoundWitness2,
|
|
3781
3789
|
isHashMeta,
|
|
3782
3790
|
PayloadBuilder as PayloadBuilder17
|
|
3783
3791
|
} from "@xyo-network/sdk-js";
|
|
3784
|
-
import { StepSizes as
|
|
3792
|
+
import { StepSizes as StepSizes11 } from "@xyo-network/xl1-protocol-lib";
|
|
3785
3793
|
async function schemasStepSummaryFromRange(context, semaphores, blockViewer, summaryMap, range) {
|
|
3786
|
-
const [frameHead] =
|
|
3794
|
+
const [frameHead] = assertEx29(await blockViewer.blockByNumber(range[1]), () => `Block not found for number: ${range[1]}`);
|
|
3787
3795
|
const frameSize = range[1] - range[0] + 1;
|
|
3788
3796
|
let result;
|
|
3789
3797
|
if (frameSize === 1) {
|
|
3790
|
-
const [block, payloads] =
|
|
3798
|
+
const [block, payloads] = assertEx29(await blockViewer.blockByNumber(range[0]), () => `Block not found for number: ${range[0]}`);
|
|
3791
3799
|
const boundWitnesses = [block, ...payloads.filter((x) => isBoundWitness2(x) && isHashMeta(x))];
|
|
3792
3800
|
const schemas = {};
|
|
3793
3801
|
for (const bw of boundWitnesses) {
|
|
@@ -3803,10 +3811,10 @@ async function schemasStepSummaryFromRange(context, semaphores, blockViewer, sum
|
|
|
3803
3811
|
schemas
|
|
3804
3812
|
});
|
|
3805
3813
|
} else {
|
|
3806
|
-
const step =
|
|
3807
|
-
|
|
3814
|
+
const step = StepSizes11.indexOf(frameSize);
|
|
3815
|
+
assertEx29(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes11.join(", ")}`);
|
|
3808
3816
|
const summaryResult = await summaryMap.get(`${frameHead._hash}|${frameSize}`);
|
|
3809
|
-
if (
|
|
3817
|
+
if (isAnyPayload5(summaryResult)) {
|
|
3810
3818
|
result = summaryResult;
|
|
3811
3819
|
} else {
|
|
3812
3820
|
await semaphores[step].acquire();
|
|
@@ -3843,7 +3851,7 @@ async function schemasStepSummaryFromRange(context, semaphores, blockViewer, sum
|
|
|
3843
3851
|
}
|
|
3844
3852
|
|
|
3845
3853
|
// src/summary/primitives/schemas/schemasSummary.ts
|
|
3846
|
-
import { assertEx as
|
|
3854
|
+
import { assertEx as assertEx30, spanRootAsync as spanRootAsync5 } from "@xylabs/sdk-js";
|
|
3847
3855
|
import {
|
|
3848
3856
|
asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta4,
|
|
3849
3857
|
asXL1BlockRange as asXL1BlockRange8,
|
|
@@ -3851,15 +3859,15 @@ import {
|
|
|
3851
3859
|
isChainQualifiedRangeConfig as isChainQualifiedRangeConfig2
|
|
3852
3860
|
} from "@xyo-network/xl1-protocol-lib";
|
|
3853
3861
|
async function schemasSummary(context, semaphores, blockViewer, summaryMap, config) {
|
|
3854
|
-
return await
|
|
3862
|
+
return await spanRootAsync5("schemasSummary", async () => {
|
|
3855
3863
|
const headHash = isChainQualifiedHeadConfig2(config) ? config.head : await blockViewer.currentBlockHash();
|
|
3856
|
-
const [head] =
|
|
3864
|
+
const [head] = assertEx30(await blockViewer.blockByHash(headHash), () => `Block not found for hash: ${headHash}`);
|
|
3857
3865
|
const headBoundWitness = asBlockBoundWitnessWithStorageMeta4(head, () => `Found Block not a BlockWithHashMeta: ${headHash}`);
|
|
3858
3866
|
const range = isChainQualifiedRangeConfig2(config) ? config.range : asXL1BlockRange8([0, headBoundWitness.block], true);
|
|
3859
3867
|
const ranges = deepCalculateFramesFromRange(asXL1BlockRange8(
|
|
3860
3868
|
range,
|
|
3861
3869
|
{ name: "schemasSummary" }
|
|
3862
|
-
));
|
|
3870
|
+
), schemasMaxStep);
|
|
3863
3871
|
const summaries = await Promise.all(ranges.map((range2) => schemasStepSummaryFromRange(context, semaphores, blockViewer, summaryMap, range2)));
|
|
3864
3872
|
const results = {};
|
|
3865
3873
|
for (const summary of summaries) {
|
|
@@ -3872,22 +3880,25 @@ async function schemasSummary(context, semaphores, blockViewer, summaryMap, conf
|
|
|
3872
3880
|
}, context);
|
|
3873
3881
|
}
|
|
3874
3882
|
|
|
3883
|
+
// src/summary/primitives/transfers/transfersMaxStep.ts
|
|
3884
|
+
var transfersMaxStep = 4;
|
|
3885
|
+
|
|
3875
3886
|
// src/summary/primitives/transfers/transfersStepSummaryFromRange.ts
|
|
3876
|
-
import { assertEx as
|
|
3877
|
-
import { isAnyPayload as
|
|
3878
|
-
import { asXL1BlockNumber as
|
|
3887
|
+
import { assertEx as assertEx31, spanRootAsync as spanRootAsync6 } from "@xylabs/sdk-js";
|
|
3888
|
+
import { isAnyPayload as isAnyPayload6 } from "@xyo-network/sdk-js";
|
|
3889
|
+
import { asXL1BlockNumber as asXL1BlockNumber7, StepSizes as StepSizes12 } from "@xyo-network/xl1-protocol-lib";
|
|
3879
3890
|
function transfersSummaryKey(frameHeadHash, frameSize) {
|
|
3880
3891
|
return `${frameHeadHash}|${frameSize}`;
|
|
3881
3892
|
}
|
|
3882
3893
|
async function transfersStepSummaryFromRange(context, semaphores, blockViewer, summaryMap, range) {
|
|
3883
3894
|
const cacheKey = `${range[0]}|${range[1]}`;
|
|
3884
3895
|
return await withContextCacheResponse(context, "transfersStepSummaryFromRange", cacheKey, async () => {
|
|
3885
|
-
return await
|
|
3886
|
-
const [frameHead] =
|
|
3896
|
+
return await spanRootAsync6("transfersStepSummaryFromRange", async () => {
|
|
3897
|
+
const [frameHead] = assertEx31(await blockViewer.blockByNumber(range[1]), () => `Block not found for number: ${range[1]}`);
|
|
3887
3898
|
const frameSize = range[1] - range[0] + 1;
|
|
3888
3899
|
let result;
|
|
3889
3900
|
if (frameSize === 1) {
|
|
3890
|
-
const [, payloads] =
|
|
3901
|
+
const [, payloads] = assertEx31(await blockViewer.blockByNumber(range[0]), () => `Block not found for number: ${range[0]}`);
|
|
3891
3902
|
const transfers = {};
|
|
3892
3903
|
for (const [from, toMap] of Object.entries(netTransfersForPayloads(context, payloads))) {
|
|
3893
3904
|
transfers[from] = transfers[from] ?? {};
|
|
@@ -3902,11 +3913,11 @@ async function transfersStepSummaryFromRange(context, semaphores, blockViewer, s
|
|
|
3902
3913
|
transfers
|
|
3903
3914
|
};
|
|
3904
3915
|
} else {
|
|
3905
|
-
const step =
|
|
3906
|
-
|
|
3916
|
+
const step = StepSizes12.indexOf(asXL1BlockNumber7(frameSize, true));
|
|
3917
|
+
assertEx31(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes12.join(", ")}`);
|
|
3907
3918
|
const key = transfersSummaryKey(frameHead._hash, frameSize);
|
|
3908
3919
|
const summaryResult = await summaryMap.get(key);
|
|
3909
|
-
if (
|
|
3920
|
+
if (isAnyPayload6(summaryResult)) {
|
|
3910
3921
|
result = asTransfersStepSummary(summaryResult, { required: true });
|
|
3911
3922
|
} else {
|
|
3912
3923
|
await semaphores[step].acquire();
|
|
@@ -3954,7 +3965,7 @@ async function transfersStepSummaryFromRange(context, semaphores, blockViewer, s
|
|
|
3954
3965
|
}
|
|
3955
3966
|
|
|
3956
3967
|
// src/summary/primitives/transfers/transfersSummary.ts
|
|
3957
|
-
import { assertEx as
|
|
3968
|
+
import { assertEx as assertEx32, spanRootAsync as spanRootAsync7 } from "@xylabs/sdk-js";
|
|
3958
3969
|
import { asXyoAddress as asXyoAddress2 } from "@xyo-network/address";
|
|
3959
3970
|
import {
|
|
3960
3971
|
asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta5,
|
|
@@ -3963,15 +3974,15 @@ import {
|
|
|
3963
3974
|
isChainQualifiedRangeConfig as isChainQualifiedRangeConfig3
|
|
3964
3975
|
} from "@xyo-network/xl1-protocol-lib";
|
|
3965
3976
|
async function transfersSummary(context, semaphores, blockViewer, summaryMap, config) {
|
|
3966
|
-
return await
|
|
3977
|
+
return await spanRootAsync7("transferSummary", async () => {
|
|
3967
3978
|
const headHash = isChainQualifiedHeadConfig3(config) ? config.head : await blockViewer.currentBlockHash();
|
|
3968
|
-
const [head] =
|
|
3979
|
+
const [head] = assertEx32(await blockViewer.blockByHash(headHash), () => `Block not found for hash: ${headHash}`);
|
|
3969
3980
|
const headBoundWitness = asBlockBoundWitnessWithStorageMeta5(head, () => `Found Block not a BlockWithHashMeta: ${headHash}`);
|
|
3970
3981
|
const range = isChainQualifiedRangeConfig3(config) ? config.range : asXL1BlockRange9([0, headBoundWitness.block], true);
|
|
3971
3982
|
const ranges = deepCalculateFramesFromRange(asXL1BlockRange9(
|
|
3972
3983
|
range,
|
|
3973
3984
|
{ name: "transfersSummary" }
|
|
3974
|
-
));
|
|
3985
|
+
), transfersMaxStep);
|
|
3975
3986
|
const summaries = await Promise.all(ranges.map((range2) => transfersStepSummaryFromRange(context, semaphores, blockViewer, summaryMap, range2)));
|
|
3976
3987
|
const transfers = {};
|
|
3977
3988
|
for (const summary of summaries) {
|
|
@@ -3991,9 +4002,9 @@ async function transfersSummary(context, semaphores, blockViewer, summaryMap, co
|
|
|
3991
4002
|
// src/simple/accountBalance/SimpleAccountBalanceViewer.ts
|
|
3992
4003
|
var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
3993
4004
|
moniker = SimpleAccountBalanceViewer.defaultMoniker;
|
|
3994
|
-
_balanceStepSemaphores =
|
|
4005
|
+
_balanceStepSemaphores = StepSizes13.map(() => new Semaphore(20));
|
|
3995
4006
|
_blockViewer;
|
|
3996
|
-
_transferStepSemaphores =
|
|
4007
|
+
_transferStepSemaphores = StepSizes13.map(() => new Semaphore(20));
|
|
3997
4008
|
get balancesSummaryMap() {
|
|
3998
4009
|
return this.params.balancesSummaryMap;
|
|
3999
4010
|
}
|
|
@@ -4006,8 +4017,8 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
4006
4017
|
static async paramsHandler(params = {}) {
|
|
4007
4018
|
return {
|
|
4008
4019
|
...await super.paramsHandler(params),
|
|
4009
|
-
balancesSummaryMap:
|
|
4010
|
-
transfersSummaryMap:
|
|
4020
|
+
balancesSummaryMap: assertEx33(params.balancesSummaryMap, () => "balancesSummaryMap is required"),
|
|
4021
|
+
transfersSummaryMap: assertEx33(params.transfersSummaryMap, () => "transfersSummaryMap is required")
|
|
4011
4022
|
};
|
|
4012
4023
|
}
|
|
4013
4024
|
async accountBalance(address, config) {
|
|
@@ -4028,11 +4039,11 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
4028
4039
|
const transferIndexes = block[0].payload_schemas.map((schema, index) => schema === TransferSchema2 ? index : void 0).filter(exists3);
|
|
4029
4040
|
const transfers = transferIndexes.map((index) => {
|
|
4030
4041
|
const hash = block[0].payload_hashes[index];
|
|
4031
|
-
return
|
|
4042
|
+
return assertEx33(
|
|
4032
4043
|
block[1].find((p) => p._hash === hash),
|
|
4033
4044
|
() => `Error: Could not find Transfer with hash ${hash} in block ${block[0]._hash}`
|
|
4034
4045
|
);
|
|
4035
|
-
}).filter(exists3).filter((t) => t.from === address ||
|
|
4046
|
+
}).filter(exists3).filter((t) => t.from === address || isDefined16(t.transfers[address]));
|
|
4036
4047
|
if (transfers.length === 0) {
|
|
4037
4048
|
continue;
|
|
4038
4049
|
}
|
|
@@ -4061,7 +4072,7 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
4061
4072
|
const head = isChainQualifiedHeadConfig4(config) ? config.head : await this.blockViewer.currentBlockHash();
|
|
4062
4073
|
const range = isChainQualifiedRangeConfig4(config) ? config.range : asXL1BlockRange10([
|
|
4063
4074
|
0,
|
|
4064
|
-
|
|
4075
|
+
assertEx33(
|
|
4065
4076
|
await this.blockViewer.blockByHash(head),
|
|
4066
4077
|
() => `Error: Could not find block with hash ${head}`
|
|
4067
4078
|
)[0].block
|
|
@@ -4076,11 +4087,11 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
4076
4087
|
const qualifiedRange = qualifiedEntries[0][1][1].range;
|
|
4077
4088
|
const qualifiedHeadHash = qualifiedEntries[0][1][1].head;
|
|
4078
4089
|
for (const [_, [__, { range: range2, head: head2 }]] of qualifiedEntries) {
|
|
4079
|
-
|
|
4090
|
+
assertEx33(
|
|
4080
4091
|
range2[0] === qualifiedRange[0] && range2[1] === qualifiedRange[1],
|
|
4081
4092
|
() => "Inconsistent ranges in qualifiedAccountBalanceHistories"
|
|
4082
4093
|
);
|
|
4083
|
-
|
|
4094
|
+
assertEx33(
|
|
4084
4095
|
head2 === qualifiedHeadHash,
|
|
4085
4096
|
() => "Inconsistent head hashes in qualifiedAccountBalanceHistories"
|
|
4086
4097
|
);
|
|
@@ -4114,10 +4125,10 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
4114
4125
|
}
|
|
4115
4126
|
async distillTransferHistory(address, range, max = 50) {
|
|
4116
4127
|
return await this.spanAsync("distillTransferHistory", async () => {
|
|
4117
|
-
if (range[1] - range[0] <=
|
|
4118
|
-
return Array.from({ length: range[1] - range[0] + 1 }, (_, i) => range[1] - i).slice(0, max).map((n) =>
|
|
4128
|
+
if (range[1] - range[0] <= StepSizes13[0] || max <= 1) {
|
|
4129
|
+
return Array.from({ length: range[1] - range[0] + 1 }, (_, i) => range[1] - i).slice(0, max).map((n) => asXL1BlockNumber8(n, true));
|
|
4119
4130
|
}
|
|
4120
|
-
const frames = deepCalculateFramesFromRange(asXL1BlockRange10(range, true));
|
|
4131
|
+
const frames = deepCalculateFramesFromRange(asXL1BlockRange10(range, true), transfersMaxStep);
|
|
4121
4132
|
const transferSummaryPairs = await Promise.all(frames.map(
|
|
4122
4133
|
async (frame) => {
|
|
4123
4134
|
return [frame, await transfersStepSummaryFromRange(this.context, this._transferStepSemaphores, this.blockViewer, this.transfersSummaryMap, frame)];
|
|
@@ -4129,7 +4140,7 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
4129
4140
|
});
|
|
4130
4141
|
const resultBlockNumbers = /* @__PURE__ */ new Set();
|
|
4131
4142
|
for (const [frame] of sortedTransferSummaryPairs) {
|
|
4132
|
-
if (frame[1] - frame[0] + 1 >
|
|
4143
|
+
if (frame[1] - frame[0] + 1 > StepSizes13[0]) {
|
|
4133
4144
|
const values = await this.distillTransferHistory(address, asXL1BlockRange10([frame[0], frame[1] - 1], true), max - resultBlockNumbers.size);
|
|
4134
4145
|
for (const value of values) {
|
|
4135
4146
|
resultBlockNumbers.add(value);
|
|
@@ -4151,7 +4162,7 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
4151
4162
|
return await this.spanAsync("qualifiedAccountBalanceHistory", async () => {
|
|
4152
4163
|
const range = asRange(headOrRange);
|
|
4153
4164
|
const headHash = asHash4(headOrRange);
|
|
4154
|
-
const [head] =
|
|
4165
|
+
const [head] = assertEx33(isDefined16(headHash) ? await this.blockViewer.blockByHash(headHash) : await this.blockViewer.currentBlock(), () => "Could not resolve head block");
|
|
4155
4166
|
const startingRange = asXL1BlockRange10(range ?? [0, head.block], true);
|
|
4156
4167
|
const blockNumbers = await this.distillTransferHistory(address, startingRange);
|
|
4157
4168
|
const blocks = (await Promise.all(blockNumbers.map(async (bn) => await this.blockViewer.blockByNumber(bn)))).filter(exists3);
|
|
@@ -4160,11 +4171,11 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
4160
4171
|
const transferIndexes = block[0].payload_schemas.map((schema, index) => schema === TransferSchema2 ? index : void 0).filter(exists3);
|
|
4161
4172
|
const transfers = transferIndexes.map((index) => {
|
|
4162
4173
|
const hash = block[0].payload_hashes[index];
|
|
4163
|
-
return
|
|
4174
|
+
return assertEx33(
|
|
4164
4175
|
block[1].find((p) => p._hash === hash),
|
|
4165
4176
|
() => `Error: Could not find Transfer with hash ${hash} in block ${block[0]._hash}`
|
|
4166
4177
|
);
|
|
4167
|
-
}).filter(exists3).filter((t) => t.from === address ||
|
|
4178
|
+
}).filter(exists3).filter((t) => t.from === address || isDefined16(t.transfers[address]));
|
|
4168
4179
|
if (transfers.length === 0) {
|
|
4169
4180
|
continue;
|
|
4170
4181
|
}
|
|
@@ -4190,20 +4201,25 @@ SimpleAccountBalanceViewer = __decorateClass([
|
|
|
4190
4201
|
|
|
4191
4202
|
// src/simple/block/SimpleBlockViewer.ts
|
|
4192
4203
|
import {
|
|
4193
|
-
assertEx as
|
|
4204
|
+
assertEx as assertEx34,
|
|
4194
4205
|
exists as exists4,
|
|
4195
4206
|
isUndefined as isUndefined8
|
|
4196
4207
|
} from "@xylabs/sdk-js";
|
|
4208
|
+
import { LruCacheMap as LruCacheMap2 } from "@xyo-network/xl1-driver-memory";
|
|
4197
4209
|
import {
|
|
4198
4210
|
asSignedHydratedBlockWithHashMeta,
|
|
4199
4211
|
asSignedHydratedBlockWithStorageMeta,
|
|
4200
|
-
asXL1BlockNumber as
|
|
4212
|
+
asXL1BlockNumber as asXL1BlockNumber9,
|
|
4213
|
+
asXL1BlockRange as asXL1BlockRange11,
|
|
4201
4214
|
BlockViewerMoniker as BlockViewerMoniker2,
|
|
4202
|
-
FinalizationViewerMoniker
|
|
4215
|
+
FinalizationViewerMoniker,
|
|
4216
|
+
stepSize as stepSize2,
|
|
4217
|
+
StepSizes as StepSizes14
|
|
4203
4218
|
} from "@xyo-network/xl1-protocol-lib";
|
|
4219
|
+
import { Semaphore as Semaphore2 } from "async-mutex";
|
|
4204
4220
|
|
|
4205
4221
|
// src/utils/HydratedCache.ts
|
|
4206
|
-
import { LRUCache as
|
|
4222
|
+
import { LRUCache as LRUCache2 } from "lru-cache";
|
|
4207
4223
|
var HydratedCache = class {
|
|
4208
4224
|
cache;
|
|
4209
4225
|
context;
|
|
@@ -4211,7 +4227,7 @@ var HydratedCache = class {
|
|
|
4211
4227
|
constructor(context, hydrateFunction, maxCount = 2e3, ttl = Number.MAX_SAFE_INTEGER) {
|
|
4212
4228
|
this.context = context;
|
|
4213
4229
|
this.hydrateFunction = hydrateFunction;
|
|
4214
|
-
this.cache = new
|
|
4230
|
+
this.cache = new LRUCache2({ max: maxCount, ttl });
|
|
4215
4231
|
}
|
|
4216
4232
|
async get(hash) {
|
|
4217
4233
|
const existing = this.cache.get(hash);
|
|
@@ -4240,8 +4256,10 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
4240
4256
|
moniker = SimpleBlockViewer.defaultMoniker;
|
|
4241
4257
|
_store;
|
|
4242
4258
|
finalizationViewer;
|
|
4243
|
-
payloadCache = new
|
|
4244
|
-
signedHydratedBlockWithHashMetaCache = new
|
|
4259
|
+
payloadCache = new LruCacheMap2({ max: 1e4 });
|
|
4260
|
+
signedHydratedBlockWithHashMetaCache = new LruCacheMap2({ max: 2e3, ttl: 1e3 * 60 * 60 });
|
|
4261
|
+
_blockStepSemaphores = StepSizes14.map(() => new Semaphore2(20));
|
|
4262
|
+
_blocksSummaryMap;
|
|
4245
4263
|
_headPollHash;
|
|
4246
4264
|
_headPollInProgress = false;
|
|
4247
4265
|
_headPollTimer = null;
|
|
@@ -4249,6 +4267,10 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
4249
4267
|
get finalizedArchivist() {
|
|
4250
4268
|
return this.params.finalizedArchivist;
|
|
4251
4269
|
}
|
|
4270
|
+
get blocksSummaryMap() {
|
|
4271
|
+
this._blocksSummaryMap ??= this.params.blocksSummaryMap ?? new LruCacheMap2({ max: 32 });
|
|
4272
|
+
return this._blocksSummaryMap;
|
|
4273
|
+
}
|
|
4252
4274
|
get headPollIntervalMs() {
|
|
4253
4275
|
return this.params.headPollIntervalMs;
|
|
4254
4276
|
}
|
|
@@ -4267,11 +4289,12 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
4267
4289
|
static async paramsHandler(params) {
|
|
4268
4290
|
const headPollIntervalMs = params.headPollIntervalMs;
|
|
4269
4291
|
if (headPollIntervalMs !== void 0) {
|
|
4270
|
-
|
|
4292
|
+
assertEx34(headPollIntervalMs >= MIN_HEAD_POLL_INTERVAL_MS, () => `headPollIntervalMs must be at least ${MIN_HEAD_POLL_INTERVAL_MS}ms`);
|
|
4271
4293
|
}
|
|
4272
4294
|
return {
|
|
4273
4295
|
...await super.paramsHandler(params),
|
|
4274
|
-
|
|
4296
|
+
blocksSummaryMap: params.blocksSummaryMap,
|
|
4297
|
+
finalizedArchivist: assertEx34(params.finalizedArchivist, () => "finalizedArchivist is required"),
|
|
4275
4298
|
headPollIntervalMs
|
|
4276
4299
|
};
|
|
4277
4300
|
}
|
|
@@ -4300,8 +4323,8 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
4300
4323
|
}
|
|
4301
4324
|
async blocksByHash(hash, limit = 50) {
|
|
4302
4325
|
return await this.spanAsync("blocksByHash", async () => {
|
|
4303
|
-
|
|
4304
|
-
|
|
4326
|
+
assertEx34(limit > 0, () => "limit must be greater than 0");
|
|
4327
|
+
assertEx34(limit <= 100, () => "limit must be less than 100");
|
|
4305
4328
|
const blocks = [];
|
|
4306
4329
|
let current = await this.blockByHash(hash);
|
|
4307
4330
|
while (current && blocks.length < limit) {
|
|
@@ -4315,8 +4338,8 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
4315
4338
|
}
|
|
4316
4339
|
async blocksByNumber(blockNumber, limit = 50) {
|
|
4317
4340
|
return await this.spanAsync("blocksByNumber", async () => {
|
|
4318
|
-
|
|
4319
|
-
|
|
4341
|
+
assertEx34(limit > 0, () => "limit must be greater than 0");
|
|
4342
|
+
assertEx34(limit <= 100, () => "limit must be less than 100");
|
|
4320
4343
|
const chainContext = await this.getChainContextRead();
|
|
4321
4344
|
if (isUndefined8(chainContext.head)) {
|
|
4322
4345
|
return [];
|
|
@@ -4326,15 +4349,39 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
4326
4349
|
while (current && blocks.length < limit) {
|
|
4327
4350
|
blocks.push(current);
|
|
4328
4351
|
if (current[0].block === 0) break;
|
|
4329
|
-
const previousNumber =
|
|
4352
|
+
const previousNumber = asXL1BlockNumber9(current[0].block - 1, true);
|
|
4330
4353
|
current = await this.blockByNumberWithContext(chainContext, previousNumber);
|
|
4331
4354
|
}
|
|
4332
4355
|
return blocks.map((b) => asSignedHydratedBlockWithHashMeta(b, true));
|
|
4333
4356
|
}, this.context);
|
|
4334
4357
|
}
|
|
4358
|
+
async blocksByStep(stepLevel, stepIndex) {
|
|
4359
|
+
return await this.spanAsync("blocksByStep", async () => {
|
|
4360
|
+
assertEx34(Number.isInteger(stepIndex) && stepIndex >= 0, () => "stepIndex must be a non-negative integer");
|
|
4361
|
+
const size = stepSize2(stepLevel);
|
|
4362
|
+
assertEx34(
|
|
4363
|
+
stepLevel <= blocksMaxStep,
|
|
4364
|
+
() => `blocksByStep does not support step levels above ${blocksMaxStep} (requested ${stepLevel})`
|
|
4365
|
+
);
|
|
4366
|
+
const chainContext = await this.getChainContextRead();
|
|
4367
|
+
if (isUndefined8(chainContext.head)) {
|
|
4368
|
+
return [];
|
|
4369
|
+
}
|
|
4370
|
+
const start = stepIndex * size;
|
|
4371
|
+
const end = Math.min(start + size - 1, chainContext.head.block);
|
|
4372
|
+
if (end < start) {
|
|
4373
|
+
return [];
|
|
4374
|
+
}
|
|
4375
|
+
const range = asXL1BlockRange11([start, end], { name: "blocksByStep" });
|
|
4376
|
+
const frames = deepCalculateFramesFromRange(range, blocksMaxStep);
|
|
4377
|
+
const summaries = await Promise.all(frames.map((frame) => blocksStepSummaryFromRange(this.context, this._blockStepSemaphores, this, this.blocksSummaryMap, frame)));
|
|
4378
|
+
const blocks = summaries.flatMap((summary) => summary.blocks);
|
|
4379
|
+
return blocks.map((b) => asSignedHydratedBlockWithHashMeta(b, true)).toReversed();
|
|
4380
|
+
}, this.context);
|
|
4381
|
+
}
|
|
4335
4382
|
async chainId(blockNumber = "latest") {
|
|
4336
4383
|
return await this.spanAsync("chainId", async () => {
|
|
4337
|
-
return blockNumber === "latest" ? (await this.finalizationViewer.headBlock()).chain :
|
|
4384
|
+
return blockNumber === "latest" ? (await this.finalizationViewer.headBlock()).chain : assertEx34(await this.blockByNumber(blockNumber), () => `Block not found [${blockNumber}]`)[0].chain;
|
|
4338
4385
|
}, this.context);
|
|
4339
4386
|
}
|
|
4340
4387
|
async createHandler() {
|
|
@@ -4362,9 +4409,9 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
4362
4409
|
remainingHashes = remainingHashes.filter((h) => !cachedHashes.has(h));
|
|
4363
4410
|
const finalizedPayloads = remainingHashes.length > 0 ? await this.finalizedArchivist.get(remainingHashes) : [];
|
|
4364
4411
|
const resultPayloads = [...cachedPayloads, ...finalizedPayloads.filter(exists4)];
|
|
4365
|
-
|
|
4412
|
+
for (const payload of resultPayloads) {
|
|
4366
4413
|
this.payloadCache.set(payload._hash, payload);
|
|
4367
|
-
}
|
|
4414
|
+
}
|
|
4368
4415
|
return resultPayloads;
|
|
4369
4416
|
}
|
|
4370
4417
|
async rate(range, timeUnit) {
|
|
@@ -4463,11 +4510,11 @@ SimpleBlockRewardViewer = __decorateClass([
|
|
|
4463
4510
|
], SimpleBlockRewardViewer);
|
|
4464
4511
|
|
|
4465
4512
|
// src/simple/blockValidation/SimpleBlockValidationViewer.ts
|
|
4466
|
-
import { assertEx as
|
|
4513
|
+
import { assertEx as assertEx35 } from "@xylabs/sdk-js";
|
|
4467
4514
|
import { PayloadBuilder as PayloadBuilder18 } from "@xyo-network/sdk-js";
|
|
4468
4515
|
import {
|
|
4469
4516
|
AccountBalanceViewerMoniker as AccountBalanceViewerMoniker2,
|
|
4470
|
-
asXL1BlockRange as
|
|
4517
|
+
asXL1BlockRange as asXL1BlockRange12,
|
|
4471
4518
|
BlockValidationViewerMoniker,
|
|
4472
4519
|
BlockViewerMoniker as BlockViewerMoniker3,
|
|
4473
4520
|
ChainContractViewerMoniker,
|
|
@@ -4516,7 +4563,7 @@ var SimpleBlockValidationViewer = class extends AbstractCreatableProvider {
|
|
|
4516
4563
|
head: void 0
|
|
4517
4564
|
};
|
|
4518
4565
|
const blocksWithMeta = await Promise.all(blocks.map((b) => Promise.all([PayloadBuilder18.addHashMeta(b[0]), PayloadBuilder18.addHashMeta(b[1])])));
|
|
4519
|
-
const head = isChainQualifiedHeadConfig5(config) ?
|
|
4566
|
+
const head = isChainQualifiedHeadConfig5(config) ? assertEx35(
|
|
4520
4567
|
(await this.blockViewer.blockByHash(config.head))?.[0],
|
|
4521
4568
|
() => `Specified a head that is not in the chain [${config.head}]`
|
|
4522
4569
|
) : void 0;
|
|
@@ -4524,7 +4571,7 @@ var SimpleBlockValidationViewer = class extends AbstractCreatableProvider {
|
|
|
4524
4571
|
const validateProtocol = value ? this.doValidateProtocol.bind(this) : void 0;
|
|
4525
4572
|
const validateState = state ? this.doValidateState.bind(this) : void 0;
|
|
4526
4573
|
const chainIdAtBlockNumber = (blockNumber) => this.chainContractViewer.chainIdAtBlockNumber(blockNumber);
|
|
4527
|
-
const qualification = { head: headBlock._hash, range:
|
|
4574
|
+
const qualification = { head: headBlock._hash, range: asXL1BlockRange12([0, headBlock.block], true) };
|
|
4528
4575
|
const [protocolResults, stateResults] = await Promise.all([
|
|
4529
4576
|
validateProtocol?.(blocksWithMeta, chainIdAtBlockNumber),
|
|
4530
4577
|
validateState?.(blocksWithMeta, chainIdAtBlockNumber)
|
|
@@ -4597,7 +4644,7 @@ SimpleBlockValidationViewer = __decorateClass([
|
|
|
4597
4644
|
], SimpleBlockValidationViewer);
|
|
4598
4645
|
|
|
4599
4646
|
// src/simple/chainContractViewer/SimpleChainContractViewer.ts
|
|
4600
|
-
import { assertEx as
|
|
4647
|
+
import { assertEx as assertEx36 } from "@xylabs/sdk-js";
|
|
4601
4648
|
import { ChainContractViewerMoniker as ChainContractViewerMoniker2, FinalizationViewerMoniker as FinalizationViewerMoniker2 } from "@xyo-network/xl1-protocol-lib";
|
|
4602
4649
|
var SimpleChainContractViewer = class extends AbstractCreatableProvider {
|
|
4603
4650
|
moniker = SimpleChainContractViewer.defaultMoniker;
|
|
@@ -4614,7 +4661,7 @@ var SimpleChainContractViewer = class extends AbstractCreatableProvider {
|
|
|
4614
4661
|
let contractViewer = this;
|
|
4615
4662
|
let forkedAtBlockNumber = await contractViewer.forkedAtBlockNumber();
|
|
4616
4663
|
while (forkedAtBlockNumber !== null && blockNumber <= forkedAtBlockNumber) {
|
|
4617
|
-
contractViewer =
|
|
4664
|
+
contractViewer = assertEx36(await contractViewer.forkedChainContractViewer());
|
|
4618
4665
|
forkedAtBlockNumber = await contractViewer.forkedAtBlockNumber();
|
|
4619
4666
|
chainId = await contractViewer.chainId();
|
|
4620
4667
|
}
|
|
@@ -4667,8 +4714,8 @@ var SimpleXyoClient = class {
|
|
|
4667
4714
|
};
|
|
4668
4715
|
|
|
4669
4716
|
// src/simple/datalake/RestDataLakeRunner.ts
|
|
4670
|
-
import { assertEx as
|
|
4671
|
-
import { isAnyPayload as
|
|
4717
|
+
import { assertEx as assertEx37, exists as exists6 } from "@xylabs/sdk-js";
|
|
4718
|
+
import { isAnyPayload as isAnyPayload8, PayloadZodLoose } from "@xyo-network/sdk-js";
|
|
4672
4719
|
import { DataLakeRunnerMoniker } from "@xyo-network/xl1-protocol-lib";
|
|
4673
4720
|
import { z as z29 } from "zod/mini";
|
|
4674
4721
|
|
|
@@ -4677,7 +4724,7 @@ import { FetchClientError, FetchJsonClient } from "@xylabs/sdk-js";
|
|
|
4677
4724
|
import {
|
|
4678
4725
|
exists as exists5
|
|
4679
4726
|
} from "@xylabs/sdk-js";
|
|
4680
|
-
import { asAnyPayload as asAnyPayload4, isAnyPayload as
|
|
4727
|
+
import { asAnyPayload as asAnyPayload4, isAnyPayload as isAnyPayload7 } from "@xyo-network/sdk-js";
|
|
4681
4728
|
var AbstractRestDataLake = class extends AbstractCreatableProvider {
|
|
4682
4729
|
get allowedSchemas() {
|
|
4683
4730
|
return this.params.allowedSchemas;
|
|
@@ -4708,7 +4755,7 @@ var AbstractRestDataLake = class extends AbstractCreatableProvider {
|
|
|
4708
4755
|
}
|
|
4709
4756
|
}
|
|
4710
4757
|
isAllowed(value) {
|
|
4711
|
-
if (
|
|
4758
|
+
if (isAnyPayload7(value)) {
|
|
4712
4759
|
return this.isAllowedSchema(value.schema);
|
|
4713
4760
|
}
|
|
4714
4761
|
return false;
|
|
@@ -4735,8 +4782,8 @@ var RestDataLakeRunner = class extends AbstractRestDataLake {
|
|
|
4735
4782
|
}
|
|
4736
4783
|
async insert(items) {
|
|
4737
4784
|
const allowedItems = items.map((item) => {
|
|
4738
|
-
if (
|
|
4739
|
-
|
|
4785
|
+
if (isAnyPayload8(item) && this.isAllowed(item)) {
|
|
4786
|
+
assertEx37(typeof item === "object" && item !== null, () => "Data must be an object");
|
|
4740
4787
|
return item;
|
|
4741
4788
|
}
|
|
4742
4789
|
return null;
|
|
@@ -4770,11 +4817,11 @@ RestDataLakeViewer = __decorateClass([
|
|
|
4770
4817
|
|
|
4771
4818
|
// src/simple/datalake/SimpleDataLakeRunner.ts
|
|
4772
4819
|
import { exists as exists7 } from "@xylabs/sdk-js";
|
|
4773
|
-
import { isAnyPayload as
|
|
4820
|
+
import { isAnyPayload as isAnyPayload10, PayloadBuilder as PayloadBuilder19 } from "@xyo-network/sdk-js";
|
|
4774
4821
|
import { DataLakeRunnerMoniker as DataLakeRunnerMoniker2 } from "@xyo-network/xl1-protocol-lib";
|
|
4775
4822
|
|
|
4776
4823
|
// src/simple/datalake/AbstractSimpleDataLake.ts
|
|
4777
|
-
import { isAnyPayload as
|
|
4824
|
+
import { isAnyPayload as isAnyPayload9 } from "@xyo-network/sdk-js";
|
|
4778
4825
|
var AbstractSimpleDataLake = class extends AbstractCreatableProvider {
|
|
4779
4826
|
get allowedSchemas() {
|
|
4780
4827
|
return this.params.allowedSchemas;
|
|
@@ -4793,7 +4840,7 @@ var AbstractSimpleDataLake = class extends AbstractCreatableProvider {
|
|
|
4793
4840
|
throw new Error("Method not implemented.");
|
|
4794
4841
|
}
|
|
4795
4842
|
isAllowed(value) {
|
|
4796
|
-
if (
|
|
4843
|
+
if (isAnyPayload9(value)) {
|
|
4797
4844
|
return this.isAllowedSchema(value.schema);
|
|
4798
4845
|
}
|
|
4799
4846
|
return true;
|
|
@@ -4822,7 +4869,7 @@ var SimpleDataLakeRunner = class extends AbstractSimpleDataLake {
|
|
|
4822
4869
|
}))).filter(exists7);
|
|
4823
4870
|
}
|
|
4824
4871
|
async insert(items) {
|
|
4825
|
-
const payloads = items.filter(
|
|
4872
|
+
const payloads = items.filter(isAnyPayload10).filter((i) => this.isAllowed(i));
|
|
4826
4873
|
const hashPairs = await PayloadBuilder19.hashPairs(payloads);
|
|
4827
4874
|
for (const [payload, hash] of hashPairs) {
|
|
4828
4875
|
await this.map.set(hash, payload);
|
|
@@ -4879,7 +4926,7 @@ SimpleFinalizationRunner = __decorateClass([
|
|
|
4879
4926
|
], SimpleFinalizationRunner);
|
|
4880
4927
|
|
|
4881
4928
|
// src/simple/finalization/SimpleFinalizationViewer.ts
|
|
4882
|
-
import { assertEx as
|
|
4929
|
+
import { assertEx as assertEx38 } from "@xylabs/sdk-js";
|
|
4883
4930
|
import {
|
|
4884
4931
|
asSignedHydratedBlockWithStorageMeta as asSignedHydratedBlockWithStorageMeta2,
|
|
4885
4932
|
ChainContractViewerMoniker as ChainContractViewerMoniker3,
|
|
@@ -4908,7 +4955,7 @@ var SimpleFinalizationViewer = class extends AbstractCreatableProvider {
|
|
|
4908
4955
|
static async paramsHandler(params) {
|
|
4909
4956
|
return {
|
|
4910
4957
|
...await super.paramsHandler(params),
|
|
4911
|
-
finalizedArchivist:
|
|
4958
|
+
finalizedArchivist: assertEx38(params.finalizedArchivist, () => "finalizedArchivist is required")
|
|
4912
4959
|
};
|
|
4913
4960
|
}
|
|
4914
4961
|
chainId() {
|
|
@@ -4916,18 +4963,18 @@ var SimpleFinalizationViewer = class extends AbstractCreatableProvider {
|
|
|
4916
4963
|
}
|
|
4917
4964
|
async createHandler() {
|
|
4918
4965
|
await super.createHandler();
|
|
4919
|
-
this._chainId =
|
|
4966
|
+
this._chainId = assertEx38(this.config.chain.id ?? (await findMostRecentBlock(this.params.finalizedArchivist))?.chain, () => "chain.id is required if empty archivist");
|
|
4920
4967
|
this._store = { chainMap: this.params.finalizedArchivist };
|
|
4921
4968
|
}
|
|
4922
4969
|
async head() {
|
|
4923
4970
|
return await this.spanAsync("head", async () => {
|
|
4924
|
-
const currentHead =
|
|
4971
|
+
const currentHead = assertEx38(await this.getCurrentHead(), () => "Could not find most recent block [currentBlock]");
|
|
4925
4972
|
const cache = this.hydratedBlockCache;
|
|
4926
4973
|
const block = await cache.get(currentHead._hash);
|
|
4927
4974
|
if (!block) {
|
|
4928
4975
|
this.logger?.error(`Could not find current block with hash ${currentHead._hash}`);
|
|
4929
4976
|
}
|
|
4930
|
-
return
|
|
4977
|
+
return assertEx38(block, () => "Could not find current block");
|
|
4931
4978
|
}, this.context);
|
|
4932
4979
|
}
|
|
4933
4980
|
async headBlock() {
|
|
@@ -4953,8 +5000,8 @@ var SimpleFinalizationViewer = class extends AbstractCreatableProvider {
|
|
|
4953
5000
|
}
|
|
4954
5001
|
async getCurrentHead() {
|
|
4955
5002
|
const chainArchivist = this.finalizedArchivist;
|
|
4956
|
-
const result =
|
|
4957
|
-
|
|
5003
|
+
const result = assertEx38(await findMostRecentBlock(chainArchivist), () => "Could not find most recent block [getCurrentHead]");
|
|
5004
|
+
assertEx38(result?.chain === this._chainId, () => "Chain ID does not match head block chain ID");
|
|
4958
5005
|
return result;
|
|
4959
5006
|
}
|
|
4960
5007
|
};
|
|
@@ -4984,13 +5031,13 @@ var SimpleXyoGateway = class _SimpleXyoGateway extends AbstractCreatableProvider
|
|
|
4984
5031
|
|
|
4985
5032
|
// src/simple/gateway/SimpleXyoGatewayRunner.ts
|
|
4986
5033
|
import {
|
|
4987
|
-
assertEx as
|
|
5034
|
+
assertEx as assertEx39,
|
|
4988
5035
|
BigIntToJsonZod,
|
|
4989
|
-
isDefined as
|
|
5036
|
+
isDefined as isDefined17
|
|
4990
5037
|
} from "@xylabs/sdk-js";
|
|
4991
5038
|
import { PayloadBuilder as PayloadBuilder20 } from "@xyo-network/sdk-js";
|
|
4992
5039
|
import {
|
|
4993
|
-
asXL1BlockNumber as
|
|
5040
|
+
asXL1BlockNumber as asXL1BlockNumber10,
|
|
4994
5041
|
DataLakeRunnerMoniker as DataLakeRunnerMoniker3,
|
|
4995
5042
|
isSignedHydratedTransaction,
|
|
4996
5043
|
TransferSchema as TransferSchema3,
|
|
@@ -5017,23 +5064,23 @@ var SimpleXyoGatewayRunner = class _SimpleXyoGatewayRunner extends AbstractCreat
|
|
|
5017
5064
|
return this._signer;
|
|
5018
5065
|
}
|
|
5019
5066
|
async addPayloadsToChain(onChain, offChain, options) {
|
|
5020
|
-
const viewer =
|
|
5067
|
+
const viewer = assertEx39(this.connection.viewer, () => "No viewer available on connection");
|
|
5021
5068
|
const {
|
|
5022
5069
|
nbf,
|
|
5023
5070
|
exp,
|
|
5024
5071
|
chain,
|
|
5025
5072
|
fees
|
|
5026
5073
|
} = options ?? {};
|
|
5027
|
-
const resolvedChainId =
|
|
5028
|
-
const resolvedNbf =
|
|
5029
|
-
const resolvedExp =
|
|
5074
|
+
const resolvedChainId = isDefined17(chain) ? chain : await viewer.chainId();
|
|
5075
|
+
const resolvedNbf = asXL1BlockNumber10(isDefined17(nbf) ? nbf : await viewer.currentBlockNumber(), true);
|
|
5076
|
+
const resolvedExp = asXL1BlockNumber10(isDefined17(exp) ? exp : resolvedNbf + 10, true);
|
|
5030
5077
|
const tx = await buildUnsignedTransaction(resolvedChainId, onChain, offChain, resolvedNbf, resolvedExp, await this.signer.address(), fees);
|
|
5031
5078
|
return await this.addTransactionToChain(tx, await PayloadBuilder20.addHashMeta(offChain));
|
|
5032
5079
|
}
|
|
5033
5080
|
async addTransactionToChain(tx, offChain = []) {
|
|
5034
5081
|
const connection = this.connection;
|
|
5035
5082
|
const signer = this.signer;
|
|
5036
|
-
const runner =
|
|
5083
|
+
const runner = assertEx39(connection.runner, () => "No runner available on connection");
|
|
5037
5084
|
let signedTx;
|
|
5038
5085
|
if (isSignedHydratedTransaction(tx)) {
|
|
5039
5086
|
const [bw, payloads] = tx;
|
|
@@ -5048,7 +5095,7 @@ var SimpleXyoGatewayRunner = class _SimpleXyoGatewayRunner extends AbstractCreat
|
|
|
5048
5095
|
}
|
|
5049
5096
|
async confirmSubmittedTransaction(txHash, options) {
|
|
5050
5097
|
return await confirmSubmittedTransaction(
|
|
5051
|
-
|
|
5098
|
+
assertEx39(this.connection.viewer, () => "Connection viewer is undefined"),
|
|
5052
5099
|
txHash,
|
|
5053
5100
|
options
|
|
5054
5101
|
);
|
|
@@ -5085,7 +5132,7 @@ var SimpleXyoGatewayRunner = class _SimpleXyoGatewayRunner extends AbstractCreat
|
|
|
5085
5132
|
|
|
5086
5133
|
// src/simple/mempool/SimpleMempoolRunner.ts
|
|
5087
5134
|
import {
|
|
5088
|
-
assertEx as
|
|
5135
|
+
assertEx as assertEx40,
|
|
5089
5136
|
exists as exists8
|
|
5090
5137
|
} from "@xylabs/sdk-js";
|
|
5091
5138
|
import { isPayloadBundle, PayloadBuilder as PayloadBuilder21 } from "@xyo-network/sdk-js";
|
|
@@ -5094,6 +5141,7 @@ import {
|
|
|
5094
5141
|
ChainContractViewerMoniker as ChainContractViewerMoniker4,
|
|
5095
5142
|
DeadLetterQueueRunnerMoniker,
|
|
5096
5143
|
DEFAULT_MAX_EXP_AHEAD,
|
|
5144
|
+
elevatedTransaction,
|
|
5097
5145
|
FinalizationViewerMoniker as FinalizationViewerMoniker4,
|
|
5098
5146
|
isSignedHydratedBlockWithHashMeta,
|
|
5099
5147
|
isSignedHydratedTransactionWithHashMeta,
|
|
@@ -5160,8 +5208,8 @@ var SimpleMempoolRunner = class extends AbstractCreatableProvider {
|
|
|
5160
5208
|
static async paramsHandler(params) {
|
|
5161
5209
|
return {
|
|
5162
5210
|
...await super.paramsHandler(params),
|
|
5163
|
-
pendingBlocksArchivist:
|
|
5164
|
-
pendingTransactionsArchivist:
|
|
5211
|
+
pendingBlocksArchivist: assertEx40(params?.pendingBlocksArchivist, () => "pendingBlocksArchivist is required"),
|
|
5212
|
+
pendingTransactionsArchivist: assertEx40(params?.pendingTransactionsArchivist, () => "pendingTransactionsArchivist is required")
|
|
5165
5213
|
};
|
|
5166
5214
|
}
|
|
5167
5215
|
async createHandler() {
|
|
@@ -5199,7 +5247,7 @@ var SimpleMempoolRunner = class extends AbstractCreatableProvider {
|
|
|
5199
5247
|
return b;
|
|
5200
5248
|
}
|
|
5201
5249
|
}).filter(exists8);
|
|
5202
|
-
|
|
5250
|
+
assertEx40(
|
|
5203
5251
|
remainingBlockMap.length === remainingBlocks.length,
|
|
5204
5252
|
() => `remainingBlockMap length should match remainingBlocks length [${remainingBlockMap.length}/${remainingBlocks.length}]`
|
|
5205
5253
|
);
|
|
@@ -5261,7 +5309,7 @@ var SimpleMempoolRunner = class extends AbstractCreatableProvider {
|
|
|
5261
5309
|
return t;
|
|
5262
5310
|
}
|
|
5263
5311
|
}).filter(exists8);
|
|
5264
|
-
|
|
5312
|
+
assertEx40(
|
|
5265
5313
|
remainingTransactionMap.length === remainingTransactions.length,
|
|
5266
5314
|
() => `remainingTransactionMap length should match remainingTransactions length [${remainingTransactionMap.length}/${remainingTransactions.length}]`
|
|
5267
5315
|
);
|
|
@@ -5324,14 +5372,15 @@ var SimpleMempoolRunner = class extends AbstractCreatableProvider {
|
|
|
5324
5372
|
await PayloadBuilder21.addHashMeta(payloads)
|
|
5325
5373
|
])
|
|
5326
5374
|
);
|
|
5375
|
+
const elevatedTransactions = hashedTransactions.map((tx) => elevatedTransaction(tx));
|
|
5327
5376
|
if (this.validateOnSubmit) {
|
|
5328
5377
|
const validationResults = await Promise.all(
|
|
5329
|
-
|
|
5378
|
+
elevatedTransactions.map(async (tx) => this.transactionValidationViewer.validateTransaction(tx, { value: true, state: true }))
|
|
5330
5379
|
);
|
|
5331
5380
|
const failures = [];
|
|
5332
5381
|
for (const [i, result] of validationResults.entries()) {
|
|
5333
5382
|
if (!isSignedHydratedTransactionWithHashMeta(result)) {
|
|
5334
|
-
failures.push({ tx:
|
|
5383
|
+
failures.push({ tx: elevatedTransactions[i], errors: result });
|
|
5335
5384
|
}
|
|
5336
5385
|
}
|
|
5337
5386
|
if (failures.length > 0) {
|
|
@@ -5340,7 +5389,7 @@ var SimpleMempoolRunner = class extends AbstractCreatableProvider {
|
|
|
5340
5389
|
throw new Error(`SimpleMempoolRunner: rejected ${failures.length} transaction(s) at admission: ${detail}`);
|
|
5341
5390
|
}
|
|
5342
5391
|
}
|
|
5343
|
-
const bundles =
|
|
5392
|
+
const bundles = elevatedTransactions.map((tx) => hydratedTransactionToPayloadBundle(tx));
|
|
5344
5393
|
const inserted = await this.pendingTransactionsArchivist.insert(bundles);
|
|
5345
5394
|
await this.enforceCap();
|
|
5346
5395
|
return inserted.map((p) => p._hash);
|
|
@@ -5512,7 +5561,7 @@ SimpleMempoolRunner = __decorateClass([
|
|
|
5512
5561
|
// src/simple/mempool/SimpleMempoolViewer.ts
|
|
5513
5562
|
import {
|
|
5514
5563
|
exists as exists9,
|
|
5515
|
-
isDefined as
|
|
5564
|
+
isDefined as isDefined18,
|
|
5516
5565
|
isHash as isHash2
|
|
5517
5566
|
} from "@xylabs/sdk-js";
|
|
5518
5567
|
import { isHashMeta as isHashMeta2, isPayloadBundle as isPayloadBundle2 } from "@xyo-network/sdk-js";
|
|
@@ -5573,7 +5622,7 @@ var SimpleMempoolViewer = class extends AbstractCreatableProvider {
|
|
|
5573
5622
|
let cursor = void 0;
|
|
5574
5623
|
if (isHash2(providedCursor)) {
|
|
5575
5624
|
const [p] = await this.pendingBlocksArchivist.get([providedCursor]);
|
|
5576
|
-
if (
|
|
5625
|
+
if (isDefined18(p)) {
|
|
5577
5626
|
cursor = p._sequence;
|
|
5578
5627
|
}
|
|
5579
5628
|
}
|
|
@@ -5592,7 +5641,7 @@ var SimpleMempoolViewer = class extends AbstractCreatableProvider {
|
|
|
5592
5641
|
let cursor = void 0;
|
|
5593
5642
|
if (isHash2(providedCursor)) {
|
|
5594
5643
|
const [p] = await this.pendingTransactionsArchivist.get([providedCursor]);
|
|
5595
|
-
if (
|
|
5644
|
+
if (isDefined18(p)) {
|
|
5596
5645
|
cursor = p._sequence;
|
|
5597
5646
|
}
|
|
5598
5647
|
}
|
|
@@ -5607,7 +5656,7 @@ var SimpleMempoolViewer = class extends AbstractCreatableProvider {
|
|
|
5607
5656
|
const hydratedWithBundle = (await Promise.all(
|
|
5608
5657
|
filteredBundles.map(async (bundle3) => {
|
|
5609
5658
|
const tx = await bundledPayloadToHydratedTransaction(bundle3);
|
|
5610
|
-
return
|
|
5659
|
+
return isDefined18(tx) ? { bundle: bundle3, tx } : void 0;
|
|
5611
5660
|
})
|
|
5612
5661
|
)).filter(exists9);
|
|
5613
5662
|
const currentBlock = await this.windowedBlockViewer.currentBlock();
|
|
@@ -5800,7 +5849,7 @@ var SimpleXyoNetwork = class {
|
|
|
5800
5849
|
};
|
|
5801
5850
|
|
|
5802
5851
|
// src/simple/permissions/SimpleXyoPermissions.ts
|
|
5803
|
-
import { assertEx as
|
|
5852
|
+
import { assertEx as assertEx41 } from "@xylabs/sdk-js";
|
|
5804
5853
|
var SimpleXyoPermissions = class {
|
|
5805
5854
|
invoker;
|
|
5806
5855
|
_store;
|
|
@@ -5809,7 +5858,7 @@ var SimpleXyoPermissions = class {
|
|
|
5809
5858
|
this.invoker = store.invoker;
|
|
5810
5859
|
}
|
|
5811
5860
|
get store() {
|
|
5812
|
-
return
|
|
5861
|
+
return assertEx41(this._store, () => "Store must be defined to get permissions");
|
|
5813
5862
|
}
|
|
5814
5863
|
async getPermissions() {
|
|
5815
5864
|
return await this.store.getPermissions();
|
|
@@ -5862,7 +5911,7 @@ var SimpleXyoPermissions = class {
|
|
|
5862
5911
|
};
|
|
5863
5912
|
|
|
5864
5913
|
// src/simple/permissions/store/MemoryPermissions.ts
|
|
5865
|
-
import { assertEx as
|
|
5914
|
+
import { assertEx as assertEx42 } from "@xylabs/sdk-js";
|
|
5866
5915
|
var MemoryPermissionsStore = class {
|
|
5867
5916
|
_invoker;
|
|
5868
5917
|
permissions = [];
|
|
@@ -5870,7 +5919,7 @@ var MemoryPermissionsStore = class {
|
|
|
5870
5919
|
this._invoker = invoker;
|
|
5871
5920
|
}
|
|
5872
5921
|
get invoker() {
|
|
5873
|
-
return
|
|
5922
|
+
return assertEx42(this._invoker, () => "Invoker must be defined to get permissions");
|
|
5874
5923
|
}
|
|
5875
5924
|
async getPermissions() {
|
|
5876
5925
|
await Promise.resolve();
|
|
@@ -5958,7 +6007,7 @@ var SimpleXyoSigner = class _SimpleXyoSigner extends AbstractCreatableProvider {
|
|
|
5958
6007
|
};
|
|
5959
6008
|
|
|
5960
6009
|
// src/simple/StakeEventsViewer/SimpleStakeEventsViewer.ts
|
|
5961
|
-
import { isDefined as
|
|
6010
|
+
import { isDefined as isDefined19 } from "@xylabs/sdk-js";
|
|
5962
6011
|
import { StakeEventsViewerMoniker } from "@xyo-network/xl1-protocol-lib";
|
|
5963
6012
|
var SimpleStakeEventsViewer = class extends AbstractCreatableProvider {
|
|
5964
6013
|
moniker = SimpleStakeEventsViewer.defaultMoniker;
|
|
@@ -5971,7 +6020,7 @@ var SimpleStakeEventsViewer = class extends AbstractCreatableProvider {
|
|
|
5971
6020
|
stakeEvents(range, { name } = {}) {
|
|
5972
6021
|
const positions = this.positionsFromRange(range);
|
|
5973
6022
|
const events = this.eventsFromPositions(positions);
|
|
5974
|
-
if (
|
|
6023
|
+
if (isDefined19(name)) {
|
|
5975
6024
|
return events.filter((event) => event.name === name);
|
|
5976
6025
|
}
|
|
5977
6026
|
return events;
|
|
@@ -6036,7 +6085,7 @@ SimpleStakeEventsViewer = __decorateClass([
|
|
|
6036
6085
|
], SimpleStakeEventsViewer);
|
|
6037
6086
|
|
|
6038
6087
|
// src/simple/StakeTotalsViewer/SimpleStakeTotalsViewer.ts
|
|
6039
|
-
import { assertEx as
|
|
6088
|
+
import { assertEx as assertEx43 } from "@xylabs/sdk-js";
|
|
6040
6089
|
import { asXyoAddress as asXyoAddress3 } from "@xyo-network/address";
|
|
6041
6090
|
import {
|
|
6042
6091
|
StakeTotalsViewerMoniker,
|
|
@@ -6080,7 +6129,7 @@ var SimpleStakeTotalsViewer = class extends AbstractCreatableProvider {
|
|
|
6080
6129
|
}
|
|
6081
6130
|
async createHandler() {
|
|
6082
6131
|
await super.createHandler();
|
|
6083
|
-
this._stakeViewer =
|
|
6132
|
+
this._stakeViewer = assertEx43(
|
|
6084
6133
|
await this.locateAndCreate(StakeViewerMoniker),
|
|
6085
6134
|
() => "Failed to create StakeViewer"
|
|
6086
6135
|
);
|
|
@@ -6134,14 +6183,14 @@ SimpleStakeTotalsViewer = __decorateClass([
|
|
|
6134
6183
|
], SimpleStakeTotalsViewer);
|
|
6135
6184
|
|
|
6136
6185
|
// src/simple/StakeViewer/SimpleStakeViewer.ts
|
|
6137
|
-
import { assertEx as
|
|
6186
|
+
import { assertEx as assertEx44, toAddress } from "@xylabs/sdk-js";
|
|
6138
6187
|
import { asXyoAddress as asXyoAddress4 } from "@xyo-network/address";
|
|
6139
6188
|
import { StakeEventsViewerMoniker as StakeEventsViewerMoniker2, StakeViewerMoniker as StakeViewerMoniker2 } from "@xyo-network/xl1-protocol-lib";
|
|
6140
6189
|
var SimpleStakeViewer = class extends AbstractCreatableProvider {
|
|
6141
6190
|
moniker = SimpleStakeViewer.defaultMoniker;
|
|
6142
6191
|
_chainStakeEventsViewer;
|
|
6143
6192
|
get stakeEvents() {
|
|
6144
|
-
return
|
|
6193
|
+
return assertEx44(this._chainStakeEventsViewer, () => "Stake events viewer not set");
|
|
6145
6194
|
}
|
|
6146
6195
|
get positions() {
|
|
6147
6196
|
return this.params.positions;
|
|
@@ -6181,7 +6230,7 @@ var SimpleStakeViewer = class extends AbstractCreatableProvider {
|
|
|
6181
6230
|
}
|
|
6182
6231
|
async createHandler() {
|
|
6183
6232
|
await super.createHandler();
|
|
6184
|
-
this._chainStakeEventsViewer =
|
|
6233
|
+
this._chainStakeEventsViewer = assertEx44(
|
|
6185
6234
|
await this.locateAndCreate(StakeEventsViewerMoniker2),
|
|
6186
6235
|
() => "Failed to create StakeEventsViewer"
|
|
6187
6236
|
);
|
|
@@ -6216,7 +6265,7 @@ var SimpleStakeViewer = class extends AbstractCreatableProvider {
|
|
|
6216
6265
|
return toAddress(toAddress(1n));
|
|
6217
6266
|
}
|
|
6218
6267
|
stakeById(id) {
|
|
6219
|
-
return
|
|
6268
|
+
return assertEx44(this.positions[id], () => new Error(`Stake with id ${id} not found`));
|
|
6220
6269
|
}
|
|
6221
6270
|
stakeByStaker(staker, slot) {
|
|
6222
6271
|
return this.positions.filter((s) => asXyoAddress4(s.staker) === asXyoAddress4(staker))[slot];
|
|
@@ -6318,12 +6367,12 @@ RestSyncViewer = __decorateClass([
|
|
|
6318
6367
|
// src/simple/timeSync2/SimpleTimeSyncViewer.ts
|
|
6319
6368
|
import {
|
|
6320
6369
|
asHash as asHash5,
|
|
6321
|
-
assertEx as
|
|
6322
|
-
isDefined as
|
|
6370
|
+
assertEx as assertEx45,
|
|
6371
|
+
isDefined as isDefined20
|
|
6323
6372
|
} from "@xylabs/sdk-js";
|
|
6324
6373
|
import {
|
|
6325
6374
|
asTimePayload as asTimePayload2,
|
|
6326
|
-
asXL1BlockNumber as
|
|
6375
|
+
asXL1BlockNumber as asXL1BlockNumber11,
|
|
6327
6376
|
BlockViewerMoniker as BlockViewerMoniker4,
|
|
6328
6377
|
TimeSchema,
|
|
6329
6378
|
TimeSyncViewerMoniker
|
|
@@ -6340,10 +6389,10 @@ var SimpleTimeSyncViewer = class extends AbstractCreatableProvider {
|
|
|
6340
6389
|
async convertTime(fromDomain, toDomain, from) {
|
|
6341
6390
|
switch (fromDomain) {
|
|
6342
6391
|
case "xl1": {
|
|
6343
|
-
const [block, payloads] =
|
|
6392
|
+
const [block, payloads] = assertEx45(await this.blockViewer.blockByNumber(asXL1BlockNumber11(from, true)), () => "Block not found");
|
|
6344
6393
|
const timeSchemaIndex = block.payload_schemas.indexOf(TimeSchema);
|
|
6345
6394
|
const hash = timeSchemaIndex === -1 ? void 0 : block.payload_hashes[timeSchemaIndex];
|
|
6346
|
-
const timePayload = asTimePayload2(
|
|
6395
|
+
const timePayload = asTimePayload2(isDefined20(hash) ? payloads.find((p) => p._hash === hash) : void 0);
|
|
6347
6396
|
if (timePayload === void 0) return 0;
|
|
6348
6397
|
switch (toDomain) {
|
|
6349
6398
|
case "xl1": {
|
|
@@ -6395,10 +6444,10 @@ var SimpleTimeSyncViewer = class extends AbstractCreatableProvider {
|
|
|
6395
6444
|
return [Date.now(), null];
|
|
6396
6445
|
}
|
|
6397
6446
|
case "ethereum": {
|
|
6398
|
-
const provider =
|
|
6447
|
+
const provider = assertEx45(this.ethProvider, () => "Ethereum provider not configured");
|
|
6399
6448
|
const blockNumber = await provider.getBlockNumber() ?? 0;
|
|
6400
6449
|
const block = await provider.getBlock(blockNumber);
|
|
6401
|
-
const blockHash = asHash5(
|
|
6450
|
+
const blockHash = asHash5(assertEx45(block?.hash, () => "Block hash not found"), true);
|
|
6402
6451
|
return [blockNumber, blockHash];
|
|
6403
6452
|
}
|
|
6404
6453
|
default: {
|
|
@@ -6413,10 +6462,10 @@ var SimpleTimeSyncViewer = class extends AbstractCreatableProvider {
|
|
|
6413
6462
|
// this is for the previous block
|
|
6414
6463
|
xl1,
|
|
6415
6464
|
// this is for the previous block
|
|
6416
|
-
xl1Hash:
|
|
6465
|
+
xl1Hash: assertEx45(xl1Hash, () => "No xl1 hash available from time sync service"),
|
|
6417
6466
|
epoch: Date.now()
|
|
6418
6467
|
};
|
|
6419
|
-
if (
|
|
6468
|
+
if (isDefined20(this.ethProvider)) {
|
|
6420
6469
|
const [ethereum, ethHashOrNull] = await this.currentTimeAndHash("ethereum");
|
|
6421
6470
|
const ethereumHash = asHash5(ethHashOrNull, () => "No ethereum hash available from time sync service");
|
|
6422
6471
|
timePayload.ethereum = ethereum;
|
|
@@ -6433,11 +6482,11 @@ SimpleTimeSyncViewer = __decorateClass([
|
|
|
6433
6482
|
], SimpleTimeSyncViewer);
|
|
6434
6483
|
|
|
6435
6484
|
// src/simple/transactionValidation/SimpleTransactionValidationViewer.ts
|
|
6436
|
-
import { assertEx as
|
|
6485
|
+
import { assertEx as assertEx46 } from "@xylabs/sdk-js";
|
|
6437
6486
|
import { PayloadBuilder as PayloadBuilder24 } from "@xyo-network/sdk-js";
|
|
6438
6487
|
import {
|
|
6439
6488
|
AccountBalanceViewerMoniker as AccountBalanceViewerMoniker3,
|
|
6440
|
-
asXL1BlockRange as
|
|
6489
|
+
asXL1BlockRange as asXL1BlockRange13,
|
|
6441
6490
|
BlockViewerMoniker as BlockViewerMoniker5,
|
|
6442
6491
|
ChainContractViewerMoniker as ChainContractViewerMoniker5,
|
|
6443
6492
|
isChainQualifiedHeadConfig as isChainQualifiedHeadConfig6,
|
|
@@ -6484,7 +6533,7 @@ var SimpleTransactionValidationViewer = class extends AbstractCreatableProvider
|
|
|
6484
6533
|
head: void 0
|
|
6485
6534
|
};
|
|
6486
6535
|
const transactionsWithMeta = await Promise.all(transactions.map((b) => Promise.all([PayloadBuilder24.addHashMeta(b[0]), PayloadBuilder24.addHashMeta(b[1])])));
|
|
6487
|
-
const head = isChainQualifiedHeadConfig6(config) ?
|
|
6536
|
+
const head = isChainQualifiedHeadConfig6(config) ? assertEx46(
|
|
6488
6537
|
(await this.blockViewer.blockByHash(config.head))?.[0],
|
|
6489
6538
|
() => `Specified a head that is not in the chain [${config.head}]`
|
|
6490
6539
|
) : void 0;
|
|
@@ -6492,7 +6541,7 @@ var SimpleTransactionValidationViewer = class extends AbstractCreatableProvider
|
|
|
6492
6541
|
const validateProtocol = value ? this.doValidateProtocol.bind(this) : void 0;
|
|
6493
6542
|
const validateState = state ? this.doValidateState.bind(this) : void 0;
|
|
6494
6543
|
const chainId = headBlock.chain;
|
|
6495
|
-
const qualification = { head: headBlock._hash, range:
|
|
6544
|
+
const qualification = { head: headBlock._hash, range: asXL1BlockRange13([0, headBlock.block], true) };
|
|
6496
6545
|
const [protocolResults, stateResults] = await Promise.all([
|
|
6497
6546
|
validateProtocol?.(transactionsWithMeta, chainId),
|
|
6498
6547
|
validateState?.(transactionsWithMeta, chainId)
|
|
@@ -6550,7 +6599,7 @@ SimpleTransactionValidationViewer = __decorateClass([
|
|
|
6550
6599
|
], SimpleTransactionValidationViewer);
|
|
6551
6600
|
|
|
6552
6601
|
// src/simple/TransactionViewer/SimpleTransactionViewer.ts
|
|
6553
|
-
import { assertEx as
|
|
6602
|
+
import { assertEx as assertEx47, exists as exists10 } from "@xylabs/sdk-js";
|
|
6554
6603
|
import { BoundWitnessSchema } from "@xyo-network/sdk-js";
|
|
6555
6604
|
import {
|
|
6556
6605
|
asSignedHydratedTransactionWithHashMeta,
|
|
@@ -6567,7 +6616,7 @@ var SimpleTransactionViewer = class extends AbstractCreatableProvider {
|
|
|
6567
6616
|
}
|
|
6568
6617
|
async byBlockHashAndIndex(blockHash, transactionIndex) {
|
|
6569
6618
|
return await this.spanAsync("byBlockHashAndIndex", async () => {
|
|
6570
|
-
|
|
6619
|
+
assertEx47(transactionIndex >= 0, () => "transactionIndex must be greater than or equal to 0");
|
|
6571
6620
|
try {
|
|
6572
6621
|
const block = await this.blockViewer.blockByHash(blockHash);
|
|
6573
6622
|
if (!block) return null;
|
|
@@ -6631,13 +6680,15 @@ SimpleTransactionViewer = __decorateClass([
|
|
|
6631
6680
|
|
|
6632
6681
|
// src/simple/windowedBlock/SimpleWindowedBlockViewer.ts
|
|
6633
6682
|
import {
|
|
6634
|
-
assertEx as
|
|
6683
|
+
assertEx as assertEx48,
|
|
6635
6684
|
exists as exists11,
|
|
6636
6685
|
isNull as isNull2
|
|
6637
6686
|
} from "@xylabs/sdk-js";
|
|
6687
|
+
import { MemoryMap as MemoryMap2 } from "@xyo-network/xl1-driver-memory";
|
|
6638
6688
|
import {
|
|
6639
|
-
asXL1BlockNumber as
|
|
6689
|
+
asXL1BlockNumber as asXL1BlockNumber12,
|
|
6640
6690
|
BlockViewerMoniker as BlockViewerMoniker7,
|
|
6691
|
+
stepSize as stepSize3,
|
|
6641
6692
|
WindowedBlockViewerMoniker as WindowedBlockViewerMoniker2
|
|
6642
6693
|
} from "@xyo-network/xl1-protocol-lib";
|
|
6643
6694
|
import { Mutex as Mutex2 } from "async-mutex";
|
|
@@ -6689,11 +6740,20 @@ var SimpleWindowedBlockViewer = class extends AbstractCreatableProvider {
|
|
|
6689
6740
|
let block = this._blockNumberMap.get(blockNumber);
|
|
6690
6741
|
while (block && (limit === void 0 || result.length < limit)) {
|
|
6691
6742
|
result.unshift(block);
|
|
6692
|
-
const previousBlockNumber =
|
|
6743
|
+
const previousBlockNumber = asXL1BlockNumber12(block[0].block - 1, true);
|
|
6693
6744
|
block = previousBlockNumber >= 0 ? this._blockNumberMap.get(previousBlockNumber) : void 0;
|
|
6694
6745
|
}
|
|
6695
6746
|
return result;
|
|
6696
6747
|
}
|
|
6748
|
+
blocksByStep(stepLevel, stepIndex) {
|
|
6749
|
+
const size = stepSize3(stepLevel);
|
|
6750
|
+
const start = stepIndex * size;
|
|
6751
|
+
const end = start + size - 1;
|
|
6752
|
+
return this._chain.filter((block) => {
|
|
6753
|
+
const blockNumber = block[0].block;
|
|
6754
|
+
return blockNumber >= start && blockNumber <= end;
|
|
6755
|
+
}).toReversed();
|
|
6756
|
+
}
|
|
6697
6757
|
blocksByTransactionHashes(hashes) {
|
|
6698
6758
|
return hashes.map((hash) => this._transactionHashMap.get(hash)).filter(exists11);
|
|
6699
6759
|
}
|
|
@@ -6702,22 +6762,22 @@ var SimpleWindowedBlockViewer = class extends AbstractCreatableProvider {
|
|
|
6702
6762
|
}
|
|
6703
6763
|
async createHandler() {
|
|
6704
6764
|
await super.createHandler();
|
|
6705
|
-
this._blockViewer =
|
|
6765
|
+
this._blockViewer = assertEx48(
|
|
6706
6766
|
this.params.blockViewer ?? await this.locator.getInstance(BlockViewerMoniker7),
|
|
6707
6767
|
() => "BlockViewer instance is required"
|
|
6708
6768
|
);
|
|
6709
|
-
this._blockHashMap = new
|
|
6710
|
-
this._blockNumberMap = new
|
|
6711
|
-
this._transactionHashMap = new
|
|
6769
|
+
this._blockHashMap = new MemoryMap2();
|
|
6770
|
+
this._blockNumberMap = new MemoryMap2();
|
|
6771
|
+
this._transactionHashMap = new MemoryMap2();
|
|
6712
6772
|
}
|
|
6713
6773
|
currentBlock() {
|
|
6714
|
-
return
|
|
6774
|
+
return assertEx48(this._chain.at(-1));
|
|
6715
6775
|
}
|
|
6716
6776
|
currentBlockHash() {
|
|
6717
|
-
return
|
|
6777
|
+
return assertEx48(this._chain.at(-1)?.[0]._hash);
|
|
6718
6778
|
}
|
|
6719
6779
|
currentBlockNumber() {
|
|
6720
|
-
return
|
|
6780
|
+
return assertEx48(this._chain.at(-1)?.[0].block);
|
|
6721
6781
|
}
|
|
6722
6782
|
async payloadByHash(hash) {
|
|
6723
6783
|
const payloads = await this.payloadsByHash([hash]);
|
|
@@ -6876,13 +6936,13 @@ var RuntimeStatusMonitor = class extends LoggerStatusReporter {
|
|
|
6876
6936
|
};
|
|
6877
6937
|
|
|
6878
6938
|
// src/time/primitives/xl1BlockNumberToEthBlockNumber.ts
|
|
6879
|
-
import { assertEx as
|
|
6939
|
+
import { assertEx as assertEx49 } from "@xylabs/sdk-js";
|
|
6880
6940
|
import { asTimePayload as asTimePayload3, TimeSchema as TimeSchema2 } from "@xyo-network/xl1-protocol-lib";
|
|
6881
6941
|
async function xl1BlockNumberToEthBlockNumber(context, xl1BlockNumber) {
|
|
6882
6942
|
const blockHash = await hashFromBlockNumber(context, xl1BlockNumber);
|
|
6883
6943
|
const hydratedBlock = await hydrateBlock(context, blockHash);
|
|
6884
6944
|
const timePayload = asTimePayload3(hydratedBlock[1].find((p) => p.schema === TimeSchema2), { required: true });
|
|
6885
|
-
return
|
|
6945
|
+
return assertEx49(timePayload.ethereum, () => "No ethereum timestamp found on block");
|
|
6886
6946
|
}
|
|
6887
6947
|
|
|
6888
6948
|
// src/validation/lib/isLocalhost.ts
|
|
@@ -6922,6 +6982,9 @@ var generateXyoBaseWalletFromPhrase = (walletPhrase) => {
|
|
|
6922
6982
|
const wallet = HDWallet.fromPhrase(walletPhrase, DEFAULT_WALLET_PATH);
|
|
6923
6983
|
return wallet;
|
|
6924
6984
|
};
|
|
6985
|
+
|
|
6986
|
+
// src/index.ts
|
|
6987
|
+
export * from "@xyo-network/xl1-driver-memory";
|
|
6925
6988
|
export {
|
|
6926
6989
|
ACCOUNT_TYPE,
|
|
6927
6990
|
ADDRESS_INDEX,
|
|
@@ -6934,6 +6997,7 @@ export {
|
|
|
6934
6997
|
BalancesStepSummarySchema,
|
|
6935
6998
|
BaseConfigContextZod,
|
|
6936
6999
|
BaseConfigZod,
|
|
7000
|
+
BlocksStepSummarySchema,
|
|
6937
7001
|
BoundWitnessHydrator,
|
|
6938
7002
|
BoundWitnessWithStorageMetaZod,
|
|
6939
7003
|
CHANGE_ADDRESS,
|
|
@@ -6961,8 +7025,6 @@ export {
|
|
|
6961
7025
|
HydratedCache,
|
|
6962
7026
|
JSONSchemaMetaSchema,
|
|
6963
7027
|
LoggerStatusReporter,
|
|
6964
|
-
LruCacheMap,
|
|
6965
|
-
MemoryMap,
|
|
6966
7028
|
MemoryPermissionsStore,
|
|
6967
7029
|
MissingCapabilityError,
|
|
6968
7030
|
MnemonicStringZod,
|
|
@@ -7042,6 +7104,8 @@ export {
|
|
|
7042
7104
|
asBalancesStepSummary,
|
|
7043
7105
|
asBalancesStepSummaryWithStorageMeta,
|
|
7044
7106
|
asBaseConfigContext,
|
|
7107
|
+
asBlocksStepSummary,
|
|
7108
|
+
asBlocksStepSummaryWithStorageMeta,
|
|
7045
7109
|
asBoundWitnessWithStorageMeta,
|
|
7046
7110
|
asChainIndexingServiceState,
|
|
7047
7111
|
asChainIndexingServiceStateWithStorageMeta,
|
|
@@ -7059,12 +7123,16 @@ export {
|
|
|
7059
7123
|
asTransfersStepSummaryWithStorageMeta,
|
|
7060
7124
|
backedFactory,
|
|
7061
7125
|
backingsSatisfied,
|
|
7126
|
+
balancesMaxStep,
|
|
7062
7127
|
balancesStepSummaryFromRange,
|
|
7063
7128
|
balancesSummary,
|
|
7064
7129
|
blockFromBlockNumber,
|
|
7065
7130
|
blockPayloadsFromHydratedBlock,
|
|
7066
7131
|
blockRangeSteps,
|
|
7067
7132
|
blockRate,
|
|
7133
|
+
blocksMaxStep,
|
|
7134
|
+
blocksStepSummaryFromRange,
|
|
7135
|
+
blocksStepSummaryKey,
|
|
7068
7136
|
buildTransaction,
|
|
7069
7137
|
buildUnsignedTransaction,
|
|
7070
7138
|
bundledPayloadToHydratedBlock,
|
|
@@ -7121,6 +7189,8 @@ export {
|
|
|
7121
7189
|
isBalancesStepSummary,
|
|
7122
7190
|
isBalancesStepSummaryWithStorageMeta,
|
|
7123
7191
|
isBaseConfigContext,
|
|
7192
|
+
isBlocksStepSummary,
|
|
7193
|
+
isBlocksStepSummaryWithStorageMeta,
|
|
7124
7194
|
isChainIndexingServiceState,
|
|
7125
7195
|
isChainIndexingServiceStateWithStorageMeta,
|
|
7126
7196
|
isCreatableProviderContext,
|
|
@@ -7162,6 +7232,7 @@ export {
|
|
|
7162
7232
|
resolveConfig,
|
|
7163
7233
|
resolveProviders,
|
|
7164
7234
|
rewardFromBlockNumber,
|
|
7235
|
+
schemasMaxStep,
|
|
7165
7236
|
schemasStepSummaryFromRange,
|
|
7166
7237
|
schemasSummary,
|
|
7167
7238
|
scoreUncle,
|
|
@@ -7195,6 +7266,7 @@ export {
|
|
|
7195
7266
|
transactionElevatedPayloads,
|
|
7196
7267
|
transactionRequiredGas,
|
|
7197
7268
|
transactionsFromHydratedBlock,
|
|
7269
|
+
transfersMaxStep,
|
|
7198
7270
|
transfersStepSummaryFromRange,
|
|
7199
7271
|
transfersSummary,
|
|
7200
7272
|
transfersSummaryKey,
|