@xyo-network/xl1-protocol-sdk 1.18.20 → 1.18.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/neutral/index.mjs +119 -110
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/primitives/chain/getWindowedChain.d.ts.map +1 -1
- package/dist/neutral/simple/accountBalance/SimpleAccountBalanceViewer.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/primitives/chain/getWindowedChain.ts +25 -22
- package/src/simple/accountBalance/SimpleAccountBalanceViewer.ts +87 -81
package/dist/neutral/index.mjs
CHANGED
|
@@ -1472,34 +1472,37 @@ var findEndBlockRecursive = async (viewer, startBlock, targetTimeMs, estimatedBl
|
|
|
1472
1472
|
import {
|
|
1473
1473
|
assertEx as assertEx11,
|
|
1474
1474
|
isDefined as isDefined6,
|
|
1475
|
-
isNull
|
|
1475
|
+
isNull,
|
|
1476
|
+
spanRootAsync
|
|
1476
1477
|
} from "@xylabs/sdk-js";
|
|
1477
1478
|
async function getWindowedChain(blockViewer, maxWindowSize, previousChain = []) {
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1479
|
+
return await spanRootAsync("getWindowedChain", async () => {
|
|
1480
|
+
const newChain = [];
|
|
1481
|
+
const previousChainByHash = new Map(previousChain.map((block) => [block[0]._hash, block]));
|
|
1482
|
+
const head = await blockViewer.currentBlock();
|
|
1483
|
+
let currentBlock = head;
|
|
1484
|
+
console.log("[getWindowedChain] Current Block:", currentBlock?.[0]._hash);
|
|
1485
|
+
while (currentBlock !== null && newChain.length < maxWindowSize) {
|
|
1486
|
+
const currentBlockNumber = currentBlock[0].block;
|
|
1487
|
+
const nextBlock = newChain[0];
|
|
1488
|
+
if (isDefined6(nextBlock)) {
|
|
1489
|
+
const nextBlockNumber = nextBlock[0].block;
|
|
1490
|
+
assertEx11(
|
|
1491
|
+
currentBlockNumber === nextBlockNumber - 1,
|
|
1492
|
+
() => `[getWindowedChain] Non-monotonic block sequence detected: current=${currentBlockNumber}, next=${nextBlockNumber}`
|
|
1493
|
+
);
|
|
1494
|
+
}
|
|
1488
1495
|
assertEx11(
|
|
1489
|
-
currentBlockNumber
|
|
1490
|
-
() => `[getWindowedChain]
|
|
1496
|
+
currentBlockNumber <= head[0].block,
|
|
1497
|
+
() => `[getWindowedChain] Current block number (${currentBlockNumber}) exceeds head block number (${head[0].block})`
|
|
1491
1498
|
);
|
|
1499
|
+
newChain.unshift(currentBlock);
|
|
1500
|
+
const previousBlockHash = currentBlock[0].previous;
|
|
1501
|
+
if (isNull(previousBlockHash)) break;
|
|
1502
|
+
currentBlock = previousChainByHash.get(previousBlockHash) ?? await blockViewer.blockByHash(previousBlockHash);
|
|
1492
1503
|
}
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
() => `[getWindowedChain] Current block number (${currentBlockNumber}) exceeds head block number (${head[0].block})`
|
|
1496
|
-
);
|
|
1497
|
-
newChain.unshift(currentBlock);
|
|
1498
|
-
const previousBlockHash = currentBlock[0].previous;
|
|
1499
|
-
if (isNull(previousBlockHash)) break;
|
|
1500
|
-
currentBlock = previousChainByHash.get(previousBlockHash) ?? await blockViewer.blockByHash(previousBlockHash);
|
|
1501
|
-
}
|
|
1502
|
-
return newChain;
|
|
1504
|
+
return newChain;
|
|
1505
|
+
}, { timeBudgetLimit: 100 });
|
|
1503
1506
|
}
|
|
1504
1507
|
|
|
1505
1508
|
// src/primitives/chain/step/chainStepRewardAddress.ts
|
|
@@ -3165,10 +3168,10 @@ async function balancesStepSummaryFromRange(context, range) {
|
|
|
3165
3168
|
}
|
|
3166
3169
|
|
|
3167
3170
|
// src/summary/primitives/balances/balancesSummary.ts
|
|
3168
|
-
import { asAddress as asAddress3, spanRootAsync } from "@xylabs/sdk-js";
|
|
3171
|
+
import { asAddress as asAddress3, spanRootAsync as spanRootAsync2 } from "@xylabs/sdk-js";
|
|
3169
3172
|
import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta2, asXL1BlockRange as asXL1BlockRange7 } from "@xyo-network/xl1-protocol";
|
|
3170
3173
|
async function balancesSummary(context, config) {
|
|
3171
|
-
return await
|
|
3174
|
+
return await spanRootAsync2("balancesSummary", async () => {
|
|
3172
3175
|
const [headHash] = isChainQualifiedHeadConfig(config) ? [config.head] : await context.head();
|
|
3173
3176
|
const headResult = await context.store.chainMap.get(headHash);
|
|
3174
3177
|
const headBoundWitness = asBlockBoundWitnessWithStorageMeta2(headResult, () => `Head block not found for hash: ${headHash}`);
|
|
@@ -3254,10 +3257,10 @@ async function schemasStepSummaryFromRange(context, range) {
|
|
|
3254
3257
|
}
|
|
3255
3258
|
|
|
3256
3259
|
// src/summary/primitives/schemas/schemasSummary.ts
|
|
3257
|
-
import { spanRootAsync as
|
|
3260
|
+
import { spanRootAsync as spanRootAsync3 } from "@xylabs/sdk-js";
|
|
3258
3261
|
import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta3, asXL1BlockRange as asXL1BlockRange8 } from "@xyo-network/xl1-protocol";
|
|
3259
3262
|
async function schemasSummary(context, config) {
|
|
3260
|
-
return await
|
|
3263
|
+
return await spanRootAsync3("schemasSummary", async () => {
|
|
3261
3264
|
const [headHash] = isChainQualifiedHeadConfig(config) ? [config.head] : await context.head();
|
|
3262
3265
|
const headResult = await context.store.chainMap.get(headHash);
|
|
3263
3266
|
const headBoundWitness = asBlockBoundWitnessWithStorageMeta3(headResult, () => `Head block not found for hash: ${headHash}`);
|
|
@@ -3284,10 +3287,10 @@ import { isAnyPayload as isAnyPayload3 } from "@xyo-network/payload-model";
|
|
|
3284
3287
|
import { StepSizes as StepSizes11 } from "@xyo-network/xl1-protocol";
|
|
3285
3288
|
|
|
3286
3289
|
// src/summary/primitives/transfers/transfersSummary.ts
|
|
3287
|
-
import { asAddress as asAddress4, spanRootAsync as
|
|
3290
|
+
import { asAddress as asAddress4, spanRootAsync as spanRootAsync4 } from "@xylabs/sdk-js";
|
|
3288
3291
|
import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta4, asXL1BlockRange as asXL1BlockRange9 } from "@xyo-network/xl1-protocol";
|
|
3289
3292
|
async function transfersSummary(context, config) {
|
|
3290
|
-
return await
|
|
3293
|
+
return await spanRootAsync4("transferSummary", async () => {
|
|
3291
3294
|
const [headHash] = isChainQualifiedHeadConfig(config) ? [config.head] : await context.head();
|
|
3292
3295
|
const headResult = await context.store.chainMap.get(headHash);
|
|
3293
3296
|
const headBoundWitness = asBlockBoundWitnessWithStorageMeta4(headResult, () => `Head block not found for hash: ${headHash}`);
|
|
@@ -3516,33 +3519,35 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
3516
3519
|
return (await this.qualifiedAccountBalanceHistories(addresses, config))[0];
|
|
3517
3520
|
}
|
|
3518
3521
|
async accountBalanceHistory(address, config) {
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
const
|
|
3526
|
-
|
|
3527
|
-
const
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3522
|
+
return await this.spanAsync("accountBalanceHistory", async () => {
|
|
3523
|
+
const range = isChainQualifiedRangeConfig(config) ? config.range : void 0;
|
|
3524
|
+
const startingRange = asXL1BlockRange10(range ?? [0, await this.blockViewer.currentBlockNumber()], true);
|
|
3525
|
+
const blockNumbers = await this.distillTransferHistory(address, startingRange);
|
|
3526
|
+
const blocks = (await Promise.all(blockNumbers.map(async (bn) => await this.blockViewer.blockByNumber(bn)))).filter(exists3);
|
|
3527
|
+
const result = [];
|
|
3528
|
+
for (const block of blocks) {
|
|
3529
|
+
const transferIndexes = block[0].payload_schemas.map((schema, index) => schema === TransferSchema2 ? index : void 0).filter(exists3);
|
|
3530
|
+
const transfers = transferIndexes.map((index) => {
|
|
3531
|
+
const hash = block[0].payload_hashes[index];
|
|
3532
|
+
return assertEx28(
|
|
3533
|
+
block[1].find((p) => p._hash === hash),
|
|
3534
|
+
() => `Error: Could not find Transfer with hash ${hash} in block ${block[0]._hash}`
|
|
3535
|
+
);
|
|
3536
|
+
}).filter(exists3).filter((t) => t.from === address || isDefined17(t.transfers[address]));
|
|
3537
|
+
if (transfers.length === 0) {
|
|
3538
|
+
continue;
|
|
3539
|
+
}
|
|
3540
|
+
const pairs = transfers.map((transfer) => {
|
|
3541
|
+
return [block[0], transfer];
|
|
3542
|
+
});
|
|
3543
|
+
result.push(...pairs.map(([block2, transfer]) => [
|
|
3544
|
+
block2,
|
|
3545
|
+
null,
|
|
3546
|
+
transfer
|
|
3547
|
+
]));
|
|
3535
3548
|
}
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
});
|
|
3539
|
-
result.push(...pairs.map(([block2, transfer]) => [
|
|
3540
|
-
block2,
|
|
3541
|
-
null,
|
|
3542
|
-
transfer
|
|
3543
|
-
]));
|
|
3544
|
-
}
|
|
3545
|
-
return result;
|
|
3549
|
+
return result;
|
|
3550
|
+
}, { timeBudgetLimit: 200 });
|
|
3546
3551
|
}
|
|
3547
3552
|
async accountBalances(address, config) {
|
|
3548
3553
|
const [result] = await this.qualifiedAccountBalances(address, config ?? {});
|
|
@@ -3606,68 +3611,72 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
3606
3611
|
]);
|
|
3607
3612
|
}
|
|
3608
3613
|
async distillTransferHistory(address, range, max = 50) {
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
const frames = deepCalculateFramesFromRange(asXL1BlockRange10(range, true));
|
|
3613
|
-
const transferSummaryPairs = await Promise.all(frames.map(
|
|
3614
|
-
async (frame) => {
|
|
3615
|
-
return [frame, await transfersStepSummaryFromRange(this.transfersSummaryContext, frame)];
|
|
3614
|
+
return await this.spanAsync("distillTransferHistory", async () => {
|
|
3615
|
+
if (range[1] - range[0] <= StepSizes12[0] || max <= 1) {
|
|
3616
|
+
return Array.from({ length: range[1] - range[0] + 1 }, (_, i) => range[1] - i).slice(0, max).map((n) => asXL1BlockNumber6(n, true));
|
|
3616
3617
|
}
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
});
|
|
3622
|
-
const resultBlockNumbers = /* @__PURE__ */ new Set();
|
|
3623
|
-
for (const [frame] of sortedTransferSummaryPairs) {
|
|
3624
|
-
if (frame[1] - frame[0] + 1 > StepSizes12[0]) {
|
|
3625
|
-
const values = await this.distillTransferHistory(address, asXL1BlockRange10([frame[0], frame[1] - 1], true), max - resultBlockNumbers.size);
|
|
3626
|
-
for (const value of values) {
|
|
3627
|
-
resultBlockNumbers.add(value);
|
|
3618
|
+
const frames = deepCalculateFramesFromRange(asXL1BlockRange10(range, true));
|
|
3619
|
+
const transferSummaryPairs = await Promise.all(frames.map(
|
|
3620
|
+
async (frame) => {
|
|
3621
|
+
return [frame, await transfersStepSummaryFromRange(this.transfersSummaryContext, frame)];
|
|
3628
3622
|
}
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3623
|
+
));
|
|
3624
|
+
const filteredTransferSummaryPairs = transferSummaryPairs.filter(([_, summary]) => Object.keys(summary.transfers).includes(address));
|
|
3625
|
+
const sortedTransferSummaryPairs = filteredTransferSummaryPairs.toSorted((a, b) => {
|
|
3626
|
+
return b[0][1] - a[0][1];
|
|
3627
|
+
});
|
|
3628
|
+
const resultBlockNumbers = /* @__PURE__ */ new Set();
|
|
3629
|
+
for (const [frame] of sortedTransferSummaryPairs) {
|
|
3630
|
+
if (frame[1] - frame[0] + 1 > StepSizes12[0]) {
|
|
3631
|
+
const values = await this.distillTransferHistory(address, asXL1BlockRange10([frame[0], frame[1] - 1], true), max - resultBlockNumbers.size);
|
|
3632
|
+
for (const value of values) {
|
|
3633
|
+
resultBlockNumbers.add(value);
|
|
3634
|
+
}
|
|
3635
|
+
resultBlockNumbers.add(frame[1]);
|
|
3636
|
+
} else {
|
|
3637
|
+
for (let i = frame[0]; i <= frame[1]; i++) {
|
|
3638
|
+
resultBlockNumbers.add(i);
|
|
3639
|
+
}
|
|
3640
|
+
}
|
|
3641
|
+
if (resultBlockNumbers.size >= max) {
|
|
3642
|
+
break;
|
|
3633
3643
|
}
|
|
3634
3644
|
}
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
}
|
|
3638
|
-
}
|
|
3639
|
-
return [...resultBlockNumbers].toSorted((a, b) => b - a).slice(0, max);
|
|
3645
|
+
return [...resultBlockNumbers].toSorted((a, b) => b - a).slice(0, max);
|
|
3646
|
+
}, { timeBudgetLimit: 200 });
|
|
3640
3647
|
}
|
|
3641
3648
|
async qualifiedAccountBalanceHistory(address, headOrRange) {
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
const
|
|
3651
|
-
|
|
3652
|
-
const
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3649
|
+
return await this.spanAsync("qualifiedAccountBalanceHistory", async () => {
|
|
3650
|
+
const range = asRange(headOrRange);
|
|
3651
|
+
const headHash = asHash5(headOrRange);
|
|
3652
|
+
const [head] = assertEx28(isDefined17(headHash) ? await this.blockViewer.blockByHash(headHash) : await this.blockViewer.currentBlock(), () => "Could not resolve head block");
|
|
3653
|
+
const startingRange = asXL1BlockRange10(range ?? [0, head.block], true);
|
|
3654
|
+
const blockNumbers = await this.distillTransferHistory(address, startingRange);
|
|
3655
|
+
const blocks = (await Promise.all(blockNumbers.map(async (bn) => await this.blockViewer.blockByNumber(bn)))).filter(exists3);
|
|
3656
|
+
const result = [];
|
|
3657
|
+
for (const block of blocks) {
|
|
3658
|
+
const transferIndexes = block[0].payload_schemas.map((schema, index) => schema === TransferSchema2 ? index : void 0).filter(exists3);
|
|
3659
|
+
const transfers = transferIndexes.map((index) => {
|
|
3660
|
+
const hash = block[0].payload_hashes[index];
|
|
3661
|
+
return assertEx28(
|
|
3662
|
+
block[1].find((p) => p._hash === hash),
|
|
3663
|
+
() => `Error: Could not find Transfer with hash ${hash} in block ${block[0]._hash}`
|
|
3664
|
+
);
|
|
3665
|
+
}).filter(exists3).filter((t) => t.from === address || isDefined17(t.transfers[address]));
|
|
3666
|
+
if (transfers.length === 0) {
|
|
3667
|
+
continue;
|
|
3668
|
+
}
|
|
3669
|
+
const pairs = transfers.map((transfer) => {
|
|
3670
|
+
return [block[0], transfer];
|
|
3671
|
+
});
|
|
3672
|
+
result.push(...pairs.map(([block2, transfer]) => [
|
|
3673
|
+
block2,
|
|
3674
|
+
null,
|
|
3675
|
+
transfer
|
|
3676
|
+
]));
|
|
3660
3677
|
}
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
});
|
|
3664
|
-
result.push(...pairs.map(([block2, transfer]) => [
|
|
3665
|
-
block2,
|
|
3666
|
-
null,
|
|
3667
|
-
transfer
|
|
3668
|
-
]));
|
|
3669
|
-
}
|
|
3670
|
-
return [result, { range: startingRange, head: head._hash }];
|
|
3678
|
+
return [result, { range: startingRange, head: head._hash }];
|
|
3679
|
+
}, { timeBudgetLimit: 200 });
|
|
3671
3680
|
}
|
|
3672
3681
|
};
|
|
3673
3682
|
__publicField(SimpleAccountBalanceViewer, "defaultMoniker", AccountBalanceViewerMoniker);
|