@acala-network/chopsticks-core 1.1.1 → 1.2.1
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/dist/cjs/blockchain/index.js +1 -1
- package/dist/cjs/blockchain/inherent/parachain/validation-data.js +55 -18
- package/dist/cjs/index.d.ts +12 -12
- package/dist/cjs/index.js +12 -12
- package/dist/cjs/rpc/dev/new-block.js +1 -1
- package/dist/cjs/rpc/dev/set-storage.d.ts +1 -1
- package/dist/cjs/rpc/dev/set-storage.js +1 -1
- package/dist/cjs/rpc/index.d.ts +1 -1
- package/dist/cjs/rpc/rpc-spec/archive_v1.d.ts +74 -0
- package/dist/cjs/rpc/rpc-spec/archive_v1.js +201 -0
- package/dist/cjs/rpc/rpc-spec/chainHead_v1.js +9 -36
- package/dist/cjs/rpc/rpc-spec/index.d.ts +9 -0
- package/dist/cjs/rpc/rpc-spec/index.js +2 -0
- package/dist/cjs/rpc/rpc-spec/storage-common.d.ts +16 -0
- package/dist/cjs/rpc/rpc-spec/storage-common.js +49 -0
- package/dist/cjs/utils/index.d.ts +2 -2
- package/dist/cjs/utils/index.js +1 -1
- package/dist/cjs/wasm-executor/index.d.ts +1 -1
- package/dist/cjs/wasm-executor/node-wasm-executor.js +1 -1
- package/dist/esm/blockchain/index.js +1 -1
- package/dist/esm/blockchain/inherent/parachain/validation-data.js +56 -19
- package/dist/esm/blockchain/storage-layer.js +1 -1
- package/dist/esm/index.d.ts +12 -12
- package/dist/esm/index.js +12 -12
- package/dist/esm/rpc/dev/new-block.js +1 -1
- package/dist/esm/rpc/dev/set-storage.d.ts +1 -1
- package/dist/esm/rpc/dev/set-storage.js +1 -1
- package/dist/esm/rpc/index.d.ts +1 -1
- package/dist/esm/rpc/rpc-spec/archive_v1.d.ts +74 -0
- package/dist/esm/rpc/rpc-spec/archive_v1.js +215 -0
- package/dist/esm/rpc/rpc-spec/chainHead_v1.js +1 -28
- package/dist/esm/rpc/rpc-spec/index.d.ts +9 -0
- package/dist/esm/rpc/rpc-spec/index.js +2 -0
- package/dist/esm/rpc/rpc-spec/storage-common.d.ts +16 -0
- package/dist/esm/rpc/rpc-spec/storage-common.js +28 -0
- package/dist/esm/utils/index.d.ts +2 -2
- package/dist/esm/utils/index.js +1 -1
- package/dist/esm/wasm-executor/index.d.ts +1 -1
- package/dist/esm/wasm-executor/node-wasm-executor.js +1 -1
- package/package.json +14 -14
|
@@ -16,8 +16,8 @@ const _lodash = /*#__PURE__*/ _interop_require_default(require("lodash"));
|
|
|
16
16
|
const _logger = require("../logger.js");
|
|
17
17
|
const _offchain = require("../offchain.js");
|
|
18
18
|
const _index = require("../utils/index.js");
|
|
19
|
-
const _blockbuilder = require("./block-builder.js");
|
|
20
19
|
const _block = require("./block.js");
|
|
20
|
+
const _blockbuilder = require("./block-builder.js");
|
|
21
21
|
const _headstate = require("./head-state.js");
|
|
22
22
|
const _txpool = require("./txpool.js");
|
|
23
23
|
function _check_private_redeclaration(obj, privateCollection) {
|
|
@@ -10,8 +10,8 @@ Object.defineProperty(exports, "SetValidationData", {
|
|
|
10
10
|
});
|
|
11
11
|
const _types = require("@polkadot/types");
|
|
12
12
|
const _util = require("@polkadot/util");
|
|
13
|
-
const _lodash = /*#__PURE__*/ _interop_require_default(require("lodash"));
|
|
14
13
|
const _utilcrypto = require("@polkadot/util-crypto");
|
|
14
|
+
const _lodash = /*#__PURE__*/ _interop_require_default(require("lodash"));
|
|
15
15
|
const _index = require("../../../utils/index.js");
|
|
16
16
|
const _proof = require("../../../utils/proof.js");
|
|
17
17
|
const _index1 = require("../../../wasm-executor/index.js");
|
|
@@ -242,22 +242,59 @@ class SetValidationData {
|
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
const { trieRootHash, nodes } = await (0, _index1.createProof)(extrinsic.relayChainState.trieNodes, newEntries);
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
245
|
+
const argsLengh = meta.tx.parachainSystem.setValidationData.meta.args.length;
|
|
246
|
+
if (argsLengh === 1) {
|
|
247
|
+
// old version
|
|
248
|
+
const newData = {
|
|
249
|
+
...extrinsic,
|
|
250
|
+
downwardMessages,
|
|
251
|
+
horizontalMessages,
|
|
252
|
+
validationData: {
|
|
253
|
+
...extrinsic.validationData,
|
|
254
|
+
relayParentStorageRoot: trieRootHash,
|
|
255
|
+
relayParentNumber: params.relayParentNumber ?? extrinsic.validationData.relayParentNumber + relaySlotIncrease
|
|
256
|
+
},
|
|
257
|
+
relayChainState: {
|
|
258
|
+
trieNodes: nodes
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
const inherent = new _types.GenericExtrinsic(meta.registry, meta.tx.parachainSystem.setValidationData(newData));
|
|
262
|
+
return [
|
|
263
|
+
inherent.toHex()
|
|
264
|
+
];
|
|
265
|
+
} else if (argsLengh === 2) {
|
|
266
|
+
// new version
|
|
267
|
+
const newData = {
|
|
268
|
+
...extrinsic,
|
|
269
|
+
validationData: {
|
|
270
|
+
...extrinsic.validationData,
|
|
271
|
+
relayParentStorageRoot: trieRootHash,
|
|
272
|
+
relayParentNumber: params.relayParentNumber ?? extrinsic.validationData.relayParentNumber + relaySlotIncrease
|
|
273
|
+
},
|
|
274
|
+
relayChainState: {
|
|
275
|
+
trieNodes: nodes
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
const horizontalMessagesArray = Object.entries(horizontalMessages).flatMap(([sender, messages])=>messages.map((msg)=>[
|
|
279
|
+
sender,
|
|
280
|
+
msg
|
|
281
|
+
]));
|
|
282
|
+
const inboundMessagesData = {
|
|
283
|
+
downwardMessages: {
|
|
284
|
+
full_messages: downwardMessages,
|
|
285
|
+
hashed_messages: []
|
|
286
|
+
},
|
|
287
|
+
horizontalMessages: {
|
|
288
|
+
full_messages: horizontalMessagesArray,
|
|
289
|
+
hashed_messages: []
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
const inherent = new _types.GenericExtrinsic(meta.registry, meta.tx.parachainSystem.setValidationData(newData, inboundMessagesData));
|
|
293
|
+
return [
|
|
294
|
+
inherent.toHex()
|
|
295
|
+
];
|
|
296
|
+
} else {
|
|
297
|
+
throw new Error('Unsupported setValidationData');
|
|
298
|
+
}
|
|
262
299
|
}
|
|
263
300
|
}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -30,22 +30,22 @@ export type SignedBlock = {
|
|
|
30
30
|
justifications?: HexString[];
|
|
31
31
|
};
|
|
32
32
|
export * from './api.js';
|
|
33
|
-
export * from './blockchain/index.js';
|
|
34
33
|
export * from './blockchain/block.js';
|
|
35
34
|
export * from './blockchain/block-builder.js';
|
|
36
|
-
export * from './blockchain/txpool.js';
|
|
37
|
-
export * from './blockchain/storage-layer.js';
|
|
38
35
|
export * from './blockchain/head-state.js';
|
|
39
|
-
export * from './
|
|
40
|
-
export * from './utils/index.js';
|
|
41
|
-
export * from './wasm-executor/index.js';
|
|
42
|
-
export * from './schema/index.js';
|
|
43
|
-
export * from './xcm/index.js';
|
|
44
|
-
export * from './setup.js';
|
|
45
|
-
export * from './database.js';
|
|
36
|
+
export * from './blockchain/index.js';
|
|
46
37
|
export * from './blockchain/inherent/index.js';
|
|
47
|
-
export * from './
|
|
48
|
-
export * from './
|
|
38
|
+
export * from './blockchain/storage-layer.js';
|
|
39
|
+
export * from './blockchain/txpool.js';
|
|
49
40
|
export * from './chopsticks-provider.js';
|
|
41
|
+
export * from './database.js';
|
|
42
|
+
export * from './env.js';
|
|
50
43
|
export * from './genesis-provider.js';
|
|
44
|
+
export * from './logger.js';
|
|
45
|
+
export * from './offchain.js';
|
|
51
46
|
export * from './rpc/index.js';
|
|
47
|
+
export * from './schema/index.js';
|
|
48
|
+
export * from './setup.js';
|
|
49
|
+
export * from './utils/index.js';
|
|
50
|
+
export * from './wasm-executor/index.js';
|
|
51
|
+
export * from './xcm/index.js';
|
package/dist/cjs/index.js
CHANGED
|
@@ -11,25 +11,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
11
11
|
value: true
|
|
12
12
|
});
|
|
13
13
|
_export_star(require("./api.js"), exports);
|
|
14
|
-
_export_star(require("./blockchain/index.js"), exports);
|
|
15
14
|
_export_star(require("./blockchain/block.js"), exports);
|
|
16
15
|
_export_star(require("./blockchain/block-builder.js"), exports);
|
|
17
|
-
_export_star(require("./blockchain/txpool.js"), exports);
|
|
18
|
-
_export_star(require("./blockchain/storage-layer.js"), exports);
|
|
19
16
|
_export_star(require("./blockchain/head-state.js"), exports);
|
|
20
|
-
_export_star(require("./
|
|
21
|
-
_export_star(require("./utils/index.js"), exports);
|
|
22
|
-
_export_star(require("./wasm-executor/index.js"), exports);
|
|
23
|
-
_export_star(require("./schema/index.js"), exports);
|
|
24
|
-
_export_star(require("./xcm/index.js"), exports);
|
|
25
|
-
_export_star(require("./setup.js"), exports);
|
|
26
|
-
_export_star(require("./database.js"), exports);
|
|
17
|
+
_export_star(require("./blockchain/index.js"), exports);
|
|
27
18
|
_export_star(require("./blockchain/inherent/index.js"), exports);
|
|
28
|
-
_export_star(require("./
|
|
29
|
-
_export_star(require("./
|
|
19
|
+
_export_star(require("./blockchain/storage-layer.js"), exports);
|
|
20
|
+
_export_star(require("./blockchain/txpool.js"), exports);
|
|
30
21
|
_export_star(require("./chopsticks-provider.js"), exports);
|
|
22
|
+
_export_star(require("./database.js"), exports);
|
|
23
|
+
_export_star(require("./env.js"), exports);
|
|
31
24
|
_export_star(require("./genesis-provider.js"), exports);
|
|
25
|
+
_export_star(require("./logger.js"), exports);
|
|
26
|
+
_export_star(require("./offchain.js"), exports);
|
|
32
27
|
_export_star(require("./rpc/index.js"), exports);
|
|
28
|
+
_export_star(require("./schema/index.js"), exports);
|
|
29
|
+
_export_star(require("./setup.js"), exports);
|
|
30
|
+
_export_star(require("./utils/index.js"), exports);
|
|
31
|
+
_export_star(require("./wasm-executor/index.js"), exports);
|
|
32
|
+
_export_star(require("./xcm/index.js"), exports);
|
|
33
33
|
function _export_star(from, to) {
|
|
34
34
|
Object.keys(from).forEach(function(k) {
|
|
35
35
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
@@ -9,8 +9,8 @@ Object.defineProperty(exports, "dev_newBlock", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _zod = require("zod");
|
|
12
|
-
const _shared = require("../shared.js");
|
|
13
12
|
const _logger = require("../../logger.js");
|
|
13
|
+
const _shared = require("../shared.js");
|
|
14
14
|
const schema = _zod.z.object({
|
|
15
15
|
count: _zod.z.number().optional(),
|
|
16
16
|
to: _zod.z.number().optional(),
|
|
@@ -8,9 +8,9 @@ Object.defineProperty(exports, "dev_setStorage", {
|
|
|
8
8
|
return dev_setStorage;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _shared = require("../shared.js");
|
|
12
11
|
const _logger = require("../../logger.js");
|
|
13
12
|
const _setstorage = require("../../utils/set-storage.js");
|
|
13
|
+
const _shared = require("../shared.js");
|
|
14
14
|
const dev_setStorage = async (context, params)=>{
|
|
15
15
|
const [values, blockHash] = params;
|
|
16
16
|
const hash = await (0, _setstorage.setStorage)(context.chain, values, blockHash).catch((error)=>{
|
package/dist/cjs/rpc/index.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ import type { Handlers } from './shared.js';
|
|
|
3
3
|
import substrate from './substrate/index.js';
|
|
4
4
|
export declare const allHandlers: Handlers;
|
|
5
5
|
export { substrate, dev };
|
|
6
|
+
export type { Context, Handler, Handlers, SubscriptionManager } from './shared.js';
|
|
6
7
|
export { ResponseError } from './shared.js';
|
|
7
|
-
export type { Context, SubscriptionManager, Handler, Handlers } from './shared.js';
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { HexString } from '@polkadot/util/types';
|
|
2
|
+
import { type Handler } from '../shared.js';
|
|
3
|
+
import type { StorageItemRequest } from './chainHead_v1.js';
|
|
4
|
+
/**
|
|
5
|
+
* Retrieve the body of a specific block
|
|
6
|
+
*
|
|
7
|
+
* @param context
|
|
8
|
+
* @param params - [`hash`]
|
|
9
|
+
*
|
|
10
|
+
* @return An array of the SCALE-encoded transactions of a block, or `null` if the block is not found.
|
|
11
|
+
*/
|
|
12
|
+
export declare const archive_v1_body: Handler<[HexString], HexString[] | null>;
|
|
13
|
+
export type CallResult = {
|
|
14
|
+
success: true;
|
|
15
|
+
value: HexString;
|
|
16
|
+
} | {
|
|
17
|
+
success: false;
|
|
18
|
+
error: any;
|
|
19
|
+
};
|
|
20
|
+
export declare const archive_v1_call: Handler<[HexString, string, HexString], CallResult | null>;
|
|
21
|
+
/**
|
|
22
|
+
* Retrieve the height of the finalized block.
|
|
23
|
+
*
|
|
24
|
+
* @param context
|
|
25
|
+
*
|
|
26
|
+
* @return The `number` of the height of the head (a.k.a. finalized) block.
|
|
27
|
+
*/
|
|
28
|
+
export declare const archive_v1_finalizedHeight: Handler<undefined, number>;
|
|
29
|
+
/**
|
|
30
|
+
* Retrieve the genesis hash
|
|
31
|
+
*
|
|
32
|
+
* @param context
|
|
33
|
+
*
|
|
34
|
+
* @return An {@link HexString} with the hash of the genesis block.
|
|
35
|
+
*/
|
|
36
|
+
export declare const archive_v1_genesisHash: Handler<undefined, HexString>;
|
|
37
|
+
/**
|
|
38
|
+
* Retrieve the hash of a specific height
|
|
39
|
+
*
|
|
40
|
+
* @param context
|
|
41
|
+
* @param params - [`height`]
|
|
42
|
+
*
|
|
43
|
+
* @return An array of {@link HexString} with the hashes of the blocks associated to the
|
|
44
|
+
* given height.
|
|
45
|
+
*/
|
|
46
|
+
export declare const archive_v1_hashByHeight: Handler<[number], HexString[]>;
|
|
47
|
+
/**
|
|
48
|
+
* Retrieve the header for a specific block
|
|
49
|
+
*
|
|
50
|
+
* @param context
|
|
51
|
+
* @param params - [`hash`]
|
|
52
|
+
*
|
|
53
|
+
* @return SCALE-encoded header, or `null` if the block is not found.
|
|
54
|
+
*/
|
|
55
|
+
export declare const archive_v1_header: Handler<[HexString], HexString | null>;
|
|
56
|
+
/**
|
|
57
|
+
* Query the storage for a given block
|
|
58
|
+
*
|
|
59
|
+
* @param context
|
|
60
|
+
* @param params - [`hash`, `items`, `childTrie`]
|
|
61
|
+
*
|
|
62
|
+
* @return the operationId to capture the notifications where to receive the result
|
|
63
|
+
*
|
|
64
|
+
* The query type `closestDescendantMerkleValue` is not up to spec.
|
|
65
|
+
* According to the spec, the result should be the Merkle value of the key or
|
|
66
|
+
* the closest descendant of the key.
|
|
67
|
+
* As chopsticks doesn't have direct access to the Merkle tree, it will return
|
|
68
|
+
* a string that will change every time that one of the descendant changes, but
|
|
69
|
+
* it won't be the actual Merkle value.
|
|
70
|
+
* This should be enough for applications that don't rely on the actual Merkle
|
|
71
|
+
* value, but just use it to detect for storage changes.
|
|
72
|
+
*/
|
|
73
|
+
export declare const archive_v1_storage: Handler<[HexString, StorageItemRequest[], HexString | null], string>;
|
|
74
|
+
export declare const archive_v1_stopStorage: Handler<[string], null>;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get archive_v1_body () {
|
|
13
|
+
return archive_v1_body;
|
|
14
|
+
},
|
|
15
|
+
get archive_v1_call () {
|
|
16
|
+
return archive_v1_call;
|
|
17
|
+
},
|
|
18
|
+
get archive_v1_finalizedHeight () {
|
|
19
|
+
return archive_v1_finalizedHeight;
|
|
20
|
+
},
|
|
21
|
+
get archive_v1_genesisHash () {
|
|
22
|
+
return archive_v1_genesisHash;
|
|
23
|
+
},
|
|
24
|
+
get archive_v1_hashByHeight () {
|
|
25
|
+
return archive_v1_hashByHeight;
|
|
26
|
+
},
|
|
27
|
+
get archive_v1_header () {
|
|
28
|
+
return archive_v1_header;
|
|
29
|
+
},
|
|
30
|
+
get archive_v1_stopStorage () {
|
|
31
|
+
return archive_v1_stopStorage;
|
|
32
|
+
},
|
|
33
|
+
get archive_v1_storage () {
|
|
34
|
+
return archive_v1_storage;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
const _utilcrypto = require("@polkadot/util-crypto");
|
|
38
|
+
const _headstate = require("../../blockchain/head-state.js");
|
|
39
|
+
const _shared = require("../shared.js");
|
|
40
|
+
const _archive = require("../substrate/archive.js");
|
|
41
|
+
const _storagecommon = require("./storage-common.js");
|
|
42
|
+
const archive_v1_body = async (...args)=>(0, _archive.archive_unstable_body)(...args).catch(()=>null);
|
|
43
|
+
/**
|
|
44
|
+
* Perform a runtime call for a block
|
|
45
|
+
*
|
|
46
|
+
* @param context
|
|
47
|
+
* @param params - [`hash`, `function`, `callParameters`]
|
|
48
|
+
*
|
|
49
|
+
* @return A {@link CallResult} with the result of the runtime call, or `null` if the block
|
|
50
|
+
* is not found.
|
|
51
|
+
*/ function isBlockNotFound(error) {
|
|
52
|
+
return error instanceof _shared.ResponseError && error.code === 1;
|
|
53
|
+
}
|
|
54
|
+
const archive_v1_call = async (...args)=>_archive.archive_unstable_call.call(undefined, ...args).then(({ value })=>({
|
|
55
|
+
success: true,
|
|
56
|
+
value
|
|
57
|
+
}), (error)=>isBlockNotFound(error) ? null : {
|
|
58
|
+
success: false,
|
|
59
|
+
error
|
|
60
|
+
});
|
|
61
|
+
const archive_v1_finalizedHeight = (context)=>{
|
|
62
|
+
return Promise.resolve(context.chain.head.number);
|
|
63
|
+
};
|
|
64
|
+
const archive_v1_genesisHash = async (context)=>{
|
|
65
|
+
const genesisBlock = await context.chain.getBlockAt(0);
|
|
66
|
+
return genesisBlock.hash;
|
|
67
|
+
};
|
|
68
|
+
const archive_v1_hashByHeight = async (context, [height])=>{
|
|
69
|
+
const block = await context.chain.getBlockAt(height);
|
|
70
|
+
return block ? [
|
|
71
|
+
block.hash
|
|
72
|
+
] : [];
|
|
73
|
+
};
|
|
74
|
+
const archive_v1_header = async (context, [hash])=>{
|
|
75
|
+
const block = await context.chain.getBlock(hash);
|
|
76
|
+
return block ? (await block.header).toHex() : null;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Contains the storage operations.
|
|
80
|
+
*/ const storageOperations = new Map();
|
|
81
|
+
const archive_v1_storage = async (context, [hash, items, _childTrie], { subscribe })=>{
|
|
82
|
+
const operationId = (0, _headstate.randomId)();
|
|
83
|
+
const callback = subscribe('chainHead_v1_storageEvent', operationId, ()=>storageOperations.delete(operationId));
|
|
84
|
+
storageOperations.set(operationId, {
|
|
85
|
+
callback,
|
|
86
|
+
hash,
|
|
87
|
+
params: [],
|
|
88
|
+
storageDiffs: new Map()
|
|
89
|
+
});
|
|
90
|
+
(0, _storagecommon.afterResponse)(async ()=>{
|
|
91
|
+
const block = await context.chain.getBlock(hash);
|
|
92
|
+
if (!block) {
|
|
93
|
+
storageOperations.get(operationId)?.callback({
|
|
94
|
+
event: 'storageError',
|
|
95
|
+
operationId,
|
|
96
|
+
error: 'Block not found'
|
|
97
|
+
});
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const handleStorageItemRequest = async (sir)=>{
|
|
101
|
+
switch(sir.type){
|
|
102
|
+
case 'value':
|
|
103
|
+
{
|
|
104
|
+
const value = await block.get(sir.key);
|
|
105
|
+
if (value) {
|
|
106
|
+
storageOperations.get(operationId)?.callback({
|
|
107
|
+
event: 'storage',
|
|
108
|
+
key: sir.key,
|
|
109
|
+
value
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
case 'hash':
|
|
115
|
+
{
|
|
116
|
+
const value = await block.get(sir.key);
|
|
117
|
+
if (value) {
|
|
118
|
+
storageOperations.get(operationId)?.callback({
|
|
119
|
+
event: 'storage',
|
|
120
|
+
key: sir.key,
|
|
121
|
+
hash
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
case 'descendantsValues':
|
|
127
|
+
{
|
|
128
|
+
let items;
|
|
129
|
+
let next = {
|
|
130
|
+
prefix: sir.key,
|
|
131
|
+
startKey: '0x'
|
|
132
|
+
};
|
|
133
|
+
do {
|
|
134
|
+
;
|
|
135
|
+
({ items, next } = await (0, _storagecommon.getDescendantValues)(block, next));
|
|
136
|
+
for (const { key, value } of items){
|
|
137
|
+
storageOperations.get(operationId)?.callback({
|
|
138
|
+
event: 'storage',
|
|
139
|
+
key,
|
|
140
|
+
value
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}while (next !== null)
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
case 'descendantsHashes':
|
|
147
|
+
{
|
|
148
|
+
let items;
|
|
149
|
+
let next = {
|
|
150
|
+
prefix: sir.key,
|
|
151
|
+
startKey: '0x'
|
|
152
|
+
};
|
|
153
|
+
do {
|
|
154
|
+
;
|
|
155
|
+
({ items, next } = await (0, _storagecommon.getDescendantValues)(block, next));
|
|
156
|
+
for (const { key, value } of items){
|
|
157
|
+
if (value === undefined) {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
storageOperations.get(operationId)?.callback({
|
|
161
|
+
event: 'storage',
|
|
162
|
+
key,
|
|
163
|
+
hash: (0, _utilcrypto.blake2AsHex)(value)
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}while (next !== null)
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
case 'closestDescendantMerkleValue':
|
|
170
|
+
{
|
|
171
|
+
const subscription = storageOperations.get(operationId);
|
|
172
|
+
if (!subscription) return null;
|
|
173
|
+
if (!subscription.storageDiffs.has(sir.key)) {
|
|
174
|
+
// Set up a diff watch for this key
|
|
175
|
+
subscription.storageDiffs.set(sir.key, 0);
|
|
176
|
+
}
|
|
177
|
+
subscription.callback({
|
|
178
|
+
event: 'storage',
|
|
179
|
+
operationId,
|
|
180
|
+
items: [
|
|
181
|
+
{
|
|
182
|
+
key: sir.key,
|
|
183
|
+
closestDescendantMerkleValue: String(subscription.storageDiffs.get(sir.key))
|
|
184
|
+
}
|
|
185
|
+
]
|
|
186
|
+
});
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
await Promise.all(items.map(handleStorageItemRequest));
|
|
192
|
+
storageOperations.get(operationId)?.callback({
|
|
193
|
+
event: 'storageDone'
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
return operationId;
|
|
197
|
+
};
|
|
198
|
+
const archive_v1_stopStorage = async (_, [operationId], { unsubscribe })=>{
|
|
199
|
+
unsubscribe(operationId);
|
|
200
|
+
return null;
|
|
201
|
+
};
|
|
@@ -40,14 +40,11 @@ _export(exports, {
|
|
|
40
40
|
const _utilcrypto = require("@polkadot/util-crypto");
|
|
41
41
|
const _logger = require("../../logger.js");
|
|
42
42
|
const _shared = require("../shared.js");
|
|
43
|
+
const _storagecommon = require("./storage-common.js");
|
|
43
44
|
const logger = _logger.defaultLogger.child({
|
|
44
45
|
name: 'rpc-chainHead_v1'
|
|
45
46
|
});
|
|
46
47
|
const following = new Map();
|
|
47
|
-
async function afterResponse(fn) {
|
|
48
|
-
await new Promise((resolve)=>setTimeout(resolve, 0));
|
|
49
|
-
fn();
|
|
50
|
-
}
|
|
51
48
|
const chainHead_v1_follow = async (context, [withRuntime], { subscribe })=>{
|
|
52
49
|
const update = async (block)=>{
|
|
53
50
|
logger.trace({
|
|
@@ -101,7 +98,7 @@ const chainHead_v1_follow = async (context, [withRuntime], { subscribe })=>{
|
|
|
101
98
|
pendingDescendantValues: new Map(),
|
|
102
99
|
storageDiffs: new Map()
|
|
103
100
|
});
|
|
104
|
-
afterResponse(async ()=>{
|
|
101
|
+
(0, _storagecommon.afterResponse)(async ()=>{
|
|
105
102
|
callback({
|
|
106
103
|
event: 'initialized',
|
|
107
104
|
finalizedBlockHashes: [
|
|
@@ -128,7 +125,7 @@ const operationStarted = (operationId)=>({
|
|
|
128
125
|
const randomId = ()=>Math.random().toString(36).substring(2);
|
|
129
126
|
const chainHead_v1_call = async (context, [followSubscription, hash, method, callParameters])=>{
|
|
130
127
|
const operationId = randomId();
|
|
131
|
-
afterResponse(async ()=>{
|
|
128
|
+
(0, _storagecommon.afterResponse)(async ()=>{
|
|
132
129
|
const block = await context.chain.getBlock(hash);
|
|
133
130
|
if (!block) {
|
|
134
131
|
following.get(followSubscription)?.callback({
|
|
@@ -157,33 +154,9 @@ const chainHead_v1_call = async (context, [followSubscription, hash, method, cal
|
|
|
157
154
|
});
|
|
158
155
|
return operationStarted(operationId);
|
|
159
156
|
};
|
|
160
|
-
const PAGE_SIZE = 1000;
|
|
161
|
-
async function getDescendantValues(block, params) {
|
|
162
|
-
const keys = await block.getKeysPaged({
|
|
163
|
-
...params,
|
|
164
|
-
pageSize: PAGE_SIZE
|
|
165
|
-
});
|
|
166
|
-
const items = await Promise.all(keys.map((key)=>block.get(key).then((value)=>({
|
|
167
|
-
key,
|
|
168
|
-
value
|
|
169
|
-
}))));
|
|
170
|
-
if (keys.length < PAGE_SIZE) {
|
|
171
|
-
return {
|
|
172
|
-
items,
|
|
173
|
-
next: null
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
return {
|
|
177
|
-
items,
|
|
178
|
-
next: {
|
|
179
|
-
...params,
|
|
180
|
-
startKey: keys[PAGE_SIZE - 1]
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
157
|
const chainHead_v1_storage = async (context, [followSubscription, hash, items, _childTrie])=>{
|
|
185
158
|
const operationId = randomId();
|
|
186
|
-
afterResponse(async ()=>{
|
|
159
|
+
(0, _storagecommon.afterResponse)(async ()=>{
|
|
187
160
|
const block = await context.chain.getBlock(hash);
|
|
188
161
|
if (!block) {
|
|
189
162
|
following.get(followSubscription)?.callback({
|
|
@@ -231,7 +204,7 @@ const chainHead_v1_storage = async (context, [followSubscription, hash, items, _
|
|
|
231
204
|
}
|
|
232
205
|
case 'descendantsValues':
|
|
233
206
|
{
|
|
234
|
-
const { items, next } = await getDescendantValues(block, {
|
|
207
|
+
const { items, next } = await (0, _storagecommon.getDescendantValues)(block, {
|
|
235
208
|
prefix: sir.key,
|
|
236
209
|
startKey: '0x'
|
|
237
210
|
});
|
|
@@ -244,7 +217,7 @@ const chainHead_v1_storage = async (context, [followSubscription, hash, items, _
|
|
|
244
217
|
}
|
|
245
218
|
case 'descendantsHashes':
|
|
246
219
|
{
|
|
247
|
-
const { items, next } = await getDescendantValues(block, {
|
|
220
|
+
const { items, next } = await (0, _storagecommon.getDescendantValues)(block, {
|
|
248
221
|
prefix: sir.key,
|
|
249
222
|
startKey: '0x'
|
|
250
223
|
});
|
|
@@ -319,7 +292,7 @@ const chainHead_v1_body = async (context, [followSubscription, hash])=>{
|
|
|
319
292
|
throw new _shared.ResponseError(-32801, 'Block not found');
|
|
320
293
|
}
|
|
321
294
|
const operationId = randomId();
|
|
322
|
-
afterResponse(async ()=>{
|
|
295
|
+
(0, _storagecommon.afterResponse)(async ()=>{
|
|
323
296
|
const body = await block.extrinsics;
|
|
324
297
|
following.get(followSubscription)?.callback({
|
|
325
298
|
event: 'operationBodyDone',
|
|
@@ -339,9 +312,9 @@ const chainHead_v1_continue = async (context, [followSubscription, operationId])
|
|
|
339
312
|
if (!block) {
|
|
340
313
|
throw new _shared.ResponseError(-32801, 'Block not found');
|
|
341
314
|
}
|
|
342
|
-
afterResponse(async ()=>{
|
|
315
|
+
(0, _storagecommon.afterResponse)(async ()=>{
|
|
343
316
|
const handlePendingOperation = async (params)=>{
|
|
344
|
-
const { items, next } = await getDescendantValues(block, params);
|
|
317
|
+
const { items, next } = await (0, _storagecommon.getDescendantValues)(block, params);
|
|
345
318
|
follower.callback({
|
|
346
319
|
event: 'operationStorageItems',
|
|
347
320
|
operationId,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as ArchiveV1RPC from './archive_v1.js';
|
|
1
2
|
import * as ChainHeadV1RPC from './chainHead_v1.js';
|
|
2
3
|
import * as ChainSpecV1RPC from './chainSpec_v1.js';
|
|
3
4
|
import * as TransactionV1RPC from './transaction_v1.js';
|
|
@@ -23,5 +24,13 @@ declare const handlers: {
|
|
|
23
24
|
chainHead_v1_continue: import("../shared.js").Handler<[string, import("@polkadot/util/types").HexString], null>;
|
|
24
25
|
chainHead_v1_stopOperation: import("../shared.js").Handler<[string, import("@polkadot/util/types").HexString], null>;
|
|
25
26
|
chainHead_v1_unpin: import("../shared.js").Handler<[string, import("@polkadot/util/types").HexString | import("@polkadot/util/types").HexString[]], null>;
|
|
27
|
+
archive_v1_body: import("../shared.js").Handler<[import("@polkadot/util/types").HexString], import("@polkadot/util/types").HexString[] | null>;
|
|
28
|
+
archive_v1_call: import("../shared.js").Handler<[import("@polkadot/util/types").HexString, string, import("@polkadot/util/types").HexString], ArchiveV1RPC.CallResult | null>;
|
|
29
|
+
archive_v1_finalizedHeight: import("../shared.js").Handler<undefined, number>;
|
|
30
|
+
archive_v1_genesisHash: import("../shared.js").Handler<undefined, import("@polkadot/util/types").HexString>;
|
|
31
|
+
archive_v1_hashByHeight: import("../shared.js").Handler<[number], import("@polkadot/util/types").HexString[]>;
|
|
32
|
+
archive_v1_header: import("../shared.js").Handler<[import("@polkadot/util/types").HexString], import("@polkadot/util/types").HexString | null>;
|
|
33
|
+
archive_v1_storage: import("../shared.js").Handler<[import("@polkadot/util/types").HexString, ChainHeadV1RPC.StorageItemRequest[], import("@polkadot/util/types").HexString | null], string>;
|
|
34
|
+
archive_v1_stopStorage: import("../shared.js").Handler<[string], null>;
|
|
26
35
|
};
|
|
27
36
|
export default handlers;
|
|
@@ -22,6 +22,7 @@ _export(exports, {
|
|
|
22
22
|
return _default;
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
|
+
const _archive_v1 = /*#__PURE__*/ _interop_require_wildcard(require("./archive_v1.js"));
|
|
25
26
|
const _chainHead_v1 = /*#__PURE__*/ _interop_require_wildcard(require("./chainHead_v1.js"));
|
|
26
27
|
const _chainSpec_v1 = /*#__PURE__*/ _interop_require_wildcard(require("./chainSpec_v1.js"));
|
|
27
28
|
const _transaction_v1 = /*#__PURE__*/ _interop_require_wildcard(require("./transaction_v1.js"));
|
|
@@ -67,6 +68,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
67
68
|
return newObj;
|
|
68
69
|
}
|
|
69
70
|
const handlers = {
|
|
71
|
+
..._archive_v1,
|
|
70
72
|
..._chainHead_v1,
|
|
71
73
|
..._transaction_v1,
|
|
72
74
|
..._chainSpec_v1
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HexString } from '@polkadot/util/types';
|
|
2
|
+
import type { Block } from '../../blockchain/block.js';
|
|
3
|
+
export declare function getDescendantValues(block: Block, params: DescendantValuesParams): Promise<{
|
|
4
|
+
items: Array<{
|
|
5
|
+
key: string;
|
|
6
|
+
value?: HexString;
|
|
7
|
+
}>;
|
|
8
|
+
next: DescendantValuesParams | null;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const PAGE_SIZE = 1000;
|
|
11
|
+
export type DescendantValuesParams = {
|
|
12
|
+
prefix: string;
|
|
13
|
+
startKey: string;
|
|
14
|
+
isDescendantHashes?: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare function afterResponse(fn: () => void): Promise<void>;
|