@typeberry/lib 0.1.3-c2321fb → 0.1.3-ca63b35

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 (4) hide show
  1. package/index.cjs +314 -213
  2. package/index.d.ts +380 -238
  3. package/index.js +314 -213
  4. package/package.json +1 -1
package/index.js CHANGED
@@ -35,8 +35,9 @@ function parseCurrentVersion(env) {
35
35
  }
36
36
  }
37
37
  function parseCurrentSuite(env) {
38
- if (env === undefined)
38
+ if (env === undefined) {
39
39
  return undefined;
40
+ }
40
41
  switch (env) {
41
42
  case TestSuite.W3F_DAVXY:
42
43
  case TestSuite.JAMDUNA:
@@ -456,10 +457,12 @@ function deepEqual(actual, expected, { context = [], errorsCollector, ignore = [
456
457
  .sort((a, b) => {
457
458
  const aKey = `${a.key}`;
458
459
  const bKey = `${b.key}`;
459
- if (aKey < bKey)
460
+ if (aKey < bKey) {
460
461
  return -1;
461
- if (bKey < aKey)
462
+ }
463
+ if (bKey < aKey) {
462
464
  return 1;
465
+ }
463
466
  return 0;
464
467
  });
465
468
  };
@@ -4352,6 +4355,47 @@ var index$o = /*#__PURE__*/Object.freeze({
4352
4355
  keccak: keccak
4353
4356
  });
4354
4357
 
4358
+ /**
4359
+ * A utility class providing a readonly view over a portion of an array without copying it.
4360
+ */
4361
+ class ArrayView {
4362
+ start;
4363
+ end;
4364
+ source;
4365
+ length;
4366
+ constructor(source, start, end) {
4367
+ this.start = start;
4368
+ this.end = end;
4369
+ this.source = source;
4370
+ this.length = end - start;
4371
+ }
4372
+ static from(source, start = 0, end = source.length) {
4373
+ check `
4374
+ ${start >= 0 && end <= source.length && start <= end}
4375
+ Invalid start (${start})/end (${end}) for ArrayView
4376
+ `;
4377
+ return new ArrayView(source, start, end);
4378
+ }
4379
+ get(i) {
4380
+ check `
4381
+ ${i >= 0 && i < this.length}
4382
+ Index out of bounds: ${i} < ${this.length}
4383
+ `;
4384
+ return this.source[this.start + i];
4385
+ }
4386
+ subview(from, to = this.length) {
4387
+ return ArrayView.from(this.source, this.start + from, this.start + to);
4388
+ }
4389
+ toArray() {
4390
+ return this.source.slice(this.start, this.end);
4391
+ }
4392
+ *[Symbol.iterator]() {
4393
+ for (let i = this.start; i < this.end; i++) {
4394
+ yield this.source[i];
4395
+ }
4396
+ }
4397
+ }
4398
+
4355
4399
  /** A map which uses hashes as keys. */
4356
4400
  class HashDictionary {
4357
4401
  // TODO [ToDr] [crit] We can't use `TrieHash` directly in the map,
@@ -4939,6 +4983,7 @@ class TruncatedHashDictionary {
4939
4983
 
4940
4984
  var index$n = /*#__PURE__*/Object.freeze({
4941
4985
  __proto__: null,
4986
+ ArrayView: ArrayView,
4942
4987
  FixedSizeArray: FixedSizeArray,
4943
4988
  HashDictionary: HashDictionary,
4944
4989
  HashSet: HashSet,
@@ -8106,7 +8151,6 @@ const O = 8;
8106
8151
  const Q = 80;
8107
8152
  /** `W_T`: The size of a transfer memo in octets. */
8108
8153
  const W_T = 128;
8109
- // TODO [ToDr] Not sure where these should live yet :(
8110
8154
  /**
8111
8155
  * `J`: The maximum sum of dependency items in a work-report.
8112
8156
  *
@@ -8118,6 +8162,194 @@ const AUTHORIZATION_QUEUE_SIZE = Q;
8118
8162
  /** `O`: Maximal authorization pool size. */
8119
8163
  const MAX_AUTH_POOL_SIZE = O;
8120
8164
 
8165
+ const MAX_VALUE = 4294967295;
8166
+ const MIN_VALUE = -2147483648;
8167
+ const MAX_SHIFT_U32 = 32;
8168
+ const MAX_SHIFT_U64 = 64n;
8169
+
8170
+ /**
8171
+ * `B_S`: The basic minimum balance which all services require.
8172
+ *
8173
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
8174
+ */
8175
+ const BASE_SERVICE_BALANCE = 100n;
8176
+ /**
8177
+ * `B_I`: The additional minimum balance required per item of elective service state.
8178
+ *
8179
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
8180
+ */
8181
+ const ELECTIVE_ITEM_BALANCE = 10n;
8182
+ /**
8183
+ * `B_L`: The additional minimum balance required per octet of elective service state.
8184
+ *
8185
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
8186
+ */
8187
+ const ELECTIVE_BYTE_BALANCE = 1n;
8188
+ const zeroSizeHint = {
8189
+ bytes: 0,
8190
+ isExact: true,
8191
+ };
8192
+ /** 0-byte read, return given default value */
8193
+ const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
8194
+ /** Encode and decode object with leading version number. */
8195
+ const codecWithVersion = (val) => Descriptor.new("withVersion", {
8196
+ bytes: val.sizeHint.bytes + 8,
8197
+ isExact: false,
8198
+ }, (e, v) => {
8199
+ e.varU64(0n);
8200
+ val.encode(e, v);
8201
+ }, (d) => {
8202
+ const version = d.varU64();
8203
+ if (version !== 0n) {
8204
+ throw new Error("Non-zero version is not supported!");
8205
+ }
8206
+ return val.decode(d);
8207
+ }, (s) => {
8208
+ s.varU64();
8209
+ val.skip(s);
8210
+ });
8211
+ /**
8212
+ * Service account details.
8213
+ *
8214
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
8215
+ */
8216
+ class ServiceAccountInfo extends WithDebug {
8217
+ codeHash;
8218
+ balance;
8219
+ accumulateMinGas;
8220
+ onTransferMinGas;
8221
+ storageUtilisationBytes;
8222
+ gratisStorage;
8223
+ storageUtilisationCount;
8224
+ created;
8225
+ lastAccumulation;
8226
+ parentService;
8227
+ static Codec = codec$1.Class(ServiceAccountInfo, {
8228
+ codeHash: codec$1.bytes(HASH_SIZE).asOpaque(),
8229
+ balance: codec$1.u64,
8230
+ accumulateMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
8231
+ onTransferMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
8232
+ storageUtilisationBytes: codec$1.u64,
8233
+ gratisStorage: codec$1.u64,
8234
+ storageUtilisationCount: codec$1.u32,
8235
+ created: codec$1.u32.convert((x) => x, tryAsTimeSlot),
8236
+ lastAccumulation: codec$1.u32.convert((x) => x, tryAsTimeSlot),
8237
+ parentService: codec$1.u32.convert((x) => x, tryAsServiceId),
8238
+ });
8239
+ static create(a) {
8240
+ return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
8241
+ }
8242
+ /**
8243
+ * `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
8244
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
8245
+ */
8246
+ static calculateThresholdBalance(items, bytes, gratisStorage) {
8247
+ const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
8248
+ if (storageCost < 0n) {
8249
+ return tryAsU64(0);
8250
+ }
8251
+ if (storageCost >= 2n ** 64n) {
8252
+ return tryAsU64(2n ** 64n - 1n);
8253
+ }
8254
+ return tryAsU64(storageCost);
8255
+ }
8256
+ constructor(
8257
+ /** `a_c`: Hash of the service code. */
8258
+ codeHash,
8259
+ /** `a_b`: Current account balance. */
8260
+ balance,
8261
+ /** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
8262
+ accumulateMinGas,
8263
+ /** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
8264
+ onTransferMinGas,
8265
+ /** `a_o`: Total number of octets in storage. */
8266
+ storageUtilisationBytes,
8267
+ /** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
8268
+ gratisStorage,
8269
+ /** `a_i`: Number of items in storage. */
8270
+ storageUtilisationCount,
8271
+ /** `a_r`: Creation account time slot. */
8272
+ created,
8273
+ /** `a_a`: Most recent accumulation time slot. */
8274
+ lastAccumulation,
8275
+ /** `a_p`: Parent service ID. */
8276
+ parentService) {
8277
+ super();
8278
+ this.codeHash = codeHash;
8279
+ this.balance = balance;
8280
+ this.accumulateMinGas = accumulateMinGas;
8281
+ this.onTransferMinGas = onTransferMinGas;
8282
+ this.storageUtilisationBytes = storageUtilisationBytes;
8283
+ this.gratisStorage = gratisStorage;
8284
+ this.storageUtilisationCount = storageUtilisationCount;
8285
+ this.created = created;
8286
+ this.lastAccumulation = lastAccumulation;
8287
+ this.parentService = parentService;
8288
+ }
8289
+ }
8290
+ class PreimageItem extends WithDebug {
8291
+ hash;
8292
+ blob;
8293
+ static Codec = codec$1.Class(PreimageItem, {
8294
+ hash: codec$1.bytes(HASH_SIZE).asOpaque(),
8295
+ blob: codec$1.blob,
8296
+ });
8297
+ static create({ hash, blob }) {
8298
+ return new PreimageItem(hash, blob);
8299
+ }
8300
+ constructor(hash, blob) {
8301
+ super();
8302
+ this.hash = hash;
8303
+ this.blob = blob;
8304
+ }
8305
+ }
8306
+ class StorageItem extends WithDebug {
8307
+ key;
8308
+ value;
8309
+ static Codec = codec$1.Class(StorageItem, {
8310
+ key: codec$1.blob.convert((i) => i, (o) => asOpaqueType(o)),
8311
+ value: codec$1.blob,
8312
+ });
8313
+ static create({ key, value }) {
8314
+ return new StorageItem(key, value);
8315
+ }
8316
+ constructor(key, value) {
8317
+ super();
8318
+ this.key = key;
8319
+ this.value = value;
8320
+ }
8321
+ }
8322
+ const MAX_LOOKUP_HISTORY_SLOTS = 3;
8323
+ function tryAsLookupHistorySlots(items) {
8324
+ const knownSize = asKnownSize(items);
8325
+ if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
8326
+ throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
8327
+ }
8328
+ return knownSize;
8329
+ }
8330
+ /** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
8331
+ class LookupHistoryItem {
8332
+ hash;
8333
+ length;
8334
+ slots;
8335
+ constructor(hash, length,
8336
+ /**
8337
+ * Preimage availability history as a sequence of time slots.
8338
+ * See PreimageStatus and the following GP fragment for more details.
8339
+ * https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
8340
+ slots) {
8341
+ this.hash = hash;
8342
+ this.length = length;
8343
+ this.slots = slots;
8344
+ }
8345
+ static isRequested(item) {
8346
+ if ("slots" in item) {
8347
+ return item.slots.length === 0;
8348
+ }
8349
+ return item.length === 0;
8350
+ }
8351
+ }
8352
+
8121
8353
  /** Dictionary entry of services that auto-accumulate every block. */
8122
8354
  class AutoAccumulate {
8123
8355
  service;
@@ -8139,39 +8371,50 @@ class AutoAccumulate {
8139
8371
  }
8140
8372
  }
8141
8373
  /**
8142
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/11da0111da01?v=0.6.7
8374
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
8143
8375
  */
8144
8376
  class PrivilegedServices {
8145
8377
  manager;
8146
- authManager;
8147
- validatorsManager;
8378
+ delegator;
8379
+ registrar;
8380
+ assigners;
8148
8381
  autoAccumulateServices;
8382
+ /** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
8149
8383
  static Codec = codec$1.Class(PrivilegedServices, {
8150
8384
  manager: codec$1.u32.asOpaque(),
8151
- authManager: codecPerCore(codec$1.u32.asOpaque()),
8152
- validatorsManager: codec$1.u32.asOpaque(),
8385
+ assigners: codecPerCore(codec$1.u32.asOpaque()),
8386
+ delegator: codec$1.u32.asOpaque(),
8387
+ registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
8388
+ ? codec$1.u32.asOpaque()
8389
+ : ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
8153
8390
  autoAccumulateServices: readonlyArray(codec$1.sequenceVarLen(AutoAccumulate.Codec)),
8154
8391
  });
8155
- static create({ manager, authManager, validatorsManager, autoAccumulateServices }) {
8156
- return new PrivilegedServices(manager, authManager, validatorsManager, autoAccumulateServices);
8392
+ static create(a) {
8393
+ return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
8157
8394
  }
8158
8395
  constructor(
8159
8396
  /**
8160
- * `chi_m`: The first, χm, is the index of the manager service which is
8161
- * the service able to effect an alteration of χ from block to block,
8397
+ * `χ_M`: Manages alteration of χ from block to block,
8162
8398
  * as well as bestow services with storage deposit credits.
8163
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/11a40111a801?v=0.6.7
8399
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
8164
8400
  */
8165
8401
  manager,
8166
- /** `chi_a`: Manages authorization queue one for each core. */
8167
- authManager,
8168
- /** `chi_v`: Managers validator keys. */
8169
- validatorsManager,
8170
- /** `chi_g`: Dictionary of services that auto-accumulate every block with their gas limit. */
8402
+ /** `χ_V`: Managers validator keys. */
8403
+ delegator,
8404
+ /**
8405
+ * `χ_R`: Manages the creation of services in protected range.
8406
+ *
8407
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
8408
+ */
8409
+ registrar,
8410
+ /** `χ_A`: Manages authorization queue one for each core. */
8411
+ assigners,
8412
+ /** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
8171
8413
  autoAccumulateServices) {
8172
8414
  this.manager = manager;
8173
- this.authManager = authManager;
8174
- this.validatorsManager = validatorsManager;
8415
+ this.delegator = delegator;
8416
+ this.registrar = registrar;
8417
+ this.assigners = assigners;
8175
8418
  this.autoAccumulateServices = autoAccumulateServices;
8176
8419
  }
8177
8420
  }
@@ -8433,172 +8676,6 @@ class SafroleData {
8433
8676
  }
8434
8677
  }
8435
8678
 
8436
- /**
8437
- * `B_S`: The basic minimum balance which all services require.
8438
- *
8439
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
8440
- */
8441
- const BASE_SERVICE_BALANCE = 100n;
8442
- /**
8443
- * `B_I`: The additional minimum balance required per item of elective service state.
8444
- *
8445
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
8446
- */
8447
- const ELECTIVE_ITEM_BALANCE = 10n;
8448
- /**
8449
- * `B_L`: The additional minimum balance required per octet of elective service state.
8450
- *
8451
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
8452
- */
8453
- const ELECTIVE_BYTE_BALANCE = 1n;
8454
- const zeroSizeHint = {
8455
- bytes: 0,
8456
- isExact: true,
8457
- };
8458
- /** 0-byte read, return given default value */
8459
- const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
8460
- /**
8461
- * Service account details.
8462
- *
8463
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
8464
- */
8465
- class ServiceAccountInfo extends WithDebug {
8466
- codeHash;
8467
- balance;
8468
- accumulateMinGas;
8469
- onTransferMinGas;
8470
- storageUtilisationBytes;
8471
- gratisStorage;
8472
- storageUtilisationCount;
8473
- created;
8474
- lastAccumulation;
8475
- parentService;
8476
- static Codec = codec$1.Class(ServiceAccountInfo, {
8477
- codeHash: codec$1.bytes(HASH_SIZE).asOpaque(),
8478
- balance: codec$1.u64,
8479
- accumulateMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
8480
- onTransferMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
8481
- storageUtilisationBytes: codec$1.u64,
8482
- gratisStorage: codec$1.u64,
8483
- storageUtilisationCount: codec$1.u32,
8484
- created: codec$1.u32.convert((x) => x, tryAsTimeSlot),
8485
- lastAccumulation: codec$1.u32.convert((x) => x, tryAsTimeSlot),
8486
- parentService: codec$1.u32.convert((x) => x, tryAsServiceId),
8487
- });
8488
- static create(a) {
8489
- return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
8490
- }
8491
- /**
8492
- * `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
8493
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
8494
- */
8495
- static calculateThresholdBalance(items, bytes, gratisStorage) {
8496
- const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
8497
- if (storageCost < 0n) {
8498
- return tryAsU64(0);
8499
- }
8500
- if (storageCost >= 2n ** 64n) {
8501
- return tryAsU64(2n ** 64n - 1n);
8502
- }
8503
- return tryAsU64(storageCost);
8504
- }
8505
- constructor(
8506
- /** `a_c`: Hash of the service code. */
8507
- codeHash,
8508
- /** `a_b`: Current account balance. */
8509
- balance,
8510
- /** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
8511
- accumulateMinGas,
8512
- /** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
8513
- onTransferMinGas,
8514
- /** `a_o`: Total number of octets in storage. */
8515
- storageUtilisationBytes,
8516
- /** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
8517
- gratisStorage,
8518
- /** `a_i`: Number of items in storage. */
8519
- storageUtilisationCount,
8520
- /** `a_r`: Creation account time slot. */
8521
- created,
8522
- /** `a_a`: Most recent accumulation time slot. */
8523
- lastAccumulation,
8524
- /** `a_p`: Parent service ID. */
8525
- parentService) {
8526
- super();
8527
- this.codeHash = codeHash;
8528
- this.balance = balance;
8529
- this.accumulateMinGas = accumulateMinGas;
8530
- this.onTransferMinGas = onTransferMinGas;
8531
- this.storageUtilisationBytes = storageUtilisationBytes;
8532
- this.gratisStorage = gratisStorage;
8533
- this.storageUtilisationCount = storageUtilisationCount;
8534
- this.created = created;
8535
- this.lastAccumulation = lastAccumulation;
8536
- this.parentService = parentService;
8537
- }
8538
- }
8539
- class PreimageItem extends WithDebug {
8540
- hash;
8541
- blob;
8542
- static Codec = codec$1.Class(PreimageItem, {
8543
- hash: codec$1.bytes(HASH_SIZE).asOpaque(),
8544
- blob: codec$1.blob,
8545
- });
8546
- static create({ hash, blob }) {
8547
- return new PreimageItem(hash, blob);
8548
- }
8549
- constructor(hash, blob) {
8550
- super();
8551
- this.hash = hash;
8552
- this.blob = blob;
8553
- }
8554
- }
8555
- class StorageItem extends WithDebug {
8556
- key;
8557
- value;
8558
- static Codec = codec$1.Class(StorageItem, {
8559
- key: codec$1.blob.convert((i) => i, (o) => asOpaqueType(o)),
8560
- value: codec$1.blob,
8561
- });
8562
- static create({ key, value }) {
8563
- return new StorageItem(key, value);
8564
- }
8565
- constructor(key, value) {
8566
- super();
8567
- this.key = key;
8568
- this.value = value;
8569
- }
8570
- }
8571
- const MAX_LOOKUP_HISTORY_SLOTS = 3;
8572
- function tryAsLookupHistorySlots(items) {
8573
- const knownSize = asKnownSize(items);
8574
- if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
8575
- throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
8576
- }
8577
- return knownSize;
8578
- }
8579
- /** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
8580
- class LookupHistoryItem {
8581
- hash;
8582
- length;
8583
- slots;
8584
- constructor(hash, length,
8585
- /**
8586
- * Preimage availability history as a sequence of time slots.
8587
- * See PreimageStatus and the following GP fragment for more details.
8588
- * https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
8589
- slots) {
8590
- this.hash = hash;
8591
- this.length = length;
8592
- this.slots = slots;
8593
- }
8594
- static isRequested(item) {
8595
- if ("slots" in item) {
8596
- return item.slots.length === 0;
8597
- }
8598
- return item.length === 0;
8599
- }
8600
- }
8601
-
8602
8679
  /**
8603
8680
  * In addition to the entropy accumulator η_0, we retain
8604
8681
  * three additional historical values of the accumulator at
@@ -9406,8 +9483,9 @@ class InMemoryState extends WithDebug {
9406
9483
  epochRoot: Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
9407
9484
  privilegedServices: PrivilegedServices.create({
9408
9485
  manager: tryAsServiceId(0),
9409
- authManager: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
9410
- validatorsManager: tryAsServiceId(0),
9486
+ assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
9487
+ delegator: tryAsServiceId(0),
9488
+ registrar: tryAsServiceId(MAX_VALUE),
9411
9489
  autoAccumulateServices: [],
9412
9490
  }),
9413
9491
  accumulationOutputLog: SortedArray.fromArray(accumulationOutputComparator, []),
@@ -9466,6 +9544,7 @@ var index$g = /*#__PURE__*/Object.freeze({
9466
9544
  ValidatorStatistics: ValidatorStatistics,
9467
9545
  accumulationOutputComparator: accumulationOutputComparator,
9468
9546
  codecPerCore: codecPerCore,
9547
+ codecWithVersion: codecWithVersion,
9469
9548
  hashComparator: hashComparator,
9470
9549
  ignoreValueWithDefault: ignoreValueWithDefault,
9471
9550
  serviceDataCodec: serviceDataCodec,
@@ -9626,7 +9705,9 @@ var serialize;
9626
9705
  /** C(255, s): https://graypaper.fluffylabs.dev/#/85129da/383103383103?v=0.6.3 */
9627
9706
  serialize.serviceData = (serviceId) => ({
9628
9707
  key: stateKeys.serviceInfo(serviceId),
9629
- Codec: ServiceAccountInfo.Codec,
9708
+ Codec: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
9709
+ ? codecWithVersion(ServiceAccountInfo.Codec)
9710
+ : ServiceAccountInfo.Codec,
9630
9711
  });
9631
9712
  /** https://graypaper.fluffylabs.dev/#/85129da/384803384803?v=0.6.3 */
9632
9713
  serialize.serviceStorage = (blake2b, serviceId, key) => ({
@@ -12011,6 +12092,8 @@ var NewServiceError;
12011
12092
  NewServiceError[NewServiceError["InsufficientFunds"] = 0] = "InsufficientFunds";
12012
12093
  /** Service is not privileged to set gratis storage. */
12013
12094
  NewServiceError[NewServiceError["UnprivilegedService"] = 1] = "UnprivilegedService";
12095
+ /** Registrar attempting to create a service with already existing id. */
12096
+ NewServiceError[NewServiceError["RegistrarServiceIdAlreadyTaken"] = 2] = "RegistrarServiceIdAlreadyTaken";
12014
12097
  })(NewServiceError || (NewServiceError = {}));
12015
12098
  var UpdatePrivilegesError;
12016
12099
  (function (UpdatePrivilegesError) {
@@ -12201,7 +12284,7 @@ class AccumulationStateUpdate {
12201
12284
  if (from.privilegedServices !== null) {
12202
12285
  update.privilegedServices = PrivilegedServices.create({
12203
12286
  ...from.privilegedServices,
12204
- authManager: asKnownSize([...from.privilegedServices.authManager]),
12287
+ assigners: asKnownSize([...from.privilegedServices.assigners]),
12205
12288
  });
12206
12289
  }
12207
12290
  return update;
@@ -12402,7 +12485,7 @@ const HostCallResult = {
12402
12485
  OOB: tryAsU64(0xfffffffffffffffdn), // 2**64 - 3
12403
12486
  /** Index unknown. */
12404
12487
  WHO: tryAsU64(0xfffffffffffffffcn), // 2**64 - 4
12405
- /** Storage full. */
12488
+ /** Storage full or resource already allocated. */
12406
12489
  FULL: tryAsU64(0xfffffffffffffffbn), // 2**64 - 5
12407
12490
  /** Core index unknown. */
12408
12491
  CORE: tryAsU64(0xfffffffffffffffan), // 2**64 - 6
@@ -12410,7 +12493,7 @@ const HostCallResult = {
12410
12493
  CASH: tryAsU64(0xfffffffffffffff9n), // 2**64 - 7
12411
12494
  /** Gas limit too low. */
12412
12495
  LOW: tryAsU64(0xfffffffffffffff8n), // 2**64 - 8
12413
- /** The item is already solicited or cannot be forgotten. */
12496
+ /** The item is already solicited, cannot be forgotten or the operation is invalid due to privilege level. */
12414
12497
  HUH: tryAsU64(0xfffffffffffffff7n), // 2**64 - 9
12415
12498
  /** The return value indicating general success. */
12416
12499
  OK: tryAsU64(0n),
@@ -14445,11 +14528,6 @@ class BitOps {
14445
14528
  }
14446
14529
  }
14447
14530
 
14448
- const MAX_VALUE = 4294967295;
14449
- const MIN_VALUE = -2147483648;
14450
- const MAX_SHIFT_U32 = 32;
14451
- const MAX_SHIFT_U64 = 64n;
14452
-
14453
14531
  /**
14454
14532
  * Overflowing addition for two-complement representation of 32-bit signed numbers.
14455
14533
  */
@@ -16819,6 +16897,7 @@ var index$2 = /*#__PURE__*/Object.freeze({
16819
16897
 
16820
16898
  class JsonServiceInfo {
16821
16899
  static fromJson = json.object({
16900
+ ...(Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? { version: "number" } : {}),
16822
16901
  code_hash: fromJson.bytes32(),
16823
16902
  balance: json.fromNumber((x) => tryAsU64(x)),
16824
16903
  min_item_gas: json.fromNumber((x) => tryAsServiceGas(x)),
@@ -16843,6 +16922,7 @@ class JsonServiceInfo {
16843
16922
  parentService: parent_service,
16844
16923
  });
16845
16924
  });
16925
+ version;
16846
16926
  code_hash;
16847
16927
  balance;
16848
16928
  min_item_gas;
@@ -16877,23 +16957,35 @@ const lookupMetaFromJson = json.object({
16877
16957
  },
16878
16958
  value: json.array("number"),
16879
16959
  }, ({ key, value }) => new LookupHistoryItem(key.hash, key.length, value));
16960
+ const preimageStatusFromJson = json.object({
16961
+ hash: fromJson.bytes32(),
16962
+ status: json.array("number"),
16963
+ }, ({ hash, status }) => new LookupHistoryItem(hash, tryAsU32(0), status));
16880
16964
  class JsonService {
16881
16965
  static fromJson = json.object({
16882
16966
  id: "number",
16883
- data: {
16884
- service: JsonServiceInfo.fromJson,
16885
- preimages: json.optional(json.array(JsonPreimageItem.fromJson)),
16886
- storage: json.optional(json.array(JsonStorageItem.fromJson)),
16887
- lookup_meta: json.optional(json.array(lookupMetaFromJson)),
16888
- },
16967
+ data: Compatibility.isLessThan(GpVersion.V0_7_1)
16968
+ ? {
16969
+ service: JsonServiceInfo.fromJson,
16970
+ preimages: json.optional(json.array(JsonPreimageItem.fromJson)),
16971
+ storage: json.optional(json.array(JsonStorageItem.fromJson)),
16972
+ lookup_meta: json.optional(json.array(lookupMetaFromJson)),
16973
+ }
16974
+ : {
16975
+ service: JsonServiceInfo.fromJson,
16976
+ storage: json.optional(json.array(JsonStorageItem.fromJson)),
16977
+ preimages_blob: json.optional(json.array(JsonPreimageItem.fromJson)),
16978
+ preimages_status: json.optional(json.array(preimageStatusFromJson)),
16979
+ },
16889
16980
  }, ({ id, data }) => {
16981
+ const preimages = HashDictionary.fromEntries((data.preimages ?? data.preimages_blob ?? []).map((x) => [x.hash, x]));
16890
16982
  const lookupHistory = HashDictionary.new();
16891
- for (const item of data.lookup_meta ?? []) {
16983
+ for (const item of data.lookup_meta ?? data.preimages_status ?? []) {
16892
16984
  const data = lookupHistory.get(item.hash) ?? [];
16893
- data.push(item);
16985
+ const length = tryAsU32(preimages.get(item.hash)?.blob.length ?? item.length);
16986
+ data.push(new LookupHistoryItem(item.hash, length, item.slots));
16894
16987
  lookupHistory.set(item.hash, data);
16895
16988
  }
16896
- const preimages = HashDictionary.fromEntries((data.preimages ?? []).map((x) => [x.hash, x]));
16897
16989
  const storage = new Map();
16898
16990
  const entries = (data.storage ?? []).map(({ key, value }) => {
16899
16991
  const opaqueKey = asOpaqueType(key);
@@ -17065,8 +17157,12 @@ class JsonServiceStatistics {
17065
17157
  extrinsic_count: "number",
17066
17158
  accumulate_count: "number",
17067
17159
  accumulate_gas_used: json.fromNumber(tryAsServiceGas),
17068
- on_transfers_count: "number",
17069
- on_transfers_gas_used: json.fromNumber(tryAsServiceGas),
17160
+ ...(Compatibility.isLessThan(GpVersion.V0_7_1)
17161
+ ? {
17162
+ on_transfers_count: "number",
17163
+ on_transfers_gas_used: json.fromNumber(tryAsServiceGas),
17164
+ }
17165
+ : {}),
17070
17166
  }, ({ provided_count, provided_size, refinement_count, refinement_gas_used, imports, exports, extrinsic_size, extrinsic_count, accumulate_count, accumulate_gas_used, on_transfers_count, on_transfers_gas_used, }) => {
17071
17167
  return ServiceStatistics.create({
17072
17168
  providedCount: provided_count,
@@ -17079,8 +17175,8 @@ class JsonServiceStatistics {
17079
17175
  extrinsicCount: extrinsic_count,
17080
17176
  accumulateCount: accumulate_count,
17081
17177
  accumulateGasUsed: accumulate_gas_used,
17082
- onTransfersCount: on_transfers_count,
17083
- onTransfersGasUsed: on_transfers_gas_used,
17178
+ onTransfersCount: on_transfers_count ?? tryAsU32(0),
17179
+ onTransfersGasUsed: on_transfers_gas_used ?? tryAsServiceGas(0),
17084
17180
  });
17085
17181
  });
17086
17182
  provided_count;
@@ -17151,6 +17247,7 @@ const fullStateDumpFromJson = (spec) => json.object({
17151
17247
  chi_m: "number",
17152
17248
  chi_a: json.array("number"),
17153
17249
  chi_v: "number",
17250
+ chi_r: json.optional("number"),
17154
17251
  chi_g: json.nullable(json.array({
17155
17252
  service: "number",
17156
17253
  gasLimit: json.fromNumber((v) => tryAsServiceGas(v)),
@@ -17162,6 +17259,9 @@ const fullStateDumpFromJson = (spec) => json.object({
17162
17259
  theta: json.nullable(json.array(accumulationOutput)),
17163
17260
  accounts: json.array(JsonService.fromJson),
17164
17261
  }, ({ alpha, varphi, beta, gamma, psi, eta, iota, kappa, lambda, rho, tau, chi, pi, omega, xi, theta, accounts, }) => {
17262
+ if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) && chi.chi_r === undefined) {
17263
+ throw new Error("Registrar is required in Privileges GP ^0.7.1");
17264
+ }
17165
17265
  return InMemoryState.create({
17166
17266
  authPools: tryAsPerCore(alpha.map((perCore) => {
17167
17267
  if (perCore.length > MAX_AUTH_POOL_SIZE) {
@@ -17189,8 +17289,9 @@ const fullStateDumpFromJson = (spec) => json.object({
17189
17289
  timeslot: tau,
17190
17290
  privilegedServices: PrivilegedServices.create({
17191
17291
  manager: chi.chi_m,
17192
- authManager: chi.chi_a,
17193
- validatorsManager: chi.chi_v,
17292
+ assigners: chi.chi_a,
17293
+ delegator: chi.chi_v,
17294
+ registrar: chi.chi_r ?? tryAsServiceId(2 ** 32 - 1),
17194
17295
  autoAccumulateServices: chi.chi_g ?? [],
17195
17296
  }),
17196
17297
  statistics: JsonStatisticsData.toStatisticsData(spec, pi),