@typeberry/lib 0.1.3-8fd7637 → 0.1.3-a6eda68

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 +274 -229
  2. package/index.d.ts +333 -261
  3. package/index.js +274 -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,11 +12287,17 @@ 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;
12273
12294
  }
12295
+ /** Retrieve and clear pending transfers. */
12296
+ takeTransfers() {
12297
+ const transfers = this.transfers;
12298
+ this.transfers = [];
12299
+ return transfers;
12300
+ }
12274
12301
  }
12275
12302
  class PartiallyUpdatedState {
12276
12303
  state;
@@ -12467,7 +12494,7 @@ const HostCallResult = {
12467
12494
  OOB: tryAsU64(0xfffffffffffffffdn), // 2**64 - 3
12468
12495
  /** Index unknown. */
12469
12496
  WHO: tryAsU64(0xfffffffffffffffcn), // 2**64 - 4
12470
- /** Storage full. */
12497
+ /** Storage full or resource already allocated. */
12471
12498
  FULL: tryAsU64(0xfffffffffffffffbn), // 2**64 - 5
12472
12499
  /** Core index unknown. */
12473
12500
  CORE: tryAsU64(0xfffffffffffffffan), // 2**64 - 6
@@ -12475,7 +12502,7 @@ const HostCallResult = {
12475
12502
  CASH: tryAsU64(0xfffffffffffffff9n), // 2**64 - 7
12476
12503
  /** Gas limit too low. */
12477
12504
  LOW: tryAsU64(0xfffffffffffffff8n), // 2**64 - 8
12478
- /** The item is already solicited or cannot be forgotten. */
12505
+ /** The item is already solicited, cannot be forgotten or the operation is invalid due to privilege level. */
12479
12506
  HUH: tryAsU64(0xfffffffffffffff7n), // 2**64 - 9
12480
12507
  /** The return value indicating general success. */
12481
12508
  OK: tryAsU64(0n),
@@ -14510,11 +14537,6 @@ class BitOps {
14510
14537
  }
14511
14538
  }
14512
14539
 
14513
- const MAX_VALUE = 4294967295;
14514
- const MIN_VALUE = -2147483648;
14515
- const MAX_SHIFT_U32 = 32;
14516
- const MAX_SHIFT_U64 = 64n;
14517
-
14518
14540
  /**
14519
14541
  * Overflowing addition for two-complement representation of 32-bit signed numbers.
14520
14542
  */
@@ -16884,6 +16906,7 @@ var index$2 = /*#__PURE__*/Object.freeze({
16884
16906
 
16885
16907
  class JsonServiceInfo {
16886
16908
  static fromJson = json.object({
16909
+ ...(Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? { version: "number" } : {}),
16887
16910
  code_hash: fromJson.bytes32(),
16888
16911
  balance: json.fromNumber((x) => tryAsU64(x)),
16889
16912
  min_item_gas: json.fromNumber((x) => tryAsServiceGas(x)),
@@ -16908,6 +16931,7 @@ class JsonServiceInfo {
16908
16931
  parentService: parent_service,
16909
16932
  });
16910
16933
  });
16934
+ version;
16911
16935
  code_hash;
16912
16936
  balance;
16913
16937
  min_item_gas;
@@ -16942,23 +16966,35 @@ const lookupMetaFromJson = json.object({
16942
16966
  },
16943
16967
  value: json.array("number"),
16944
16968
  }, ({ key, value }) => new LookupHistoryItem(key.hash, key.length, value));
16969
+ const preimageStatusFromJson = json.object({
16970
+ hash: fromJson.bytes32(),
16971
+ status: json.array("number"),
16972
+ }, ({ hash, status }) => new LookupHistoryItem(hash, tryAsU32(0), status));
16945
16973
  class JsonService {
16946
16974
  static fromJson = json.object({
16947
16975
  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
- },
16976
+ data: Compatibility.isLessThan(GpVersion.V0_7_1)
16977
+ ? {
16978
+ service: JsonServiceInfo.fromJson,
16979
+ preimages: json.optional(json.array(JsonPreimageItem.fromJson)),
16980
+ storage: json.optional(json.array(JsonStorageItem.fromJson)),
16981
+ lookup_meta: json.optional(json.array(lookupMetaFromJson)),
16982
+ }
16983
+ : {
16984
+ service: JsonServiceInfo.fromJson,
16985
+ storage: json.optional(json.array(JsonStorageItem.fromJson)),
16986
+ preimages_blob: json.optional(json.array(JsonPreimageItem.fromJson)),
16987
+ preimages_status: json.optional(json.array(preimageStatusFromJson)),
16988
+ },
16954
16989
  }, ({ id, data }) => {
16990
+ const preimages = HashDictionary.fromEntries((data.preimages ?? data.preimages_blob ?? []).map((x) => [x.hash, x]));
16955
16991
  const lookupHistory = HashDictionary.new();
16956
- for (const item of data.lookup_meta ?? []) {
16992
+ for (const item of data.lookup_meta ?? data.preimages_status ?? []) {
16957
16993
  const data = lookupHistory.get(item.hash) ?? [];
16958
- data.push(item);
16994
+ const length = tryAsU32(preimages.get(item.hash)?.blob.length ?? item.length);
16995
+ data.push(new LookupHistoryItem(item.hash, length, item.slots));
16959
16996
  lookupHistory.set(item.hash, data);
16960
16997
  }
16961
- const preimages = HashDictionary.fromEntries((data.preimages ?? []).map((x) => [x.hash, x]));
16962
16998
  const storage = new Map();
16963
16999
  const entries = (data.storage ?? []).map(({ key, value }) => {
16964
17000
  const opaqueKey = asOpaqueType(key);
@@ -17130,8 +17166,12 @@ class JsonServiceStatistics {
17130
17166
  extrinsic_count: "number",
17131
17167
  accumulate_count: "number",
17132
17168
  accumulate_gas_used: json.fromNumber(tryAsServiceGas),
17133
- on_transfers_count: "number",
17134
- on_transfers_gas_used: json.fromNumber(tryAsServiceGas),
17169
+ ...(Compatibility.isLessThan(GpVersion.V0_7_1)
17170
+ ? {
17171
+ on_transfers_count: "number",
17172
+ on_transfers_gas_used: json.fromNumber(tryAsServiceGas),
17173
+ }
17174
+ : {}),
17135
17175
  }, ({ 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
17176
  return ServiceStatistics.create({
17137
17177
  providedCount: provided_count,
@@ -17144,8 +17184,8 @@ class JsonServiceStatistics {
17144
17184
  extrinsicCount: extrinsic_count,
17145
17185
  accumulateCount: accumulate_count,
17146
17186
  accumulateGasUsed: accumulate_gas_used,
17147
- onTransfersCount: on_transfers_count,
17148
- onTransfersGasUsed: on_transfers_gas_used,
17187
+ onTransfersCount: on_transfers_count ?? tryAsU32(0),
17188
+ onTransfersGasUsed: on_transfers_gas_used ?? tryAsServiceGas(0),
17149
17189
  });
17150
17190
  });
17151
17191
  provided_count;
@@ -17216,6 +17256,7 @@ const fullStateDumpFromJson = (spec) => json.object({
17216
17256
  chi_m: "number",
17217
17257
  chi_a: json.array("number"),
17218
17258
  chi_v: "number",
17259
+ chi_r: json.optional("number"),
17219
17260
  chi_g: json.nullable(json.array({
17220
17261
  service: "number",
17221
17262
  gasLimit: json.fromNumber((v) => tryAsServiceGas(v)),
@@ -17227,6 +17268,9 @@ const fullStateDumpFromJson = (spec) => json.object({
17227
17268
  theta: json.nullable(json.array(accumulationOutput)),
17228
17269
  accounts: json.array(JsonService.fromJson),
17229
17270
  }, ({ alpha, varphi, beta, gamma, psi, eta, iota, kappa, lambda, rho, tau, chi, pi, omega, xi, theta, accounts, }) => {
17271
+ if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) && chi.chi_r === undefined) {
17272
+ throw new Error("Registrar is required in Privileges GP ^0.7.1");
17273
+ }
17230
17274
  return InMemoryState.create({
17231
17275
  authPools: tryAsPerCore(alpha.map((perCore) => {
17232
17276
  if (perCore.length > MAX_AUTH_POOL_SIZE) {
@@ -17254,8 +17298,9 @@ const fullStateDumpFromJson = (spec) => json.object({
17254
17298
  timeslot: tau,
17255
17299
  privilegedServices: PrivilegedServices.create({
17256
17300
  manager: chi.chi_m,
17257
- authManager: chi.chi_a,
17258
- validatorsManager: chi.chi_v,
17301
+ assigners: chi.chi_a,
17302
+ delegator: chi.chi_v,
17303
+ registrar: chi.chi_r ?? tryAsServiceId(2 ** 32 - 1),
17259
17304
  autoAccumulateServices: chi.chi_g ?? [],
17260
17305
  }),
17261
17306
  statistics: JsonStatisticsData.toStatisticsData(spec, pi),