@typeberry/convert 0.1.3-0eba10b → 0.1.3-2fdafd6
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.js +68 -13
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -21223,24 +21223,78 @@ class accumulate_externalities_AccumulateExternalities {
|
|
|
21223
21223
|
this.updatedState.stateUpdate.authorizationQueues.set(coreIndex, authQueue);
|
|
21224
21224
|
return Result.ok(OK);
|
|
21225
21225
|
}
|
|
21226
|
+
updatePrivilegedServiceId(
|
|
21227
|
+
// The id that privileged service wants to be updated to
|
|
21228
|
+
newId,
|
|
21229
|
+
// Current id of privileged service (updated state)
|
|
21230
|
+
currentId, {
|
|
21231
|
+
// is current service id a manager (can update anything)
|
|
21232
|
+
isManager,
|
|
21233
|
+
// is current service attempting to update itself (privileged are owned)
|
|
21234
|
+
isSelf,
|
|
21235
|
+
// is the service id already changed in this block
|
|
21236
|
+
isAlreadyChanged, }) {
|
|
21237
|
+
if (isManager) {
|
|
21238
|
+
return newId;
|
|
21239
|
+
}
|
|
21240
|
+
// current service can update itself, only if it was a privileged
|
|
21241
|
+
// service at the start of the block. I.e. owned privileges cannot
|
|
21242
|
+
// be transfered multiple times in a block.
|
|
21243
|
+
if (isSelf && !isAlreadyChanged) {
|
|
21244
|
+
return newId;
|
|
21245
|
+
}
|
|
21246
|
+
return currentId;
|
|
21247
|
+
}
|
|
21226
21248
|
updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulate) {
|
|
21227
21249
|
/** https://graypaper.fluffylabs.dev/#/7e6ff6a/36d90036de00?v=0.6.7 */
|
|
21228
|
-
const
|
|
21229
|
-
|
|
21230
|
-
|
|
21231
|
-
|
|
21232
|
-
|
|
21233
|
-
|
|
21250
|
+
const current = this.updatedState.getPrivilegedServices();
|
|
21251
|
+
const isManager = current.manager === this.currentServiceId;
|
|
21252
|
+
if (Compatibility.isLessThan(GpVersion.V0_7_1)) {
|
|
21253
|
+
if (!isManager) {
|
|
21254
|
+
return Result.error(UpdatePrivilegesError.UnprivilegedService);
|
|
21255
|
+
}
|
|
21256
|
+
if (manager === null || delegator === null) {
|
|
21257
|
+
return Result.error(UpdatePrivilegesError.InvalidServiceId, "Either manager or delegator is not a valid service id.");
|
|
21258
|
+
}
|
|
21259
|
+
this.updatedState.stateUpdate.privilegedServices = PrivilegedServices.create({
|
|
21260
|
+
manager,
|
|
21261
|
+
assigners: authorizers,
|
|
21262
|
+
delegator: delegator,
|
|
21263
|
+
registrar: registrar ?? tryAsServiceId(0),
|
|
21264
|
+
autoAccumulateServices: autoAccumulate.map(([service, gasLimit]) => AutoAccumulate.create({ service, gasLimit })),
|
|
21265
|
+
});
|
|
21266
|
+
return Result.ok(OK);
|
|
21234
21267
|
}
|
|
21235
|
-
|
|
21236
|
-
|
|
21268
|
+
const original = this.updatedState.state.privilegedServices;
|
|
21269
|
+
if (manager === null || delegator === null || registrar === null) {
|
|
21270
|
+
return Result.error(UpdatePrivilegesError.InvalidServiceId, "Either manager or delegator or registrar is not a valid service id.");
|
|
21237
21271
|
}
|
|
21272
|
+
const newDelegator = this.updatePrivilegedServiceId(delegator, current.delegator, {
|
|
21273
|
+
isManager,
|
|
21274
|
+
isSelf: this.currentServiceId === current.delegator,
|
|
21275
|
+
isAlreadyChanged: current.delegator !== original.delegator,
|
|
21276
|
+
});
|
|
21277
|
+
const newRegistrar = this.updatePrivilegedServiceId(registrar, current.registrar, {
|
|
21278
|
+
isManager,
|
|
21279
|
+
isSelf: this.currentServiceId === current.registrar,
|
|
21280
|
+
isAlreadyChanged: current.registrar !== original.registrar,
|
|
21281
|
+
});
|
|
21282
|
+
const newAssigners = current.assigners.map((currentAssigner, index) => this.updatePrivilegedServiceId(authorizers[index], currentAssigner, {
|
|
21283
|
+
isManager,
|
|
21284
|
+
isSelf: this.currentServiceId === currentAssigner,
|
|
21285
|
+
isAlreadyChanged: currentAssigner !== original.assigners[index],
|
|
21286
|
+
}));
|
|
21287
|
+
const newManager = isManager ? manager : current.manager;
|
|
21288
|
+
const newAutoAccumulateServices = isManager
|
|
21289
|
+
? autoAccumulate.map(([service, gasLimit]) => AutoAccumulate.create({ service, gasLimit }))
|
|
21290
|
+
: current.autoAccumulateServices;
|
|
21291
|
+
// finally update the privileges
|
|
21238
21292
|
this.updatedState.stateUpdate.privilegedServices = PrivilegedServices.create({
|
|
21239
|
-
manager,
|
|
21240
|
-
assigners:
|
|
21241
|
-
delegator,
|
|
21242
|
-
registrar:
|
|
21243
|
-
autoAccumulateServices:
|
|
21293
|
+
manager: newManager,
|
|
21294
|
+
assigners: tryAsPerCore(newAssigners, this.chainSpec),
|
|
21295
|
+
delegator: newDelegator,
|
|
21296
|
+
registrar: newRegistrar,
|
|
21297
|
+
autoAccumulateServices: newAutoAccumulateServices,
|
|
21244
21298
|
});
|
|
21245
21299
|
return Result.ok(OK);
|
|
21246
21300
|
}
|
|
@@ -22595,6 +22649,7 @@ class Bless {
|
|
|
22595
22649
|
return;
|
|
22596
22650
|
}
|
|
22597
22651
|
const e = updateResult.error;
|
|
22652
|
+
// NOTE: `UpdatePrivilegesError.UnprivilegedService` won't happen in 0.7.1+
|
|
22598
22653
|
if (e === partial_state_UpdatePrivilegesError.UnprivilegedService) {
|
|
22599
22654
|
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- HUH`;
|
|
22600
22655
|
regs.set(bless_IN_OUT_REG, results_HostCallResult.HUH);
|