@acala-network/chopsticks-core 0.9.9-1 → 0.9.9
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 +6 -4
- package/dist/cjs/chopsticks-provider.js +1 -5
- package/dist/cjs/genesis-provider.js +39 -7
- package/dist/cjs/rpc/dev/index.d.ts +15 -0
- package/dist/cjs/rpc/dev/index.js +38 -0
- package/dist/cjs/rpc/dev/new-block.d.ts +128 -0
- package/dist/cjs/rpc/dev/new-block.js +57 -0
- package/dist/cjs/rpc/dev/set-block-build-mode.d.ts +21 -0
- package/dist/cjs/rpc/dev/set-block-build-mode.js +22 -0
- package/dist/cjs/rpc/dev/set-head.d.ts +21 -0
- package/dist/cjs/rpc/dev/set-head.js +28 -0
- package/dist/cjs/rpc/dev/set-runtime-log-level.d.ts +17 -0
- package/dist/cjs/rpc/dev/set-runtime-log-level.js +21 -0
- package/dist/cjs/rpc/dev/set-storage.d.ts +29 -0
- package/dist/cjs/rpc/dev/set-storage.js +24 -0
- package/dist/cjs/rpc/dev/time-travel.d.ts +17 -0
- package/dist/cjs/rpc/dev/time-travel.js +18 -0
- package/dist/cjs/rpc/index.d.ts +3 -1
- package/dist/cjs/rpc/index.js +8 -5
- package/dist/cjs/rpc/shared.d.ts +3 -0
- package/dist/cjs/rpc/shared.js +9 -0
- package/dist/cjs/wasm-executor/index.d.ts +0 -1
- package/dist/cjs/wasm-executor/index.js +0 -7
- package/dist/esm/blockchain/inherent/parachain/validation-data.js +6 -4
- package/dist/esm/chopsticks-provider.js +1 -5
- package/dist/esm/genesis-provider.js +39 -7
- package/dist/esm/rpc/dev/index.d.ts +15 -0
- package/dist/esm/rpc/dev/index.js +21 -0
- package/dist/esm/rpc/dev/new-block.d.ts +128 -0
- package/dist/esm/rpc/dev/new-block.js +84 -0
- package/dist/esm/rpc/dev/set-block-build-mode.d.ts +21 -0
- package/dist/esm/rpc/dev/set-block-build-mode.js +29 -0
- package/dist/esm/rpc/dev/set-head.d.ts +21 -0
- package/dist/esm/rpc/dev/set-head.js +32 -0
- package/dist/esm/rpc/dev/set-runtime-log-level.d.ts +17 -0
- package/dist/esm/rpc/dev/set-runtime-log-level.js +25 -0
- package/dist/esm/rpc/dev/set-storage.d.ts +29 -0
- package/dist/esm/rpc/dev/set-storage.js +38 -0
- package/dist/esm/rpc/dev/time-travel.d.ts +17 -0
- package/dist/esm/rpc/dev/time-travel.js +22 -0
- package/dist/esm/rpc/index.d.ts +3 -1
- package/dist/esm/rpc/index.js +4 -4
- package/dist/esm/rpc/shared.d.ts +3 -0
- package/dist/esm/rpc/shared.js +3 -0
- package/dist/esm/wasm-executor/index.d.ts +0 -1
- package/dist/esm/wasm-executor/index.js +0 -7
- package/package.json +2 -2
|
@@ -71,7 +71,6 @@ export declare const runTask: (task: {
|
|
|
71
71
|
export declare const taskHandler: (block: Block) => JsCallback;
|
|
72
72
|
export declare const emptyTaskHandler: {
|
|
73
73
|
getStorage: (_key: HexString) => Promise<never>;
|
|
74
|
-
getStateRoot: () => Promise<never>;
|
|
75
74
|
getNextKey: (_prefix: HexString, _key: HexString) => Promise<never>;
|
|
76
75
|
offchainGetStorage: (_key: HexString) => Promise<never>;
|
|
77
76
|
offchainTimestamp: () => Promise<never>;
|
|
@@ -153,10 +153,6 @@ const taskHandler = (block)=>{
|
|
|
153
153
|
getStorage: async function(key) {
|
|
154
154
|
return block.get(key);
|
|
155
155
|
},
|
|
156
|
-
getStateRoot: async function() {
|
|
157
|
-
const header = await block.header;
|
|
158
|
-
return header.stateRoot.toHex();
|
|
159
|
-
},
|
|
160
156
|
getNextKey: async function(prefix, key) {
|
|
161
157
|
const [nextKey] = await block.getKeysPaged({
|
|
162
158
|
prefix: prefix.length === 2 /** 0x */ ? key.slice(0, _index.PREFIX_LENGTH) : prefix,
|
|
@@ -196,9 +192,6 @@ const emptyTaskHandler = {
|
|
|
196
192
|
getStorage: async function(_key) {
|
|
197
193
|
throw new Error('Method not implemented');
|
|
198
194
|
},
|
|
199
|
-
getStateRoot: async function() {
|
|
200
|
-
throw new Error('Method not implemented');
|
|
201
|
-
},
|
|
202
195
|
getNextKey: async function(_prefix, _key) {
|
|
203
196
|
throw new Error('Method not implemented');
|
|
204
197
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GenericExtrinsic } from '@polkadot/types';
|
|
2
1
|
import { hexToU8a, u8aConcat, u8aToHex } from '@polkadot/util';
|
|
2
|
+
import { GenericExtrinsic } from '@polkadot/types';
|
|
3
3
|
import _ from 'lodash';
|
|
4
4
|
import { WELL_KNOWN_KEYS, dmqMqcHead, hrmpChannels, hrmpEgressChannelIndex, hrmpIngressChannelIndex, paraHead, upgradeGoAheadSignal } from '../../../utils/proof.js';
|
|
5
5
|
import { blake2AsHex, blake2AsU8a } from '@polkadot/util-crypto';
|
|
@@ -73,11 +73,13 @@ export class SetValidationData {
|
|
|
73
73
|
const hrmpIngressChannelIndexKey = hrmpIngressChannelIndex(paraId);
|
|
74
74
|
const hrmpEgressChannelIndexKey = hrmpEgressChannelIndex(paraId);
|
|
75
75
|
const decoded = await decodeProof(extrinsic.validationData.relayParentStorageRoot, extrinsic.relayChainState.trieNodes);
|
|
76
|
+
const slotIncrease = meta.consts.timestamp.minimumPeriod.divn(3000) // relaychain min period
|
|
77
|
+
.toNumber();
|
|
76
78
|
for (const key of Object.values(WELL_KNOWN_KEYS)){
|
|
77
79
|
if (key === WELL_KNOWN_KEYS.CURRENT_SLOT) {
|
|
78
80
|
// increment current slot
|
|
79
|
-
const
|
|
80
|
-
const newSlot = meta.registry.createType('Slot',
|
|
81
|
+
const relayCurrentSlot = decoded[key] ? meta.registry.createType('Slot', hexToU8a(decoded[key])).toNumber() : await getCurrentSlot(parent.chain) * slotIncrease;
|
|
82
|
+
const newSlot = meta.registry.createType('Slot', relayCurrentSlot + slotIncrease);
|
|
81
83
|
newEntries.push([
|
|
82
84
|
key,
|
|
83
85
|
u8aToHex(newSlot.toU8a())
|
|
@@ -217,7 +219,7 @@ export class SetValidationData {
|
|
|
217
219
|
validationData: {
|
|
218
220
|
...extrinsic.validationData,
|
|
219
221
|
relayParentStorageRoot: trieRootHash,
|
|
220
|
-
relayParentNumber: extrinsic.validationData.relayParentNumber +
|
|
222
|
+
relayParentNumber: extrinsic.validationData.relayParentNumber + slotIncrease
|
|
221
223
|
},
|
|
222
224
|
relayChainState: {
|
|
223
225
|
trieNodes: nodes
|
|
@@ -3,11 +3,7 @@ import { allHandlers } from './rpc/index.js';
|
|
|
3
3
|
import { defaultLogger } from './logger.js';
|
|
4
4
|
import { setup } from './setup.js';
|
|
5
5
|
const providerHandlers = {
|
|
6
|
-
...allHandlers
|
|
7
|
-
dev_newBlock: async (context, _params, _subscriptionManager)=>{
|
|
8
|
-
const block = await context.chain.newBlock();
|
|
9
|
-
return block.hash;
|
|
10
|
-
}
|
|
6
|
+
...allHandlers
|
|
11
7
|
};
|
|
12
8
|
const logger = defaultLogger.child({
|
|
13
9
|
name: '[Chopsticks provider]'
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EventEmitter } from 'eventemitter3';
|
|
2
2
|
import { genesisSchema } from './schema/index.js';
|
|
3
3
|
import { calculateStateRoot, emptyTaskHandler } from './wasm-executor/index.js';
|
|
4
|
+
import { defaultLogger, isPrefixedChildKey } from './index.js';
|
|
4
5
|
/**
|
|
5
6
|
* Provider to start a chain from genesis
|
|
6
7
|
*/ export class GenesisProvider {
|
|
@@ -86,13 +87,29 @@ import { calculateStateRoot, emptyTaskHandler } from './wasm-executor/index.js';
|
|
|
86
87
|
return {
|
|
87
88
|
...emptyTaskHandler,
|
|
88
89
|
getStorage: async function(key) {
|
|
90
|
+
if (isPrefixedChildKey(key)) {
|
|
91
|
+
defaultLogger.warn({
|
|
92
|
+
key
|
|
93
|
+
}, 'genesis child storage not supported');
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
89
96
|
return storage[key];
|
|
90
97
|
},
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
98
|
+
getNextKey: async function(prefix, key) {
|
|
99
|
+
if (isPrefixedChildKey(key)) {
|
|
100
|
+
defaultLogger.warn({
|
|
101
|
+
prefix,
|
|
102
|
+
key
|
|
103
|
+
}, 'genesis child storage not supported');
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
return Object.keys(storage).find((k)=>{
|
|
107
|
+
if (!k.startsWith(prefix)) return false;
|
|
108
|
+
if (key.length > prefix.length) {
|
|
109
|
+
return k > key;
|
|
110
|
+
}
|
|
111
|
+
return true;
|
|
112
|
+
});
|
|
96
113
|
}
|
|
97
114
|
};
|
|
98
115
|
}
|
|
@@ -113,10 +130,25 @@ import { calculateStateRoot, emptyTaskHandler } from './wasm-executor/index.js';
|
|
|
113
130
|
return this.blockHash;
|
|
114
131
|
case 'state_getKeysPaged':
|
|
115
132
|
case 'state_getKeysPagedAt':
|
|
116
|
-
|
|
133
|
+
{
|
|
134
|
+
if (params.length < 2) throw Error('invalid params');
|
|
135
|
+
const [prefix, size, start] = params;
|
|
136
|
+
let startKey = start || prefix;
|
|
137
|
+
const keys = [];
|
|
138
|
+
while(keys.length < size){
|
|
139
|
+
const nextKey = await this._jsCallback.getNextKey(prefix, startKey);
|
|
140
|
+
if (!nextKey) break;
|
|
141
|
+
keys.push(nextKey);
|
|
142
|
+
startKey = nextKey;
|
|
143
|
+
}
|
|
144
|
+
return keys;
|
|
145
|
+
}
|
|
117
146
|
case 'state_getStorage':
|
|
118
147
|
case 'state_getStorageAt':
|
|
119
|
-
|
|
148
|
+
{
|
|
149
|
+
if (params.length < 1) throw Error('invalid params');
|
|
150
|
+
return this.#genesis.genesis.raw.top[params[0]];
|
|
151
|
+
}
|
|
120
152
|
default:
|
|
121
153
|
throw Error(`${method} not implemented`);
|
|
122
154
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare const handlers: {
|
|
2
|
+
dev_newBlock: (context: import("../shared.js").Context, [params]: [import("./new-block.js").NewBlockParams]) => Promise<`0x${string}`>;
|
|
3
|
+
dev_setBlockBuildMode: (context: import("../shared.js").Context, [mode]: [import("../../index.js").BuildBlockMode]) => Promise<void>;
|
|
4
|
+
dev_setHead: (context: import("../shared.js").Context, [params]: [number | `0x${string}`]) => Promise<`0x${string}`>;
|
|
5
|
+
dev_setRuntimeLogLevel: (context: import("../shared.js").Context, [runtimeLogLevel]: [number]) => Promise<void>;
|
|
6
|
+
dev_setStorage: (context: import("../shared.js").Context, params: [import("../../index.js").StorageValues, (`0x${string}` | undefined)?]) => Promise<`0x${string}`>;
|
|
7
|
+
dev_timeTravel: (context: import("../shared.js").Context, [date]: [string | number]) => Promise<number>;
|
|
8
|
+
};
|
|
9
|
+
export default handlers;
|
|
10
|
+
export * from './new-block.js';
|
|
11
|
+
export * from './set-block-build-mode.js';
|
|
12
|
+
export * from './set-head.js';
|
|
13
|
+
export * from './set-runtime-log-level.js';
|
|
14
|
+
export * from './set-storage.js';
|
|
15
|
+
export * from './time-travel.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { dev_newBlock } from './new-block.js';
|
|
2
|
+
import { dev_setBlockBuildMode } from './set-block-build-mode.js';
|
|
3
|
+
import { dev_setHead } from './set-head.js';
|
|
4
|
+
import { dev_setRuntimeLogLevel } from './set-runtime-log-level.js';
|
|
5
|
+
import { dev_setStorage } from './set-storage.js';
|
|
6
|
+
import { dev_timeTravel } from './time-travel.js';
|
|
7
|
+
const handlers = {
|
|
8
|
+
dev_newBlock,
|
|
9
|
+
dev_setBlockBuildMode,
|
|
10
|
+
dev_setHead,
|
|
11
|
+
dev_setRuntimeLogLevel,
|
|
12
|
+
dev_setStorage,
|
|
13
|
+
dev_timeTravel
|
|
14
|
+
};
|
|
15
|
+
export default handlers;
|
|
16
|
+
export * from './new-block.js';
|
|
17
|
+
export * from './set-block-build-mode.js';
|
|
18
|
+
export * from './set-head.js';
|
|
19
|
+
export * from './set-runtime-log-level.js';
|
|
20
|
+
export * from './set-storage.js';
|
|
21
|
+
export * from './time-travel.js';
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { Context } from '../shared.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
declare const schema: z.ZodObject<{
|
|
4
|
+
count: z.ZodOptional<z.ZodNumber>;
|
|
5
|
+
to: z.ZodOptional<z.ZodNumber>;
|
|
6
|
+
dmp: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
7
|
+
sentAt: z.ZodNumber;
|
|
8
|
+
msg: z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
msg: `0x${string}`;
|
|
11
|
+
sentAt: number;
|
|
12
|
+
}, {
|
|
13
|
+
msg: `0x${string}`;
|
|
14
|
+
sentAt: number;
|
|
15
|
+
}>, "many">>;
|
|
16
|
+
ump: z.ZodOptional<z.ZodRecord<z.ZodNumber, z.ZodArray<z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, "many">>>;
|
|
17
|
+
hrmp: z.ZodOptional<z.ZodRecord<z.ZodUnion<[z.ZodNumber, z.ZodString]>, z.ZodArray<z.ZodObject<{
|
|
18
|
+
sentAt: z.ZodNumber;
|
|
19
|
+
data: z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>;
|
|
20
|
+
}, "strip", z.ZodTypeAny, {
|
|
21
|
+
data: `0x${string}`;
|
|
22
|
+
sentAt: number;
|
|
23
|
+
}, {
|
|
24
|
+
data: `0x${string}`;
|
|
25
|
+
sentAt: number;
|
|
26
|
+
}>, "many">>>;
|
|
27
|
+
transactions: z.ZodOptional<z.ZodArray<z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, "many">>;
|
|
28
|
+
unsafeBlockHeight: z.ZodOptional<z.ZodNumber>;
|
|
29
|
+
}, "strip", z.ZodTypeAny, {
|
|
30
|
+
count?: number | undefined;
|
|
31
|
+
to?: number | undefined;
|
|
32
|
+
dmp?: {
|
|
33
|
+
msg: `0x${string}`;
|
|
34
|
+
sentAt: number;
|
|
35
|
+
}[] | undefined;
|
|
36
|
+
ump?: Record<number, `0x${string}`[]> | undefined;
|
|
37
|
+
hrmp?: Record<string | number, {
|
|
38
|
+
data: `0x${string}`;
|
|
39
|
+
sentAt: number;
|
|
40
|
+
}[]> | undefined;
|
|
41
|
+
transactions?: `0x${string}`[] | undefined;
|
|
42
|
+
unsafeBlockHeight?: number | undefined;
|
|
43
|
+
}, {
|
|
44
|
+
count?: number | undefined;
|
|
45
|
+
to?: number | undefined;
|
|
46
|
+
dmp?: {
|
|
47
|
+
msg: `0x${string}`;
|
|
48
|
+
sentAt: number;
|
|
49
|
+
}[] | undefined;
|
|
50
|
+
ump?: Record<number, `0x${string}`[]> | undefined;
|
|
51
|
+
hrmp?: Record<string | number, {
|
|
52
|
+
data: `0x${string}`;
|
|
53
|
+
sentAt: number;
|
|
54
|
+
}[]> | undefined;
|
|
55
|
+
transactions?: `0x${string}`[] | undefined;
|
|
56
|
+
unsafeBlockHeight?: number | undefined;
|
|
57
|
+
}>;
|
|
58
|
+
type Params = z.infer<typeof schema>;
|
|
59
|
+
export interface NewBlockParams {
|
|
60
|
+
/**
|
|
61
|
+
* The number of blocks to build
|
|
62
|
+
*/
|
|
63
|
+
count: Params['count'];
|
|
64
|
+
/**
|
|
65
|
+
* The block number to build to
|
|
66
|
+
*/
|
|
67
|
+
to: Params['to'];
|
|
68
|
+
/**
|
|
69
|
+
* The downward messages to include in the block
|
|
70
|
+
*/
|
|
71
|
+
dmp: Params['dmp'];
|
|
72
|
+
/**
|
|
73
|
+
* The upward messages to include in the block
|
|
74
|
+
*/
|
|
75
|
+
ump: Params['ump'];
|
|
76
|
+
/**
|
|
77
|
+
* The horizontal messages to include in the block
|
|
78
|
+
*/
|
|
79
|
+
hrmp: Params['hrmp'];
|
|
80
|
+
/**
|
|
81
|
+
* The transactions to include in the block
|
|
82
|
+
*/
|
|
83
|
+
transactions: Params['transactions'];
|
|
84
|
+
/**
|
|
85
|
+
* Build block using a specific block height (unsafe)
|
|
86
|
+
*/
|
|
87
|
+
unsafeBlockHeight: Params['unsafeBlockHeight'];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Build new blocks.
|
|
91
|
+
*
|
|
92
|
+
* This function is a dev rpc handler. Use `dev_newBlock` as the method name when calling it.
|
|
93
|
+
*
|
|
94
|
+
* @param context - The context object of the rpc handler
|
|
95
|
+
* @param params - The parameters of the rpc handler
|
|
96
|
+
*
|
|
97
|
+
* @example Build 2 blocks
|
|
98
|
+
* ```ts
|
|
99
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
100
|
+
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
101
|
+
* await ws.send('dev_newBlock', [{ count: 2 }])
|
|
102
|
+
* ```
|
|
103
|
+
* @example Build a block with upward messages
|
|
104
|
+
* ```ts
|
|
105
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
106
|
+
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
107
|
+
* await ws.send('dev_newBlock', [
|
|
108
|
+
* {
|
|
109
|
+
* ump: {
|
|
110
|
+
* // https://acala.subscan.io/xcm_message/polkadot-ff66f28818d0b74573e62db8317e354b253fbc80
|
|
111
|
+
* 2000: [
|
|
112
|
+
* '0x021000040000000007903fc4db080a130000000007903fc4db08000d010004000101009c4b11a0974cba4a395c94832fba812868a6cb0ba09e8519b3521093ea359905',
|
|
113
|
+
* ],
|
|
114
|
+
* }
|
|
115
|
+
* }
|
|
116
|
+
* ])
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @example Build two blocks with unsafeBlockHeight
|
|
120
|
+
* ```ts
|
|
121
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
122
|
+
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
123
|
+
* // this will create two blocks with block height 100000001 and 100000002
|
|
124
|
+
* await ws.send('dev_newBlock', [{ count: 2, unsafeBlockHeight: 100000001 }])
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export declare const dev_newBlock: (context: Context, [params]: [NewBlockParams]) => Promise<`0x${string}`>;
|
|
128
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { ResponseError, zHex } from '../shared.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { defaultLogger } from '../../logger.js';
|
|
4
|
+
const schema = z.object({
|
|
5
|
+
count: z.number().optional(),
|
|
6
|
+
to: z.number().optional(),
|
|
7
|
+
dmp: z.array(z.object({
|
|
8
|
+
sentAt: z.number(),
|
|
9
|
+
msg: zHex
|
|
10
|
+
})).min(1).optional(),
|
|
11
|
+
ump: z.record(z.number(), z.array(zHex).min(1)).optional(),
|
|
12
|
+
hrmp: z.record(z.union([
|
|
13
|
+
z.number(),
|
|
14
|
+
z.string()
|
|
15
|
+
]), z.array(z.object({
|
|
16
|
+
sentAt: z.number(),
|
|
17
|
+
data: zHex
|
|
18
|
+
})).min(1)).optional(),
|
|
19
|
+
transactions: z.array(zHex).min(1).optional(),
|
|
20
|
+
unsafeBlockHeight: z.number().optional()
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* Build new blocks.
|
|
24
|
+
*
|
|
25
|
+
* This function is a dev rpc handler. Use `dev_newBlock` as the method name when calling it.
|
|
26
|
+
*
|
|
27
|
+
* @param context - The context object of the rpc handler
|
|
28
|
+
* @param params - The parameters of the rpc handler
|
|
29
|
+
*
|
|
30
|
+
* @example Build 2 blocks
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
33
|
+
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
34
|
+
* await ws.send('dev_newBlock', [{ count: 2 }])
|
|
35
|
+
* ```
|
|
36
|
+
* @example Build a block with upward messages
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
39
|
+
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
40
|
+
* await ws.send('dev_newBlock', [
|
|
41
|
+
* {
|
|
42
|
+
* ump: {
|
|
43
|
+
* // https://acala.subscan.io/xcm_message/polkadot-ff66f28818d0b74573e62db8317e354b253fbc80
|
|
44
|
+
* 2000: [
|
|
45
|
+
* '0x021000040000000007903fc4db080a130000000007903fc4db08000d010004000101009c4b11a0974cba4a395c94832fba812868a6cb0ba09e8519b3521093ea359905',
|
|
46
|
+
* ],
|
|
47
|
+
* }
|
|
48
|
+
* }
|
|
49
|
+
* ])
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @example Build two blocks with unsafeBlockHeight
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
55
|
+
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
56
|
+
* // this will create two blocks with block height 100000001 and 100000002
|
|
57
|
+
* await ws.send('dev_newBlock', [{ count: 2, unsafeBlockHeight: 100000001 }])
|
|
58
|
+
* ```
|
|
59
|
+
*/ export const dev_newBlock = async (context, [params])=>{
|
|
60
|
+
const { count, to, hrmp, ump, dmp, transactions, unsafeBlockHeight } = schema.parse(params || {});
|
|
61
|
+
const now = context.chain.head.number;
|
|
62
|
+
const diff = to ? to - now : count;
|
|
63
|
+
const finalCount = diff !== undefined ? Math.max(diff, 1) : 1;
|
|
64
|
+
let finalHash;
|
|
65
|
+
if (unsafeBlockHeight !== undefined && unsafeBlockHeight <= now) {
|
|
66
|
+
throw new ResponseError(1, 'unsafeBlockHeight must be greater than current block height');
|
|
67
|
+
}
|
|
68
|
+
for(let i = 0; i < finalCount; i++){
|
|
69
|
+
const block = await context.chain.newBlock({
|
|
70
|
+
transactions,
|
|
71
|
+
horizontalMessages: hrmp,
|
|
72
|
+
upwardMessages: ump,
|
|
73
|
+
downwardMessages: dmp,
|
|
74
|
+
unsafeBlockHeight: i === 0 ? unsafeBlockHeight : undefined
|
|
75
|
+
}).catch((error)=>{
|
|
76
|
+
throw new ResponseError(1, error.toString());
|
|
77
|
+
});
|
|
78
|
+
defaultLogger.debug({
|
|
79
|
+
hash: block.hash
|
|
80
|
+
}, 'dev_newBlock');
|
|
81
|
+
finalHash = block.hash;
|
|
82
|
+
}
|
|
83
|
+
return finalHash;
|
|
84
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BuildBlockMode } from '../../blockchain/txpool.js';
|
|
2
|
+
import { Context } from '../shared.js';
|
|
3
|
+
/**
|
|
4
|
+
* Set block build mode.
|
|
5
|
+
*
|
|
6
|
+
* 1 - Batch, 2 - Instant, 3 - Manual
|
|
7
|
+
*
|
|
8
|
+
* This function is a dev rpc handler. Use `dev_setBlockBuildMode` as the method name when calling it.
|
|
9
|
+
*
|
|
10
|
+
* @param context - The context object of the rpc handler
|
|
11
|
+
* @param params - The parameters of the rpc handler
|
|
12
|
+
*
|
|
13
|
+
* @example Set build block mode to instant
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
16
|
+
* import { BuildBlockMode } from '@acala-network/chopsticks-core'
|
|
17
|
+
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
18
|
+
* await ws.send('dev_setBlockBuildMode', [BuildBlockMode.Instant])
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const dev_setBlockBuildMode: (context: Context, [mode]: [BuildBlockMode]) => Promise<void>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BuildBlockMode } from '../../blockchain/txpool.js';
|
|
2
|
+
import { ResponseError } from '../shared.js';
|
|
3
|
+
import { defaultLogger } from '../../logger.js';
|
|
4
|
+
/**
|
|
5
|
+
* Set block build mode.
|
|
6
|
+
*
|
|
7
|
+
* 1 - Batch, 2 - Instant, 3 - Manual
|
|
8
|
+
*
|
|
9
|
+
* This function is a dev rpc handler. Use `dev_setBlockBuildMode` as the method name when calling it.
|
|
10
|
+
*
|
|
11
|
+
* @param context - The context object of the rpc handler
|
|
12
|
+
* @param params - The parameters of the rpc handler
|
|
13
|
+
*
|
|
14
|
+
* @example Set build block mode to instant
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
17
|
+
* import { BuildBlockMode } from '@acala-network/chopsticks-core'
|
|
18
|
+
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
19
|
+
* await ws.send('dev_setBlockBuildMode', [BuildBlockMode.Instant])
|
|
20
|
+
* ```
|
|
21
|
+
*/ export const dev_setBlockBuildMode = async (context, [mode])=>{
|
|
22
|
+
defaultLogger.debug({
|
|
23
|
+
mode: BuildBlockMode[mode]
|
|
24
|
+
}, 'dev_setBlockBuildMode');
|
|
25
|
+
if (BuildBlockMode[mode] === undefined) {
|
|
26
|
+
throw new ResponseError(1, `Invalid mode ${mode}`);
|
|
27
|
+
}
|
|
28
|
+
context.chain.txPool.mode = mode;
|
|
29
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Context } from '../shared.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
declare const schema: z.ZodUnion<[z.ZodIntersection<z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>>, z.ZodNumber]>;
|
|
4
|
+
type Params = z.infer<typeof schema>;
|
|
5
|
+
/**
|
|
6
|
+
* Set head.
|
|
7
|
+
*
|
|
8
|
+
* This function is a dev rpc handler. Use `dev_setHead` as the method name when calling it.
|
|
9
|
+
*
|
|
10
|
+
* @param context - The context object of the rpc handler
|
|
11
|
+
* @param hashOrNumber - The block hash or number to set as head
|
|
12
|
+
*
|
|
13
|
+
* @example Set head to block 1000000
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
16
|
+
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
17
|
+
* await ws.send('dev_setHead', [1000000])
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare const dev_setHead: (context: Context, [params]: [Params]) => Promise<`0x${string}`>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ResponseError, zHash } from '../shared.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
const schema = zHash.or(z.number());
|
|
4
|
+
/**
|
|
5
|
+
* Set head.
|
|
6
|
+
*
|
|
7
|
+
* This function is a dev rpc handler. Use `dev_setHead` as the method name when calling it.
|
|
8
|
+
*
|
|
9
|
+
* @param context - The context object of the rpc handler
|
|
10
|
+
* @param hashOrNumber - The block hash or number to set as head
|
|
11
|
+
*
|
|
12
|
+
* @example Set head to block 1000000
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
15
|
+
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
16
|
+
* await ws.send('dev_setHead', [1000000])
|
|
17
|
+
* ```
|
|
18
|
+
*/ export const dev_setHead = async (context, [params])=>{
|
|
19
|
+
const hashOrNumber = schema.parse(params);
|
|
20
|
+
let block;
|
|
21
|
+
if (typeof hashOrNumber === 'number') {
|
|
22
|
+
const blockNumber = hashOrNumber > 0 ? hashOrNumber : context.chain.head.number + hashOrNumber;
|
|
23
|
+
block = await context.chain.getBlockAt(blockNumber);
|
|
24
|
+
} else {
|
|
25
|
+
block = await context.chain.getBlock(hashOrNumber);
|
|
26
|
+
}
|
|
27
|
+
if (!block) {
|
|
28
|
+
throw new ResponseError(1, `Block not found ${hashOrNumber}`);
|
|
29
|
+
}
|
|
30
|
+
await context.chain.setHead(block);
|
|
31
|
+
return block.hash;
|
|
32
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Context } from '../shared.js';
|
|
2
|
+
/**
|
|
3
|
+
* Set runtime log level.
|
|
4
|
+
*
|
|
5
|
+
* This function is a dev rpc handler. Use `dev_setRuntimeLogLevel` as the method name when calling it.
|
|
6
|
+
*
|
|
7
|
+
* @param context - The context object of the rpc handler
|
|
8
|
+
* @param runtimeLogLevel - The runtime log level to set
|
|
9
|
+
*
|
|
10
|
+
* @example Set runtime log level to 1
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
13
|
+
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
14
|
+
* await ws.send('dev_setRuntimeLogLevel', [1])
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare const dev_setRuntimeLogLevel: (context: Context, [runtimeLogLevel]: [number]) => Promise<void>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ResponseError } from '../shared.js';
|
|
2
|
+
import { defaultLogger } from '../../logger.js';
|
|
3
|
+
/**
|
|
4
|
+
* Set runtime log level.
|
|
5
|
+
*
|
|
6
|
+
* This function is a dev rpc handler. Use `dev_setRuntimeLogLevel` as the method name when calling it.
|
|
7
|
+
*
|
|
8
|
+
* @param context - The context object of the rpc handler
|
|
9
|
+
* @param runtimeLogLevel - The runtime log level to set
|
|
10
|
+
*
|
|
11
|
+
* @example Set runtime log level to 1
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
14
|
+
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
15
|
+
* await ws.send('dev_setRuntimeLogLevel', [1])
|
|
16
|
+
* ```
|
|
17
|
+
*/ export const dev_setRuntimeLogLevel = async (context, [runtimeLogLevel])=>{
|
|
18
|
+
defaultLogger.debug({
|
|
19
|
+
runtimeLogLevel
|
|
20
|
+
}, 'dev_setRuntimeLogLevel');
|
|
21
|
+
if (typeof runtimeLogLevel !== 'number') {
|
|
22
|
+
throw new ResponseError(1, `Invalid runtimeLogLevel ${runtimeLogLevel}`);
|
|
23
|
+
}
|
|
24
|
+
context.chain.runtimeLogLevel = runtimeLogLevel;
|
|
25
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Context } from '../shared.js';
|
|
2
|
+
import { HexString } from '@polkadot/util/types';
|
|
3
|
+
import { StorageValues } from '../../utils/set-storage.js';
|
|
4
|
+
/**
|
|
5
|
+
* Set storage values.
|
|
6
|
+
*
|
|
7
|
+
* This function is a dev rpc handler. Use `dev_setStorage` as the method name when calling it.
|
|
8
|
+
*
|
|
9
|
+
* @param context - The context object of the rpc handler
|
|
10
|
+
* @param params - The parameters of the rpc handler
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
15
|
+
* import { Keyring } from '@polkadot/keyring'
|
|
16
|
+
*
|
|
17
|
+
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
18
|
+
* const keyring = new Keyring({ type: 'ed25519' })
|
|
19
|
+
* const bob = keyring.addFromUri('//Bob')
|
|
20
|
+
*
|
|
21
|
+
* const storage = {
|
|
22
|
+
* System: {
|
|
23
|
+
* Account: [[[bob.address], { data: { free: 100000 }, nonce: 1 }]],
|
|
24
|
+
* },
|
|
25
|
+
* }
|
|
26
|
+
* await ws.send('dev_setStorage', [storage])
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare const dev_setStorage: (context: Context, params: [StorageValues, HexString?]) => Promise<`0x${string}`>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ResponseError } from '../shared.js';
|
|
2
|
+
import { setStorage } from '../../utils/set-storage.js';
|
|
3
|
+
import { defaultLogger } from '../../logger.js';
|
|
4
|
+
/**
|
|
5
|
+
* Set storage values.
|
|
6
|
+
*
|
|
7
|
+
* This function is a dev rpc handler. Use `dev_setStorage` as the method name when calling it.
|
|
8
|
+
*
|
|
9
|
+
* @param context - The context object of the rpc handler
|
|
10
|
+
* @param params - The parameters of the rpc handler
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
15
|
+
* import { Keyring } from '@polkadot/keyring'
|
|
16
|
+
*
|
|
17
|
+
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
18
|
+
* const keyring = new Keyring({ type: 'ed25519' })
|
|
19
|
+
* const bob = keyring.addFromUri('//Bob')
|
|
20
|
+
*
|
|
21
|
+
* const storage = {
|
|
22
|
+
* System: {
|
|
23
|
+
* Account: [[[bob.address], { data: { free: 100000 }, nonce: 1 }]],
|
|
24
|
+
* },
|
|
25
|
+
* }
|
|
26
|
+
* await ws.send('dev_setStorage', [storage])
|
|
27
|
+
* ```
|
|
28
|
+
*/ export const dev_setStorage = async (context, params)=>{
|
|
29
|
+
const [values, blockHash] = params;
|
|
30
|
+
const hash = await setStorage(context.chain, values, blockHash).catch((error)=>{
|
|
31
|
+
throw new ResponseError(1, error.toString());
|
|
32
|
+
});
|
|
33
|
+
defaultLogger.debug({
|
|
34
|
+
hash,
|
|
35
|
+
values
|
|
36
|
+
}, 'dev_setStorage');
|
|
37
|
+
return hash;
|
|
38
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Context } from '../shared.js';
|
|
2
|
+
/**
|
|
3
|
+
* Travel to a specific time.
|
|
4
|
+
*
|
|
5
|
+
* This function is a dev rpc handler. Use `dev_timeTravel` as the method name when calling it.
|
|
6
|
+
*
|
|
7
|
+
* @param context - The context object of the rpc handler
|
|
8
|
+
* @param date - Timestamp or date string to set
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
13
|
+
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
14
|
+
* await ws.send('dev_timeTravel', ['Jan 1, 2023'])
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare const dev_timeTravel: (context: Context, [date]: [string | number]) => Promise<number>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ResponseError } from '../shared.js';
|
|
2
|
+
import { timeTravel } from '../../utils/time-travel.js';
|
|
3
|
+
/**
|
|
4
|
+
* Travel to a specific time.
|
|
5
|
+
*
|
|
6
|
+
* This function is a dev rpc handler. Use `dev_timeTravel` as the method name when calling it.
|
|
7
|
+
*
|
|
8
|
+
* @param context - The context object of the rpc handler
|
|
9
|
+
* @param date - Timestamp or date string to set
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
14
|
+
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
15
|
+
* await ws.send('dev_timeTravel', ['Jan 1, 2023'])
|
|
16
|
+
* ```
|
|
17
|
+
*/ export const dev_timeTravel = async (context, [date])=>{
|
|
18
|
+
const timestamp = typeof date === 'string' ? Date.parse(date) : date;
|
|
19
|
+
if (Number.isNaN(timestamp)) throw new ResponseError(1, 'Invalid date');
|
|
20
|
+
await timeTravel(context.chain, timestamp);
|
|
21
|
+
return timestamp;
|
|
22
|
+
};
|