@acala-network/chopsticks-core 0.14.2-1 → 0.16.0
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/inherent/parachain/validation-data.js +13 -1
- package/dist/cjs/blockchain/txpool.d.ts +1 -0
- package/dist/cjs/blockchain/txpool.js +3 -1
- package/dist/cjs/rpc/dev/new-block.d.ts +7 -0
- package/dist/cjs/rpc/dev/new-block.js +11 -3
- package/dist/cjs/rpc/index.js +4 -2
- package/dist/cjs/rpc/rpc-spec/chainHead_v1.d.ts +79 -0
- package/dist/cjs/rpc/rpc-spec/chainHead_v1.js +245 -0
- package/dist/cjs/rpc/rpc-spec/chainSpec_v1.d.ts +6 -0
- package/dist/cjs/rpc/rpc-spec/chainSpec_v1.js +35 -0
- package/dist/cjs/rpc/rpc-spec/index.d.ts +27 -0
- package/dist/cjs/rpc/rpc-spec/index.js +74 -0
- package/dist/cjs/rpc/rpc-spec/transaction_v1.d.ts +16 -0
- package/dist/cjs/rpc/rpc-spec/transaction_v1.js +35 -0
- package/dist/cjs/utils/proof.d.ts +1 -0
- package/dist/cjs/utils/proof.js +7 -0
- package/dist/esm/blockchain/inherent/parachain/validation-data.js +13 -1
- package/dist/esm/blockchain/txpool.d.ts +1 -0
- package/dist/esm/blockchain/txpool.js +3 -1
- package/dist/esm/rpc/dev/new-block.d.ts +7 -0
- package/dist/esm/rpc/dev/new-block.js +11 -3
- package/dist/esm/rpc/index.js +2 -0
- package/dist/esm/rpc/rpc-spec/chainHead_v1.d.ts +79 -0
- package/dist/esm/rpc/rpc-spec/chainHead_v1.js +250 -0
- package/dist/esm/rpc/rpc-spec/chainSpec_v1.d.ts +6 -0
- package/dist/esm/rpc/rpc-spec/chainSpec_v1.js +14 -0
- package/dist/esm/rpc/rpc-spec/index.d.ts +27 -0
- package/dist/esm/rpc/rpc-spec/index.js +10 -0
- package/dist/esm/rpc/rpc-spec/transaction_v1.d.ts +16 -0
- package/dist/esm/rpc/rpc-spec/transaction_v1.js +27 -0
- package/dist/esm/utils/proof.d.ts +1 -0
- package/dist/esm/utils/proof.js +4 -0
- package/package.json +2 -2
|
@@ -80,7 +80,7 @@ class SetValidationData {
|
|
|
80
80
|
return [];
|
|
81
81
|
}
|
|
82
82
|
const extrinsic = await getValidationData(parent);
|
|
83
|
-
|
|
83
|
+
let newEntries = [];
|
|
84
84
|
const downwardMessages = [];
|
|
85
85
|
const horizontalMessages = {};
|
|
86
86
|
const paraId = await (0, _index.getParaId)(parent.chain);
|
|
@@ -229,6 +229,18 @@ class SetValidationData {
|
|
|
229
229
|
null
|
|
230
230
|
]);
|
|
231
231
|
}
|
|
232
|
+
// Apply relay chain state overrides
|
|
233
|
+
if (params.relayChainStateOverrides) {
|
|
234
|
+
for (const [key, value] of params.relayChainStateOverrides){
|
|
235
|
+
// Remove any entry that matches the key being overridden
|
|
236
|
+
newEntries = newEntries.filter(([k, _])=>k != key);
|
|
237
|
+
// Push override
|
|
238
|
+
newEntries.push([
|
|
239
|
+
key,
|
|
240
|
+
value
|
|
241
|
+
]);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
232
244
|
const { trieRootHash, nodes } = await (0, _index1.createProof)(extrinsic.relayChainState.trieNodes, newEntries);
|
|
233
245
|
const newData = {
|
|
234
246
|
...extrinsic,
|
|
@@ -25,6 +25,7 @@ export interface BuildBlockParams {
|
|
|
25
25
|
horizontalMessages: Record<number, HorizontalMessage[]>;
|
|
26
26
|
transactions: HexString[];
|
|
27
27
|
unsafeBlockHeight?: number;
|
|
28
|
+
relayChainStateOverrides?: [HexString, HexString | null][];
|
|
28
29
|
}
|
|
29
30
|
export declare class TxPool {
|
|
30
31
|
#private;
|
|
@@ -193,6 +193,7 @@ class TxPool {
|
|
|
193
193
|
..._class_private_field_get(this, _hrmp)
|
|
194
194
|
};
|
|
195
195
|
const unsafeBlockHeight = params?.unsafeBlockHeight;
|
|
196
|
+
const relayChainStateOverrides = params?.relayChainStateOverrides;
|
|
196
197
|
if (!params?.upwardMessages) {
|
|
197
198
|
for (const id of Object.keys(_class_private_field_get(this, _ump))){
|
|
198
199
|
delete _class_private_field_get(this, _ump)[id];
|
|
@@ -209,7 +210,8 @@ class TxPool {
|
|
|
209
210
|
upwardMessages,
|
|
210
211
|
downwardMessages,
|
|
211
212
|
horizontalMessages,
|
|
212
|
-
unsafeBlockHeight
|
|
213
|
+
unsafeBlockHeight,
|
|
214
|
+
relayChainStateOverrides
|
|
213
215
|
});
|
|
214
216
|
// with the latest message queue, messages could be processed in the upcoming block
|
|
215
217
|
if (!_class_private_field_get(this, _chain).processQueuedMessages) return;
|
|
@@ -26,6 +26,7 @@ declare const schema: z.ZodObject<{
|
|
|
26
26
|
}>, "many">>>;
|
|
27
27
|
transactions: z.ZodOptional<z.ZodArray<z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, "many">>;
|
|
28
28
|
unsafeBlockHeight: z.ZodOptional<z.ZodNumber>;
|
|
29
|
+
relayChainStateOverrides: z.ZodOptional<z.ZodArray<z.ZodTuple<[z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, z.ZodUnion<[z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, z.ZodNull]>], null>, "many">>;
|
|
29
30
|
}, "strip", z.ZodTypeAny, {
|
|
30
31
|
transactions?: `0x${string}`[] | undefined;
|
|
31
32
|
unsafeBlockHeight?: number | undefined;
|
|
@@ -38,6 +39,7 @@ declare const schema: z.ZodObject<{
|
|
|
38
39
|
data: `0x${string}`;
|
|
39
40
|
sentAt: number;
|
|
40
41
|
}[]> | undefined;
|
|
42
|
+
relayChainStateOverrides?: [`0x${string}`, `0x${string}` | null][] | undefined;
|
|
41
43
|
count?: number | undefined;
|
|
42
44
|
to?: number | undefined;
|
|
43
45
|
}, {
|
|
@@ -52,6 +54,7 @@ declare const schema: z.ZodObject<{
|
|
|
52
54
|
data: `0x${string}`;
|
|
53
55
|
sentAt: number;
|
|
54
56
|
}[]> | undefined;
|
|
57
|
+
relayChainStateOverrides?: [`0x${string}`, `0x${string}` | null][] | undefined;
|
|
55
58
|
count?: number | undefined;
|
|
56
59
|
to?: number | undefined;
|
|
57
60
|
}>;
|
|
@@ -85,6 +88,10 @@ export interface NewBlockParams {
|
|
|
85
88
|
* Build block using a specific block height (unsafe)
|
|
86
89
|
*/
|
|
87
90
|
unsafeBlockHeight: Params['unsafeBlockHeight'];
|
|
91
|
+
/**
|
|
92
|
+
* Build block using a custom relay chain state
|
|
93
|
+
*/
|
|
94
|
+
relayChainStateOverrides: Params['relayChainStateOverrides'];
|
|
88
95
|
}
|
|
89
96
|
/**
|
|
90
97
|
* Build new blocks.
|
|
@@ -27,10 +27,17 @@ const schema = _zod.z.object({
|
|
|
27
27
|
data: _shared.zHex
|
|
28
28
|
})).min(1)).optional(),
|
|
29
29
|
transactions: _zod.z.array(_shared.zHex).min(1).optional(),
|
|
30
|
-
unsafeBlockHeight: _zod.z.number().optional()
|
|
30
|
+
unsafeBlockHeight: _zod.z.number().optional(),
|
|
31
|
+
relayChainStateOverrides: _zod.z.array(_zod.z.tuple([
|
|
32
|
+
_shared.zHex,
|
|
33
|
+
_zod.z.union([
|
|
34
|
+
_shared.zHex,
|
|
35
|
+
_zod.z.null()
|
|
36
|
+
])
|
|
37
|
+
])).optional()
|
|
31
38
|
});
|
|
32
39
|
const dev_newBlock = async (context, [params])=>{
|
|
33
|
-
const { count, to, hrmp, ump, dmp, transactions, unsafeBlockHeight } = schema.parse(params || {});
|
|
40
|
+
const { count, to, hrmp, ump, dmp, transactions, unsafeBlockHeight, relayChainStateOverrides } = schema.parse(params || {});
|
|
34
41
|
const now = context.chain.head.number;
|
|
35
42
|
const diff = to ? to - now : count;
|
|
36
43
|
const finalCount = diff !== undefined ? Math.max(diff, 1) : 1;
|
|
@@ -44,7 +51,8 @@ const dev_newBlock = async (context, [params])=>{
|
|
|
44
51
|
horizontalMessages: hrmp,
|
|
45
52
|
upwardMessages: ump,
|
|
46
53
|
downwardMessages: dmp,
|
|
47
|
-
unsafeBlockHeight: i === 0 ? unsafeBlockHeight : undefined
|
|
54
|
+
unsafeBlockHeight: i === 0 ? unsafeBlockHeight : undefined,
|
|
55
|
+
relayChainStateOverrides: relayChainStateOverrides
|
|
48
56
|
}).catch((error)=>{
|
|
49
57
|
throw new _shared.ResponseError(1, error.toString());
|
|
50
58
|
});
|
package/dist/cjs/rpc/index.js
CHANGED
|
@@ -19,11 +19,12 @@ _export(exports, {
|
|
|
19
19
|
return _index.default;
|
|
20
20
|
},
|
|
21
21
|
substrate: function() {
|
|
22
|
-
return
|
|
22
|
+
return _index2.default;
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
25
|
const _index = /*#__PURE__*/ _interop_require_default(require("./dev/index.js"));
|
|
26
|
-
const _index1 = /*#__PURE__*/ _interop_require_default(require("./
|
|
26
|
+
const _index1 = /*#__PURE__*/ _interop_require_default(require("./rpc-spec/index.js"));
|
|
27
|
+
const _index2 = /*#__PURE__*/ _interop_require_default(require("./substrate/index.js"));
|
|
27
28
|
const _shared = require("./shared.js");
|
|
28
29
|
function _interop_require_default(obj) {
|
|
29
30
|
return obj && obj.__esModule ? obj : {
|
|
@@ -31,6 +32,7 @@ function _interop_require_default(obj) {
|
|
|
31
32
|
};
|
|
32
33
|
}
|
|
33
34
|
const allHandlers = {
|
|
35
|
+
..._index2.default,
|
|
34
36
|
..._index1.default,
|
|
35
37
|
..._index.default,
|
|
36
38
|
rpc_methods: async ()=>Promise.resolve({
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Handler } from '../shared.js';
|
|
2
|
+
import { HexString } from '@polkadot/util/types';
|
|
3
|
+
/**
|
|
4
|
+
* Start a chainHead follow subscription
|
|
5
|
+
*
|
|
6
|
+
* @param context
|
|
7
|
+
* @param params - [`withRuntime`]
|
|
8
|
+
* @param subscriptionManager
|
|
9
|
+
*
|
|
10
|
+
* @return subscription id
|
|
11
|
+
*/
|
|
12
|
+
export declare const chainHead_v1_follow: Handler<[boolean], string>;
|
|
13
|
+
/**
|
|
14
|
+
* Stop a chainHead follow subscription
|
|
15
|
+
*
|
|
16
|
+
* @param context
|
|
17
|
+
* @param params - [`followSubscription`]
|
|
18
|
+
* @param subscriptionManager
|
|
19
|
+
*/
|
|
20
|
+
export declare const chainHead_v1_unfollow: Handler<[string], null>;
|
|
21
|
+
/**
|
|
22
|
+
* Retrieve the header for a specific block
|
|
23
|
+
*
|
|
24
|
+
* @param context
|
|
25
|
+
* @param params - [`followSubscription`, `hash`]
|
|
26
|
+
*
|
|
27
|
+
* @return SCALE-encoded header, or null if the block is not found.
|
|
28
|
+
*/
|
|
29
|
+
export declare const chainHead_v1_header: Handler<[string, HexString], HexString | null>;
|
|
30
|
+
type OperationStarted = {
|
|
31
|
+
result: 'started';
|
|
32
|
+
operationId: string;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Perform a runtime call for a block
|
|
36
|
+
*
|
|
37
|
+
* @param context
|
|
38
|
+
* @param params - [`followSubscription`, `hash`, `function`, `callParameters`]
|
|
39
|
+
*
|
|
40
|
+
* @return OperationStarted event with operationId to receive the result on the follow subscription
|
|
41
|
+
*/
|
|
42
|
+
export declare const chainHead_v1_call: Handler<[string, HexString, string, HexString], OperationStarted>;
|
|
43
|
+
export type StorageStarted = OperationStarted & {
|
|
44
|
+
discardedItems: number;
|
|
45
|
+
};
|
|
46
|
+
export interface StorageItemRequest {
|
|
47
|
+
key: HexString;
|
|
48
|
+
type: 'value' | 'hash' | 'closestDescendantMerkleValue' | 'descendantsValues' | 'descendantsHashes';
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Query the storage for a given block
|
|
52
|
+
*
|
|
53
|
+
* @param context
|
|
54
|
+
* @param params - [`followSubscription`, `hash`, `items`, `childTrie`]
|
|
55
|
+
*
|
|
56
|
+
* @return OperationStarted event with operationId to receive the result on the follow subscription
|
|
57
|
+
*/
|
|
58
|
+
export declare const chainHead_v1_storage: Handler<[
|
|
59
|
+
string,
|
|
60
|
+
HexString,
|
|
61
|
+
StorageItemRequest[],
|
|
62
|
+
HexString | null
|
|
63
|
+
], StorageStarted>;
|
|
64
|
+
export type LimitReached = {
|
|
65
|
+
result: 'limitReached';
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Retrieve the body of a specific block
|
|
69
|
+
*
|
|
70
|
+
* @param context
|
|
71
|
+
* @param params - [`followSubscription`, `hash`]
|
|
72
|
+
*
|
|
73
|
+
* @return OperationStarted event with operationId to receive the result on the follow subscription
|
|
74
|
+
*/
|
|
75
|
+
export declare const chainHead_v1_body: Handler<[string, HexString], OperationStarted | LimitReached>;
|
|
76
|
+
export declare const chainHead_v1_continue: Handler<[string, HexString], null>;
|
|
77
|
+
export declare const chainHead_v1_stopOperation: Handler<[string, HexString], null>;
|
|
78
|
+
export declare const chainHead_v1_unpin: Handler<[string, HexString | HexString[]], null>;
|
|
79
|
+
export {};
|
|
@@ -0,0 +1,245 @@
|
|
|
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: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
chainHead_v1_body: function() {
|
|
13
|
+
return chainHead_v1_body;
|
|
14
|
+
},
|
|
15
|
+
chainHead_v1_call: function() {
|
|
16
|
+
return chainHead_v1_call;
|
|
17
|
+
},
|
|
18
|
+
chainHead_v1_continue: function() {
|
|
19
|
+
return chainHead_v1_continue;
|
|
20
|
+
},
|
|
21
|
+
chainHead_v1_follow: function() {
|
|
22
|
+
return chainHead_v1_follow;
|
|
23
|
+
},
|
|
24
|
+
chainHead_v1_header: function() {
|
|
25
|
+
return chainHead_v1_header;
|
|
26
|
+
},
|
|
27
|
+
chainHead_v1_stopOperation: function() {
|
|
28
|
+
return chainHead_v1_stopOperation;
|
|
29
|
+
},
|
|
30
|
+
chainHead_v1_storage: function() {
|
|
31
|
+
return chainHead_v1_storage;
|
|
32
|
+
},
|
|
33
|
+
chainHead_v1_unfollow: function() {
|
|
34
|
+
return chainHead_v1_unfollow;
|
|
35
|
+
},
|
|
36
|
+
chainHead_v1_unpin: function() {
|
|
37
|
+
return chainHead_v1_unpin;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
const _shared = require("../shared.js");
|
|
41
|
+
const _logger = require("../../logger.js");
|
|
42
|
+
const logger = _logger.defaultLogger.child({
|
|
43
|
+
name: 'rpc-chainHead_v1'
|
|
44
|
+
});
|
|
45
|
+
const callbacks = new Map();
|
|
46
|
+
async function afterResponse(fn) {
|
|
47
|
+
await new Promise((resolve)=>setTimeout(resolve, 0));
|
|
48
|
+
fn();
|
|
49
|
+
}
|
|
50
|
+
const chainHead_v1_follow = async (context, [withRuntime], { subscribe })=>{
|
|
51
|
+
const update = async (block)=>{
|
|
52
|
+
logger.trace({
|
|
53
|
+
hash: block.hash
|
|
54
|
+
}, 'chainHead_v1_follow');
|
|
55
|
+
const getNewRuntime = async ()=>{
|
|
56
|
+
const [runtime, previousRuntime] = await Promise.all([
|
|
57
|
+
block.runtimeVersion,
|
|
58
|
+
block.parentBlock.then((b)=>b?.runtimeVersion)
|
|
59
|
+
]);
|
|
60
|
+
const hasNewRuntime = runtime.implVersion !== previousRuntime?.implVersion || runtime.specVersion !== previousRuntime.specVersion;
|
|
61
|
+
return hasNewRuntime ? runtime : null;
|
|
62
|
+
};
|
|
63
|
+
const newRuntime = withRuntime ? await getNewRuntime() : null;
|
|
64
|
+
callback({
|
|
65
|
+
event: 'newBlock',
|
|
66
|
+
blockHash: block.hash,
|
|
67
|
+
parentBlockHash: (await block.parentBlock)?.hash,
|
|
68
|
+
newRuntime
|
|
69
|
+
});
|
|
70
|
+
callback({
|
|
71
|
+
event: 'bestBlockChanged',
|
|
72
|
+
bestBlockHash: block.hash
|
|
73
|
+
});
|
|
74
|
+
callback({
|
|
75
|
+
event: 'finalized',
|
|
76
|
+
finalizedBlockHashes: [
|
|
77
|
+
block.hash
|
|
78
|
+
],
|
|
79
|
+
prunedBlockHashes: []
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
const id = context.chain.headState.subscribeHead(update);
|
|
83
|
+
const cleanup = ()=>{
|
|
84
|
+
context.chain.headState.unsubscribeHead(id);
|
|
85
|
+
callbacks.delete(id);
|
|
86
|
+
};
|
|
87
|
+
const callback = subscribe('chainHead_v1_followEvent', id, cleanup);
|
|
88
|
+
callbacks.set(id, callback);
|
|
89
|
+
afterResponse(async ()=>{
|
|
90
|
+
callback({
|
|
91
|
+
event: 'initialized',
|
|
92
|
+
finalizedBlockHashes: [
|
|
93
|
+
context.chain.head.hash
|
|
94
|
+
],
|
|
95
|
+
finalizedBlockRuntime: withRuntime ? await context.chain.head.runtimeVersion : null
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
return id;
|
|
99
|
+
};
|
|
100
|
+
const chainHead_v1_unfollow = async (_, [followSubscription], { unsubscribe })=>{
|
|
101
|
+
unsubscribe(followSubscription);
|
|
102
|
+
return null;
|
|
103
|
+
};
|
|
104
|
+
const chainHead_v1_header = async (context, [followSubscription, hash])=>{
|
|
105
|
+
if (!callbacks.has(followSubscription)) return null;
|
|
106
|
+
const block = await context.chain.getBlock(hash);
|
|
107
|
+
return block ? (await block.header).toHex() : null;
|
|
108
|
+
};
|
|
109
|
+
const operationStarted = (operationId)=>({
|
|
110
|
+
result: 'started',
|
|
111
|
+
operationId
|
|
112
|
+
});
|
|
113
|
+
const randomId = ()=>Math.random().toString(36).substring(2);
|
|
114
|
+
const chainHead_v1_call = async (context, [followSubscription, hash, method, callParameters])=>{
|
|
115
|
+
const operationId = randomId();
|
|
116
|
+
afterResponse(async ()=>{
|
|
117
|
+
const block = await context.chain.getBlock(hash);
|
|
118
|
+
if (!block) {
|
|
119
|
+
callbacks.get(followSubscription)?.({
|
|
120
|
+
event: 'operationError',
|
|
121
|
+
operationId,
|
|
122
|
+
error: `Block ${hash} not found`
|
|
123
|
+
});
|
|
124
|
+
} else {
|
|
125
|
+
try {
|
|
126
|
+
const resp = await block.call(method, [
|
|
127
|
+
callParameters
|
|
128
|
+
]);
|
|
129
|
+
callbacks.get(followSubscription)?.({
|
|
130
|
+
event: 'operationCallDone',
|
|
131
|
+
operationId,
|
|
132
|
+
output: resp.result
|
|
133
|
+
});
|
|
134
|
+
} catch (ex) {
|
|
135
|
+
callbacks.get(followSubscription)?.({
|
|
136
|
+
event: 'operationError',
|
|
137
|
+
operationId,
|
|
138
|
+
error: ex.message
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
return operationStarted(operationId);
|
|
144
|
+
};
|
|
145
|
+
const chainHead_v1_storage = async (context, [followSubscription, hash, items, _childTrie])=>{
|
|
146
|
+
const operationId = randomId();
|
|
147
|
+
afterResponse(async ()=>{
|
|
148
|
+
const block = await context.chain.getBlock(hash);
|
|
149
|
+
if (!block) {
|
|
150
|
+
callbacks.get(followSubscription)?.({
|
|
151
|
+
event: 'operationError',
|
|
152
|
+
operationId,
|
|
153
|
+
error: 'Block not found'
|
|
154
|
+
});
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const handleStorageItemRequest = async (sir)=>{
|
|
158
|
+
switch(sir.type){
|
|
159
|
+
case 'value':
|
|
160
|
+
{
|
|
161
|
+
const value = await block.get(sir.key);
|
|
162
|
+
if (value) {
|
|
163
|
+
callbacks.get(followSubscription)?.({
|
|
164
|
+
event: 'operationStorageItems',
|
|
165
|
+
operationId,
|
|
166
|
+
items: [
|
|
167
|
+
{
|
|
168
|
+
key: sir.key,
|
|
169
|
+
value
|
|
170
|
+
}
|
|
171
|
+
]
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
case 'descendantsValues':
|
|
177
|
+
{
|
|
178
|
+
// TODO expose pagination
|
|
179
|
+
const pageSize = 100;
|
|
180
|
+
let startKey = '0x';
|
|
181
|
+
while(startKey){
|
|
182
|
+
const keys = await block.getKeysPaged({
|
|
183
|
+
prefix: sir.key,
|
|
184
|
+
pageSize,
|
|
185
|
+
startKey
|
|
186
|
+
});
|
|
187
|
+
startKey = keys[pageSize - 1] ?? null;
|
|
188
|
+
const items = await Promise.all(keys.map((key)=>block.get(key).then((value)=>({
|
|
189
|
+
key,
|
|
190
|
+
value
|
|
191
|
+
}))));
|
|
192
|
+
callbacks.get(followSubscription)?.({
|
|
193
|
+
event: 'operationStorageItems',
|
|
194
|
+
operationId,
|
|
195
|
+
items
|
|
196
|
+
});
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
default:
|
|
202
|
+
// TODO
|
|
203
|
+
console.warn(`Storage type not implemented ${sir.type}`);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
await Promise.all(items.map(handleStorageItemRequest));
|
|
207
|
+
callbacks.get(followSubscription)?.({
|
|
208
|
+
event: 'operationStorageDone',
|
|
209
|
+
operationId
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
return {
|
|
213
|
+
...operationStarted(operationId),
|
|
214
|
+
discardedItems: 0
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
const limitReached = {
|
|
218
|
+
result: 'limitReached'
|
|
219
|
+
};
|
|
220
|
+
const chainHead_v1_body = async (context, [followSubscription, hash])=>{
|
|
221
|
+
if (!callbacks.has(followSubscription)) return limitReached;
|
|
222
|
+
const block = await context.chain.getBlock(hash);
|
|
223
|
+
if (!block) {
|
|
224
|
+
throw new _shared.ResponseError(-32801, 'Block not found');
|
|
225
|
+
}
|
|
226
|
+
const operationId = randomId();
|
|
227
|
+
afterResponse(async ()=>{
|
|
228
|
+
const body = await block.extrinsics;
|
|
229
|
+
callbacks.get(followSubscription)?.({
|
|
230
|
+
event: 'operationBodyDone',
|
|
231
|
+
operationId,
|
|
232
|
+
value: body
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
return operationStarted(operationId);
|
|
236
|
+
};
|
|
237
|
+
const chainHead_v1_continue = async (_context, [_followSubscription, _operationId])=>{
|
|
238
|
+
return null;
|
|
239
|
+
};
|
|
240
|
+
const chainHead_v1_stopOperation = async (_context, [_followSubscription, _operationId])=>{
|
|
241
|
+
return null;
|
|
242
|
+
};
|
|
243
|
+
const chainHead_v1_unpin = async (_context, [_followSubscription, _hashOrHashes])=>{
|
|
244
|
+
return null;
|
|
245
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ChainProperties } from '../../index.js';
|
|
2
|
+
import { Handler } from '../shared.js';
|
|
3
|
+
import { HexString } from '@polkadot/util/types';
|
|
4
|
+
export declare const chainSpec_v1_chainName: Handler<[], string>;
|
|
5
|
+
export declare const chainSpec_v1_genesisHash: Handler<[], HexString>;
|
|
6
|
+
export declare const chainSpec_v1_properties: Handler<[], ChainProperties>;
|
|
@@ -0,0 +1,35 @@
|
|
|
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: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
chainSpec_v1_chainName: function() {
|
|
13
|
+
return chainSpec_v1_chainName;
|
|
14
|
+
},
|
|
15
|
+
chainSpec_v1_genesisHash: function() {
|
|
16
|
+
return chainSpec_v1_genesisHash;
|
|
17
|
+
},
|
|
18
|
+
chainSpec_v1_properties: function() {
|
|
19
|
+
return chainSpec_v1_properties;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const _shared = require("../shared.js");
|
|
23
|
+
const chainSpec_v1_chainName = async (context)=>{
|
|
24
|
+
return context.chain.api.getSystemChain();
|
|
25
|
+
};
|
|
26
|
+
const chainSpec_v1_genesisHash = async (context)=>{
|
|
27
|
+
const genesisHash = await context.chain.api.getBlockHash(0);
|
|
28
|
+
if (genesisHash === null) {
|
|
29
|
+
throw new _shared.ResponseError(1, 'Unexpected null genesis hash');
|
|
30
|
+
}
|
|
31
|
+
return genesisHash;
|
|
32
|
+
};
|
|
33
|
+
const chainSpec_v1_properties = async (context)=>{
|
|
34
|
+
return context.chain.api.getSystemProperties();
|
|
35
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as ChainHeadV1RPC from './chainHead_v1.js';
|
|
2
|
+
import * as ChainSpecV1RPC from './chainSpec_v1.js';
|
|
3
|
+
import * as TransactionV1RPC from './transaction_v1.js';
|
|
4
|
+
export { ChainHeadV1RPC, TransactionV1RPC, ChainSpecV1RPC };
|
|
5
|
+
declare const handlers: {
|
|
6
|
+
chainSpec_v1_chainName: import("../shared.js").Handler<[], string>;
|
|
7
|
+
chainSpec_v1_genesisHash: import("../shared.js").Handler<[], import("@polkadot/util/types").HexString>;
|
|
8
|
+
chainSpec_v1_properties: import("../shared.js").Handler<[], import("../../index.js").ChainProperties>;
|
|
9
|
+
transaction_v1_broadcast: import("../shared.js").Handler<[import("@polkadot/util/types").HexString], string | null>;
|
|
10
|
+
transaction_v1_stop: import("../shared.js").Handler<[string], null>;
|
|
11
|
+
chainHead_v1_follow: import("../shared.js").Handler<[boolean], string>;
|
|
12
|
+
chainHead_v1_unfollow: import("../shared.js").Handler<[string], null>;
|
|
13
|
+
chainHead_v1_header: import("../shared.js").Handler<[string, import("@polkadot/util/types").HexString], import("@polkadot/util/types").HexString | null>;
|
|
14
|
+
chainHead_v1_call: import("../shared.js").Handler<[string, import("@polkadot/util/types").HexString, string, import("@polkadot/util/types").HexString], {
|
|
15
|
+
result: "started";
|
|
16
|
+
operationId: string;
|
|
17
|
+
}>;
|
|
18
|
+
chainHead_v1_storage: import("../shared.js").Handler<[string, import("@polkadot/util/types").HexString, ChainHeadV1RPC.StorageItemRequest[], import("@polkadot/util/types").HexString | null], ChainHeadV1RPC.StorageStarted>;
|
|
19
|
+
chainHead_v1_body: import("../shared.js").Handler<[string, import("@polkadot/util/types").HexString], {
|
|
20
|
+
result: "started";
|
|
21
|
+
operationId: string;
|
|
22
|
+
} | ChainHeadV1RPC.LimitReached>;
|
|
23
|
+
chainHead_v1_continue: import("../shared.js").Handler<[string, import("@polkadot/util/types").HexString], null>;
|
|
24
|
+
chainHead_v1_stopOperation: import("../shared.js").Handler<[string, import("@polkadot/util/types").HexString], null>;
|
|
25
|
+
chainHead_v1_unpin: import("../shared.js").Handler<[string, import("@polkadot/util/types").HexString | import("@polkadot/util/types").HexString[]], null>;
|
|
26
|
+
};
|
|
27
|
+
export default handlers;
|
|
@@ -0,0 +1,74 @@
|
|
|
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: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
ChainHeadV1RPC: function() {
|
|
13
|
+
return _chainHead_v1;
|
|
14
|
+
},
|
|
15
|
+
ChainSpecV1RPC: function() {
|
|
16
|
+
return _chainSpec_v1;
|
|
17
|
+
},
|
|
18
|
+
TransactionV1RPC: function() {
|
|
19
|
+
return _transaction_v1;
|
|
20
|
+
},
|
|
21
|
+
default: function() {
|
|
22
|
+
return _default;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const _chainHead_v1 = /*#__PURE__*/ _interop_require_wildcard(require("./chainHead_v1.js"));
|
|
26
|
+
const _chainSpec_v1 = /*#__PURE__*/ _interop_require_wildcard(require("./chainSpec_v1.js"));
|
|
27
|
+
const _transaction_v1 = /*#__PURE__*/ _interop_require_wildcard(require("./transaction_v1.js"));
|
|
28
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
29
|
+
if (typeof WeakMap !== "function") return null;
|
|
30
|
+
var cacheBabelInterop = new WeakMap();
|
|
31
|
+
var cacheNodeInterop = new WeakMap();
|
|
32
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
33
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
34
|
+
})(nodeInterop);
|
|
35
|
+
}
|
|
36
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
37
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
38
|
+
return obj;
|
|
39
|
+
}
|
|
40
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
41
|
+
return {
|
|
42
|
+
default: obj
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
46
|
+
if (cache && cache.has(obj)) {
|
|
47
|
+
return cache.get(obj);
|
|
48
|
+
}
|
|
49
|
+
var newObj = {
|
|
50
|
+
__proto__: null
|
|
51
|
+
};
|
|
52
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
53
|
+
for(var key in obj){
|
|
54
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
55
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
56
|
+
if (desc && (desc.get || desc.set)) {
|
|
57
|
+
Object.defineProperty(newObj, key, desc);
|
|
58
|
+
} else {
|
|
59
|
+
newObj[key] = obj[key];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
newObj.default = obj;
|
|
64
|
+
if (cache) {
|
|
65
|
+
cache.set(obj, newObj);
|
|
66
|
+
}
|
|
67
|
+
return newObj;
|
|
68
|
+
}
|
|
69
|
+
const handlers = {
|
|
70
|
+
..._chainHead_v1,
|
|
71
|
+
..._transaction_v1,
|
|
72
|
+
..._chainSpec_v1
|
|
73
|
+
};
|
|
74
|
+
const _default = handlers;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Handler } from '../shared.js';
|
|
2
|
+
import { HexString } from '@polkadot/util/types';
|
|
3
|
+
/**
|
|
4
|
+
* Submit the extrinsic to the transaction pool
|
|
5
|
+
*
|
|
6
|
+
* @param context
|
|
7
|
+
* @param params - [`extrinsic`]
|
|
8
|
+
*
|
|
9
|
+
* @return operation id
|
|
10
|
+
*/
|
|
11
|
+
export declare const transaction_v1_broadcast: Handler<[HexString], string | null>;
|
|
12
|
+
/**
|
|
13
|
+
* Stop broadcasting the transaction to other nodes.
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
export declare const transaction_v1_stop: Handler<[string], null>;
|
|
@@ -0,0 +1,35 @@
|
|
|
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: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
transaction_v1_broadcast: function() {
|
|
13
|
+
return transaction_v1_broadcast;
|
|
14
|
+
},
|
|
15
|
+
transaction_v1_stop: function() {
|
|
16
|
+
return transaction_v1_stop;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _logger = require("../../logger.js");
|
|
20
|
+
const logger = _logger.defaultLogger.child({
|
|
21
|
+
name: 'rpc-transaction_v1'
|
|
22
|
+
});
|
|
23
|
+
const randomId = ()=>Math.random().toString(36).substring(2);
|
|
24
|
+
const transaction_v1_broadcast = async (context, [extrinsic])=>{
|
|
25
|
+
await context.chain.submitExtrinsic(extrinsic).catch((err)=>{
|
|
26
|
+
// As per the spec, the invalid transaction errors should be ignored.
|
|
27
|
+
logger.warn('Submit extrinsic failed', err);
|
|
28
|
+
});
|
|
29
|
+
return randomId();
|
|
30
|
+
};
|
|
31
|
+
const transaction_v1_stop = async (_context, [_operationId])=>{
|
|
32
|
+
// Chopsticks doesn't have any process to broadcast the transaction through P2P
|
|
33
|
+
// so stopping doesn't have any effect.
|
|
34
|
+
return null;
|
|
35
|
+
};
|
|
@@ -11,6 +11,7 @@ export declare const WELL_KNOWN_KEYS: {
|
|
|
11
11
|
};
|
|
12
12
|
export declare const dmqMqcHead: (paraId: u32) => `0x${string}`;
|
|
13
13
|
export declare const upgradeGoAheadSignal: (paraId: u32) => `0x${string}`;
|
|
14
|
+
export declare const upgradeRestrictionSignal: (paraId: u32) => `0x${string}`;
|
|
14
15
|
export declare const hrmpIngressChannelIndex: (paraId: u32) => `0x${string}`;
|
|
15
16
|
export declare const hrmpEgressChannelIndex: (paraId: u32) => `0x${string}`;
|
|
16
17
|
export declare const hrmpChannels: (channelId: HrmpChannelId) => `0x${string}`;
|