@typeberry/convert 0.5.0-4da816c → 0.5.0-6a64d40

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.
Files changed (3) hide show
  1. package/index.js +43 -28
  2. package/index.js.map +1 -1
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -8860,6 +8860,10 @@ class TruncatedHashDictionary {
8860
8860
  const truncatedKey = getTruncatedKey(key);
8861
8861
  this.dict.delete(truncatedKey);
8862
8862
  }
8863
+ /** Iterator over keys of the dictionary. */
8864
+ keys() {
8865
+ return this.dict.keys();
8866
+ }
8863
8867
  /** Iterator over values of the dictionary. */
8864
8868
  values() {
8865
8869
  return this.dict.values();
@@ -10310,7 +10314,6 @@ class header_Header extends WithDebug {
10310
10314
  static create(h) {
10311
10315
  return Object.assign(header_Header.empty(), h);
10312
10316
  }
10313
- // TODO [ToDr] the fields should be readonly
10314
10317
  /**
10315
10318
  * `H_p`: Hash of the parent header.
10316
10319
  *
@@ -10497,8 +10500,7 @@ class Block extends WithDebug {
10497
10500
  }
10498
10501
  }
10499
10502
  function emptyBlock(slot = tryAsTimeSlot(0)) {
10500
- const header = Header.empty();
10501
- header.timeSlotIndex = slot;
10503
+ const header = Header.create({ ...Header.empty(), timeSlotIndex: slot });
10502
10504
  return Block.create({
10503
10505
  header,
10504
10506
  extrinsic: Extrinsic.create({
@@ -11095,21 +11097,22 @@ const headerFromJson = json.object({
11095
11097
  entropy_source: bandersnatchVrfSignature,
11096
11098
  seal: bandersnatchVrfSignature,
11097
11099
  }, ({ parent, parent_state_root, extrinsic_hash, slot, epoch_mark, tickets_mark, offenders_mark, author_index, entropy_source, seal, }) => {
11098
- const header = header_Header.empty();
11099
- header.parentHeaderHash = parent;
11100
- header.priorStateRoot = parent_state_root;
11101
- header.extrinsicHash = extrinsic_hash;
11102
- header.timeSlotIndex = slot;
11103
- header.epochMarker = epoch_mark ?? null;
11104
- header.ticketsMarker =
11105
- tickets_mark === undefined || tickets_mark === null
11106
- ? null
11107
- : TicketsMarker.create({ tickets: opaque_asOpaqueType(tickets_mark) });
11108
- header.offendersMarker = offenders_mark;
11109
- header.bandersnatchBlockAuthorIndex = author_index;
11110
- header.entropySource = entropy_source;
11111
- header.seal = seal;
11112
- return header;
11100
+ const epochMarker = epoch_mark ?? null;
11101
+ const ticketsMarker = tickets_mark === undefined || tickets_mark === null
11102
+ ? null
11103
+ : TicketsMarker.create({ tickets: opaque_asOpaqueType(tickets_mark) });
11104
+ return header_Header.create({
11105
+ parentHeaderHash: parent,
11106
+ priorStateRoot: parent_state_root,
11107
+ extrinsicHash: extrinsic_hash,
11108
+ timeSlotIndex: slot,
11109
+ epochMarker,
11110
+ ticketsMarker,
11111
+ offendersMarker: offenders_mark,
11112
+ bandersnatchBlockAuthorIndex: author_index,
11113
+ entropySource: entropy_source,
11114
+ seal,
11115
+ });
11113
11116
  });
11114
11117
 
11115
11118
  ;// CONCATENATED MODULE: ./packages/jam/block-json/block.ts
@@ -15667,14 +15670,14 @@ const stateEntriesSequenceCodec = sequenceVarLen(pair(bytes(TRUNCATED_HASH_SIZE)
15667
15670
  * State entries may be wrapped into `SerializedState` to access the contained values.
15668
15671
  */
15669
15672
  class state_entries_StateEntries {
15670
- entries;
15673
+ dictionary;
15671
15674
  static Codec = custom({
15672
15675
  name: "StateEntries",
15673
15676
  sizeHint: {
15674
15677
  isExact: false,
15675
15678
  bytes: TYPICAL_STATE_ITEMS * (hash_HASH_SIZE + TYPICAL_STATE_ITEM_LEN),
15676
15679
  },
15677
- }, (e, v) => stateEntriesSequenceCodec.encode(e, Array.from(v.entries)), (d) => state_entries_StateEntries.fromEntriesUnsafe(stateEntriesSequenceCodec.decode(d)), (s) => stateEntriesSequenceCodec.skip(s));
15680
+ }, (e, v) => stateEntriesSequenceCodec.encode(e, Array.from(v.dictionary)), (d) => state_entries_StateEntries.fromEntriesUnsafe(stateEntriesSequenceCodec.decode(d)), (s) => stateEntriesSequenceCodec.skip(s));
15678
15681
  /** Turn in-memory state into it's serialized form. */
15679
15682
  static serializeInMemory(spec, blake2b, state) {
15680
15683
  return new state_entries_StateEntries(convertInMemoryStateToDictionary(spec, blake2b, state));
@@ -15697,35 +15700,47 @@ class state_entries_StateEntries {
15697
15700
  static fromEntriesUnsafe(entries) {
15698
15701
  return new state_entries_StateEntries(TruncatedHashDictionary.fromEntries(entries));
15699
15702
  }
15700
- constructor(entries) {
15701
- this.entries = entries;
15703
+ constructor(dictionary) {
15704
+ this.dictionary = dictionary;
15702
15705
  }
15703
15706
  /** When comparing, we can safely ignore `trieCache` and just use entries. */
15704
15707
  [TEST_COMPARE_USING]() {
15705
- return Object.fromEntries(this.entries);
15708
+ return Object.fromEntries(this.dictionary);
15709
+ }
15710
+ /** Iterator over entries */
15711
+ entries() {
15712
+ return this.dictionary.entries();
15713
+ }
15714
+ /** Iterator over entries keys */
15715
+ *keys() {
15716
+ yield* this.dictionary.keys();
15717
+ }
15718
+ /** Iterator over entries values */
15719
+ *values() {
15720
+ yield* this.dictionary.values();
15706
15721
  }
15707
15722
  /** Dump state entries to JSON string (format compatible with stf vectors). */
15708
15723
  toString() {
15709
- return JSON.stringify(Array.from(this.entries.entries()).map(([key, value]) => ({
15724
+ return JSON.stringify(Array.from(this.entries()).map(([key, value]) => ({
15710
15725
  key,
15711
15726
  value,
15712
15727
  })), null, 2);
15713
15728
  }
15714
15729
  [Symbol.iterator]() {
15715
- return this.entries[Symbol.iterator]();
15730
+ return this.dictionary[Symbol.iterator]();
15716
15731
  }
15717
15732
  /** Retrieve value of some serialized key (if present). */
15718
15733
  get(key) {
15719
- return this.entries.get(key) ?? null;
15734
+ return this.dictionary.get(key) ?? null;
15720
15735
  }
15721
15736
  /** Modify underlying entries dictionary with given update. */
15722
15737
  applyUpdate(stateEntriesUpdate) {
15723
15738
  for (const [action, key, value] of stateEntriesUpdate) {
15724
15739
  if (action === StateEntryUpdateAction.Insert) {
15725
- this.entries.set(key, value);
15740
+ this.dictionary.set(key, value);
15726
15741
  }
15727
15742
  else if (action === StateEntryUpdateAction.Remove) {
15728
- this.entries.delete(key);
15743
+ this.dictionary.delete(key);
15729
15744
  }
15730
15745
  else {
15731
15746
  debug_assertNever(action);