@typeberry/lib 0.5.0-5c5fc1c → 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.
- package/index.cjs +43 -28
- package/index.d.ts +19 -11
- package/index.js +43 -28
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -5523,6 +5523,10 @@ class TruncatedHashDictionary {
|
|
|
5523
5523
|
const truncatedKey = getTruncatedKey(key);
|
|
5524
5524
|
this.dict.delete(truncatedKey);
|
|
5525
5525
|
}
|
|
5526
|
+
/** Iterator over keys of the dictionary. */
|
|
5527
|
+
keys() {
|
|
5528
|
+
return this.dict.keys();
|
|
5529
|
+
}
|
|
5526
5530
|
/** Iterator over values of the dictionary. */
|
|
5527
5531
|
values() {
|
|
5528
5532
|
return this.dict.values();
|
|
@@ -6966,7 +6970,6 @@ class Header extends WithDebug {
|
|
|
6966
6970
|
static create(h) {
|
|
6967
6971
|
return Object.assign(Header.empty(), h);
|
|
6968
6972
|
}
|
|
6969
|
-
// TODO [ToDr] the fields should be readonly
|
|
6970
6973
|
/**
|
|
6971
6974
|
* `H_p`: Hash of the parent header.
|
|
6972
6975
|
*
|
|
@@ -7145,8 +7148,7 @@ class Block extends WithDebug {
|
|
|
7145
7148
|
}
|
|
7146
7149
|
}
|
|
7147
7150
|
function emptyBlock(slot = tryAsTimeSlot(0)) {
|
|
7148
|
-
const header = Header.empty();
|
|
7149
|
-
header.timeSlotIndex = slot;
|
|
7151
|
+
const header = Header.create({ ...Header.empty(), timeSlotIndex: slot });
|
|
7150
7152
|
return Block.create({
|
|
7151
7153
|
header,
|
|
7152
7154
|
extrinsic: Extrinsic.create({
|
|
@@ -7694,21 +7696,22 @@ const headerFromJson = json.object({
|
|
|
7694
7696
|
entropy_source: bandersnatchVrfSignature,
|
|
7695
7697
|
seal: bandersnatchVrfSignature,
|
|
7696
7698
|
}, ({ parent, parent_state_root, extrinsic_hash, slot, epoch_mark, tickets_mark, offenders_mark, author_index, entropy_source, seal, }) => {
|
|
7697
|
-
const
|
|
7698
|
-
|
|
7699
|
-
|
|
7700
|
-
|
|
7701
|
-
|
|
7702
|
-
|
|
7703
|
-
|
|
7704
|
-
|
|
7705
|
-
|
|
7706
|
-
|
|
7707
|
-
|
|
7708
|
-
|
|
7709
|
-
|
|
7710
|
-
|
|
7711
|
-
|
|
7699
|
+
const epochMarker = epoch_mark ?? null;
|
|
7700
|
+
const ticketsMarker = tickets_mark === undefined || tickets_mark === null
|
|
7701
|
+
? null
|
|
7702
|
+
: TicketsMarker.create({ tickets: asOpaqueType(tickets_mark) });
|
|
7703
|
+
return Header.create({
|
|
7704
|
+
parentHeaderHash: parent,
|
|
7705
|
+
priorStateRoot: parent_state_root,
|
|
7706
|
+
extrinsicHash: extrinsic_hash,
|
|
7707
|
+
timeSlotIndex: slot,
|
|
7708
|
+
epochMarker,
|
|
7709
|
+
ticketsMarker,
|
|
7710
|
+
offendersMarker: offenders_mark,
|
|
7711
|
+
bandersnatchBlockAuthorIndex: author_index,
|
|
7712
|
+
entropySource: entropy_source,
|
|
7713
|
+
seal,
|
|
7714
|
+
});
|
|
7712
7715
|
});
|
|
7713
7716
|
|
|
7714
7717
|
const blockFromJson = (spec) => json.object({
|
|
@@ -11504,14 +11507,14 @@ const stateEntriesSequenceCodec = sequenceVarLen(pair(bytes(TRUNCATED_HASH_SIZE)
|
|
|
11504
11507
|
* State entries may be wrapped into `SerializedState` to access the contained values.
|
|
11505
11508
|
*/
|
|
11506
11509
|
class StateEntries {
|
|
11507
|
-
|
|
11510
|
+
dictionary;
|
|
11508
11511
|
static Codec = custom({
|
|
11509
11512
|
name: "StateEntries",
|
|
11510
11513
|
sizeHint: {
|
|
11511
11514
|
isExact: false,
|
|
11512
11515
|
bytes: TYPICAL_STATE_ITEMS * (HASH_SIZE + TYPICAL_STATE_ITEM_LEN),
|
|
11513
11516
|
},
|
|
11514
|
-
}, (e, v) => stateEntriesSequenceCodec.encode(e, Array.from(v.
|
|
11517
|
+
}, (e, v) => stateEntriesSequenceCodec.encode(e, Array.from(v.dictionary)), (d) => StateEntries.fromEntriesUnsafe(stateEntriesSequenceCodec.decode(d)), (s) => stateEntriesSequenceCodec.skip(s));
|
|
11515
11518
|
/** Turn in-memory state into it's serialized form. */
|
|
11516
11519
|
static serializeInMemory(spec, blake2b, state) {
|
|
11517
11520
|
return new StateEntries(convertInMemoryStateToDictionary(spec, blake2b, state));
|
|
@@ -11534,35 +11537,47 @@ class StateEntries {
|
|
|
11534
11537
|
static fromEntriesUnsafe(entries) {
|
|
11535
11538
|
return new StateEntries(TruncatedHashDictionary.fromEntries(entries));
|
|
11536
11539
|
}
|
|
11537
|
-
constructor(
|
|
11538
|
-
this.
|
|
11540
|
+
constructor(dictionary) {
|
|
11541
|
+
this.dictionary = dictionary;
|
|
11539
11542
|
}
|
|
11540
11543
|
/** When comparing, we can safely ignore `trieCache` and just use entries. */
|
|
11541
11544
|
[TEST_COMPARE_USING]() {
|
|
11542
|
-
return Object.fromEntries(this.
|
|
11545
|
+
return Object.fromEntries(this.dictionary);
|
|
11546
|
+
}
|
|
11547
|
+
/** Iterator over entries */
|
|
11548
|
+
entries() {
|
|
11549
|
+
return this.dictionary.entries();
|
|
11550
|
+
}
|
|
11551
|
+
/** Iterator over entries keys */
|
|
11552
|
+
*keys() {
|
|
11553
|
+
yield* this.dictionary.keys();
|
|
11554
|
+
}
|
|
11555
|
+
/** Iterator over entries values */
|
|
11556
|
+
*values() {
|
|
11557
|
+
yield* this.dictionary.values();
|
|
11543
11558
|
}
|
|
11544
11559
|
/** Dump state entries to JSON string (format compatible with stf vectors). */
|
|
11545
11560
|
toString() {
|
|
11546
|
-
return JSON.stringify(Array.from(this.entries
|
|
11561
|
+
return JSON.stringify(Array.from(this.entries()).map(([key, value]) => ({
|
|
11547
11562
|
key,
|
|
11548
11563
|
value,
|
|
11549
11564
|
})), null, 2);
|
|
11550
11565
|
}
|
|
11551
11566
|
[Symbol.iterator]() {
|
|
11552
|
-
return this.
|
|
11567
|
+
return this.dictionary[Symbol.iterator]();
|
|
11553
11568
|
}
|
|
11554
11569
|
/** Retrieve value of some serialized key (if present). */
|
|
11555
11570
|
get(key) {
|
|
11556
|
-
return this.
|
|
11571
|
+
return this.dictionary.get(key) ?? null;
|
|
11557
11572
|
}
|
|
11558
11573
|
/** Modify underlying entries dictionary with given update. */
|
|
11559
11574
|
applyUpdate(stateEntriesUpdate) {
|
|
11560
11575
|
for (const [action, key, value] of stateEntriesUpdate) {
|
|
11561
11576
|
if (action === StateEntryUpdateAction.Insert) {
|
|
11562
|
-
this.
|
|
11577
|
+
this.dictionary.set(key, value);
|
|
11563
11578
|
}
|
|
11564
11579
|
else if (action === StateEntryUpdateAction.Remove) {
|
|
11565
|
-
this.
|
|
11580
|
+
this.dictionary.delete(key);
|
|
11566
11581
|
}
|
|
11567
11582
|
else {
|
|
11568
11583
|
assertNever(action);
|
package/index.d.ts
CHANGED
|
@@ -1960,6 +1960,8 @@ declare class TruncatedHashDictionary<T extends OpaqueHash, V> {
|
|
|
1960
1960
|
set(key: T | TruncatedHash, value: V): void;
|
|
1961
1961
|
/** Remove a value that matches the key on `TRUNCATED_HASH_SIZE`. */
|
|
1962
1962
|
delete(key: T | TruncatedHash): void;
|
|
1963
|
+
/** Iterator over keys of the dictionary. */
|
|
1964
|
+
keys(): Iterator<TruncatedHash, any, any> & Iterable<TruncatedHash>;
|
|
1963
1965
|
/** Iterator over values of the dictionary. */
|
|
1964
1966
|
values(): Iterator<V, any, any> & Iterable<V>;
|
|
1965
1967
|
/** Iterator over entries of the dictionary (with truncated keys) */
|
|
@@ -2767,35 +2769,35 @@ declare class Header extends WithDebug {
|
|
|
2767
2769
|
*
|
|
2768
2770
|
* In case of the genesis block, the hash will be zero.
|
|
2769
2771
|
*/
|
|
2770
|
-
parentHeaderHash: HeaderHash;
|
|
2772
|
+
readonly parentHeaderHash: HeaderHash;
|
|
2771
2773
|
/** `H_r`: The state trie root hash before executing that block. */
|
|
2772
|
-
priorStateRoot: StateRootHash;
|
|
2774
|
+
readonly priorStateRoot: StateRootHash;
|
|
2773
2775
|
/** `H_x`: The hash of block extrinsic. */
|
|
2774
|
-
extrinsicHash: ExtrinsicHash;
|
|
2776
|
+
readonly extrinsicHash: ExtrinsicHash;
|
|
2775
2777
|
/** `H_t`: JAM time-slot index. */
|
|
2776
|
-
timeSlotIndex: TimeSlot;
|
|
2778
|
+
readonly timeSlotIndex: TimeSlot;
|
|
2777
2779
|
/**
|
|
2778
2780
|
* `H_e`: Key and entropy relevant to the following epoch in case the ticket
|
|
2779
2781
|
* contest does not complete adequately.
|
|
2780
2782
|
*/
|
|
2781
|
-
epochMarker: EpochMarker | null;
|
|
2783
|
+
readonly epochMarker: EpochMarker | null;
|
|
2782
2784
|
/**
|
|
2783
2785
|
* `H_w`: Winning tickets provides the series of 600 slot sealing "tickets"
|
|
2784
2786
|
* for the next epoch.
|
|
2785
2787
|
*/
|
|
2786
|
-
ticketsMarker: TicketsMarker | null;
|
|
2788
|
+
readonly ticketsMarker: TicketsMarker | null;
|
|
2787
2789
|
/** `H_i`: Block author's index in the current validator set. */
|
|
2788
|
-
bandersnatchBlockAuthorIndex: ValidatorIndex;
|
|
2790
|
+
readonly bandersnatchBlockAuthorIndex: ValidatorIndex;
|
|
2789
2791
|
/** `H_v`: Entropy-yielding VRF signature. */
|
|
2790
|
-
entropySource: BandersnatchVrfSignature;
|
|
2792
|
+
readonly entropySource: BandersnatchVrfSignature;
|
|
2791
2793
|
/** `H_o`: Sequence of keys of newly misbehaving validators. */
|
|
2792
|
-
offendersMarker: Ed25519Key[];
|
|
2794
|
+
readonly offendersMarker: Ed25519Key[];
|
|
2793
2795
|
/**
|
|
2794
2796
|
* `H_s`: Block seal.
|
|
2795
2797
|
*
|
|
2796
2798
|
* https://graypaper.fluffylabs.dev/#/579bd12/0d0c010d1101
|
|
2797
2799
|
*/
|
|
2798
|
-
seal: BandersnatchVrfSignature;
|
|
2800
|
+
readonly seal: BandersnatchVrfSignature;
|
|
2799
2801
|
private constructor();
|
|
2800
2802
|
/** Create an empty header with some dummy values. */
|
|
2801
2803
|
static empty(): Header;
|
|
@@ -6237,7 +6239,7 @@ declare function serializeStateUpdate(spec: ChainSpec, blake2b: Blake2b, update:
|
|
|
6237
6239
|
* State entries may be wrapped into `SerializedState` to access the contained values.
|
|
6238
6240
|
*/
|
|
6239
6241
|
declare class StateEntries {
|
|
6240
|
-
private readonly
|
|
6242
|
+
private readonly dictionary;
|
|
6241
6243
|
static Codec: Descriptor<StateEntries, StateEntries>;
|
|
6242
6244
|
/** Turn in-memory state into it's serialized form. */
|
|
6243
6245
|
static serializeInMemory(spec: ChainSpec, blake2b: Blake2b, state: InMemoryState): StateEntries;
|
|
@@ -6258,6 +6260,12 @@ declare class StateEntries {
|
|
|
6258
6260
|
private constructor();
|
|
6259
6261
|
/** When comparing, we can safely ignore `trieCache` and just use entries. */
|
|
6260
6262
|
[TEST_COMPARE_USING](): any;
|
|
6263
|
+
/** Iterator over entries */
|
|
6264
|
+
entries(): Generator<[TruncatedHash, BytesBlob]>;
|
|
6265
|
+
/** Iterator over entries keys */
|
|
6266
|
+
keys(): Generator<TruncatedHash>;
|
|
6267
|
+
/** Iterator over entries values */
|
|
6268
|
+
values(): Generator<BytesBlob>;
|
|
6261
6269
|
/** Dump state entries to JSON string (format compatible with stf vectors). */
|
|
6262
6270
|
toString(): string;
|
|
6263
6271
|
[Symbol.iterator](): Generator<[TruncatedHash, BytesBlob], any, any>;
|
package/index.js
CHANGED
|
@@ -5520,6 +5520,10 @@ class TruncatedHashDictionary {
|
|
|
5520
5520
|
const truncatedKey = getTruncatedKey(key);
|
|
5521
5521
|
this.dict.delete(truncatedKey);
|
|
5522
5522
|
}
|
|
5523
|
+
/** Iterator over keys of the dictionary. */
|
|
5524
|
+
keys() {
|
|
5525
|
+
return this.dict.keys();
|
|
5526
|
+
}
|
|
5523
5527
|
/** Iterator over values of the dictionary. */
|
|
5524
5528
|
values() {
|
|
5525
5529
|
return this.dict.values();
|
|
@@ -6963,7 +6967,6 @@ class Header extends WithDebug {
|
|
|
6963
6967
|
static create(h) {
|
|
6964
6968
|
return Object.assign(Header.empty(), h);
|
|
6965
6969
|
}
|
|
6966
|
-
// TODO [ToDr] the fields should be readonly
|
|
6967
6970
|
/**
|
|
6968
6971
|
* `H_p`: Hash of the parent header.
|
|
6969
6972
|
*
|
|
@@ -7142,8 +7145,7 @@ class Block extends WithDebug {
|
|
|
7142
7145
|
}
|
|
7143
7146
|
}
|
|
7144
7147
|
function emptyBlock(slot = tryAsTimeSlot(0)) {
|
|
7145
|
-
const header = Header.empty();
|
|
7146
|
-
header.timeSlotIndex = slot;
|
|
7148
|
+
const header = Header.create({ ...Header.empty(), timeSlotIndex: slot });
|
|
7147
7149
|
return Block.create({
|
|
7148
7150
|
header,
|
|
7149
7151
|
extrinsic: Extrinsic.create({
|
|
@@ -7691,21 +7693,22 @@ const headerFromJson = json.object({
|
|
|
7691
7693
|
entropy_source: bandersnatchVrfSignature,
|
|
7692
7694
|
seal: bandersnatchVrfSignature,
|
|
7693
7695
|
}, ({ parent, parent_state_root, extrinsic_hash, slot, epoch_mark, tickets_mark, offenders_mark, author_index, entropy_source, seal, }) => {
|
|
7694
|
-
const
|
|
7695
|
-
|
|
7696
|
-
|
|
7697
|
-
|
|
7698
|
-
|
|
7699
|
-
|
|
7700
|
-
|
|
7701
|
-
|
|
7702
|
-
|
|
7703
|
-
|
|
7704
|
-
|
|
7705
|
-
|
|
7706
|
-
|
|
7707
|
-
|
|
7708
|
-
|
|
7696
|
+
const epochMarker = epoch_mark ?? null;
|
|
7697
|
+
const ticketsMarker = tickets_mark === undefined || tickets_mark === null
|
|
7698
|
+
? null
|
|
7699
|
+
: TicketsMarker.create({ tickets: asOpaqueType(tickets_mark) });
|
|
7700
|
+
return Header.create({
|
|
7701
|
+
parentHeaderHash: parent,
|
|
7702
|
+
priorStateRoot: parent_state_root,
|
|
7703
|
+
extrinsicHash: extrinsic_hash,
|
|
7704
|
+
timeSlotIndex: slot,
|
|
7705
|
+
epochMarker,
|
|
7706
|
+
ticketsMarker,
|
|
7707
|
+
offendersMarker: offenders_mark,
|
|
7708
|
+
bandersnatchBlockAuthorIndex: author_index,
|
|
7709
|
+
entropySource: entropy_source,
|
|
7710
|
+
seal,
|
|
7711
|
+
});
|
|
7709
7712
|
});
|
|
7710
7713
|
|
|
7711
7714
|
const blockFromJson = (spec) => json.object({
|
|
@@ -11501,14 +11504,14 @@ const stateEntriesSequenceCodec = sequenceVarLen(pair(bytes(TRUNCATED_HASH_SIZE)
|
|
|
11501
11504
|
* State entries may be wrapped into `SerializedState` to access the contained values.
|
|
11502
11505
|
*/
|
|
11503
11506
|
class StateEntries {
|
|
11504
|
-
|
|
11507
|
+
dictionary;
|
|
11505
11508
|
static Codec = custom({
|
|
11506
11509
|
name: "StateEntries",
|
|
11507
11510
|
sizeHint: {
|
|
11508
11511
|
isExact: false,
|
|
11509
11512
|
bytes: TYPICAL_STATE_ITEMS * (HASH_SIZE + TYPICAL_STATE_ITEM_LEN),
|
|
11510
11513
|
},
|
|
11511
|
-
}, (e, v) => stateEntriesSequenceCodec.encode(e, Array.from(v.
|
|
11514
|
+
}, (e, v) => stateEntriesSequenceCodec.encode(e, Array.from(v.dictionary)), (d) => StateEntries.fromEntriesUnsafe(stateEntriesSequenceCodec.decode(d)), (s) => stateEntriesSequenceCodec.skip(s));
|
|
11512
11515
|
/** Turn in-memory state into it's serialized form. */
|
|
11513
11516
|
static serializeInMemory(spec, blake2b, state) {
|
|
11514
11517
|
return new StateEntries(convertInMemoryStateToDictionary(spec, blake2b, state));
|
|
@@ -11531,35 +11534,47 @@ class StateEntries {
|
|
|
11531
11534
|
static fromEntriesUnsafe(entries) {
|
|
11532
11535
|
return new StateEntries(TruncatedHashDictionary.fromEntries(entries));
|
|
11533
11536
|
}
|
|
11534
|
-
constructor(
|
|
11535
|
-
this.
|
|
11537
|
+
constructor(dictionary) {
|
|
11538
|
+
this.dictionary = dictionary;
|
|
11536
11539
|
}
|
|
11537
11540
|
/** When comparing, we can safely ignore `trieCache` and just use entries. */
|
|
11538
11541
|
[TEST_COMPARE_USING]() {
|
|
11539
|
-
return Object.fromEntries(this.
|
|
11542
|
+
return Object.fromEntries(this.dictionary);
|
|
11543
|
+
}
|
|
11544
|
+
/** Iterator over entries */
|
|
11545
|
+
entries() {
|
|
11546
|
+
return this.dictionary.entries();
|
|
11547
|
+
}
|
|
11548
|
+
/** Iterator over entries keys */
|
|
11549
|
+
*keys() {
|
|
11550
|
+
yield* this.dictionary.keys();
|
|
11551
|
+
}
|
|
11552
|
+
/** Iterator over entries values */
|
|
11553
|
+
*values() {
|
|
11554
|
+
yield* this.dictionary.values();
|
|
11540
11555
|
}
|
|
11541
11556
|
/** Dump state entries to JSON string (format compatible with stf vectors). */
|
|
11542
11557
|
toString() {
|
|
11543
|
-
return JSON.stringify(Array.from(this.entries
|
|
11558
|
+
return JSON.stringify(Array.from(this.entries()).map(([key, value]) => ({
|
|
11544
11559
|
key,
|
|
11545
11560
|
value,
|
|
11546
11561
|
})), null, 2);
|
|
11547
11562
|
}
|
|
11548
11563
|
[Symbol.iterator]() {
|
|
11549
|
-
return this.
|
|
11564
|
+
return this.dictionary[Symbol.iterator]();
|
|
11550
11565
|
}
|
|
11551
11566
|
/** Retrieve value of some serialized key (if present). */
|
|
11552
11567
|
get(key) {
|
|
11553
|
-
return this.
|
|
11568
|
+
return this.dictionary.get(key) ?? null;
|
|
11554
11569
|
}
|
|
11555
11570
|
/** Modify underlying entries dictionary with given update. */
|
|
11556
11571
|
applyUpdate(stateEntriesUpdate) {
|
|
11557
11572
|
for (const [action, key, value] of stateEntriesUpdate) {
|
|
11558
11573
|
if (action === StateEntryUpdateAction.Insert) {
|
|
11559
|
-
this.
|
|
11574
|
+
this.dictionary.set(key, value);
|
|
11560
11575
|
}
|
|
11561
11576
|
else if (action === StateEntryUpdateAction.Remove) {
|
|
11562
|
-
this.
|
|
11577
|
+
this.dictionary.delete(key);
|
|
11563
11578
|
}
|
|
11564
11579
|
else {
|
|
11565
11580
|
assertNever(action);
|