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