@typeberry/lib 0.10.0 → 0.11.0-6310ba4
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/package.json +3 -3
- package/packages/configs/index.d.ts +9 -0
- package/packages/configs/index.d.ts.map +1 -1
- package/packages/configs/typeberry-default.json +4 -1
- package/packages/configs/typeberry-dev-full.json +3 -0
- package/packages/configs/typeberry-dev-tiny.json +3 -0
- package/packages/jam/config-node/index.d.ts +1 -0
- package/packages/jam/config-node/index.d.ts.map +1 -1
- package/packages/jam/config-node/index.js +1 -0
- package/packages/jam/config-node/node-config.d.ts +5 -1
- package/packages/jam/config-node/node-config.d.ts.map +1 -1
- package/packages/jam/config-node/node-config.js +9 -3
- package/packages/jam/config-node/node-config.test.js +9 -0
- package/packages/jam/config-node/rpc.d.ts +11 -0
- package/packages/jam/config-node/rpc.d.ts.map +1 -0
- package/packages/jam/config-node/rpc.js +16 -0
- package/packages/jam/node/jam-config.d.ts +5 -1
- package/packages/jam/node/jam-config.d.ts.map +1 -1
- package/packages/jam/node/jam-config.js +6 -2
- package/packages/jam/node/main-fuzz.d.ts.map +1 -1
- package/packages/jam/node/main-fuzz.js +31 -16
- package/packages/jam/node/main-importer.d.ts.map +1 -1
- package/packages/jam/node/main-importer.js +1 -1
- package/packages/jam/rpc/index.d.ts +3 -0
- package/packages/jam/rpc/index.d.ts.map +1 -0
- package/packages/jam/rpc/index.js +2 -0
- package/packages/jam/rpc/src/handlers/best-block.d.ts +6 -0
- package/packages/jam/rpc/src/handlers/best-block.d.ts.map +1 -0
- package/packages/jam/rpc/src/handlers/best-block.js +15 -0
- package/packages/jam/rpc/src/handlers/finalized-block.d.ts +6 -0
- package/packages/jam/rpc/src/handlers/finalized-block.d.ts.map +1 -0
- package/packages/jam/rpc/src/handlers/finalized-block.js +7 -0
- package/packages/jam/rpc/src/handlers/list-services.d.ts +6 -0
- package/packages/jam/rpc/src/handlers/list-services.d.ts.map +1 -0
- package/packages/jam/rpc/src/handlers/list-services.js +15 -0
- package/packages/jam/rpc/src/handlers/not-implemented.d.ts +4 -0
- package/packages/jam/rpc/src/handlers/not-implemented.d.ts.map +1 -0
- package/packages/jam/rpc/src/handlers/not-implemented.js +4 -0
- package/packages/jam/rpc/src/handlers/parameters.d.ts +7 -0
- package/packages/jam/rpc/src/handlers/parameters.d.ts.map +1 -0
- package/packages/jam/rpc/src/handlers/parameters.js +53 -0
- package/packages/jam/rpc/src/handlers/parent.d.ts +6 -0
- package/packages/jam/rpc/src/handlers/parent.d.ts.map +1 -0
- package/packages/jam/rpc/src/handlers/parent.js +25 -0
- package/packages/jam/rpc/src/handlers/service-data.d.ts +6 -0
- package/packages/jam/rpc/src/handlers/service-data.d.ts.map +1 -0
- package/packages/jam/rpc/src/handlers/service-data.js +21 -0
- package/packages/jam/rpc/src/handlers/service-preimage.d.ts +6 -0
- package/packages/jam/rpc/src/handlers/service-preimage.d.ts.map +1 -0
- package/packages/jam/rpc/src/handlers/service-preimage.js +23 -0
- package/packages/jam/rpc/src/handlers/service-request.d.ts +6 -0
- package/packages/jam/rpc/src/handlers/service-request.d.ts.map +1 -0
- package/packages/jam/rpc/src/handlers/service-request.js +23 -0
- package/packages/jam/rpc/src/handlers/service-value.d.ts +6 -0
- package/packages/jam/rpc/src/handlers/service-value.d.ts.map +1 -0
- package/packages/jam/rpc/src/handlers/service-value.js +23 -0
- package/packages/jam/rpc/src/handlers/state-root.d.ts +6 -0
- package/packages/jam/rpc/src/handlers/state-root.d.ts.map +1 -0
- package/packages/jam/rpc/src/handlers/state-root.js +14 -0
- package/packages/jam/rpc/src/handlers/statistics.d.ts +6 -0
- package/packages/jam/rpc/src/handlers/statistics.d.ts.map +1 -0
- package/packages/jam/rpc/src/handlers/statistics.js +16 -0
- package/packages/jam/rpc/src/handlers/subscribe-best-block.d.ts +6 -0
- package/packages/jam/rpc/src/handlers/subscribe-best-block.d.ts.map +1 -0
- package/packages/jam/rpc/src/handlers/subscribe-best-block.js +8 -0
- package/packages/jam/rpc/src/handlers/subscribe-finalized-block.d.ts +6 -0
- package/packages/jam/rpc/src/handlers/subscribe-finalized-block.d.ts.map +1 -0
- package/packages/jam/rpc/src/handlers/subscribe-finalized-block.js +8 -0
- package/packages/jam/rpc/src/handlers/subscribe-service-data.d.ts +6 -0
- package/packages/jam/rpc/src/handlers/subscribe-service-data.d.ts.map +1 -0
- package/packages/jam/rpc/src/handlers/subscribe-service-data.js +13 -0
- package/packages/jam/rpc/src/handlers/subscribe-service-preimage.d.ts +6 -0
- package/packages/jam/rpc/src/handlers/subscribe-service-preimage.d.ts.map +1 -0
- package/packages/jam/rpc/src/handlers/subscribe-service-preimage.js +13 -0
- package/packages/jam/rpc/src/handlers/subscribe-service-request.d.ts +6 -0
- package/packages/jam/rpc/src/handlers/subscribe-service-request.d.ts.map +1 -0
- package/packages/jam/rpc/src/handlers/subscribe-service-request.js +13 -0
- package/packages/jam/rpc/src/handlers/subscribe-service-value.d.ts +6 -0
- package/packages/jam/rpc/src/handlers/subscribe-service-value.d.ts.map +1 -0
- package/packages/jam/rpc/src/handlers/subscribe-service-value.js +13 -0
- package/packages/jam/rpc/src/handlers/subscribe-statistics.d.ts +6 -0
- package/packages/jam/rpc/src/handlers/subscribe-statistics.d.ts.map +1 -0
- package/packages/jam/rpc/src/handlers/subscribe-statistics.js +13 -0
- package/packages/jam/rpc/src/handlers/typeberry/refine-work-package.d.ts +8 -0
- package/packages/jam/rpc/src/handlers/typeberry/refine-work-package.d.ts.map +1 -0
- package/packages/jam/rpc/src/handlers/typeberry/refine-work-package.js +68 -0
- package/packages/jam/rpc/src/handlers/unsubscribe.d.ts +4 -0
- package/packages/jam/rpc/src/handlers/unsubscribe.d.ts.map +1 -0
- package/packages/jam/rpc/src/handlers/unsubscribe.js +3 -0
- package/packages/jam/rpc/src/handlers.d.ts +3 -0
- package/packages/jam/rpc/src/handlers.d.ts.map +1 -0
- package/packages/jam/rpc/src/handlers.js +60 -0
- package/packages/jam/rpc/src/server.d.ts +31 -0
- package/packages/jam/rpc/src/server.d.ts.map +1 -0
- package/packages/jam/rpc/src/server.js +179 -0
- package/packages/jam/rpc/src/subscription-manager.d.ts +20 -0
- package/packages/jam/rpc/src/subscription-manager.d.ts.map +1 -0
- package/packages/jam/rpc/src/subscription-manager.js +74 -0
- package/packages/jam/rpc/test/e2e-server.d.ts +3 -0
- package/packages/jam/rpc/test/e2e-server.d.ts.map +1 -0
- package/packages/jam/rpc/test/e2e-server.js +32 -0
- package/packages/jam/rpc/test/e2e-setup.d.ts +2 -0
- package/packages/jam/rpc/test/e2e-setup.d.ts.map +1 -0
- package/packages/jam/rpc/test/e2e-setup.js +126 -0
- package/packages/jam/rpc/test/e2e.d.ts +2 -0
- package/packages/jam/rpc/test/e2e.d.ts.map +1 -0
- package/packages/jam/rpc/test/e2e.js +326 -0
- package/packages/workers/importer/main.d.ts +2 -0
- package/packages/workers/importer/main.d.ts.map +1 -1
- package/packages/workers/importer/main.js +1 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { W_E } from "#@typeberry/block";
|
|
2
|
+
import { G_I, MAX_REPORT_DEPENDENCIES, O, Q, T, W_B, W_C, W_T } from "#@typeberry/block/gp-constants.js";
|
|
3
|
+
import { MAX_NUMBER_OF_WORK_ITEMS } from "#@typeberry/block/work-package.js";
|
|
4
|
+
import { BASE_SERVICE_BALANCE, ELECTIVE_BYTE_BALANCE, ELECTIVE_ITEM_BALANCE, MAX_RECENT_HISTORY, } from "#@typeberry/state";
|
|
5
|
+
import { REPORT_TIMEOUT_GRACE_PERIOD } from "#@typeberry/transition/assurances.js";
|
|
6
|
+
import { G_A } from "#@typeberry/transition/reports/verify-post-signature.js";
|
|
7
|
+
/**
|
|
8
|
+
* https://github.com/polkadot-fellows/JIPs/blob/77cba2dcc1887233d4b19371c05284ff761a5fa6/JIP-2.md#chain-parameters
|
|
9
|
+
* Returns the parameters of the current node/chain.
|
|
10
|
+
*/
|
|
11
|
+
export const parameters = async (_params, { chainSpec }) => {
|
|
12
|
+
return {
|
|
13
|
+
V1: {
|
|
14
|
+
deposit_per_account: Number(BASE_SERVICE_BALANCE),
|
|
15
|
+
deposit_per_item: Number(ELECTIVE_ITEM_BALANCE),
|
|
16
|
+
deposit_per_byte: Number(ELECTIVE_BYTE_BALANCE),
|
|
17
|
+
min_turnaround_period: 32,
|
|
18
|
+
epoch_period: chainSpec.epochLength,
|
|
19
|
+
max_accumulate_gas: G_A,
|
|
20
|
+
max_is_authorized_gas: G_I,
|
|
21
|
+
max_refine_gas: Number(chainSpec.maxRefineGas),
|
|
22
|
+
block_gas_limit: Number(chainSpec.maxBlockGas),
|
|
23
|
+
recent_block_count: MAX_RECENT_HISTORY,
|
|
24
|
+
max_work_items: MAX_NUMBER_OF_WORK_ITEMS,
|
|
25
|
+
max_dependencies: MAX_REPORT_DEPENDENCIES,
|
|
26
|
+
max_tickets_per_block: chainSpec.maxTicketsPerExtrinsic,
|
|
27
|
+
max_lookup_anchor_age: chainSpec.maxLookupAnchorAge,
|
|
28
|
+
tickets_attempts_number: chainSpec.ticketsPerValidator,
|
|
29
|
+
auth_window: O,
|
|
30
|
+
auth_queue_len: Q,
|
|
31
|
+
rotation_period: chainSpec.rotationPeriod,
|
|
32
|
+
max_extrinsics: T,
|
|
33
|
+
availability_timeout: REPORT_TIMEOUT_GRACE_PERIOD,
|
|
34
|
+
val_count: chainSpec.validatorsCount,
|
|
35
|
+
max_input: W_B,
|
|
36
|
+
max_refine_code_size: W_C,
|
|
37
|
+
basic_piece_len: W_E,
|
|
38
|
+
max_imports: 3072,
|
|
39
|
+
max_is_authorized_code_size: 64000,
|
|
40
|
+
max_exports: 3072,
|
|
41
|
+
max_refine_memory: 4096,
|
|
42
|
+
max_is_authorized_memory: 4096,
|
|
43
|
+
segment_piece_count: chainSpec.numberECPiecesPerSegment,
|
|
44
|
+
max_report_elective_data: 49152,
|
|
45
|
+
transfer_memo_size: W_T,
|
|
46
|
+
epoch_tail_start: chainSpec.contestLength,
|
|
47
|
+
core_count: chainSpec.coresCount,
|
|
48
|
+
slot_period_sec: chainSpec.slotDuration,
|
|
49
|
+
max_authorizer_code_size: 64000,
|
|
50
|
+
max_service_code_size: 4000000,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Handler } from "#@typeberry/rpc-validation";
|
|
2
|
+
/**
|
|
3
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#parentheader_hash
|
|
4
|
+
*/
|
|
5
|
+
export declare const parent: Handler<"parent">;
|
|
6
|
+
//# sourceMappingURL=parent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parent.d.ts","sourceRoot":"","sources":["../../../../../../../packages/jam/rpc/src/handlers/parent.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,OAAO,EAAsC,MAAM,2BAA2B,CAAC;AAE7F;;GAEG;AACH,eAAO,MAAM,MAAM,EAAE,OAAO,CAAC,QAAQ,CA6BpC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Bytes } from "#@typeberry/bytes";
|
|
2
|
+
import { HASH_SIZE } from "#@typeberry/hash";
|
|
3
|
+
import { RpcError, RpcErrorCode, validation } from "#@typeberry/rpc-validation";
|
|
4
|
+
/**
|
|
5
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#parentheader_hash
|
|
6
|
+
*/
|
|
7
|
+
export const parent = async ([headerHash], { db }) => {
|
|
8
|
+
const hashOpaque = Bytes.fromBlob(headerHash, HASH_SIZE).asOpaque();
|
|
9
|
+
const header = db.blocks.getHeader(hashOpaque);
|
|
10
|
+
if (header === null) {
|
|
11
|
+
throw new RpcError(RpcErrorCode.BlockUnavailable, `Block unavailable: ${hashOpaque.toString()}`, validation.hash.encode(hashOpaque.raw));
|
|
12
|
+
}
|
|
13
|
+
const parentHash = header.parentHeaderHash.materialize();
|
|
14
|
+
if (parentHash.isEqualTo(Bytes.zero(HASH_SIZE).asOpaque())) {
|
|
15
|
+
throw new RpcError(RpcErrorCode.Other, `Parent not found for block: ${hashOpaque.toString()}`);
|
|
16
|
+
}
|
|
17
|
+
const parentHeader = db.blocks.getHeader(parentHash);
|
|
18
|
+
if (parentHeader === null) {
|
|
19
|
+
throw new RpcError(RpcErrorCode.Other, `The hash of parent was found (${parentHash}) but its header doesn't exist in the database.`);
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
header_hash: parentHash.raw,
|
|
23
|
+
slot: parentHeader.timeSlotIndex.materialize(),
|
|
24
|
+
};
|
|
25
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Handler } from "#@typeberry/rpc-validation";
|
|
2
|
+
/**
|
|
3
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#servicedataheader_hash-id
|
|
4
|
+
*/
|
|
5
|
+
export declare const serviceData: Handler<"serviceData">;
|
|
6
|
+
//# sourceMappingURL=service-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-data.d.ts","sourceRoot":"","sources":["../../../../../../../packages/jam/rpc/src/handlers/service-data.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,OAAO,EAA0B,MAAM,2BAA2B,CAAC;AAGjF;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,OAAO,CAAC,aAAa,CAe9C,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { tryAsServiceId } from "#@typeberry/block";
|
|
2
|
+
import { Bytes } from "#@typeberry/bytes";
|
|
3
|
+
import { Encoder } from "#@typeberry/codec";
|
|
4
|
+
import { HASH_SIZE } from "#@typeberry/hash";
|
|
5
|
+
import { RpcError, RpcErrorCode } from "#@typeberry/rpc-validation";
|
|
6
|
+
import { ServiceAccountInfo } from "#@typeberry/state";
|
|
7
|
+
/**
|
|
8
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#servicedataheader_hash-id
|
|
9
|
+
*/
|
|
10
|
+
export const serviceData = async ([headerHash, serviceId], { db, chainSpec }) => {
|
|
11
|
+
const hashOpaque = Bytes.fromBlob(headerHash, HASH_SIZE).asOpaque();
|
|
12
|
+
const state = db.states.getState(hashOpaque);
|
|
13
|
+
if (state === null) {
|
|
14
|
+
throw new RpcError(RpcErrorCode.Other, `State not found for block: ${hashOpaque.toString()}`);
|
|
15
|
+
}
|
|
16
|
+
const serviceData = state.getService(tryAsServiceId(serviceId));
|
|
17
|
+
if (serviceData === null) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return Encoder.encodeObject(ServiceAccountInfo.Codec, serviceData.getInfo(), chainSpec).raw;
|
|
21
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Handler } from "#@typeberry/rpc-validation";
|
|
2
|
+
/**
|
|
3
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#servicepreimageheader_hash-id-hash
|
|
4
|
+
*/
|
|
5
|
+
export declare const servicePreimage: Handler<"servicePreimage">;
|
|
6
|
+
//# sourceMappingURL=service-preimage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-preimage.d.ts","sourceRoot":"","sources":["../../../../../../../packages/jam/rpc/src/handlers/service-preimage.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,OAAO,EAA0B,MAAM,2BAA2B,CAAC;AAEjF;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,OAAO,CAAC,iBAAiB,CAqBtD,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { tryAsServiceId } from "#@typeberry/block";
|
|
2
|
+
import { Bytes } from "#@typeberry/bytes";
|
|
3
|
+
import { HASH_SIZE } from "#@typeberry/hash";
|
|
4
|
+
import { RpcError, RpcErrorCode } from "#@typeberry/rpc-validation";
|
|
5
|
+
/**
|
|
6
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#servicepreimageheader_hash-id-hash
|
|
7
|
+
*/
|
|
8
|
+
export const servicePreimage = async ([headerHash, serviceId, preimageHash], { db }) => {
|
|
9
|
+
const hashOpaque = Bytes.fromBlob(headerHash, HASH_SIZE).asOpaque();
|
|
10
|
+
const state = db.states.getState(hashOpaque);
|
|
11
|
+
if (state === null) {
|
|
12
|
+
throw new RpcError(RpcErrorCode.Other, `State not found for block: ${hashOpaque.toString()}`);
|
|
13
|
+
}
|
|
14
|
+
const service = state.getService(tryAsServiceId(serviceId));
|
|
15
|
+
if (service === null) {
|
|
16
|
+
throw new RpcError(RpcErrorCode.Other, `Service not found: ${serviceId.toString()}`);
|
|
17
|
+
}
|
|
18
|
+
const preimage = service.getPreimage(Bytes.fromBlob(preimageHash, HASH_SIZE).asOpaque());
|
|
19
|
+
if (preimage === null) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return preimage.raw;
|
|
23
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Handler } from "#@typeberry/rpc-validation";
|
|
2
|
+
/**
|
|
3
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#servicerequestheader_hash-id-hash-len
|
|
4
|
+
*/
|
|
5
|
+
export declare const serviceRequest: Handler<"serviceRequest">;
|
|
6
|
+
//# sourceMappingURL=service-request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-request.d.ts","sourceRoot":"","sources":["../../../../../../../packages/jam/rpc/src/handlers/service-request.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAEzD;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,OAAO,CAAC,gBAAgB,CAqBpD,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { tryAsServiceId } from "#@typeberry/block";
|
|
2
|
+
import { Bytes } from "#@typeberry/bytes";
|
|
3
|
+
import { HASH_SIZE } from "#@typeberry/hash";
|
|
4
|
+
import { tryAsU32 } from "#@typeberry/numbers";
|
|
5
|
+
/**
|
|
6
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#servicerequestheader_hash-id-hash-len
|
|
7
|
+
*/
|
|
8
|
+
export const serviceRequest = async ([headerHash, serviceId, preimageHash, preimageLength], { db }) => {
|
|
9
|
+
const hashOpaque = Bytes.fromBlob(headerHash, HASH_SIZE).asOpaque();
|
|
10
|
+
const state = db.states.getState(hashOpaque);
|
|
11
|
+
if (state === null) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const service = state.getService(tryAsServiceId(serviceId));
|
|
15
|
+
if (service === null) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const slots = service.getLookupHistory(Bytes.fromBlob(preimageHash, HASH_SIZE).asOpaque(), tryAsU32(preimageLength));
|
|
19
|
+
if (slots === null) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return slots;
|
|
23
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Handler } from "#@typeberry/rpc-validation";
|
|
2
|
+
/**
|
|
3
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#servicevalueheader_hash-id-key
|
|
4
|
+
*/
|
|
5
|
+
export declare const serviceValue: Handler<"serviceValue">;
|
|
6
|
+
//# sourceMappingURL=service-value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-value.d.ts","sourceRoot":"","sources":["../../../../../../../packages/jam/rpc/src/handlers/service-value.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,OAAO,EAA0B,MAAM,2BAA2B,CAAC;AAEjF;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,OAAO,CAAC,cAAc,CAqBhD,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { tryAsServiceId } from "#@typeberry/block";
|
|
2
|
+
import { Bytes } from "#@typeberry/bytes";
|
|
3
|
+
import { HASH_SIZE } from "#@typeberry/hash";
|
|
4
|
+
import { RpcError, RpcErrorCode } from "#@typeberry/rpc-validation";
|
|
5
|
+
/**
|
|
6
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#servicevalueheader_hash-id-key
|
|
7
|
+
*/
|
|
8
|
+
export const serviceValue = async ([headerHash, serviceId, key], { db }) => {
|
|
9
|
+
const hashOpaque = Bytes.fromBlob(headerHash, HASH_SIZE).asOpaque();
|
|
10
|
+
const state = db.states.getState(hashOpaque);
|
|
11
|
+
if (state === null) {
|
|
12
|
+
throw new RpcError(RpcErrorCode.Other, `State not found for block: ${hashOpaque.toString()}`);
|
|
13
|
+
}
|
|
14
|
+
const service = state.getService(tryAsServiceId(serviceId));
|
|
15
|
+
if (service === null) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const storageValue = service.getStorage(Bytes.fromBlob(key, key.length).asOpaque());
|
|
19
|
+
if (storageValue === null) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return storageValue.raw;
|
|
23
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Handler } from "#@typeberry/rpc-validation";
|
|
2
|
+
/**
|
|
3
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#staterootheader_hash
|
|
4
|
+
*/
|
|
5
|
+
export declare const stateRoot: Handler<"stateRoot">;
|
|
6
|
+
//# sourceMappingURL=state-root.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-root.d.ts","sourceRoot":"","sources":["../../../../../../../packages/jam/rpc/src/handlers/state-root.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,OAAO,EAA0B,MAAM,2BAA2B,CAAC;AAEjF;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,OAAO,CAAC,WAAW,CAU1C,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Bytes } from "#@typeberry/bytes";
|
|
2
|
+
import { HASH_SIZE } from "#@typeberry/hash";
|
|
3
|
+
import { RpcError, RpcErrorCode } from "#@typeberry/rpc-validation";
|
|
4
|
+
/**
|
|
5
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#staterootheader_hash
|
|
6
|
+
*/
|
|
7
|
+
export const stateRoot = async ([headerHash], { db }) => {
|
|
8
|
+
const hashOpaque = Bytes.fromBlob(headerHash, HASH_SIZE).asOpaque();
|
|
9
|
+
const stateRoot = db.blocks.getPostStateRoot(hashOpaque);
|
|
10
|
+
if (stateRoot === null) {
|
|
11
|
+
throw new RpcError(RpcErrorCode.BlockUnavailable, `Block unavailable: ${hashOpaque.toString()}`, hashOpaque.raw);
|
|
12
|
+
}
|
|
13
|
+
return stateRoot.raw;
|
|
14
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Handler } from "#@typeberry/rpc-validation";
|
|
2
|
+
/**
|
|
3
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#statisticsheader_hash
|
|
4
|
+
*/
|
|
5
|
+
export declare const statistics: Handler<"statistics">;
|
|
6
|
+
//# sourceMappingURL=statistics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statistics.d.ts","sourceRoot":"","sources":["../../../../../../../packages/jam/rpc/src/handlers/statistics.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,OAAO,EAA0B,MAAM,2BAA2B,CAAC;AAGjF;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,OAAO,CAAC,YAAY,CAS5C,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Bytes } from "#@typeberry/bytes";
|
|
2
|
+
import { Encoder } from "#@typeberry/codec";
|
|
3
|
+
import { HASH_SIZE } from "#@typeberry/hash";
|
|
4
|
+
import { RpcError, RpcErrorCode } from "#@typeberry/rpc-validation";
|
|
5
|
+
import { StatisticsData } from "#@typeberry/state";
|
|
6
|
+
/**
|
|
7
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#statisticsheader_hash
|
|
8
|
+
*/
|
|
9
|
+
export const statistics = async ([headerHash], { db, chainSpec }) => {
|
|
10
|
+
const hashOpaque = Bytes.fromBlob(headerHash, HASH_SIZE).asOpaque();
|
|
11
|
+
const state = db.states.getState(hashOpaque);
|
|
12
|
+
if (state === null) {
|
|
13
|
+
throw new RpcError(RpcErrorCode.Other, `State not found for block: ${hashOpaque.toString()}`);
|
|
14
|
+
}
|
|
15
|
+
return Encoder.encodeObject(StatisticsData.Codec, state.statistics, chainSpec).raw;
|
|
16
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Handler } from "#@typeberry/rpc-validation";
|
|
2
|
+
/**
|
|
3
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#subscribebestblock
|
|
4
|
+
*/
|
|
5
|
+
export declare const subscribeBestBlock: Handler<"subscribeBestBlock">;
|
|
6
|
+
//# sourceMappingURL=subscribe-best-block.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribe-best-block.d.ts","sourceRoot":"","sources":["../../../../../../../packages/jam/rpc/src/handlers/subscribe-best-block.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAc,MAAM,2BAA2B,CAAC;AAGrE;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,OAAO,CAAC,oBAAoB,CAE5D,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { validation } from "#@typeberry/rpc-validation";
|
|
2
|
+
import { bestBlock } from "./best-block.js";
|
|
3
|
+
/**
|
|
4
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#subscribebestblock
|
|
5
|
+
*/
|
|
6
|
+
export const subscribeBestBlock = async (params, { subscription }) => {
|
|
7
|
+
return subscription.subscribe("subscribeBestBlock", bestBlock, validation.schemas.bestBlock.output, params);
|
|
8
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Handler } from "#@typeberry/rpc-validation";
|
|
2
|
+
/**
|
|
3
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#subscribefinalizedblock
|
|
4
|
+
*/
|
|
5
|
+
export declare const subscribeFinalizedBlock: Handler<"subscribeFinalizedBlock">;
|
|
6
|
+
//# sourceMappingURL=subscribe-finalized-block.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribe-finalized-block.d.ts","sourceRoot":"","sources":["../../../../../../../packages/jam/rpc/src/handlers/subscribe-finalized-block.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAc,MAAM,2BAA2B,CAAC;AAGrE;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,OAAO,CAAC,yBAAyB,CAOtE,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { validation } from "#@typeberry/rpc-validation";
|
|
2
|
+
import { finalizedBlock } from "./finalized-block.js";
|
|
3
|
+
/**
|
|
4
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#subscribefinalizedblock
|
|
5
|
+
*/
|
|
6
|
+
export const subscribeFinalizedBlock = async (params, { subscription }) => {
|
|
7
|
+
return subscription.subscribe("subscribeFinalizedBlock", finalizedBlock, validation.schemas.finalizedBlock.output, params);
|
|
8
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Handler } from "#@typeberry/rpc-validation";
|
|
2
|
+
/**
|
|
3
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#subscribeservicedataid-finalized
|
|
4
|
+
*/
|
|
5
|
+
export declare const subscribeServiceData: Handler<"subscribeServiceData">;
|
|
6
|
+
//# sourceMappingURL=subscribe-service-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribe-service-data.d.ts","sourceRoot":"","sources":["../../../../../../../packages/jam/rpc/src/handlers/subscribe-service-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAc,MAAM,2BAA2B,CAAC;AAKrE;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,OAAO,CAAC,sBAAsB,CAWhE,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { validation } from "#@typeberry/rpc-validation";
|
|
2
|
+
import { bestBlock } from "./best-block.js";
|
|
3
|
+
import { finalizedBlock } from "./finalized-block.js";
|
|
4
|
+
import { serviceData } from "./service-data.js";
|
|
5
|
+
/**
|
|
6
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#subscribeservicedataid-finalized
|
|
7
|
+
*/
|
|
8
|
+
export const subscribeServiceData = async (params, { subscription }) => {
|
|
9
|
+
return subscription.subscribe("subscribeServiceData", async ([serviceId, finalized], context) => {
|
|
10
|
+
const block = finalized ? await finalizedBlock([], context) : await bestBlock([], context);
|
|
11
|
+
return serviceData([block.header_hash, serviceId], context);
|
|
12
|
+
}, validation.schemas.serviceData.output, params);
|
|
13
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Handler } from "#@typeberry/rpc-validation";
|
|
2
|
+
/**
|
|
3
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#subscribeservicepreimageid-hash-finalized
|
|
4
|
+
*/
|
|
5
|
+
export declare const subscribeServicePreimage: Handler<"subscribeServicePreimage">;
|
|
6
|
+
//# sourceMappingURL=subscribe-service-preimage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribe-service-preimage.d.ts","sourceRoot":"","sources":["../../../../../../../packages/jam/rpc/src/handlers/subscribe-service-preimage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAc,MAAM,2BAA2B,CAAC;AAKrE;;GAEG;AACH,eAAO,MAAM,wBAAwB,EAAE,OAAO,CAAC,0BAA0B,CAWxE,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { validation } from "#@typeberry/rpc-validation";
|
|
2
|
+
import { bestBlock } from "./best-block.js";
|
|
3
|
+
import { finalizedBlock } from "./finalized-block.js";
|
|
4
|
+
import { servicePreimage } from "./service-preimage.js";
|
|
5
|
+
/**
|
|
6
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#subscribeservicepreimageid-hash-finalized
|
|
7
|
+
*/
|
|
8
|
+
export const subscribeServicePreimage = async (params, { subscription }) => {
|
|
9
|
+
return subscription.subscribe("subscribeServicePreimage", async ([serviceId, preimageHash, finalized], context) => {
|
|
10
|
+
const block = finalized ? await finalizedBlock([], context) : await bestBlock([], context);
|
|
11
|
+
return servicePreimage([block.header_hash, serviceId, preimageHash], context);
|
|
12
|
+
}, validation.schemas.servicePreimage.output, params);
|
|
13
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Handler } from "#@typeberry/rpc-validation";
|
|
2
|
+
/**
|
|
3
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#subscribeservicerequestid-hash-len-finalized
|
|
4
|
+
*/
|
|
5
|
+
export declare const subscribeServiceRequest: Handler<"subscribeServiceRequest">;
|
|
6
|
+
//# sourceMappingURL=subscribe-service-request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribe-service-request.d.ts","sourceRoot":"","sources":["../../../../../../../packages/jam/rpc/src/handlers/subscribe-service-request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAc,MAAM,2BAA2B,CAAC;AAKrE;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,OAAO,CAAC,yBAAyB,CAWtE,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { validation } from "#@typeberry/rpc-validation";
|
|
2
|
+
import { bestBlock } from "./best-block.js";
|
|
3
|
+
import { finalizedBlock } from "./finalized-block.js";
|
|
4
|
+
import { serviceRequest } from "./service-request.js";
|
|
5
|
+
/**
|
|
6
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#subscribeservicerequestid-hash-len-finalized
|
|
7
|
+
*/
|
|
8
|
+
export const subscribeServiceRequest = async (params, { subscription }) => {
|
|
9
|
+
return subscription.subscribe("subscribeServiceRequest", async ([serviceId, preimageHash, preimageLength, finalized], context) => {
|
|
10
|
+
const block = finalized ? await finalizedBlock([], context) : await bestBlock([], context);
|
|
11
|
+
return serviceRequest([block.header_hash, serviceId, preimageHash, preimageLength], context);
|
|
12
|
+
}, validation.schemas.serviceRequest.output, params);
|
|
13
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Handler } from "#@typeberry/rpc-validation";
|
|
2
|
+
/**
|
|
3
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#subscribeservicevalueid-key-finalized
|
|
4
|
+
*/
|
|
5
|
+
export declare const subscribeServiceValue: Handler<"subscribeServiceValue">;
|
|
6
|
+
//# sourceMappingURL=subscribe-service-value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribe-service-value.d.ts","sourceRoot":"","sources":["../../../../../../../packages/jam/rpc/src/handlers/subscribe-service-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAc,MAAM,2BAA2B,CAAC;AAKrE;;GAEG;AACH,eAAO,MAAM,qBAAqB,EAAE,OAAO,CAAC,uBAAuB,CAWlE,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { validation } from "#@typeberry/rpc-validation";
|
|
2
|
+
import { bestBlock } from "./best-block.js";
|
|
3
|
+
import { finalizedBlock } from "./finalized-block.js";
|
|
4
|
+
import { serviceValue } from "./service-value.js";
|
|
5
|
+
/**
|
|
6
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#subscribeservicevalueid-key-finalized
|
|
7
|
+
*/
|
|
8
|
+
export const subscribeServiceValue = async (params, { subscription }) => {
|
|
9
|
+
return subscription.subscribe("subscribeServiceValue", async ([serviceId, key, finalized], context) => {
|
|
10
|
+
const block = finalized ? await finalizedBlock([], context) : await bestBlock([], context);
|
|
11
|
+
return serviceValue([block.header_hash, serviceId, key], context);
|
|
12
|
+
}, validation.schemas.serviceValue.output, params);
|
|
13
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Handler } from "#@typeberry/rpc-validation";
|
|
2
|
+
/**
|
|
3
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#subscribestatisticsfinalized
|
|
4
|
+
*/
|
|
5
|
+
export declare const subscribeStatistics: Handler<"subscribeStatistics">;
|
|
6
|
+
//# sourceMappingURL=subscribe-statistics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribe-statistics.d.ts","sourceRoot":"","sources":["../../../../../../../packages/jam/rpc/src/handlers/subscribe-statistics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAc,MAAM,2BAA2B,CAAC;AAKrE;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,OAAO,CAAC,qBAAqB,CAW9D,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { validation } from "#@typeberry/rpc-validation";
|
|
2
|
+
import { bestBlock } from "./best-block.js";
|
|
3
|
+
import { finalizedBlock } from "./finalized-block.js";
|
|
4
|
+
import { statistics } from "./statistics.js";
|
|
5
|
+
/**
|
|
6
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#subscribestatisticsfinalized
|
|
7
|
+
*/
|
|
8
|
+
export const subscribeStatistics = async (params, { subscription }) => {
|
|
9
|
+
return subscription.subscribe("subscribeStatistics", async ([finalized], context) => {
|
|
10
|
+
const block = finalized ? await finalizedBlock([], context) : await bestBlock([], context);
|
|
11
|
+
return statistics([block.header_hash], context);
|
|
12
|
+
}, validation.schemas.statistics.output, params);
|
|
13
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Handler } from "#@typeberry/rpc-validation";
|
|
2
|
+
/**
|
|
3
|
+
* Simulate package refinement.
|
|
4
|
+
*
|
|
5
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#submitworkpackagecore-package-extrinsics
|
|
6
|
+
*/
|
|
7
|
+
export declare const refineWorkPackage: Handler<"typeberry_refineWorkPackage">;
|
|
8
|
+
//# sourceMappingURL=refine-work-package.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refine-work-package.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/jam/rpc/src/handlers/typeberry/refine-work-package.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,OAAO,EAA0B,MAAM,2BAA2B,CAAC;AAIjF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,OAAO,CAAC,6BAA6B,CA6CpE,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { tryAsCoreIndex } from "#@typeberry/block";
|
|
2
|
+
import { WorkPackage } from "#@typeberry/block/work-package.js";
|
|
3
|
+
import { WorkReport } from "#@typeberry/block/work-report.js";
|
|
4
|
+
import { BytesBlob } from "#@typeberry/bytes";
|
|
5
|
+
import { Decoder, Encoder } from "#@typeberry/codec";
|
|
6
|
+
import { asKnownSize } from "#@typeberry/collections";
|
|
7
|
+
import { WithHash } from "#@typeberry/hash";
|
|
8
|
+
import { InCore } from "#@typeberry/in-core";
|
|
9
|
+
import { Logger } from "#@typeberry/logger";
|
|
10
|
+
import { RpcError, RpcErrorCode } from "#@typeberry/rpc-validation";
|
|
11
|
+
const logger = Logger.new(import.meta.filename, "rpc");
|
|
12
|
+
/**
|
|
13
|
+
* Simulate package refinement.
|
|
14
|
+
*
|
|
15
|
+
* https://github.com/polkadot-fellows/JIPs/blob/772ce90bfc33f4e1de9de3bbe10c561753cc0d41/JIP-2.md#submitworkpackagecore-package-extrinsics
|
|
16
|
+
*/
|
|
17
|
+
export const refineWorkPackage = async ([coreIndexRaw, workPackageBytes, extrinsicsRaw], { db, chainSpec, pvmBackend, blake2b }) => {
|
|
18
|
+
const coreIndex = tryAsCoreIndex(coreIndexRaw);
|
|
19
|
+
// Decode the work package
|
|
20
|
+
const workPackageBlob = BytesBlob.blobFrom(workPackageBytes);
|
|
21
|
+
const workPackage = Decoder.decodeObject(WorkPackage.Codec, workPackageBlob, chainSpec);
|
|
22
|
+
// Hash the work package
|
|
23
|
+
const workPackageHash = blake2b.hashBytes(workPackageBlob).asOpaque();
|
|
24
|
+
const workPackageAndHash = WithHash.new(workPackageHash, workPackage);
|
|
25
|
+
logger.info `Refining work package ${workPackageHash} to core ${coreIndex} with ${workPackage.items.length} items`;
|
|
26
|
+
// Convert extrinsics to the expected format (per work item)
|
|
27
|
+
// For now, we assume the extrinsics are provided in a flat array and need to be
|
|
28
|
+
// distributed to work items according to their extrinsic specs
|
|
29
|
+
const extrinsics = distributeExtrinsics(workPackage, extrinsicsRaw);
|
|
30
|
+
// For now, we don't have any imports - this would need to be fetched from DA layer
|
|
31
|
+
// TODO [ToDr] Fetch imported segments from DA layer based on work items' importSegments
|
|
32
|
+
const emptyImports = workPackage.items.map(() => []);
|
|
33
|
+
const imports = asKnownSize(emptyImports);
|
|
34
|
+
// Create in-core instance and process the work package
|
|
35
|
+
const inCore = InCore.new(chainSpec, db.states, pvmBackend, blake2b);
|
|
36
|
+
const result = await inCore.refine(workPackageAndHash, coreIndex, imports, extrinsics);
|
|
37
|
+
if (result.isError) {
|
|
38
|
+
throw new RpcError(RpcErrorCode.Other, `Refine error: ${result.details()}`);
|
|
39
|
+
}
|
|
40
|
+
logger.info `Work package ${workPackageHash} refined successfully on core ${coreIndex}`;
|
|
41
|
+
// encode report as response
|
|
42
|
+
const report = Encoder.encodeObject(WorkReport.Codec, result.ok.report, chainSpec);
|
|
43
|
+
// And concatenated all exports
|
|
44
|
+
const exports = BytesBlob.blobFromParts(result.ok.exports.flat().map((segment) => segment.raw));
|
|
45
|
+
return {
|
|
46
|
+
report: report.raw,
|
|
47
|
+
exports: exports.raw,
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Distribute the flat array of extrinsics to work items based on their extrinsic specs.
|
|
52
|
+
*/
|
|
53
|
+
function distributeExtrinsics(workPackage, extrinsicsRaw) {
|
|
54
|
+
const result = [];
|
|
55
|
+
let extrinsicIndex = 0;
|
|
56
|
+
for (const item of workPackage.items) {
|
|
57
|
+
const itemExtrinsics = [];
|
|
58
|
+
for (let i = 0; i < item.extrinsic.length; i++) {
|
|
59
|
+
if (extrinsicIndex >= extrinsicsRaw.length) {
|
|
60
|
+
throw new RpcError(RpcErrorCode.Other, `Not enough extrinsics provided. Expected at least ${extrinsicIndex + 1}, got ${extrinsicsRaw.length}`);
|
|
61
|
+
}
|
|
62
|
+
itemExtrinsics.push(BytesBlob.blobFrom(extrinsicsRaw[extrinsicIndex]));
|
|
63
|
+
extrinsicIndex++;
|
|
64
|
+
}
|
|
65
|
+
result.push(itemExtrinsics);
|
|
66
|
+
}
|
|
67
|
+
return asKnownSize(result);
|
|
68
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { GenericHandler, validation } from "#@typeberry/rpc-validation";
|
|
2
|
+
import type z from "zod";
|
|
3
|
+
export declare const unsubscribe: GenericHandler<z.infer<typeof validation.unsubscribeSchema.input>, z.infer<typeof validation.unsubscribeSchema.output>>;
|
|
4
|
+
//# sourceMappingURL=unsubscribe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unsubscribe.d.ts","sourceRoot":"","sources":["../../../../../../../packages/jam/rpc/src/handlers/unsubscribe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,eAAO,MAAM,WAAW,EAAE,cAAc,CACtC,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAClD,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAGpD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../../../../../packages/jam/rpc/src/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAuB5D,eAAO,MAAM,QAAQ,EAAE,UAsCtB,CAAC"}
|