@xyo-network/xl1-protocol-sdk 1.18.21 → 1.18.23

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.
@@ -3060,7 +3060,7 @@ import {
3060
3060
  } from "@xylabs/sdk-js";
3061
3061
  import {
3062
3062
  asRange,
3063
- asXL1BlockNumber as asXL1BlockNumber6,
3063
+ asXL1BlockNumber as asXL1BlockNumber7,
3064
3064
  asXL1BlockRange as asXL1BlockRange10,
3065
3065
  AttoXL1 as AttoXL12,
3066
3066
  StepSizes as StepSizes12,
@@ -3104,74 +3104,79 @@ var isTransfersStepSummaryWithStorageMeta = (value) => {
3104
3104
  var asTransfersStepSummaryWithStorageMeta = AsObjectFactory7.create(isTransfersStepSummaryWithStorageMeta);
3105
3105
 
3106
3106
  // src/summary/primitives/balances/balancesStepSummaryFromRange.ts
3107
+ import { spanRootAsync as spanRootAsync2 } from "@xylabs/sdk-js";
3107
3108
  import { assertEx as assertEx25 } from "@xylabs/sdk-js";
3108
3109
  import { PayloadBuilder as PayloadBuilder14 } from "@xyo-network/payload-builder";
3109
3110
  import { isAnyPayload } from "@xyo-network/payload-model";
3110
- import { StepSizes as StepSizes9 } from "@xyo-network/xl1-protocol";
3111
+ import { asXL1BlockNumber as asXL1BlockNumber6, StepSizes as StepSizes9 } from "@xyo-network/xl1-protocol";
3111
3112
  async function balancesStepSummaryFromRange(context, range) {
3112
- const frameHeadHash = await hashFromBlockNumber(context, range[1]);
3113
- const frameSize = range[1] - range[0] + 1;
3114
- const [headHash] = await context.head();
3115
- let result = void 0;
3116
- if (frameSize === 1) {
3117
- const hash = await hashFromBlockNumber(context, range[0]);
3118
- const [, payloads] = await hydrateBlock(context.store, hash);
3119
- const balances = {};
3120
- for (const [address, balance] of Object.entries(netBalancesForPayloads(payloads))) {
3121
- balances[address] = toSignedBigInt(balance);
3122
- }
3123
- result = {
3124
- schema: BalancesStepSummarySchema,
3125
- hash: headHash,
3126
- stepSize: -1,
3127
- balances
3128
- };
3129
- } else {
3130
- const step = StepSizes9.indexOf(frameSize);
3131
- assertEx25(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes9.join(", ")}`);
3132
- const summaryResult = await context.summaryMap.get(`${frameHeadHash}|${frameSize}`);
3133
- if (isAnyPayload(summaryResult)) {
3134
- result = summaryResult;
3135
- } else {
3136
- await context.stepSemaphores[step].acquire();
3137
- try {
3138
- const subRanges = deepCalculateFramesFromRange(range, step - 1);
3139
- const promises = subRanges.map((subRange) => balancesStepSummaryFromRange(
3140
- context,
3141
- subRange
3142
- ));
3143
- const subResults = await Promise.all(promises);
3144
- const bigIntBalances = {};
3145
- for (const subResult of subResults) {
3146
- for (const [address, balance] of Object.entries(subResult.balances)) {
3147
- bigIntBalances[address] = (bigIntBalances[address] ?? 0n) + parseSignedBigInt(balance);
3148
- }
3149
- }
3113
+ const cacheKey = `${range[0]}|${range[1]}`;
3114
+ return await withContextCacheResponse(context, "balancesStepSummaryFromRange", cacheKey, async () => {
3115
+ return await spanRootAsync2("balancesStepSummaryFromRange", async () => {
3116
+ const frameHeadHash = await hashFromBlockNumber(context, range[1]);
3117
+ const frameSize = range[1] - range[0] + 1;
3118
+ const [headHash] = await context.head();
3119
+ const key = `${frameHeadHash}|${frameSize}`;
3120
+ return frameSize === 1 ? await spanRootAsync2(`balancesStepSummaryFromRange.frameSize=1[${key}]`, async () => {
3121
+ const hash = await hashFromBlockNumber(context, range[0]);
3122
+ const [, payloads] = await hydrateBlock(context.store, hash);
3150
3123
  const balances = {};
3151
- for (const [address, balance] of Object.entries(bigIntBalances)) {
3124
+ for (const [address, balance] of Object.entries(netBalancesForPayloads(payloads))) {
3152
3125
  balances[address] = toSignedBigInt(balance);
3153
3126
  }
3154
- result = {
3127
+ return await PayloadBuilder14.addHashMeta({
3155
3128
  schema: BalancesStepSummarySchema,
3156
- hash: frameHeadHash,
3157
- stepSize: frameSize,
3129
+ hash: headHash,
3130
+ stepSize: -1,
3158
3131
  balances
3159
- };
3160
- await context.summaryMap.set(`${frameHeadHash}|${frameSize}`, result);
3161
- } finally {
3162
- context.stepSemaphores[step].release();
3163
- }
3164
- }
3165
- }
3166
- const finalResult = await PayloadBuilder14.addStorageMeta(result);
3167
- return finalResult;
3132
+ });
3133
+ }, { timeBudgetLimit: 100 }) : await spanRootAsync2(`balancesStepSummaryFromRange.frameSize>1[${key}]`, async () => {
3134
+ const step = StepSizes9.indexOf(asXL1BlockNumber6(frameSize, true));
3135
+ assertEx25(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes9.join(", ")}`);
3136
+ const summaryResult = await context.summaryMap.get(key);
3137
+ if (isAnyPayload(summaryResult)) {
3138
+ return summaryResult;
3139
+ } else {
3140
+ await context.stepSemaphores[step].acquire();
3141
+ try {
3142
+ const subRanges = deepCalculateFramesFromRange(range, step - 1);
3143
+ const promises = subRanges.map((subRange) => balancesStepSummaryFromRange(
3144
+ context,
3145
+ subRange
3146
+ ));
3147
+ const subResults = await Promise.all(promises);
3148
+ const bigIntBalances = {};
3149
+ for (const subResult of subResults) {
3150
+ for (const [address, balance] of Object.entries(subResult.balances)) {
3151
+ bigIntBalances[address] = (bigIntBalances[address] ?? 0n) + parseSignedBigInt(balance);
3152
+ }
3153
+ }
3154
+ const balances = {};
3155
+ for (const [address, balance] of Object.entries(bigIntBalances)) {
3156
+ balances[address] = toSignedBigInt(balance);
3157
+ }
3158
+ const result = await PayloadBuilder14.addHashMeta({
3159
+ schema: BalancesStepSummarySchema,
3160
+ hash: frameHeadHash,
3161
+ stepSize: frameSize,
3162
+ balances
3163
+ });
3164
+ await context.summaryMap.set(key, result);
3165
+ return result;
3166
+ } finally {
3167
+ context.stepSemaphores[step].release();
3168
+ }
3169
+ }
3170
+ }, { timeBudgetLimit: 100 });
3171
+ }, { timeBudgetLimit: 200 });
3172
+ }, { max: 1e5, timeBudgetMs: 200 });
3168
3173
  }
3169
3174
 
3170
3175
  // src/summary/primitives/balances/balancesSummary.ts
3171
- import { asAddress as asAddress3, spanRootAsync as spanRootAsync2 } from "@xylabs/sdk-js";
3176
+ import { asAddress as asAddress3, spanRootAsync as spanRootAsync3 } from "@xylabs/sdk-js";
3172
3177
  import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta2, asXL1BlockRange as asXL1BlockRange7 } from "@xyo-network/xl1-protocol";
3173
3178
  async function balancesSummary(context, config) {
3174
- return await spanRootAsync2("balancesSummary", async () => {
3179
+ return await spanRootAsync3("balancesSummary", async () => {
3175
3180
  const [headHash] = isChainQualifiedHeadConfig(config) ? [config.head] : await context.head();
3176
3181
  const headResult = await context.store.chainMap.get(headHash);
3177
3182
  const headBoundWitness = asBlockBoundWitnessWithStorageMeta2(headResult, () => `Head block not found for hash: ${headHash}`);
@@ -3214,12 +3219,12 @@ async function schemasStepSummaryFromRange(context, range) {
3214
3219
  schemas[schema] = (schemas[schema] ?? 0) + 1;
3215
3220
  }
3216
3221
  }
3217
- result = {
3222
+ result = await PayloadBuilder15.addHashMeta({
3218
3223
  schema: SchemasStepSummarySchema,
3219
3224
  hash: headHash,
3220
3225
  stepSize: -1,
3221
3226
  schemas
3222
- };
3227
+ });
3223
3228
  } else {
3224
3229
  const step = StepSizes10.indexOf(frameSize);
3225
3230
  assertEx26(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes10.join(", ")}`);
@@ -3241,12 +3246,12 @@ async function schemasStepSummaryFromRange(context, range) {
3241
3246
  schemas[schema] = (schemas[schema] ?? 0) + count;
3242
3247
  }
3243
3248
  }
3244
- result = {
3249
+ result = await PayloadBuilder15.addHashMeta({
3245
3250
  schema: SchemasStepSummarySchema,
3246
3251
  hash: frameHeadHash,
3247
3252
  stepSize: frameSize,
3248
3253
  schemas
3249
- };
3254
+ });
3250
3255
  await context.summaryMap.set(`${frameHeadHash}|${frameSize}`, result);
3251
3256
  } finally {
3252
3257
  context.stepSemaphores[step].release();
@@ -3257,10 +3262,10 @@ async function schemasStepSummaryFromRange(context, range) {
3257
3262
  }
3258
3263
 
3259
3264
  // src/summary/primitives/schemas/schemasSummary.ts
3260
- import { spanRootAsync as spanRootAsync3 } from "@xylabs/sdk-js";
3265
+ import { spanRootAsync as spanRootAsync4 } from "@xylabs/sdk-js";
3261
3266
  import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta3, asXL1BlockRange as asXL1BlockRange8 } from "@xyo-network/xl1-protocol";
3262
3267
  async function schemasSummary(context, config) {
3263
- return await spanRootAsync3("schemasSummary", async () => {
3268
+ return await spanRootAsync4("schemasSummary", async () => {
3264
3269
  const [headHash] = isChainQualifiedHeadConfig(config) ? [config.head] : await context.head();
3265
3270
  const headResult = await context.store.chainMap.get(headHash);
3266
3271
  const headBoundWitness = asBlockBoundWitnessWithStorageMeta3(headResult, () => `Head block not found for hash: ${headHash}`);
@@ -3287,10 +3292,10 @@ import { isAnyPayload as isAnyPayload3 } from "@xyo-network/payload-model";
3287
3292
  import { StepSizes as StepSizes11 } from "@xyo-network/xl1-protocol";
3288
3293
 
3289
3294
  // src/summary/primitives/transfers/transfersSummary.ts
3290
- import { asAddress as asAddress4, spanRootAsync as spanRootAsync4 } from "@xylabs/sdk-js";
3295
+ import { asAddress as asAddress4, spanRootAsync as spanRootAsync5 } from "@xylabs/sdk-js";
3291
3296
  import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta4, asXL1BlockRange as asXL1BlockRange9 } from "@xyo-network/xl1-protocol";
3292
3297
  async function transfersSummary(context, config) {
3293
- return await spanRootAsync4("transferSummary", async () => {
3298
+ return await spanRootAsync5("transferSummary", async () => {
3294
3299
  const [headHash] = isChainQualifiedHeadConfig(config) ? [config.head] : await context.head();
3295
3300
  const headResult = await context.store.chainMap.get(headHash);
3296
3301
  const headBoundWitness = asBlockBoundWitnessWithStorageMeta4(headResult, () => `Head block not found for hash: ${headHash}`);
@@ -3334,12 +3339,12 @@ async function transfersStepSummaryFromRange(context, range) {
3334
3339
  transfers[from][to] = toSignedBigInt(amount);
3335
3340
  }
3336
3341
  }
3337
- result = {
3342
+ result = await PayloadBuilder16.addHashMeta({
3338
3343
  schema: TransfersStepSummarySchema,
3339
3344
  hash: headHash,
3340
3345
  stepSize: -1,
3341
3346
  transfers
3342
- };
3347
+ });
3343
3348
  } else {
3344
3349
  const step = StepSizes11.indexOf(frameSize);
3345
3350
  assertEx27(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes11.join(", ")}`);
@@ -3372,20 +3377,19 @@ async function transfersStepSummaryFromRange(context, range) {
3372
3377
  transfers[from][to] = toSignedBigInt(transfer);
3373
3378
  }
3374
3379
  }
3375
- result = {
3380
+ result = await PayloadBuilder16.addHashMeta({
3376
3381
  schema: TransfersStepSummarySchema,
3377
3382
  hash: frameHeadHash,
3378
3383
  stepSize: frameSize,
3379
3384
  transfers
3380
- };
3385
+ });
3381
3386
  await context.summaryMap.set(key, result);
3382
3387
  } finally {
3383
3388
  context.stepSemaphores[step].release();
3384
3389
  }
3385
3390
  }
3386
3391
  }
3387
- const finalResult = await PayloadBuilder16.addStorageMeta(result);
3388
- return finalResult;
3392
+ return result;
3389
3393
  }
3390
3394
 
3391
3395
  // src/viewers/AccountBalance.ts
@@ -3613,7 +3617,7 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
3613
3617
  async distillTransferHistory(address, range, max = 50) {
3614
3618
  return await this.spanAsync("distillTransferHistory", async () => {
3615
3619
  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));
3620
+ return Array.from({ length: range[1] - range[0] + 1 }, (_, i) => range[1] - i).slice(0, max).map((n) => asXL1BlockNumber7(n, true));
3617
3621
  }
3618
3622
  const frames = deepCalculateFramesFromRange(asXL1BlockRange10(range, true));
3619
3623
  const transferSummaryPairs = await Promise.all(frames.map(
@@ -3696,7 +3700,7 @@ import {
3696
3700
  import {
3697
3701
  asSignedHydratedBlockWithHashMeta,
3698
3702
  asSignedHydratedBlockWithStorageMeta,
3699
- asXL1BlockNumber as asXL1BlockNumber7
3703
+ asXL1BlockNumber as asXL1BlockNumber8
3700
3704
  } from "@xyo-network/xl1-protocol";
3701
3705
 
3702
3706
  // src/utils/HydratedCache.ts
@@ -3808,7 +3812,7 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
3808
3812
  while (current && blocks.length < limit) {
3809
3813
  blocks.push(current);
3810
3814
  if (current[0].block === 0) break;
3811
- const previousNumber = asXL1BlockNumber7(current[0].block - 1, true);
3815
+ const previousNumber = asXL1BlockNumber8(current[0].block - 1, true);
3812
3816
  current = await this.blockByNumber(previousNumber);
3813
3817
  }
3814
3818
  return blocks.map((b) => asSignedHydratedBlockWithHashMeta(b, true));
@@ -4318,7 +4322,7 @@ import {
4318
4322
  } from "@xylabs/sdk-js";
4319
4323
  import { PayloadBuilder as PayloadBuilder17 } from "@xyo-network/payload-builder";
4320
4324
  import {
4321
- asXL1BlockNumber as asXL1BlockNumber8,
4325
+ asXL1BlockNumber as asXL1BlockNumber9,
4322
4326
  TransferSchema as TransferSchema3
4323
4327
  } from "@xyo-network/xl1-protocol";
4324
4328
  var SimpleXyoGatewayRunner = class {
@@ -4352,8 +4356,8 @@ var SimpleXyoGatewayRunner = class {
4352
4356
  fees
4353
4357
  } = options ?? {};
4354
4358
  const resolvedChainId = isDefined19(chain) ? chain : await viewer.chainId();
4355
- const resolvedNbf = asXL1BlockNumber8(isDefined19(nbf) ? nbf : await viewer.currentBlockNumber(), true);
4356
- const resolvedExp = asXL1BlockNumber8(isDefined19(exp) ? exp : resolvedNbf + 10, true);
4359
+ const resolvedNbf = asXL1BlockNumber9(isDefined19(nbf) ? nbf : await viewer.currentBlockNumber(), true);
4360
+ const resolvedExp = asXL1BlockNumber9(isDefined19(exp) ? exp : resolvedNbf + 10, true);
4357
4361
  const tx = await buildUnsignedTransaction(resolvedChainId, onChain, offChain, resolvedNbf, resolvedExp, await (await this.signer()).address(), fees);
4358
4362
  return await this.addTransactionToChain(tx);
4359
4363
  }
@@ -4900,7 +4904,7 @@ import {
4900
4904
  } from "@xylabs/sdk-js";
4901
4905
  import {
4902
4906
  asTimePayload as asTimePayload2,
4903
- asXL1BlockNumber as asXL1BlockNumber9,
4907
+ asXL1BlockNumber as asXL1BlockNumber10,
4904
4908
  TimeSchema
4905
4909
  } from "@xyo-network/xl1-protocol";
4906
4910
  var SimpleTimeSyncViewer = class extends AbstractCreatableProvider {
@@ -4915,7 +4919,7 @@ var SimpleTimeSyncViewer = class extends AbstractCreatableProvider {
4915
4919
  async convertTime(fromDomain, toDomain, from) {
4916
4920
  switch (fromDomain) {
4917
4921
  case "xl1": {
4918
- const [block, payloads] = assertEx36(await this.blockViewer.blockByNumber(asXL1BlockNumber9(from, true)), () => "Block not found");
4922
+ const [block, payloads] = assertEx36(await this.blockViewer.blockByNumber(asXL1BlockNumber10(from, true)), () => "Block not found");
4919
4923
  const timeSchemaIndex = block.payload_schemas.indexOf(TimeSchema);
4920
4924
  const hash = timeSchemaIndex === -1 ? void 0 : block.payload_hashes[timeSchemaIndex];
4921
4925
  const timePayload = asTimePayload2(isDefined22(hash) ? payloads.find((p) => p._hash === hash) : void 0);
@@ -5013,7 +5017,7 @@ import {
5013
5017
  exists as exists7,
5014
5018
  isNull as isNull2
5015
5019
  } from "@xylabs/sdk-js";
5016
- import { asXL1BlockNumber as asXL1BlockNumber10 } from "@xyo-network/xl1-protocol";
5020
+ import { asXL1BlockNumber as asXL1BlockNumber11 } from "@xyo-network/xl1-protocol";
5017
5021
  import { Mutex } from "async-mutex";
5018
5022
  var SimpleWindowedBlockViewer = class extends AbstractCreatableProvider {
5019
5023
  moniker = WindowedBlockViewerMoniker;
@@ -5063,7 +5067,7 @@ var SimpleWindowedBlockViewer = class extends AbstractCreatableProvider {
5063
5067
  let block = this._blockNumberMap.get(blockNumber);
5064
5068
  while (block && (limit === void 0 || result.length < limit)) {
5065
5069
  result.unshift(block);
5066
- const previousBlockNumber = asXL1BlockNumber10(block[0].block - 1, true);
5070
+ const previousBlockNumber = asXL1BlockNumber11(block[0].block - 1, true);
5067
5071
  block = previousBlockNumber >= 0 ? this._blockNumberMap.get(previousBlockNumber) : void 0;
5068
5072
  }
5069
5073
  return result;