@typeberry/convert 0.5.3-5a6cfcc → 0.5.3-a1dad13
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 -34
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -9752,14 +9752,18 @@ class work_item_WorkItem extends WithDebug {
|
|
|
9752
9752
|
|
|
9753
9753
|
|
|
9754
9754
|
|
|
9755
|
-
/**
|
|
9755
|
+
/** Convert the value to `WorkItemsCount` bounds. */
|
|
9756
9756
|
function tryAsWorkItemsCount(len) {
|
|
9757
9757
|
debug_check `
|
|
9758
|
-
${len
|
|
9758
|
+
${isWorkItemsCount(len)}
|
|
9759
9759
|
WorkItemsCount: Expected '${MIN_NUMBER_OF_WORK_ITEMS} <= count <= ${work_package_MAX_NUMBER_OF_WORK_ITEMS}' got ${len}
|
|
9760
9760
|
`;
|
|
9761
9761
|
return tryAsU8(len);
|
|
9762
9762
|
}
|
|
9763
|
+
/** Verify the value is within the `WorkItemsCount` bounds. */
|
|
9764
|
+
function isWorkItemsCount(len) {
|
|
9765
|
+
return len >= MIN_NUMBER_OF_WORK_ITEMS && len <= work_package_MAX_NUMBER_OF_WORK_ITEMS;
|
|
9766
|
+
}
|
|
9763
9767
|
/** Minimal number of work items in the work package or results in work report. */
|
|
9764
9768
|
const MIN_NUMBER_OF_WORK_ITEMS = 1;
|
|
9765
9769
|
/** `I`: Maximal number of work items in the work package or results in work report. */
|
|
@@ -11169,6 +11173,13 @@ const blockFromJson = (spec) => json.object({
|
|
|
11169
11173
|
header: headerFromJson,
|
|
11170
11174
|
extrinsic: getExtrinsicFromJson(spec),
|
|
11171
11175
|
}, ({ header, extrinsic }) => Block.create({ header, extrinsic }));
|
|
11176
|
+
const blockViewFromJson = (spec) => {
|
|
11177
|
+
const parseBlock = blockFromJson(spec);
|
|
11178
|
+
return json.fromAny((p) => {
|
|
11179
|
+
const block = parse_parseFromJson(p, parseBlock);
|
|
11180
|
+
return reencodeAsView(Block.Codec, block, spec);
|
|
11181
|
+
});
|
|
11182
|
+
};
|
|
11172
11183
|
|
|
11173
11184
|
;// CONCATENATED MODULE: ./packages/jam/block-json/index.ts
|
|
11174
11185
|
|
|
@@ -11663,13 +11674,13 @@ const getStateCodec = codec_codec.bytes(hash_HASH_SIZE).asOpaque();
|
|
|
11663
11674
|
/** StateRoot ::= StateRootHash */
|
|
11664
11675
|
const stateRootCodec = codec_codec.bytes(hash_HASH_SIZE).asOpaque();
|
|
11665
11676
|
/** Error ::= UTF8String */
|
|
11666
|
-
class
|
|
11677
|
+
class types_ErrorMessage extends WithDebug {
|
|
11667
11678
|
message;
|
|
11668
|
-
static Codec = codec_codec.Class(
|
|
11679
|
+
static Codec = codec_codec.Class(types_ErrorMessage, {
|
|
11669
11680
|
message: codec_codec.string,
|
|
11670
11681
|
});
|
|
11671
11682
|
static create({ message }) {
|
|
11672
|
-
return new
|
|
11683
|
+
return new types_ErrorMessage(message);
|
|
11673
11684
|
}
|
|
11674
11685
|
constructor(message) {
|
|
11675
11686
|
super();
|
|
@@ -11723,7 +11734,7 @@ const types_messageCodec = codec_codec.custom({
|
|
|
11723
11734
|
stateCodec.encode(e, msg.value);
|
|
11724
11735
|
break;
|
|
11725
11736
|
case types_MessageType.Error:
|
|
11726
|
-
|
|
11737
|
+
types_ErrorMessage.Codec.encode(e, msg.value);
|
|
11727
11738
|
break;
|
|
11728
11739
|
default:
|
|
11729
11740
|
throw new Error(`Unknown message type: ${msg}`);
|
|
@@ -11744,7 +11755,7 @@ const types_messageCodec = codec_codec.custom({
|
|
|
11744
11755
|
case types_MessageType.State:
|
|
11745
11756
|
return { type: types_MessageType.State, value: stateCodec.decode(d) };
|
|
11746
11757
|
case types_MessageType.Error:
|
|
11747
|
-
return { type: types_MessageType.Error, value:
|
|
11758
|
+
return { type: types_MessageType.Error, value: types_ErrorMessage.Codec.decode(d) };
|
|
11748
11759
|
default:
|
|
11749
11760
|
throw new Error(`Unknown message type: ${type}`);
|
|
11750
11761
|
}
|
|
@@ -11770,7 +11781,7 @@ const types_messageCodec = codec_codec.custom({
|
|
|
11770
11781
|
stateCodec.View.skip(s);
|
|
11771
11782
|
break;
|
|
11772
11783
|
case types_MessageType.Error:
|
|
11773
|
-
|
|
11784
|
+
types_ErrorMessage.Codec.View.skip(s);
|
|
11774
11785
|
break;
|
|
11775
11786
|
default:
|
|
11776
11787
|
throw new Error(`Unknown message type: ${type}`);
|
|
@@ -11833,35 +11844,59 @@ class FuzzTarget {
|
|
|
11833
11844
|
break;
|
|
11834
11845
|
}
|
|
11835
11846
|
case MessageType.Initialize: {
|
|
11836
|
-
|
|
11837
|
-
|
|
11838
|
-
type: MessageType.StateRoot,
|
|
11839
|
-
value: stateRoot,
|
|
11840
|
-
};
|
|
11841
|
-
break;
|
|
11842
|
-
}
|
|
11843
|
-
case MessageType.ImportBlock: {
|
|
11844
|
-
const result = await this.msgHandler.importBlock(message.value);
|
|
11845
|
-
if (result.isOk) {
|
|
11847
|
+
try {
|
|
11848
|
+
const stateRoot = await this.msgHandler.initialize(message.value);
|
|
11846
11849
|
response = {
|
|
11847
11850
|
type: MessageType.StateRoot,
|
|
11848
|
-
value:
|
|
11851
|
+
value: stateRoot,
|
|
11849
11852
|
};
|
|
11850
11853
|
}
|
|
11851
|
-
|
|
11854
|
+
catch (e) {
|
|
11852
11855
|
response = {
|
|
11853
11856
|
type: MessageType.Error,
|
|
11854
|
-
value:
|
|
11857
|
+
value: ErrorMessage.create({ message: `initialize error: ${e}` }),
|
|
11858
|
+
};
|
|
11859
|
+
}
|
|
11860
|
+
break;
|
|
11861
|
+
}
|
|
11862
|
+
case MessageType.ImportBlock: {
|
|
11863
|
+
try {
|
|
11864
|
+
const result = await this.msgHandler.importBlock(message.value);
|
|
11865
|
+
if (result.isOk) {
|
|
11866
|
+
response = {
|
|
11867
|
+
type: MessageType.StateRoot,
|
|
11868
|
+
value: result.ok,
|
|
11869
|
+
};
|
|
11870
|
+
}
|
|
11871
|
+
else {
|
|
11872
|
+
response = {
|
|
11873
|
+
type: MessageType.Error,
|
|
11874
|
+
value: result.error,
|
|
11875
|
+
};
|
|
11876
|
+
}
|
|
11877
|
+
}
|
|
11878
|
+
catch (e) {
|
|
11879
|
+
response = {
|
|
11880
|
+
type: MessageType.Error,
|
|
11881
|
+
value: ErrorMessage.create({ message: `importBlock error: ${e}` }),
|
|
11855
11882
|
};
|
|
11856
11883
|
}
|
|
11857
11884
|
break;
|
|
11858
11885
|
}
|
|
11859
11886
|
case MessageType.GetState: {
|
|
11860
|
-
|
|
11861
|
-
|
|
11862
|
-
|
|
11863
|
-
|
|
11864
|
-
|
|
11887
|
+
try {
|
|
11888
|
+
const state = await this.msgHandler.getSerializedState(message.value);
|
|
11889
|
+
response = {
|
|
11890
|
+
type: MessageType.State,
|
|
11891
|
+
value: state,
|
|
11892
|
+
};
|
|
11893
|
+
}
|
|
11894
|
+
catch (e) {
|
|
11895
|
+
response = {
|
|
11896
|
+
type: MessageType.Error,
|
|
11897
|
+
value: ErrorMessage.create({ message: `getState error: ${e}` }),
|
|
11898
|
+
};
|
|
11899
|
+
}
|
|
11865
11900
|
break;
|
|
11866
11901
|
}
|
|
11867
11902
|
case MessageType.StateRoot: {
|
|
@@ -16064,11 +16099,11 @@ class StateTransition {
|
|
|
16064
16099
|
static fromJson = {
|
|
16065
16100
|
pre_state: TestState.fromJson,
|
|
16066
16101
|
post_state: TestState.fromJson,
|
|
16067
|
-
block:
|
|
16102
|
+
block: blockViewFromJson(chain_spec_tinyChainSpec),
|
|
16068
16103
|
};
|
|
16069
16104
|
static Codec = codec_codec.object({
|
|
16070
16105
|
pre_state: TestState.Codec,
|
|
16071
|
-
block: Block.Codec,
|
|
16106
|
+
block: Block.Codec.View,
|
|
16072
16107
|
post_state: TestState.Codec,
|
|
16073
16108
|
});
|
|
16074
16109
|
pre_state;
|
|
@@ -20272,7 +20307,7 @@ const SUPPORTED_TYPES = [
|
|
|
20272
20307
|
if (option === "as-block") {
|
|
20273
20308
|
return looseType({
|
|
20274
20309
|
encode: Block.Codec,
|
|
20275
|
-
value: test.block,
|
|
20310
|
+
value: test.block.materialize(),
|
|
20276
20311
|
});
|
|
20277
20312
|
}
|
|
20278
20313
|
if (option === "as-fuzz-message") {
|
|
@@ -20280,11 +20315,9 @@ const SUPPORTED_TYPES = [
|
|
|
20280
20315
|
console.warn("⚠️ Warning: 'as-fuzz-message' is deprecated and will be removed in version 0.6.0. Use 'as-block-fuzz-message' instead.");
|
|
20281
20316
|
}
|
|
20282
20317
|
if (option === "as-block-fuzz-message" || option === "as-fuzz-message") {
|
|
20283
|
-
const encoded = encoder_Encoder.encodeObject(Block.Codec, test.block, spec);
|
|
20284
|
-
const blockView = decoder_Decoder.decodeObject(Block.Codec.View, encoded, spec);
|
|
20285
20318
|
const msg = {
|
|
20286
20319
|
type: types_MessageType.ImportBlock,
|
|
20287
|
-
value:
|
|
20320
|
+
value: test.block,
|
|
20288
20321
|
};
|
|
20289
20322
|
return looseType({
|
|
20290
20323
|
value: msg,
|
|
@@ -20292,13 +20325,14 @@ const SUPPORTED_TYPES = [
|
|
|
20292
20325
|
});
|
|
20293
20326
|
}
|
|
20294
20327
|
if (option === "as-state-fuzz-message") {
|
|
20328
|
+
const blockHeader = test.block.header.materialize();
|
|
20295
20329
|
const init = Initialize.create({
|
|
20296
20330
|
header: header_Header.empty(),
|
|
20297
20331
|
keyvals: test.pre_state.keyvals,
|
|
20298
20332
|
ancestry: [
|
|
20299
20333
|
AncestryItem.create({
|
|
20300
|
-
headerHash:
|
|
20301
|
-
slot: common_tryAsTimeSlot(Math.max(0,
|
|
20334
|
+
headerHash: blockHeader.parentHeaderHash,
|
|
20335
|
+
slot: common_tryAsTimeSlot(Math.max(0, blockHeader.timeSlotIndex - 1)),
|
|
20302
20336
|
}),
|
|
20303
20337
|
],
|
|
20304
20338
|
});
|