@typeberry/lib 0.1.3-b635981 → 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 +268 -229
  2. package/index.d.ts +325 -260
  3. package/index.js +268 -229
  4. package/package.json +1 -1
package/index.cjs CHANGED
@@ -38,8 +38,9 @@ function parseCurrentVersion(env) {
38
38
  }
39
39
  }
40
40
  function parseCurrentSuite(env) {
41
- if (env === undefined)
41
+ if (env === undefined) {
42
42
  return undefined;
43
+ }
43
44
  switch (env) {
44
45
  case TestSuite.W3F_DAVXY:
45
46
  case TestSuite.JAMDUNA:
@@ -459,10 +460,12 @@ function deepEqual(actual, expected, { context = [], errorsCollector, ignore = [
459
460
  .sort((a, b) => {
460
461
  const aKey = `${a.key}`;
461
462
  const bKey = `${b.key}`;
462
- if (aKey < bKey)
463
+ if (aKey < bKey) {
463
464
  return -1;
464
- if (bKey < aKey)
465
+ }
466
+ if (bKey < aKey) {
465
467
  return 1;
468
+ }
466
469
  return 0;
467
470
  });
468
471
  };
@@ -8151,7 +8154,6 @@ const O = 8;
8151
8154
  const Q = 80;
8152
8155
  /** `W_T`: The size of a transfer memo in octets. */
8153
8156
  const W_T = 128;
8154
- // TODO [ToDr] Not sure where these should live yet :(
8155
8157
  /**
8156
8158
  * `J`: The maximum sum of dependency items in a work-report.
8157
8159
  *
@@ -8163,6 +8165,194 @@ const AUTHORIZATION_QUEUE_SIZE = Q;
8163
8165
  /** `O`: Maximal authorization pool size. */
8164
8166
  const MAX_AUTH_POOL_SIZE = O;
8165
8167
 
8168
+ const MAX_VALUE = 4294967295;
8169
+ const MIN_VALUE = -2147483648;
8170
+ const MAX_SHIFT_U32 = 32;
8171
+ const MAX_SHIFT_U64 = 64n;
8172
+
8173
+ /**
8174
+ * `B_S`: The basic minimum balance which all services require.
8175
+ *
8176
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
8177
+ */
8178
+ const BASE_SERVICE_BALANCE = 100n;
8179
+ /**
8180
+ * `B_I`: The additional minimum balance required per item of elective service state.
8181
+ *
8182
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
8183
+ */
8184
+ const ELECTIVE_ITEM_BALANCE = 10n;
8185
+ /**
8186
+ * `B_L`: The additional minimum balance required per octet of elective service state.
8187
+ *
8188
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
8189
+ */
8190
+ const ELECTIVE_BYTE_BALANCE = 1n;
8191
+ const zeroSizeHint = {
8192
+ bytes: 0,
8193
+ isExact: true,
8194
+ };
8195
+ /** 0-byte read, return given default value */
8196
+ const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
8197
+ /** Encode and decode object with leading version number. */
8198
+ const codecWithVersion = (val) => Descriptor.new("withVersion", {
8199
+ bytes: val.sizeHint.bytes + 8,
8200
+ isExact: false,
8201
+ }, (e, v) => {
8202
+ e.varU64(0n);
8203
+ val.encode(e, v);
8204
+ }, (d) => {
8205
+ const version = d.varU64();
8206
+ if (version !== 0n) {
8207
+ throw new Error("Non-zero version is not supported!");
8208
+ }
8209
+ return val.decode(d);
8210
+ }, (s) => {
8211
+ s.varU64();
8212
+ val.skip(s);
8213
+ });
8214
+ /**
8215
+ * Service account details.
8216
+ *
8217
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
8218
+ */
8219
+ class ServiceAccountInfo extends WithDebug {
8220
+ codeHash;
8221
+ balance;
8222
+ accumulateMinGas;
8223
+ onTransferMinGas;
8224
+ storageUtilisationBytes;
8225
+ gratisStorage;
8226
+ storageUtilisationCount;
8227
+ created;
8228
+ lastAccumulation;
8229
+ parentService;
8230
+ static Codec = codec$1.Class(ServiceAccountInfo, {
8231
+ codeHash: codec$1.bytes(HASH_SIZE).asOpaque(),
8232
+ balance: codec$1.u64,
8233
+ accumulateMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
8234
+ onTransferMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
8235
+ storageUtilisationBytes: codec$1.u64,
8236
+ gratisStorage: codec$1.u64,
8237
+ storageUtilisationCount: codec$1.u32,
8238
+ created: codec$1.u32.convert((x) => x, tryAsTimeSlot),
8239
+ lastAccumulation: codec$1.u32.convert((x) => x, tryAsTimeSlot),
8240
+ parentService: codec$1.u32.convert((x) => x, tryAsServiceId),
8241
+ });
8242
+ static create(a) {
8243
+ return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
8244
+ }
8245
+ /**
8246
+ * `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
8247
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
8248
+ */
8249
+ static calculateThresholdBalance(items, bytes, gratisStorage) {
8250
+ const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
8251
+ if (storageCost < 0n) {
8252
+ return tryAsU64(0);
8253
+ }
8254
+ if (storageCost >= 2n ** 64n) {
8255
+ return tryAsU64(2n ** 64n - 1n);
8256
+ }
8257
+ return tryAsU64(storageCost);
8258
+ }
8259
+ constructor(
8260
+ /** `a_c`: Hash of the service code. */
8261
+ codeHash,
8262
+ /** `a_b`: Current account balance. */
8263
+ balance,
8264
+ /** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
8265
+ accumulateMinGas,
8266
+ /** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
8267
+ onTransferMinGas,
8268
+ /** `a_o`: Total number of octets in storage. */
8269
+ storageUtilisationBytes,
8270
+ /** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
8271
+ gratisStorage,
8272
+ /** `a_i`: Number of items in storage. */
8273
+ storageUtilisationCount,
8274
+ /** `a_r`: Creation account time slot. */
8275
+ created,
8276
+ /** `a_a`: Most recent accumulation time slot. */
8277
+ lastAccumulation,
8278
+ /** `a_p`: Parent service ID. */
8279
+ parentService) {
8280
+ super();
8281
+ this.codeHash = codeHash;
8282
+ this.balance = balance;
8283
+ this.accumulateMinGas = accumulateMinGas;
8284
+ this.onTransferMinGas = onTransferMinGas;
8285
+ this.storageUtilisationBytes = storageUtilisationBytes;
8286
+ this.gratisStorage = gratisStorage;
8287
+ this.storageUtilisationCount = storageUtilisationCount;
8288
+ this.created = created;
8289
+ this.lastAccumulation = lastAccumulation;
8290
+ this.parentService = parentService;
8291
+ }
8292
+ }
8293
+ class PreimageItem extends WithDebug {
8294
+ hash;
8295
+ blob;
8296
+ static Codec = codec$1.Class(PreimageItem, {
8297
+ hash: codec$1.bytes(HASH_SIZE).asOpaque(),
8298
+ blob: codec$1.blob,
8299
+ });
8300
+ static create({ hash, blob }) {
8301
+ return new PreimageItem(hash, blob);
8302
+ }
8303
+ constructor(hash, blob) {
8304
+ super();
8305
+ this.hash = hash;
8306
+ this.blob = blob;
8307
+ }
8308
+ }
8309
+ class StorageItem extends WithDebug {
8310
+ key;
8311
+ value;
8312
+ static Codec = codec$1.Class(StorageItem, {
8313
+ key: codec$1.blob.convert((i) => i, (o) => asOpaqueType(o)),
8314
+ value: codec$1.blob,
8315
+ });
8316
+ static create({ key, value }) {
8317
+ return new StorageItem(key, value);
8318
+ }
8319
+ constructor(key, value) {
8320
+ super();
8321
+ this.key = key;
8322
+ this.value = value;
8323
+ }
8324
+ }
8325
+ const MAX_LOOKUP_HISTORY_SLOTS = 3;
8326
+ function tryAsLookupHistorySlots(items) {
8327
+ const knownSize = asKnownSize(items);
8328
+ if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
8329
+ throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
8330
+ }
8331
+ return knownSize;
8332
+ }
8333
+ /** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
8334
+ class LookupHistoryItem {
8335
+ hash;
8336
+ length;
8337
+ slots;
8338
+ constructor(hash, length,
8339
+ /**
8340
+ * Preimage availability history as a sequence of time slots.
8341
+ * See PreimageStatus and the following GP fragment for more details.
8342
+ * https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
8343
+ slots) {
8344
+ this.hash = hash;
8345
+ this.length = length;
8346
+ this.slots = slots;
8347
+ }
8348
+ static isRequested(item) {
8349
+ if ("slots" in item) {
8350
+ return item.slots.length === 0;
8351
+ }
8352
+ return item.length === 0;
8353
+ }
8354
+ }
8355
+
8166
8356
  /** Dictionary entry of services that auto-accumulate every block. */
8167
8357
  class AutoAccumulate {
8168
8358
  service;
@@ -8184,39 +8374,50 @@ class AutoAccumulate {
8184
8374
  }
8185
8375
  }
8186
8376
  /**
8187
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/11da0111da01?v=0.6.7
8377
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
8188
8378
  */
8189
8379
  class PrivilegedServices {
8190
8380
  manager;
8191
- authManager;
8192
- validatorsManager;
8381
+ delegator;
8382
+ registrar;
8383
+ assigners;
8193
8384
  autoAccumulateServices;
8385
+ /** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
8194
8386
  static Codec = codec$1.Class(PrivilegedServices, {
8195
8387
  manager: codec$1.u32.asOpaque(),
8196
- authManager: codecPerCore(codec$1.u32.asOpaque()),
8197
- validatorsManager: codec$1.u32.asOpaque(),
8388
+ assigners: codecPerCore(codec$1.u32.asOpaque()),
8389
+ delegator: codec$1.u32.asOpaque(),
8390
+ registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
8391
+ ? codec$1.u32.asOpaque()
8392
+ : ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
8198
8393
  autoAccumulateServices: readonlyArray(codec$1.sequenceVarLen(AutoAccumulate.Codec)),
8199
8394
  });
8200
- static create({ manager, authManager, validatorsManager, autoAccumulateServices }) {
8201
- return new PrivilegedServices(manager, authManager, validatorsManager, autoAccumulateServices);
8395
+ static create(a) {
8396
+ return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
8202
8397
  }
8203
8398
  constructor(
8204
8399
  /**
8205
- * `chi_m`: The first, χm, is the index of the manager service which is
8206
- * the service able to effect an alteration of χ from block to block,
8400
+ * `χ_M`: Manages alteration of χ from block to block,
8207
8401
  * as well as bestow services with storage deposit credits.
8208
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/11a40111a801?v=0.6.7
8402
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
8209
8403
  */
8210
8404
  manager,
8211
- /** `chi_a`: Manages authorization queue one for each core. */
8212
- authManager,
8213
- /** `chi_v`: Managers validator keys. */
8214
- validatorsManager,
8215
- /** `chi_g`: Dictionary of services that auto-accumulate every block with their gas limit. */
8405
+ /** `χ_V`: Managers validator keys. */
8406
+ delegator,
8407
+ /**
8408
+ * `χ_R`: Manages the creation of services in protected range.
8409
+ *
8410
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
8411
+ */
8412
+ registrar,
8413
+ /** `χ_A`: Manages authorization queue one for each core. */
8414
+ assigners,
8415
+ /** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
8216
8416
  autoAccumulateServices) {
8217
8417
  this.manager = manager;
8218
- this.authManager = authManager;
8219
- this.validatorsManager = validatorsManager;
8418
+ this.delegator = delegator;
8419
+ this.registrar = registrar;
8420
+ this.assigners = assigners;
8220
8421
  this.autoAccumulateServices = autoAccumulateServices;
8221
8422
  }
8222
8423
  }
@@ -8478,189 +8679,6 @@ class SafroleData {
8478
8679
  }
8479
8680
  }
8480
8681
 
8481
- /**
8482
- * `B_S`: The basic minimum balance which all services require.
8483
- *
8484
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
8485
- */
8486
- const BASE_SERVICE_BALANCE = 100n;
8487
- /**
8488
- * `B_I`: The additional minimum balance required per item of elective service state.
8489
- *
8490
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
8491
- */
8492
- const ELECTIVE_ITEM_BALANCE = 10n;
8493
- /**
8494
- * `B_L`: The additional minimum balance required per octet of elective service state.
8495
- *
8496
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
8497
- */
8498
- const ELECTIVE_BYTE_BALANCE = 1n;
8499
- const zeroSizeHint = {
8500
- bytes: 0,
8501
- isExact: true,
8502
- };
8503
- /** 0-byte read, return given default value */
8504
- const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
8505
- /** Encode and decode object with leading version number. */
8506
- const codecWithVersion = (val) => Descriptor.new("withVersion", {
8507
- bytes: val.sizeHint.bytes + 8,
8508
- isExact: false,
8509
- }, (e, v) => {
8510
- e.varU64(0n);
8511
- val.encode(e, v);
8512
- }, (d) => {
8513
- const version = d.varU64();
8514
- if (version !== 0n) {
8515
- throw new Error("Non-zero version is not supported!");
8516
- }
8517
- return val.decode(d);
8518
- }, (s) => {
8519
- s.varU64();
8520
- val.skip(s);
8521
- });
8522
- /**
8523
- * Service account details.
8524
- *
8525
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
8526
- */
8527
- class ServiceAccountInfo extends WithDebug {
8528
- codeHash;
8529
- balance;
8530
- accumulateMinGas;
8531
- onTransferMinGas;
8532
- storageUtilisationBytes;
8533
- gratisStorage;
8534
- storageUtilisationCount;
8535
- created;
8536
- lastAccumulation;
8537
- parentService;
8538
- static Codec = codec$1.Class(ServiceAccountInfo, {
8539
- codeHash: codec$1.bytes(HASH_SIZE).asOpaque(),
8540
- balance: codec$1.u64,
8541
- accumulateMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
8542
- onTransferMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
8543
- storageUtilisationBytes: codec$1.u64,
8544
- gratisStorage: codec$1.u64,
8545
- storageUtilisationCount: codec$1.u32,
8546
- created: codec$1.u32.convert((x) => x, tryAsTimeSlot),
8547
- lastAccumulation: codec$1.u32.convert((x) => x, tryAsTimeSlot),
8548
- parentService: codec$1.u32.convert((x) => x, tryAsServiceId),
8549
- });
8550
- static create(a) {
8551
- return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
8552
- }
8553
- /**
8554
- * `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
8555
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
8556
- */
8557
- static calculateThresholdBalance(items, bytes, gratisStorage) {
8558
- const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
8559
- if (storageCost < 0n) {
8560
- return tryAsU64(0);
8561
- }
8562
- if (storageCost >= 2n ** 64n) {
8563
- return tryAsU64(2n ** 64n - 1n);
8564
- }
8565
- return tryAsU64(storageCost);
8566
- }
8567
- constructor(
8568
- /** `a_c`: Hash of the service code. */
8569
- codeHash,
8570
- /** `a_b`: Current account balance. */
8571
- balance,
8572
- /** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
8573
- accumulateMinGas,
8574
- /** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
8575
- onTransferMinGas,
8576
- /** `a_o`: Total number of octets in storage. */
8577
- storageUtilisationBytes,
8578
- /** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
8579
- gratisStorage,
8580
- /** `a_i`: Number of items in storage. */
8581
- storageUtilisationCount,
8582
- /** `a_r`: Creation account time slot. */
8583
- created,
8584
- /** `a_a`: Most recent accumulation time slot. */
8585
- lastAccumulation,
8586
- /** `a_p`: Parent service ID. */
8587
- parentService) {
8588
- super();
8589
- this.codeHash = codeHash;
8590
- this.balance = balance;
8591
- this.accumulateMinGas = accumulateMinGas;
8592
- this.onTransferMinGas = onTransferMinGas;
8593
- this.storageUtilisationBytes = storageUtilisationBytes;
8594
- this.gratisStorage = gratisStorage;
8595
- this.storageUtilisationCount = storageUtilisationCount;
8596
- this.created = created;
8597
- this.lastAccumulation = lastAccumulation;
8598
- this.parentService = parentService;
8599
- }
8600
- }
8601
- class PreimageItem extends WithDebug {
8602
- hash;
8603
- blob;
8604
- static Codec = codec$1.Class(PreimageItem, {
8605
- hash: codec$1.bytes(HASH_SIZE).asOpaque(),
8606
- blob: codec$1.blob,
8607
- });
8608
- static create({ hash, blob }) {
8609
- return new PreimageItem(hash, blob);
8610
- }
8611
- constructor(hash, blob) {
8612
- super();
8613
- this.hash = hash;
8614
- this.blob = blob;
8615
- }
8616
- }
8617
- class StorageItem extends WithDebug {
8618
- key;
8619
- value;
8620
- static Codec = codec$1.Class(StorageItem, {
8621
- key: codec$1.blob.convert((i) => i, (o) => asOpaqueType(o)),
8622
- value: codec$1.blob,
8623
- });
8624
- static create({ key, value }) {
8625
- return new StorageItem(key, value);
8626
- }
8627
- constructor(key, value) {
8628
- super();
8629
- this.key = key;
8630
- this.value = value;
8631
- }
8632
- }
8633
- const MAX_LOOKUP_HISTORY_SLOTS = 3;
8634
- function tryAsLookupHistorySlots(items) {
8635
- const knownSize = asKnownSize(items);
8636
- if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
8637
- throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
8638
- }
8639
- return knownSize;
8640
- }
8641
- /** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
8642
- class LookupHistoryItem {
8643
- hash;
8644
- length;
8645
- slots;
8646
- constructor(hash, length,
8647
- /**
8648
- * Preimage availability history as a sequence of time slots.
8649
- * See PreimageStatus and the following GP fragment for more details.
8650
- * https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
8651
- slots) {
8652
- this.hash = hash;
8653
- this.length = length;
8654
- this.slots = slots;
8655
- }
8656
- static isRequested(item) {
8657
- if ("slots" in item) {
8658
- return item.slots.length === 0;
8659
- }
8660
- return item.length === 0;
8661
- }
8662
- }
8663
-
8664
8682
  /**
8665
8683
  * In addition to the entropy accumulator η_0, we retain
8666
8684
  * three additional historical values of the accumulator at
@@ -9468,8 +9486,9 @@ class InMemoryState extends WithDebug {
9468
9486
  epochRoot: Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
9469
9487
  privilegedServices: PrivilegedServices.create({
9470
9488
  manager: tryAsServiceId(0),
9471
- authManager: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
9472
- validatorsManager: tryAsServiceId(0),
9489
+ assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
9490
+ delegator: tryAsServiceId(0),
9491
+ registrar: tryAsServiceId(MAX_VALUE),
9473
9492
  autoAccumulateServices: [],
9474
9493
  }),
9475
9494
  accumulationOutputLog: SortedArray.fromArray(accumulationOutputComparator, []),
@@ -12076,6 +12095,8 @@ var NewServiceError;
12076
12095
  NewServiceError[NewServiceError["InsufficientFunds"] = 0] = "InsufficientFunds";
12077
12096
  /** Service is not privileged to set gratis storage. */
12078
12097
  NewServiceError[NewServiceError["UnprivilegedService"] = 1] = "UnprivilegedService";
12098
+ /** Registrar attempting to create a service with already existing id. */
12099
+ NewServiceError[NewServiceError["RegistrarServiceIdAlreadyTaken"] = 2] = "RegistrarServiceIdAlreadyTaken";
12079
12100
  })(NewServiceError || (NewServiceError = {}));
12080
12101
  var UpdatePrivilegesError;
12081
12102
  (function (UpdatePrivilegesError) {
@@ -12266,7 +12287,7 @@ class AccumulationStateUpdate {
12266
12287
  if (from.privilegedServices !== null) {
12267
12288
  update.privilegedServices = PrivilegedServices.create({
12268
12289
  ...from.privilegedServices,
12269
- authManager: asKnownSize([...from.privilegedServices.authManager]),
12290
+ assigners: asKnownSize([...from.privilegedServices.assigners]),
12270
12291
  });
12271
12292
  }
12272
12293
  return update;
@@ -12467,7 +12488,7 @@ const HostCallResult = {
12467
12488
  OOB: tryAsU64(0xfffffffffffffffdn), // 2**64 - 3
12468
12489
  /** Index unknown. */
12469
12490
  WHO: tryAsU64(0xfffffffffffffffcn), // 2**64 - 4
12470
- /** Storage full. */
12491
+ /** Storage full or resource already allocated. */
12471
12492
  FULL: tryAsU64(0xfffffffffffffffbn), // 2**64 - 5
12472
12493
  /** Core index unknown. */
12473
12494
  CORE: tryAsU64(0xfffffffffffffffan), // 2**64 - 6
@@ -12475,7 +12496,7 @@ const HostCallResult = {
12475
12496
  CASH: tryAsU64(0xfffffffffffffff9n), // 2**64 - 7
12476
12497
  /** Gas limit too low. */
12477
12498
  LOW: tryAsU64(0xfffffffffffffff8n), // 2**64 - 8
12478
- /** The item is already solicited or cannot be forgotten. */
12499
+ /** The item is already solicited, cannot be forgotten or the operation is invalid due to privilege level. */
12479
12500
  HUH: tryAsU64(0xfffffffffffffff7n), // 2**64 - 9
12480
12501
  /** The return value indicating general success. */
12481
12502
  OK: tryAsU64(0n),
@@ -14510,11 +14531,6 @@ class BitOps {
14510
14531
  }
14511
14532
  }
14512
14533
 
14513
- const MAX_VALUE = 4294967295;
14514
- const MIN_VALUE = -2147483648;
14515
- const MAX_SHIFT_U32 = 32;
14516
- const MAX_SHIFT_U64 = 64n;
14517
-
14518
14534
  /**
14519
14535
  * Overflowing addition for two-complement representation of 32-bit signed numbers.
14520
14536
  */
@@ -16884,6 +16900,7 @@ var index$2 = /*#__PURE__*/Object.freeze({
16884
16900
 
16885
16901
  class JsonServiceInfo {
16886
16902
  static fromJson = json.object({
16903
+ ...(Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? { version: "number" } : {}),
16887
16904
  code_hash: fromJson.bytes32(),
16888
16905
  balance: json.fromNumber((x) => tryAsU64(x)),
16889
16906
  min_item_gas: json.fromNumber((x) => tryAsServiceGas(x)),
@@ -16908,6 +16925,7 @@ class JsonServiceInfo {
16908
16925
  parentService: parent_service,
16909
16926
  });
16910
16927
  });
16928
+ version;
16911
16929
  code_hash;
16912
16930
  balance;
16913
16931
  min_item_gas;
@@ -16942,23 +16960,35 @@ const lookupMetaFromJson = json.object({
16942
16960
  },
16943
16961
  value: json.array("number"),
16944
16962
  }, ({ key, value }) => new LookupHistoryItem(key.hash, key.length, value));
16963
+ const preimageStatusFromJson = json.object({
16964
+ hash: fromJson.bytes32(),
16965
+ status: json.array("number"),
16966
+ }, ({ hash, status }) => new LookupHistoryItem(hash, tryAsU32(0), status));
16945
16967
  class JsonService {
16946
16968
  static fromJson = json.object({
16947
16969
  id: "number",
16948
- data: {
16949
- service: JsonServiceInfo.fromJson,
16950
- preimages: json.optional(json.array(JsonPreimageItem.fromJson)),
16951
- storage: json.optional(json.array(JsonStorageItem.fromJson)),
16952
- lookup_meta: json.optional(json.array(lookupMetaFromJson)),
16953
- },
16970
+ data: Compatibility.isLessThan(GpVersion.V0_7_1)
16971
+ ? {
16972
+ service: JsonServiceInfo.fromJson,
16973
+ preimages: json.optional(json.array(JsonPreimageItem.fromJson)),
16974
+ storage: json.optional(json.array(JsonStorageItem.fromJson)),
16975
+ lookup_meta: json.optional(json.array(lookupMetaFromJson)),
16976
+ }
16977
+ : {
16978
+ service: JsonServiceInfo.fromJson,
16979
+ storage: json.optional(json.array(JsonStorageItem.fromJson)),
16980
+ preimages_blob: json.optional(json.array(JsonPreimageItem.fromJson)),
16981
+ preimages_status: json.optional(json.array(preimageStatusFromJson)),
16982
+ },
16954
16983
  }, ({ id, data }) => {
16984
+ const preimages = HashDictionary.fromEntries((data.preimages ?? data.preimages_blob ?? []).map((x) => [x.hash, x]));
16955
16985
  const lookupHistory = HashDictionary.new();
16956
- for (const item of data.lookup_meta ?? []) {
16986
+ for (const item of data.lookup_meta ?? data.preimages_status ?? []) {
16957
16987
  const data = lookupHistory.get(item.hash) ?? [];
16958
- data.push(item);
16988
+ const length = tryAsU32(preimages.get(item.hash)?.blob.length ?? item.length);
16989
+ data.push(new LookupHistoryItem(item.hash, length, item.slots));
16959
16990
  lookupHistory.set(item.hash, data);
16960
16991
  }
16961
- const preimages = HashDictionary.fromEntries((data.preimages ?? []).map((x) => [x.hash, x]));
16962
16992
  const storage = new Map();
16963
16993
  const entries = (data.storage ?? []).map(({ key, value }) => {
16964
16994
  const opaqueKey = asOpaqueType(key);
@@ -17130,8 +17160,12 @@ class JsonServiceStatistics {
17130
17160
  extrinsic_count: "number",
17131
17161
  accumulate_count: "number",
17132
17162
  accumulate_gas_used: json.fromNumber(tryAsServiceGas),
17133
- on_transfers_count: "number",
17134
- on_transfers_gas_used: json.fromNumber(tryAsServiceGas),
17163
+ ...(Compatibility.isLessThan(GpVersion.V0_7_1)
17164
+ ? {
17165
+ on_transfers_count: "number",
17166
+ on_transfers_gas_used: json.fromNumber(tryAsServiceGas),
17167
+ }
17168
+ : {}),
17135
17169
  }, ({ 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, }) => {
17136
17170
  return ServiceStatistics.create({
17137
17171
  providedCount: provided_count,
@@ -17144,8 +17178,8 @@ class JsonServiceStatistics {
17144
17178
  extrinsicCount: extrinsic_count,
17145
17179
  accumulateCount: accumulate_count,
17146
17180
  accumulateGasUsed: accumulate_gas_used,
17147
- onTransfersCount: on_transfers_count,
17148
- onTransfersGasUsed: on_transfers_gas_used,
17181
+ onTransfersCount: on_transfers_count ?? tryAsU32(0),
17182
+ onTransfersGasUsed: on_transfers_gas_used ?? tryAsServiceGas(0),
17149
17183
  });
17150
17184
  });
17151
17185
  provided_count;
@@ -17216,6 +17250,7 @@ const fullStateDumpFromJson = (spec) => json.object({
17216
17250
  chi_m: "number",
17217
17251
  chi_a: json.array("number"),
17218
17252
  chi_v: "number",
17253
+ chi_r: json.optional("number"),
17219
17254
  chi_g: json.nullable(json.array({
17220
17255
  service: "number",
17221
17256
  gasLimit: json.fromNumber((v) => tryAsServiceGas(v)),
@@ -17227,6 +17262,9 @@ const fullStateDumpFromJson = (spec) => json.object({
17227
17262
  theta: json.nullable(json.array(accumulationOutput)),
17228
17263
  accounts: json.array(JsonService.fromJson),
17229
17264
  }, ({ alpha, varphi, beta, gamma, psi, eta, iota, kappa, lambda, rho, tau, chi, pi, omega, xi, theta, accounts, }) => {
17265
+ if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) && chi.chi_r === undefined) {
17266
+ throw new Error("Registrar is required in Privileges GP ^0.7.1");
17267
+ }
17230
17268
  return InMemoryState.create({
17231
17269
  authPools: tryAsPerCore(alpha.map((perCore) => {
17232
17270
  if (perCore.length > MAX_AUTH_POOL_SIZE) {
@@ -17254,8 +17292,9 @@ const fullStateDumpFromJson = (spec) => json.object({
17254
17292
  timeslot: tau,
17255
17293
  privilegedServices: PrivilegedServices.create({
17256
17294
  manager: chi.chi_m,
17257
- authManager: chi.chi_a,
17258
- validatorsManager: chi.chi_v,
17295
+ assigners: chi.chi_a,
17296
+ delegator: chi.chi_v,
17297
+ registrar: chi.chi_r ?? tryAsServiceId(2 ** 32 - 1),
17259
17298
  autoAccumulateServices: chi.chi_g ?? [],
17260
17299
  }),
17261
17300
  statistics: JsonStatisticsData.toStatisticsData(spec, pi),