@typeberry/lib 0.1.3-8258907 → 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.
- package/index.cjs +268 -226
- package/index.d.ts +324 -258
- package/index.js +268 -226
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -8154,7 +8154,6 @@ const O = 8;
|
|
|
8154
8154
|
const Q = 80;
|
|
8155
8155
|
/** `W_T`: The size of a transfer memo in octets. */
|
|
8156
8156
|
const W_T = 128;
|
|
8157
|
-
// TODO [ToDr] Not sure where these should live yet :(
|
|
8158
8157
|
/**
|
|
8159
8158
|
* `J`: The maximum sum of dependency items in a work-report.
|
|
8160
8159
|
*
|
|
@@ -8166,6 +8165,194 @@ const AUTHORIZATION_QUEUE_SIZE = Q;
|
|
|
8166
8165
|
/** `O`: Maximal authorization pool size. */
|
|
8167
8166
|
const MAX_AUTH_POOL_SIZE = O;
|
|
8168
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
|
+
|
|
8169
8356
|
/** Dictionary entry of services that auto-accumulate every block. */
|
|
8170
8357
|
class AutoAccumulate {
|
|
8171
8358
|
service;
|
|
@@ -8187,39 +8374,50 @@ class AutoAccumulate {
|
|
|
8187
8374
|
}
|
|
8188
8375
|
}
|
|
8189
8376
|
/**
|
|
8190
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
8377
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
|
|
8191
8378
|
*/
|
|
8192
8379
|
class PrivilegedServices {
|
|
8193
8380
|
manager;
|
|
8194
|
-
|
|
8195
|
-
|
|
8381
|
+
delegator;
|
|
8382
|
+
registrar;
|
|
8383
|
+
assigners;
|
|
8196
8384
|
autoAccumulateServices;
|
|
8385
|
+
/** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
|
|
8197
8386
|
static Codec = codec$1.Class(PrivilegedServices, {
|
|
8198
8387
|
manager: codec$1.u32.asOpaque(),
|
|
8199
|
-
|
|
8200
|
-
|
|
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)),
|
|
8201
8393
|
autoAccumulateServices: readonlyArray(codec$1.sequenceVarLen(AutoAccumulate.Codec)),
|
|
8202
8394
|
});
|
|
8203
|
-
static create(
|
|
8204
|
-
return new PrivilegedServices(manager,
|
|
8395
|
+
static create(a) {
|
|
8396
|
+
return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
|
|
8205
8397
|
}
|
|
8206
8398
|
constructor(
|
|
8207
8399
|
/**
|
|
8208
|
-
*
|
|
8209
|
-
* the service able to effect an alteration of χ from block to block,
|
|
8400
|
+
* `χ_M`: Manages alteration of χ from block to block,
|
|
8210
8401
|
* as well as bestow services with storage deposit credits.
|
|
8211
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
8402
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
|
|
8212
8403
|
*/
|
|
8213
8404
|
manager,
|
|
8214
|
-
/**
|
|
8215
|
-
|
|
8216
|
-
/**
|
|
8217
|
-
|
|
8218
|
-
|
|
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. */
|
|
8219
8416
|
autoAccumulateServices) {
|
|
8220
8417
|
this.manager = manager;
|
|
8221
|
-
this.
|
|
8222
|
-
this.
|
|
8418
|
+
this.delegator = delegator;
|
|
8419
|
+
this.registrar = registrar;
|
|
8420
|
+
this.assigners = assigners;
|
|
8223
8421
|
this.autoAccumulateServices = autoAccumulateServices;
|
|
8224
8422
|
}
|
|
8225
8423
|
}
|
|
@@ -8481,189 +8679,6 @@ class SafroleData {
|
|
|
8481
8679
|
}
|
|
8482
8680
|
}
|
|
8483
8681
|
|
|
8484
|
-
/**
|
|
8485
|
-
* `B_S`: The basic minimum balance which all services require.
|
|
8486
|
-
*
|
|
8487
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
|
|
8488
|
-
*/
|
|
8489
|
-
const BASE_SERVICE_BALANCE = 100n;
|
|
8490
|
-
/**
|
|
8491
|
-
* `B_I`: The additional minimum balance required per item of elective service state.
|
|
8492
|
-
*
|
|
8493
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
|
|
8494
|
-
*/
|
|
8495
|
-
const ELECTIVE_ITEM_BALANCE = 10n;
|
|
8496
|
-
/**
|
|
8497
|
-
* `B_L`: The additional minimum balance required per octet of elective service state.
|
|
8498
|
-
*
|
|
8499
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
|
|
8500
|
-
*/
|
|
8501
|
-
const ELECTIVE_BYTE_BALANCE = 1n;
|
|
8502
|
-
const zeroSizeHint = {
|
|
8503
|
-
bytes: 0,
|
|
8504
|
-
isExact: true,
|
|
8505
|
-
};
|
|
8506
|
-
/** 0-byte read, return given default value */
|
|
8507
|
-
const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
|
|
8508
|
-
/** Encode and decode object with leading version number. */
|
|
8509
|
-
const codecWithVersion = (val) => Descriptor.new("withVersion", {
|
|
8510
|
-
bytes: val.sizeHint.bytes + 8,
|
|
8511
|
-
isExact: false,
|
|
8512
|
-
}, (e, v) => {
|
|
8513
|
-
e.varU64(0n);
|
|
8514
|
-
val.encode(e, v);
|
|
8515
|
-
}, (d) => {
|
|
8516
|
-
const version = d.varU64();
|
|
8517
|
-
if (version !== 0n) {
|
|
8518
|
-
throw new Error("Non-zero version is not supported!");
|
|
8519
|
-
}
|
|
8520
|
-
return val.decode(d);
|
|
8521
|
-
}, (s) => {
|
|
8522
|
-
s.varU64();
|
|
8523
|
-
val.skip(s);
|
|
8524
|
-
});
|
|
8525
|
-
/**
|
|
8526
|
-
* Service account details.
|
|
8527
|
-
*
|
|
8528
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
|
|
8529
|
-
*/
|
|
8530
|
-
class ServiceAccountInfo extends WithDebug {
|
|
8531
|
-
codeHash;
|
|
8532
|
-
balance;
|
|
8533
|
-
accumulateMinGas;
|
|
8534
|
-
onTransferMinGas;
|
|
8535
|
-
storageUtilisationBytes;
|
|
8536
|
-
gratisStorage;
|
|
8537
|
-
storageUtilisationCount;
|
|
8538
|
-
created;
|
|
8539
|
-
lastAccumulation;
|
|
8540
|
-
parentService;
|
|
8541
|
-
static Codec = codec$1.Class(ServiceAccountInfo, {
|
|
8542
|
-
codeHash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
8543
|
-
balance: codec$1.u64,
|
|
8544
|
-
accumulateMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
|
|
8545
|
-
onTransferMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
|
|
8546
|
-
storageUtilisationBytes: codec$1.u64,
|
|
8547
|
-
gratisStorage: codec$1.u64,
|
|
8548
|
-
storageUtilisationCount: codec$1.u32,
|
|
8549
|
-
created: codec$1.u32.convert((x) => x, tryAsTimeSlot),
|
|
8550
|
-
lastAccumulation: codec$1.u32.convert((x) => x, tryAsTimeSlot),
|
|
8551
|
-
parentService: codec$1.u32.convert((x) => x, tryAsServiceId),
|
|
8552
|
-
});
|
|
8553
|
-
static create(a) {
|
|
8554
|
-
return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
|
|
8555
|
-
}
|
|
8556
|
-
/**
|
|
8557
|
-
* `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
|
|
8558
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
|
|
8559
|
-
*/
|
|
8560
|
-
static calculateThresholdBalance(items, bytes, gratisStorage) {
|
|
8561
|
-
const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
|
|
8562
|
-
if (storageCost < 0n) {
|
|
8563
|
-
return tryAsU64(0);
|
|
8564
|
-
}
|
|
8565
|
-
if (storageCost >= 2n ** 64n) {
|
|
8566
|
-
return tryAsU64(2n ** 64n - 1n);
|
|
8567
|
-
}
|
|
8568
|
-
return tryAsU64(storageCost);
|
|
8569
|
-
}
|
|
8570
|
-
constructor(
|
|
8571
|
-
/** `a_c`: Hash of the service code. */
|
|
8572
|
-
codeHash,
|
|
8573
|
-
/** `a_b`: Current account balance. */
|
|
8574
|
-
balance,
|
|
8575
|
-
/** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
|
|
8576
|
-
accumulateMinGas,
|
|
8577
|
-
/** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
|
|
8578
|
-
onTransferMinGas,
|
|
8579
|
-
/** `a_o`: Total number of octets in storage. */
|
|
8580
|
-
storageUtilisationBytes,
|
|
8581
|
-
/** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
|
|
8582
|
-
gratisStorage,
|
|
8583
|
-
/** `a_i`: Number of items in storage. */
|
|
8584
|
-
storageUtilisationCount,
|
|
8585
|
-
/** `a_r`: Creation account time slot. */
|
|
8586
|
-
created,
|
|
8587
|
-
/** `a_a`: Most recent accumulation time slot. */
|
|
8588
|
-
lastAccumulation,
|
|
8589
|
-
/** `a_p`: Parent service ID. */
|
|
8590
|
-
parentService) {
|
|
8591
|
-
super();
|
|
8592
|
-
this.codeHash = codeHash;
|
|
8593
|
-
this.balance = balance;
|
|
8594
|
-
this.accumulateMinGas = accumulateMinGas;
|
|
8595
|
-
this.onTransferMinGas = onTransferMinGas;
|
|
8596
|
-
this.storageUtilisationBytes = storageUtilisationBytes;
|
|
8597
|
-
this.gratisStorage = gratisStorage;
|
|
8598
|
-
this.storageUtilisationCount = storageUtilisationCount;
|
|
8599
|
-
this.created = created;
|
|
8600
|
-
this.lastAccumulation = lastAccumulation;
|
|
8601
|
-
this.parentService = parentService;
|
|
8602
|
-
}
|
|
8603
|
-
}
|
|
8604
|
-
class PreimageItem extends WithDebug {
|
|
8605
|
-
hash;
|
|
8606
|
-
blob;
|
|
8607
|
-
static Codec = codec$1.Class(PreimageItem, {
|
|
8608
|
-
hash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
8609
|
-
blob: codec$1.blob,
|
|
8610
|
-
});
|
|
8611
|
-
static create({ hash, blob }) {
|
|
8612
|
-
return new PreimageItem(hash, blob);
|
|
8613
|
-
}
|
|
8614
|
-
constructor(hash, blob) {
|
|
8615
|
-
super();
|
|
8616
|
-
this.hash = hash;
|
|
8617
|
-
this.blob = blob;
|
|
8618
|
-
}
|
|
8619
|
-
}
|
|
8620
|
-
class StorageItem extends WithDebug {
|
|
8621
|
-
key;
|
|
8622
|
-
value;
|
|
8623
|
-
static Codec = codec$1.Class(StorageItem, {
|
|
8624
|
-
key: codec$1.blob.convert((i) => i, (o) => asOpaqueType(o)),
|
|
8625
|
-
value: codec$1.blob,
|
|
8626
|
-
});
|
|
8627
|
-
static create({ key, value }) {
|
|
8628
|
-
return new StorageItem(key, value);
|
|
8629
|
-
}
|
|
8630
|
-
constructor(key, value) {
|
|
8631
|
-
super();
|
|
8632
|
-
this.key = key;
|
|
8633
|
-
this.value = value;
|
|
8634
|
-
}
|
|
8635
|
-
}
|
|
8636
|
-
const MAX_LOOKUP_HISTORY_SLOTS = 3;
|
|
8637
|
-
function tryAsLookupHistorySlots(items) {
|
|
8638
|
-
const knownSize = asKnownSize(items);
|
|
8639
|
-
if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
|
|
8640
|
-
throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
|
|
8641
|
-
}
|
|
8642
|
-
return knownSize;
|
|
8643
|
-
}
|
|
8644
|
-
/** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
|
|
8645
|
-
class LookupHistoryItem {
|
|
8646
|
-
hash;
|
|
8647
|
-
length;
|
|
8648
|
-
slots;
|
|
8649
|
-
constructor(hash, length,
|
|
8650
|
-
/**
|
|
8651
|
-
* Preimage availability history as a sequence of time slots.
|
|
8652
|
-
* See PreimageStatus and the following GP fragment for more details.
|
|
8653
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
|
|
8654
|
-
slots) {
|
|
8655
|
-
this.hash = hash;
|
|
8656
|
-
this.length = length;
|
|
8657
|
-
this.slots = slots;
|
|
8658
|
-
}
|
|
8659
|
-
static isRequested(item) {
|
|
8660
|
-
if ("slots" in item) {
|
|
8661
|
-
return item.slots.length === 0;
|
|
8662
|
-
}
|
|
8663
|
-
return item.length === 0;
|
|
8664
|
-
}
|
|
8665
|
-
}
|
|
8666
|
-
|
|
8667
8682
|
/**
|
|
8668
8683
|
* In addition to the entropy accumulator η_0, we retain
|
|
8669
8684
|
* three additional historical values of the accumulator at
|
|
@@ -9471,8 +9486,9 @@ class InMemoryState extends WithDebug {
|
|
|
9471
9486
|
epochRoot: Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
9472
9487
|
privilegedServices: PrivilegedServices.create({
|
|
9473
9488
|
manager: tryAsServiceId(0),
|
|
9474
|
-
|
|
9475
|
-
|
|
9489
|
+
assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
|
|
9490
|
+
delegator: tryAsServiceId(0),
|
|
9491
|
+
registrar: tryAsServiceId(MAX_VALUE),
|
|
9476
9492
|
autoAccumulateServices: [],
|
|
9477
9493
|
}),
|
|
9478
9494
|
accumulationOutputLog: SortedArray.fromArray(accumulationOutputComparator, []),
|
|
@@ -12079,6 +12095,8 @@ var NewServiceError;
|
|
|
12079
12095
|
NewServiceError[NewServiceError["InsufficientFunds"] = 0] = "InsufficientFunds";
|
|
12080
12096
|
/** Service is not privileged to set gratis storage. */
|
|
12081
12097
|
NewServiceError[NewServiceError["UnprivilegedService"] = 1] = "UnprivilegedService";
|
|
12098
|
+
/** Registrar attempting to create a service with already existing id. */
|
|
12099
|
+
NewServiceError[NewServiceError["RegistrarServiceIdAlreadyTaken"] = 2] = "RegistrarServiceIdAlreadyTaken";
|
|
12082
12100
|
})(NewServiceError || (NewServiceError = {}));
|
|
12083
12101
|
var UpdatePrivilegesError;
|
|
12084
12102
|
(function (UpdatePrivilegesError) {
|
|
@@ -12269,11 +12287,17 @@ class AccumulationStateUpdate {
|
|
|
12269
12287
|
if (from.privilegedServices !== null) {
|
|
12270
12288
|
update.privilegedServices = PrivilegedServices.create({
|
|
12271
12289
|
...from.privilegedServices,
|
|
12272
|
-
|
|
12290
|
+
assigners: asKnownSize([...from.privilegedServices.assigners]),
|
|
12273
12291
|
});
|
|
12274
12292
|
}
|
|
12275
12293
|
return update;
|
|
12276
12294
|
}
|
|
12295
|
+
/** Retrieve and clear pending transfers. */
|
|
12296
|
+
takeTransfers() {
|
|
12297
|
+
const transfers = this.transfers;
|
|
12298
|
+
this.transfers = [];
|
|
12299
|
+
return transfers;
|
|
12300
|
+
}
|
|
12277
12301
|
}
|
|
12278
12302
|
class PartiallyUpdatedState {
|
|
12279
12303
|
state;
|
|
@@ -12470,7 +12494,7 @@ const HostCallResult = {
|
|
|
12470
12494
|
OOB: tryAsU64(0xfffffffffffffffdn), // 2**64 - 3
|
|
12471
12495
|
/** Index unknown. */
|
|
12472
12496
|
WHO: tryAsU64(0xfffffffffffffffcn), // 2**64 - 4
|
|
12473
|
-
/** Storage full. */
|
|
12497
|
+
/** Storage full or resource already allocated. */
|
|
12474
12498
|
FULL: tryAsU64(0xfffffffffffffffbn), // 2**64 - 5
|
|
12475
12499
|
/** Core index unknown. */
|
|
12476
12500
|
CORE: tryAsU64(0xfffffffffffffffan), // 2**64 - 6
|
|
@@ -12478,7 +12502,7 @@ const HostCallResult = {
|
|
|
12478
12502
|
CASH: tryAsU64(0xfffffffffffffff9n), // 2**64 - 7
|
|
12479
12503
|
/** Gas limit too low. */
|
|
12480
12504
|
LOW: tryAsU64(0xfffffffffffffff8n), // 2**64 - 8
|
|
12481
|
-
/** The item is already solicited
|
|
12505
|
+
/** The item is already solicited, cannot be forgotten or the operation is invalid due to privilege level. */
|
|
12482
12506
|
HUH: tryAsU64(0xfffffffffffffff7n), // 2**64 - 9
|
|
12483
12507
|
/** The return value indicating general success. */
|
|
12484
12508
|
OK: tryAsU64(0n),
|
|
@@ -14513,11 +14537,6 @@ class BitOps {
|
|
|
14513
14537
|
}
|
|
14514
14538
|
}
|
|
14515
14539
|
|
|
14516
|
-
const MAX_VALUE = 4294967295;
|
|
14517
|
-
const MIN_VALUE = -2147483648;
|
|
14518
|
-
const MAX_SHIFT_U32 = 32;
|
|
14519
|
-
const MAX_SHIFT_U64 = 64n;
|
|
14520
|
-
|
|
14521
14540
|
/**
|
|
14522
14541
|
* Overflowing addition for two-complement representation of 32-bit signed numbers.
|
|
14523
14542
|
*/
|
|
@@ -16887,6 +16906,7 @@ var index$2 = /*#__PURE__*/Object.freeze({
|
|
|
16887
16906
|
|
|
16888
16907
|
class JsonServiceInfo {
|
|
16889
16908
|
static fromJson = json.object({
|
|
16909
|
+
...(Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? { version: "number" } : {}),
|
|
16890
16910
|
code_hash: fromJson.bytes32(),
|
|
16891
16911
|
balance: json.fromNumber((x) => tryAsU64(x)),
|
|
16892
16912
|
min_item_gas: json.fromNumber((x) => tryAsServiceGas(x)),
|
|
@@ -16911,6 +16931,7 @@ class JsonServiceInfo {
|
|
|
16911
16931
|
parentService: parent_service,
|
|
16912
16932
|
});
|
|
16913
16933
|
});
|
|
16934
|
+
version;
|
|
16914
16935
|
code_hash;
|
|
16915
16936
|
balance;
|
|
16916
16937
|
min_item_gas;
|
|
@@ -16945,23 +16966,35 @@ const lookupMetaFromJson = json.object({
|
|
|
16945
16966
|
},
|
|
16946
16967
|
value: json.array("number"),
|
|
16947
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));
|
|
16948
16973
|
class JsonService {
|
|
16949
16974
|
static fromJson = json.object({
|
|
16950
16975
|
id: "number",
|
|
16951
|
-
data:
|
|
16952
|
-
|
|
16953
|
-
|
|
16954
|
-
|
|
16955
|
-
|
|
16956
|
-
|
|
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
|
+
},
|
|
16957
16989
|
}, ({ id, data }) => {
|
|
16990
|
+
const preimages = HashDictionary.fromEntries((data.preimages ?? data.preimages_blob ?? []).map((x) => [x.hash, x]));
|
|
16958
16991
|
const lookupHistory = HashDictionary.new();
|
|
16959
|
-
for (const item of data.lookup_meta ?? []) {
|
|
16992
|
+
for (const item of data.lookup_meta ?? data.preimages_status ?? []) {
|
|
16960
16993
|
const data = lookupHistory.get(item.hash) ?? [];
|
|
16961
|
-
|
|
16994
|
+
const length = tryAsU32(preimages.get(item.hash)?.blob.length ?? item.length);
|
|
16995
|
+
data.push(new LookupHistoryItem(item.hash, length, item.slots));
|
|
16962
16996
|
lookupHistory.set(item.hash, data);
|
|
16963
16997
|
}
|
|
16964
|
-
const preimages = HashDictionary.fromEntries((data.preimages ?? []).map((x) => [x.hash, x]));
|
|
16965
16998
|
const storage = new Map();
|
|
16966
16999
|
const entries = (data.storage ?? []).map(({ key, value }) => {
|
|
16967
17000
|
const opaqueKey = asOpaqueType(key);
|
|
@@ -17133,8 +17166,12 @@ class JsonServiceStatistics {
|
|
|
17133
17166
|
extrinsic_count: "number",
|
|
17134
17167
|
accumulate_count: "number",
|
|
17135
17168
|
accumulate_gas_used: json.fromNumber(tryAsServiceGas),
|
|
17136
|
-
|
|
17137
|
-
|
|
17169
|
+
...(Compatibility.isLessThan(GpVersion.V0_7_1)
|
|
17170
|
+
? {
|
|
17171
|
+
on_transfers_count: "number",
|
|
17172
|
+
on_transfers_gas_used: json.fromNumber(tryAsServiceGas),
|
|
17173
|
+
}
|
|
17174
|
+
: {}),
|
|
17138
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, }) => {
|
|
17139
17176
|
return ServiceStatistics.create({
|
|
17140
17177
|
providedCount: provided_count,
|
|
@@ -17147,8 +17184,8 @@ class JsonServiceStatistics {
|
|
|
17147
17184
|
extrinsicCount: extrinsic_count,
|
|
17148
17185
|
accumulateCount: accumulate_count,
|
|
17149
17186
|
accumulateGasUsed: accumulate_gas_used,
|
|
17150
|
-
onTransfersCount: on_transfers_count,
|
|
17151
|
-
onTransfersGasUsed: on_transfers_gas_used,
|
|
17187
|
+
onTransfersCount: on_transfers_count ?? tryAsU32(0),
|
|
17188
|
+
onTransfersGasUsed: on_transfers_gas_used ?? tryAsServiceGas(0),
|
|
17152
17189
|
});
|
|
17153
17190
|
});
|
|
17154
17191
|
provided_count;
|
|
@@ -17219,6 +17256,7 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
17219
17256
|
chi_m: "number",
|
|
17220
17257
|
chi_a: json.array("number"),
|
|
17221
17258
|
chi_v: "number",
|
|
17259
|
+
chi_r: json.optional("number"),
|
|
17222
17260
|
chi_g: json.nullable(json.array({
|
|
17223
17261
|
service: "number",
|
|
17224
17262
|
gasLimit: json.fromNumber((v) => tryAsServiceGas(v)),
|
|
@@ -17230,6 +17268,9 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
17230
17268
|
theta: json.nullable(json.array(accumulationOutput)),
|
|
17231
17269
|
accounts: json.array(JsonService.fromJson),
|
|
17232
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
|
+
}
|
|
17233
17274
|
return InMemoryState.create({
|
|
17234
17275
|
authPools: tryAsPerCore(alpha.map((perCore) => {
|
|
17235
17276
|
if (perCore.length > MAX_AUTH_POOL_SIZE) {
|
|
@@ -17257,8 +17298,9 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
17257
17298
|
timeslot: tau,
|
|
17258
17299
|
privilegedServices: PrivilegedServices.create({
|
|
17259
17300
|
manager: chi.chi_m,
|
|
17260
|
-
|
|
17261
|
-
|
|
17301
|
+
assigners: chi.chi_a,
|
|
17302
|
+
delegator: chi.chi_v,
|
|
17303
|
+
registrar: chi.chi_r ?? tryAsServiceId(2 ** 32 - 1),
|
|
17262
17304
|
autoAccumulateServices: chi.chi_g ?? [],
|
|
17263
17305
|
}),
|
|
17264
17306
|
statistics: JsonStatisticsData.toStatisticsData(spec, pi),
|