@typeberry/jam 0.2.0-8017bfd → 0.2.0-adde0dd

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.
@@ -3170,7 +3170,7 @@ function resultToString(res) {
3170
3170
  if (res.isOk) {
3171
3171
  return `OK: ${typeof res.ok === "symbol" ? res.ok.toString() : res.ok}`;
3172
3172
  }
3173
- return `${res.details}\nError: ${maybeTaggedErrorToString(res.error)}`;
3173
+ return `${res.details()}\nError: ${maybeTaggedErrorToString(res.error)}`;
3174
3174
  }
3175
3175
  /** An indication of two possible outcomes returned from a function. */
3176
3176
  const result_Result = {
@@ -3184,7 +3184,7 @@ const result_Result = {
3184
3184
  };
3185
3185
  },
3186
3186
  /** Create new [`Result`] with `Error` status. */
3187
- error: (error, details = "") => {
3187
+ error: (error, details) => {
3188
3188
  debug_check `${error !== undefined} 'Error' type cannot be undefined.`;
3189
3189
  return {
3190
3190
  isOk: false,
@@ -3303,7 +3303,7 @@ function deepEqual(actual, expected, { context = [], errorsCollector, ignore = [
3303
3303
  }
3304
3304
  if (actual.isError && expected.isError) {
3305
3305
  deepEqual(actual.error, expected.error, { context: ctx.concat(["error"]), errorsCollector: errors, ignore });
3306
- deepEqual(actual.details, expected.details, {
3306
+ deepEqual(actual.details(), expected.details(), {
3307
3307
  context: ctx.concat(["details"]),
3308
3308
  errorsCollector: errors,
3309
3309
  // display details when error does not match
@@ -10517,7 +10517,7 @@ class in_memory_state_InMemoryState extends WithDebug {
10517
10517
  const { kind } = update.action;
10518
10518
  const service = this.services.get(serviceId);
10519
10519
  if (service === undefined) {
10520
- return result_Result.error(in_memory_state_UpdateError.NoService, `Attempting to update storage of non-existing service: ${serviceId}`);
10520
+ return result_Result.error(in_memory_state_UpdateError.NoService, () => `Attempting to update storage of non-existing service: ${serviceId}`);
10521
10521
  }
10522
10522
  if (kind === UpdateStorageKind.Set) {
10523
10523
  const { key, value } = update.action.storage;
@@ -10545,14 +10545,14 @@ class in_memory_state_InMemoryState extends WithDebug {
10545
10545
  for (const [serviceId, updates] of preimagesUpdates.entries()) {
10546
10546
  const service = this.services.get(serviceId);
10547
10547
  if (service === undefined) {
10548
- return result_Result.error(in_memory_state_UpdateError.NoService, `Attempting to update preimage of non-existing service: ${serviceId}`);
10548
+ return result_Result.error(in_memory_state_UpdateError.NoService, () => `Attempting to update preimage of non-existing service: ${serviceId}`);
10549
10549
  }
10550
10550
  for (const update of updates) {
10551
10551
  const { kind } = update.action;
10552
10552
  if (kind === UpdatePreimageKind.Provide) {
10553
10553
  const { preimage, slot } = update.action;
10554
10554
  if (service.data.preimages.has(preimage.hash)) {
10555
- return result_Result.error(in_memory_state_UpdateError.PreimageExists, `Overwriting existing preimage at ${serviceId}: ${preimage}`);
10555
+ return result_Result.error(in_memory_state_UpdateError.PreimageExists, () => `Overwriting existing preimage at ${serviceId}: ${preimage}`);
10556
10556
  }
10557
10557
  service.data.preimages.set(preimage.hash, preimage);
10558
10558
  if (slot !== null) {
@@ -10603,7 +10603,7 @@ class in_memory_state_InMemoryState extends WithDebug {
10603
10603
  if (kind === UpdateServiceKind.Create) {
10604
10604
  const { lookupHistory } = update.action;
10605
10605
  if (this.services.has(serviceId)) {
10606
- return result_Result.error(in_memory_state_UpdateError.DuplicateService, `${serviceId} already exists!`);
10606
+ return result_Result.error(in_memory_state_UpdateError.DuplicateService, () => `${serviceId} already exists!`);
10607
10607
  }
10608
10608
  this.services.set(serviceId, new InMemoryService(serviceId, {
10609
10609
  info: account,
@@ -10615,7 +10615,7 @@ class in_memory_state_InMemoryState extends WithDebug {
10615
10615
  else if (kind === UpdateServiceKind.Update) {
10616
10616
  const existingService = this.services.get(serviceId);
10617
10617
  if (existingService === undefined) {
10618
- return result_Result.error(in_memory_state_UpdateError.NoService, `Cannot update ${serviceId} because it does not exist.`);
10618
+ return result_Result.error(in_memory_state_UpdateError.NoService, () => `Cannot update ${serviceId} because it does not exist.`);
10619
10619
  }
10620
10620
  existingService.data.info = account;
10621
10621
  }
@@ -12245,13 +12245,13 @@ class LeafDb {
12245
12245
  */
12246
12246
  static fromLeavesBlob(blob, db) {
12247
12247
  if (blob.length % TRIE_NODE_BYTES !== 0) {
12248
- return result_Result.error(LeafDbError.InvalidLeafData, `${blob.length} is not a multiply of ${TRIE_NODE_BYTES}: ${blob}`);
12248
+ return result_Result.error(LeafDbError.InvalidLeafData, () => `${blob.length} is not a multiply of ${TRIE_NODE_BYTES}: ${blob}`);
12249
12249
  }
12250
12250
  const leaves = SortedSet.fromArray(leafComparator, []);
12251
12251
  for (const nodeData of blob.chunks(TRIE_NODE_BYTES)) {
12252
12252
  const node = new TrieNode(nodeData.raw);
12253
12253
  if (node.getNodeType() === NodeType.Branch) {
12254
- return result_Result.error(LeafDbError.InvalidLeafData, `Branch node detected: ${nodeData}`);
12254
+ return result_Result.error(LeafDbError.InvalidLeafData, () => `Branch node detected: ${nodeData}`);
12255
12255
  }
12256
12256
  leaves.insert(node.asLeafNode());
12257
12257
  }
@@ -12970,7 +12970,7 @@ class LmdbStates {
12970
12970
  }
12971
12971
  catch (e) {
12972
12972
  logger.error `${e}`;
12973
- return result_Result.error(StateUpdateError.Commit);
12973
+ return result_Result.error(StateUpdateError.Commit, () => `Failed to commit state update: ${e}`);
12974
12974
  }
12975
12975
  return result_Result.ok(result_OK);
12976
12976
  }
@@ -13769,7 +13769,7 @@ class Preimages {
13769
13769
  }
13770
13770
  if (prevPreimage.requester > currPreimage.requester ||
13771
13771
  currPreimage.blob.compare(prevPreimage.blob).isLessOrEqual()) {
13772
- return Result.error(PreimagesErrorCode.PreimagesNotSortedUnique);
13772
+ return Result.error(PreimagesErrorCode.PreimagesNotSortedUnique, () => `Preimages not sorted/unique at index ${i}`);
13773
13773
  }
13774
13774
  }
13775
13775
  const { preimages, slot } = input;
@@ -13780,14 +13780,14 @@ class Preimages {
13780
13780
  const hash = this.blake2b.hashBytes(blob).asOpaque();
13781
13781
  const service = this.state.getService(requester);
13782
13782
  if (service === null) {
13783
- return Result.error(PreimagesErrorCode.AccountNotFound);
13783
+ return Result.error(PreimagesErrorCode.AccountNotFound, () => `Service not found: ${requester}`);
13784
13784
  }
13785
13785
  const hasPreimage = service.hasPreimage(hash);
13786
13786
  const slots = service.getLookupHistory(hash, tryAsU32(blob.length));
13787
13787
  // https://graypaper.fluffylabs.dev/#/5f542d7/181800181900
13788
13788
  // https://graypaper.fluffylabs.dev/#/5f542d7/116f0011a500
13789
13789
  if (hasPreimage || slots === null || !LookupHistoryItem.isRequested(slots)) {
13790
- return Result.error(PreimagesErrorCode.PreimageUnneeded);
13790
+ return Result.error(PreimagesErrorCode.PreimageUnneeded, () => `Preimage unneeded: requester=${requester}, hash=${hash}, hasPreimage=${hasPreimage}, isRequested=${slots !== null && LookupHistoryItem.isRequested(slots)}`);
13791
13791
  }
13792
13792
  // https://graypaper.fluffylabs.dev/#/5f542d7/18c00018f300
13793
13793
  const updates = pendingChanges.get(requester) ?? [];