@acala-network/chopsticks 0.8.5-1 → 0.8.5-3
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/lib/cli.js +1 -1
- package/lib/context.js +11 -10
- package/lib/plugins/dry-run/dry-run-preimage.js +1 -1
- package/lib/plugins/dry-run/rpc.d.ts +1 -1
- package/lib/plugins/dry-run/rpc.js +1 -1
- package/lib/plugins/new-block/index.d.ts +3 -3
- package/lib/plugins/new-block/index.js +3 -3
- package/lib/plugins/run-block/index.d.ts +125 -0
- package/lib/plugins/run-block/index.js +124 -4
- package/lib/plugins/set-block-build-mode/index.d.ts +2 -2
- package/lib/plugins/set-block-build-mode/index.js +2 -2
- package/lib/plugins/set-head/index.d.ts +1 -1
- package/lib/plugins/set-head/index.js +1 -1
- package/lib/plugins/set-runtime-log-level/index.d.ts +1 -1
- package/lib/plugins/set-runtime-log-level/index.js +1 -1
- package/lib/plugins/set-storage/index.d.ts +1 -1
- package/lib/plugins/set-storage/index.js +1 -1
- package/lib/plugins/time-travel/index.d.ts +1 -1
- package/lib/plugins/time-travel/index.js +1 -1
- package/lib/plugins/types.d.ts +1 -0
- package/lib/plugins/types.js +3 -1
- package/lib/server.js +2 -25
- package/lib/utils/index.d.ts +0 -1
- package/lib/utils/index.js +0 -1
- package/package.json +7 -4
- package/lib/utils/signFake.d.ts +0 -6
- package/lib/utils/signFake.js +0 -22
package/lib/cli.js
CHANGED
|
@@ -21,7 +21,7 @@ const processArgv = async (argv) => {
|
|
|
21
21
|
};
|
|
22
22
|
const commands = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
23
23
|
.scriptName('chopsticks')
|
|
24
|
-
.middleware(processArgv,
|
|
24
|
+
.middleware(processArgv, false)
|
|
25
25
|
.command('*', 'Dev mode, fork off a chain', (yargs) => yargs.options({
|
|
26
26
|
...cli_options_1.defaultOptions,
|
|
27
27
|
...cli_options_1.mockOptions,
|
package/lib/context.js
CHANGED
|
@@ -76,16 +76,17 @@ const setupContext = async (argv, overrideParent = false) => {
|
|
|
76
76
|
if (chain.db) {
|
|
77
77
|
if (argv.resume) {
|
|
78
78
|
let blockData = null;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
79
|
+
if (typeof argv.resume === 'string' && argv.resume.startsWith('0x')) {
|
|
80
|
+
blockData = await chain.db.queryBlock(argv.resume);
|
|
81
|
+
}
|
|
82
|
+
else if (typeof argv.resume === 'boolean' || argv.resume === 'true') {
|
|
83
|
+
blockData = await chain.db.queryHighestBlock();
|
|
84
|
+
}
|
|
85
|
+
else if (Number.isInteger(+argv.resume)) {
|
|
86
|
+
blockData = await chain.db.queryBlockByNumber(+argv.resume);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
throw new Error(`Resume failed. Invalid resume option ${argv.resume}`);
|
|
89
90
|
}
|
|
90
91
|
if (blockData) {
|
|
91
92
|
const block = await chain.loadBlockFromDB(blockData.number);
|
|
@@ -66,7 +66,7 @@ const dryRunPreimage = async (argv) => {
|
|
|
66
66
|
allowUnresolvedImports: false,
|
|
67
67
|
runtimeLogLevel: argv['runtime-log-level'] || 0,
|
|
68
68
|
}, (0, chopsticks_core_1.taskHandler)(block));
|
|
69
|
-
if (result
|
|
69
|
+
if ('Error' in result) {
|
|
70
70
|
throw new Error(result.Error);
|
|
71
71
|
}
|
|
72
72
|
for (const logs of result.Call.runtimeLogs) {
|
|
@@ -115,7 +115,7 @@ export interface DryRunParams {
|
|
|
115
115
|
*
|
|
116
116
|
* @example Dry run an dmp
|
|
117
117
|
* ```ts
|
|
118
|
-
* import { WsProvider } from '@polkadot/
|
|
118
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
119
119
|
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
120
120
|
* const params = [
|
|
121
121
|
{
|
|
@@ -40,13 +40,13 @@ export interface NewBlockParams {
|
|
|
40
40
|
*
|
|
41
41
|
* @example Build 2 blocks
|
|
42
42
|
* ```ts
|
|
43
|
-
* import { WsProvider } from '@polkadot/
|
|
43
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
44
44
|
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
45
45
|
* await ws.send('dev_newBlock', [{ count: 2 }])
|
|
46
46
|
* ```
|
|
47
47
|
* @example Build a block with upward messages
|
|
48
48
|
* ```ts
|
|
49
|
-
* import { WsProvider } from '@polkadot/
|
|
49
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
50
50
|
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
51
51
|
* await ws.send('dev_newBlock', [
|
|
52
52
|
* {
|
|
@@ -62,7 +62,7 @@ export interface NewBlockParams {
|
|
|
62
62
|
*
|
|
63
63
|
* @example Build two blocks with unsafeBlockHeight
|
|
64
64
|
* ```ts
|
|
65
|
-
* import { WsProvider } from '@polkadot/
|
|
65
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
66
66
|
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
67
67
|
* // this will create two blocks with block height 100000001 and 100000002
|
|
68
68
|
* await ws.send('dev_newBlock', [{ count: 2, unsafeBlockHeight: 100000001 }])
|
|
@@ -13,13 +13,13 @@ const logger_1 = require("../../logger");
|
|
|
13
13
|
*
|
|
14
14
|
* @example Build 2 blocks
|
|
15
15
|
* ```ts
|
|
16
|
-
* import { WsProvider } from '@polkadot/
|
|
16
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
17
17
|
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
18
18
|
* await ws.send('dev_newBlock', [{ count: 2 }])
|
|
19
19
|
* ```
|
|
20
20
|
* @example Build a block with upward messages
|
|
21
21
|
* ```ts
|
|
22
|
-
* import { WsProvider } from '@polkadot/
|
|
22
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
23
23
|
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
24
24
|
* await ws.send('dev_newBlock', [
|
|
25
25
|
* {
|
|
@@ -35,7 +35,7 @@ const logger_1 = require("../../logger");
|
|
|
35
35
|
*
|
|
36
36
|
* @example Build two blocks with unsafeBlockHeight
|
|
37
37
|
* ```ts
|
|
38
|
-
* import { WsProvider } from '@polkadot/
|
|
38
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
39
39
|
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
40
40
|
* // this will create two blocks with block height 100000001 and 100000002
|
|
41
41
|
* await ws.send('dev_newBlock', [{ count: 2, unsafeBlockHeight: 100000001 }])
|
|
@@ -1,2 +1,127 @@
|
|
|
1
|
+
import { HexString } from '@polkadot/util/types';
|
|
2
|
+
import { z } from 'zod';
|
|
1
3
|
import type yargs from 'yargs';
|
|
4
|
+
import { Context } from '@acala-network/chopsticks-core';
|
|
2
5
|
export declare const cli: (y: yargs.Argv) => void;
|
|
6
|
+
declare const schema: z.ZodObject<{
|
|
7
|
+
includeRaw: z.ZodOptional<z.ZodBoolean>;
|
|
8
|
+
includeParsed: z.ZodOptional<z.ZodBoolean>;
|
|
9
|
+
includeBlockDetails: z.ZodOptional<z.ZodBoolean>;
|
|
10
|
+
parent: z.ZodOptional<z.ZodIntersection<z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>>>;
|
|
11
|
+
block: z.ZodObject<{
|
|
12
|
+
header: z.ZodAny;
|
|
13
|
+
extrinsics: z.ZodArray<z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, "many">;
|
|
14
|
+
}, "strip", z.ZodTypeAny, {
|
|
15
|
+
extrinsics: `0x${string}`[];
|
|
16
|
+
header?: any;
|
|
17
|
+
}, {
|
|
18
|
+
extrinsics: `0x${string}`[];
|
|
19
|
+
header?: any;
|
|
20
|
+
}>;
|
|
21
|
+
}, "strip", z.ZodTypeAny, {
|
|
22
|
+
block: {
|
|
23
|
+
extrinsics: `0x${string}`[];
|
|
24
|
+
header?: any;
|
|
25
|
+
};
|
|
26
|
+
includeRaw?: boolean | undefined;
|
|
27
|
+
includeParsed?: boolean | undefined;
|
|
28
|
+
includeBlockDetails?: boolean | undefined;
|
|
29
|
+
parent?: `0x${string}` | undefined;
|
|
30
|
+
}, {
|
|
31
|
+
block: {
|
|
32
|
+
extrinsics: `0x${string}`[];
|
|
33
|
+
header?: any;
|
|
34
|
+
};
|
|
35
|
+
includeRaw?: boolean | undefined;
|
|
36
|
+
includeParsed?: boolean | undefined;
|
|
37
|
+
includeBlockDetails?: boolean | undefined;
|
|
38
|
+
parent?: `0x${string}` | undefined;
|
|
39
|
+
}>;
|
|
40
|
+
type Params = z.infer<typeof schema>;
|
|
41
|
+
export interface RunBlockParams {
|
|
42
|
+
/**
|
|
43
|
+
* Include raw storage diff. Default to true
|
|
44
|
+
*/
|
|
45
|
+
includeRaw: Params['includeRaw'];
|
|
46
|
+
/**
|
|
47
|
+
* Include parsed storage diff in json format
|
|
48
|
+
*/
|
|
49
|
+
includeParsed: Params['includeParsed'];
|
|
50
|
+
/**
|
|
51
|
+
* Include block details such as parsed extrinsics in json format
|
|
52
|
+
*/
|
|
53
|
+
includeBlockDetails: Params['includeBlockDetails'];
|
|
54
|
+
/**
|
|
55
|
+
* The parent block hash to run on top of. Deafult to chain head.
|
|
56
|
+
*/
|
|
57
|
+
parent: Params['parent'];
|
|
58
|
+
/**
|
|
59
|
+
* Block to run
|
|
60
|
+
*/
|
|
61
|
+
block: Params['block'];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The phase of an execution.
|
|
65
|
+
* `number` means the phase is ApplyExtrinsic and the value is the extrinsic index.
|
|
66
|
+
*/
|
|
67
|
+
export type Phase = 'Initialization' | 'Finalization' | number;
|
|
68
|
+
export interface RunBlockResponse {
|
|
69
|
+
/**
|
|
70
|
+
* The storage diff of each phase.
|
|
71
|
+
*/
|
|
72
|
+
phases: {
|
|
73
|
+
/**
|
|
74
|
+
* The phase of the execution. See {@link Phase}.
|
|
75
|
+
*/
|
|
76
|
+
phase: Phase;
|
|
77
|
+
/**
|
|
78
|
+
* Parsed storage diff. Only available when `includeParsed` is true.
|
|
79
|
+
*/
|
|
80
|
+
parsed?: Record<string, Record<string, any>>;
|
|
81
|
+
/**
|
|
82
|
+
* Raw storage diff. Only available when `includeRaw` is true.
|
|
83
|
+
*/
|
|
84
|
+
raw?: [HexString, HexString | null][];
|
|
85
|
+
/**
|
|
86
|
+
* Runtime logs.
|
|
87
|
+
*/
|
|
88
|
+
logs?: string[];
|
|
89
|
+
}[];
|
|
90
|
+
/**
|
|
91
|
+
* Block details. Only available when `includeBlockDetails` is true.
|
|
92
|
+
*/
|
|
93
|
+
blockDetails?: {
|
|
94
|
+
/**
|
|
95
|
+
* Block timestamp in ms
|
|
96
|
+
*/
|
|
97
|
+
timestamp?: string;
|
|
98
|
+
/**
|
|
99
|
+
* Parsed events in this block.
|
|
100
|
+
*/
|
|
101
|
+
events?: {
|
|
102
|
+
phase: Phase;
|
|
103
|
+
section: string;
|
|
104
|
+
method: string;
|
|
105
|
+
args: any[];
|
|
106
|
+
}[];
|
|
107
|
+
/**
|
|
108
|
+
* Parsed extrinsics in this block.
|
|
109
|
+
*/
|
|
110
|
+
extrinsics: {
|
|
111
|
+
section: string;
|
|
112
|
+
method: string;
|
|
113
|
+
args: any[];
|
|
114
|
+
success: boolean;
|
|
115
|
+
}[];
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
export declare const name = "runBlock";
|
|
119
|
+
/**
|
|
120
|
+
* Run a set of extrinsics on top of a block and get the storage diff
|
|
121
|
+
* and optionally the parsed storage diff and block details.
|
|
122
|
+
* NOTE: The extrinsics should include inherents or tranasctions may have unexpected results.
|
|
123
|
+
*
|
|
124
|
+
* This function is a dev rpc handler. Use `dev_runBlock` as the method name when calling it.
|
|
125
|
+
*/
|
|
126
|
+
export declare const rpc: ({ chain }: Context, [params]: [RunBlockParams]) => Promise<RunBlockResponse>;
|
|
127
|
+
export {};
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cli = void 0;
|
|
4
|
-
const cli_options_1 = require("../../cli-options");
|
|
6
|
+
exports.rpc = exports.name = exports.cli = void 0;
|
|
5
7
|
const node_fs_1 = require("node:fs");
|
|
8
|
+
const zod_1 = require("zod");
|
|
9
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
10
|
+
const chopsticks_core_1 = require("@acala-network/chopsticks-core");
|
|
6
11
|
const logger_1 = require("../../logger");
|
|
12
|
+
const cli_options_1 = require("../../cli-options");
|
|
7
13
|
const generate_html_diff_1 = require("../../utils/generate-html-diff");
|
|
8
14
|
const open_html_1 = require("../../utils/open-html");
|
|
9
|
-
const chopsticks_core_1 = require("@acala-network/chopsticks-core");
|
|
10
15
|
const context_1 = require("../../context");
|
|
11
16
|
const cli = (y) => {
|
|
12
17
|
y.command('run-block', 'Replay a block', (yargs) => yargs.options({
|
|
@@ -42,7 +47,7 @@ const cli = (y) => {
|
|
|
42
47
|
allowUnresolvedImports: false,
|
|
43
48
|
runtimeLogLevel: argv.runtimeLogLevel || 0,
|
|
44
49
|
}, (0, chopsticks_core_1.taskHandler)(parent));
|
|
45
|
-
if (result
|
|
50
|
+
if ('Error' in result) {
|
|
46
51
|
throw new Error(result.Error);
|
|
47
52
|
}
|
|
48
53
|
for (const logs of result.Call.runtimeLogs) {
|
|
@@ -65,3 +70,118 @@ const cli = (y) => {
|
|
|
65
70
|
});
|
|
66
71
|
};
|
|
67
72
|
exports.cli = cli;
|
|
73
|
+
const zHex = zod_1.z.custom((val) => /^0x\w+$/.test(val));
|
|
74
|
+
const zHash = zod_1.z.string().length(66).and(zHex);
|
|
75
|
+
const schema = zod_1.z.object({
|
|
76
|
+
includeRaw: zod_1.z.boolean().optional(),
|
|
77
|
+
includeParsed: zod_1.z.boolean().optional(),
|
|
78
|
+
includeBlockDetails: zod_1.z.boolean().optional(),
|
|
79
|
+
parent: zHash.optional(),
|
|
80
|
+
block: zod_1.z.object({
|
|
81
|
+
header: zod_1.z.any(),
|
|
82
|
+
extrinsics: zod_1.z.array(zHex),
|
|
83
|
+
}),
|
|
84
|
+
});
|
|
85
|
+
exports.name = 'runBlock';
|
|
86
|
+
/**
|
|
87
|
+
* Run a set of extrinsics on top of a block and get the storage diff
|
|
88
|
+
* and optionally the parsed storage diff and block details.
|
|
89
|
+
* NOTE: The extrinsics should include inherents or tranasctions may have unexpected results.
|
|
90
|
+
*
|
|
91
|
+
* This function is a dev rpc handler. Use `dev_runBlock` as the method name when calling it.
|
|
92
|
+
*/
|
|
93
|
+
const rpc = async ({ chain }, [params]) => {
|
|
94
|
+
const { includeRaw, includeParsed, includeBlockDetails, parent, block } = schema.parse(params);
|
|
95
|
+
const includeRawStorage = includeRaw ?? true;
|
|
96
|
+
const parentBlock = await chain.getBlock(parent);
|
|
97
|
+
if (!parentBlock) {
|
|
98
|
+
throw Error(`Invalid block hash ${parent}`);
|
|
99
|
+
}
|
|
100
|
+
const registry = await parentBlock.registry;
|
|
101
|
+
const header = registry.createType('Header', block.header);
|
|
102
|
+
const wasm = await parentBlock.wasm;
|
|
103
|
+
const blockNumber = parentBlock.number + 1;
|
|
104
|
+
const hash = `0x${Math.round(Math.random() * 100000000)
|
|
105
|
+
.toString(16)
|
|
106
|
+
.padEnd(64, '0')}`;
|
|
107
|
+
const newBlock = new chopsticks_core_1.Block(chain, blockNumber, hash, parentBlock, {
|
|
108
|
+
header,
|
|
109
|
+
extrinsics: [],
|
|
110
|
+
storage: parentBlock.storage,
|
|
111
|
+
});
|
|
112
|
+
const resp = {
|
|
113
|
+
phases: [],
|
|
114
|
+
};
|
|
115
|
+
const run = async (fn, args) => {
|
|
116
|
+
const result = await (0, chopsticks_core_1.runTask)({
|
|
117
|
+
wasm,
|
|
118
|
+
calls: [[fn, args]],
|
|
119
|
+
mockSignatureHost: false,
|
|
120
|
+
allowUnresolvedImports: false,
|
|
121
|
+
runtimeLogLevel: 5,
|
|
122
|
+
}, (0, chopsticks_core_1.taskHandler)(newBlock));
|
|
123
|
+
if ('Error' in result) {
|
|
124
|
+
throw new Error(result.Error);
|
|
125
|
+
}
|
|
126
|
+
const resp = {};
|
|
127
|
+
const raw = result.Call.storageDiff;
|
|
128
|
+
newBlock.pushStorageLayer().setAll(raw);
|
|
129
|
+
if (includeRawStorage) {
|
|
130
|
+
resp.raw = raw;
|
|
131
|
+
}
|
|
132
|
+
if (includeParsed) {
|
|
133
|
+
const meta = await newBlock.meta;
|
|
134
|
+
const parsed = {};
|
|
135
|
+
for (const [key, value] of raw) {
|
|
136
|
+
lodash_1.default.merge(parsed, (0, chopsticks_core_1.decodeKeyValue)(meta, newBlock, key, value, false));
|
|
137
|
+
}
|
|
138
|
+
// clear events because it can be stupidly large and redudant
|
|
139
|
+
if (parsed['system']?.['events']) {
|
|
140
|
+
delete parsed['system']['events'];
|
|
141
|
+
}
|
|
142
|
+
resp.parsed = parsed;
|
|
143
|
+
}
|
|
144
|
+
resp.logs = result.Call.runtimeLogs;
|
|
145
|
+
return resp;
|
|
146
|
+
};
|
|
147
|
+
const resInit = await run('Core_initialize_block', [header.toHex()]);
|
|
148
|
+
resp.phases.push({ phase: 'Initialization', ...resInit });
|
|
149
|
+
for (const extrinsic of block.extrinsics) {
|
|
150
|
+
const res = await run('BlockBuilder_apply_extrinsic', [extrinsic]);
|
|
151
|
+
resp.phases.push({ phase: resp.phases.length - 1, ...res });
|
|
152
|
+
}
|
|
153
|
+
const resFinalize = await run('BlockBuilder_finalize_block', []);
|
|
154
|
+
resp.phases.push({ phase: 'Finalization', ...resFinalize });
|
|
155
|
+
if (includeBlockDetails) {
|
|
156
|
+
const meta = await newBlock.meta;
|
|
157
|
+
const registry = await newBlock.registry;
|
|
158
|
+
const timestamp = await newBlock.read('u64', meta.query.timestamp.now);
|
|
159
|
+
const events = await newBlock.read('Vec<EventRecord>', meta.query.system.events);
|
|
160
|
+
const parsedEvents = events?.map((event) => ({
|
|
161
|
+
phase: event.phase.isApplyExtrinsic ? event.phase.asApplyExtrinsic.toNumber() : event.phase.toString(),
|
|
162
|
+
section: event.event.section,
|
|
163
|
+
method: event.event.method,
|
|
164
|
+
args: event.event.data.map((arg) => arg.toJSON()),
|
|
165
|
+
}));
|
|
166
|
+
const extrinsics = block.extrinsics.map((extrinsic, idx) => {
|
|
167
|
+
const parsed = registry.createType('GenericExtrinsic', extrinsic);
|
|
168
|
+
const resultEvent = events?.find(({ event, phase }) => event.section === 'system' &&
|
|
169
|
+
(event.method === 'ExtrinsicSuccess' || event.method === 'ExtrinsicFailed') &&
|
|
170
|
+
phase.isApplyExtrinsic &&
|
|
171
|
+
phase.asApplyExtrinsic.eq(idx));
|
|
172
|
+
return {
|
|
173
|
+
section: parsed.method.section,
|
|
174
|
+
method: parsed.method.method,
|
|
175
|
+
args: parsed.method.args.map((arg) => arg.toJSON()),
|
|
176
|
+
success: resultEvent?.event.method === 'ExtrinsicSuccess',
|
|
177
|
+
};
|
|
178
|
+
});
|
|
179
|
+
resp.blockDetails = {
|
|
180
|
+
timestamp: timestamp?.toString(),
|
|
181
|
+
events: parsedEvents,
|
|
182
|
+
extrinsics,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
return resp;
|
|
186
|
+
};
|
|
187
|
+
exports.rpc = rpc;
|
|
@@ -9,8 +9,8 @@ import { BuildBlockMode, Context } from '@acala-network/chopsticks-core';
|
|
|
9
9
|
*
|
|
10
10
|
* @example Set build block mode to instant
|
|
11
11
|
* ```ts
|
|
12
|
-
* import { WsProvider } from '@polkadot/
|
|
13
|
-
* import { BuildBlockMode } from '@acala-network/chopsticks'
|
|
12
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
13
|
+
* import { BuildBlockMode } from '@acala-network/chopsticks-core'
|
|
14
14
|
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
15
15
|
* await ws.send('dev_setBlockBuildMode', [BuildBlockMode.Instant])
|
|
16
16
|
* ```
|
|
@@ -13,8 +13,8 @@ const logger_1 = require("../../logger");
|
|
|
13
13
|
*
|
|
14
14
|
* @example Set build block mode to instant
|
|
15
15
|
* ```ts
|
|
16
|
-
* import { WsProvider } from '@polkadot/
|
|
17
|
-
* import { BuildBlockMode } from '@acala-network/chopsticks'
|
|
16
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
17
|
+
* import { BuildBlockMode } from '@acala-network/chopsticks-core'
|
|
18
18
|
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
19
19
|
* await ws.send('dev_setBlockBuildMode', [BuildBlockMode.Instant])
|
|
20
20
|
* ```
|
|
@@ -10,7 +10,7 @@ import { HexString } from '@polkadot/util/types';
|
|
|
10
10
|
*
|
|
11
11
|
* @example Set head to block 1000000
|
|
12
12
|
* ```ts
|
|
13
|
-
* import { WsProvider } from '@polkadot/
|
|
13
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
14
14
|
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
15
15
|
* await ws.send('dev_setHead', [1000000])
|
|
16
16
|
* ```
|
|
@@ -12,7 +12,7 @@ const chopsticks_core_1 = require("@acala-network/chopsticks-core");
|
|
|
12
12
|
*
|
|
13
13
|
* @example Set head to block 1000000
|
|
14
14
|
* ```ts
|
|
15
|
-
* import { WsProvider } from '@polkadot/
|
|
15
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
16
16
|
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
17
17
|
* await ws.send('dev_setHead', [1000000])
|
|
18
18
|
* ```
|
|
@@ -9,7 +9,7 @@ import { Context } from '@acala-network/chopsticks-core';
|
|
|
9
9
|
*
|
|
10
10
|
* @example Set runtime log level to 1
|
|
11
11
|
* ```ts
|
|
12
|
-
* import { WsProvider } from '@polkadot/
|
|
12
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
13
13
|
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
14
14
|
* await ws.send('dev_setRuntimeLogLevel', [1])
|
|
15
15
|
* ```
|
|
@@ -13,7 +13,7 @@ const logger_1 = require("../../logger");
|
|
|
13
13
|
*
|
|
14
14
|
* @example Set runtime log level to 1
|
|
15
15
|
* ```ts
|
|
16
|
-
* import { WsProvider } from '@polkadot/
|
|
16
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
17
17
|
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
18
18
|
* await ws.send('dev_setRuntimeLogLevel', [1])
|
|
19
19
|
* ```
|
|
@@ -10,7 +10,7 @@ import { HexString } from '@polkadot/util/types';
|
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
* ```ts
|
|
13
|
-
* import { WsProvider } from '@polkadot/
|
|
13
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
14
14
|
* import { Keyring } from '@polkadot/keyring'
|
|
15
15
|
*
|
|
16
16
|
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
@@ -13,7 +13,7 @@ const logger_1 = require("../../logger");
|
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```ts
|
|
16
|
-
* import { WsProvider } from '@polkadot/
|
|
16
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
17
17
|
* import { Keyring } from '@polkadot/keyring'
|
|
18
18
|
*
|
|
19
19
|
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
@@ -9,7 +9,7 @@ import { Context } from '@acala-network/chopsticks-core';
|
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```ts
|
|
12
|
-
* import { WsProvider } from '@polkadot/
|
|
12
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
13
13
|
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
14
14
|
* await ws.send('dev_timeTravel', ['Jan 1, 2023'])
|
|
15
15
|
* ```
|
|
@@ -12,7 +12,7 @@ const chopsticks_core_1 = require("@acala-network/chopsticks-core");
|
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```ts
|
|
15
|
-
* import { WsProvider } from '@polkadot/
|
|
15
|
+
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
16
16
|
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
17
17
|
* await ws.send('dev_timeTravel', ['Jan 1, 2023'])
|
|
18
18
|
* ```
|
package/lib/plugins/types.d.ts
CHANGED
|
@@ -5,3 +5,4 @@ export { rpc as setHead } from './set-head';
|
|
|
5
5
|
export { rpc as setRuntimeLogLevel } from './set-runtime-log-level';
|
|
6
6
|
export { rpc as setStorage } from './set-storage';
|
|
7
7
|
export { rpc as timeTravel } from './time-travel';
|
|
8
|
+
export { rpc as runBlock, RunBlockParams } from './run-block';
|
package/lib/plugins/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.timeTravel = exports.setStorage = exports.setRuntimeLogLevel = exports.setHead = exports.setBlockBuildMode = exports.dryRun = exports.newBlock = void 0;
|
|
3
|
+
exports.runBlock = exports.timeTravel = exports.setStorage = exports.setRuntimeLogLevel = exports.setHead = exports.setBlockBuildMode = exports.dryRun = exports.newBlock = void 0;
|
|
4
4
|
var new_block_1 = require("./new-block");
|
|
5
5
|
Object.defineProperty(exports, "newBlock", { enumerable: true, get: function () { return new_block_1.rpc; } });
|
|
6
6
|
var dry_run_1 = require("./dry-run");
|
|
@@ -15,3 +15,5 @@ var set_storage_1 = require("./set-storage");
|
|
|
15
15
|
Object.defineProperty(exports, "setStorage", { enumerable: true, get: function () { return set_storage_1.rpc; } });
|
|
16
16
|
var time_travel_1 = require("./time-travel");
|
|
17
17
|
Object.defineProperty(exports, "timeTravel", { enumerable: true, get: function () { return time_travel_1.rpc; } });
|
|
18
|
+
var run_block_1 = require("./run-block");
|
|
19
|
+
Object.defineProperty(exports, "runBlock", { enumerable: true, get: function () { return run_block_1.rpc; } });
|
package/lib/server.js
CHANGED
|
@@ -1,32 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.createServer = void 0;
|
|
4
|
+
const ws_1 = require("ws");
|
|
27
5
|
const chopsticks_core_1 = require("@acala-network/chopsticks-core");
|
|
28
6
|
const zod_1 = require("zod");
|
|
29
|
-
const ws_1 = __importStar(require("ws"));
|
|
30
7
|
const logger_1 = require("./logger");
|
|
31
8
|
const logger = logger_1.defaultLogger.child({ name: 'ws' });
|
|
32
9
|
const singleRequest = zod_1.z.object({
|
|
@@ -76,7 +53,7 @@ const createServer = async (handler, port) => {
|
|
|
76
53
|
wss.on('connection', (ws) => {
|
|
77
54
|
logger.debug('New connection');
|
|
78
55
|
const send = (data) => {
|
|
79
|
-
if (ws.readyState === ws_1.
|
|
56
|
+
if (ws.readyState === ws_1.WebSocket.OPEN) {
|
|
80
57
|
ws.send(JSON.stringify(data));
|
|
81
58
|
}
|
|
82
59
|
};
|
package/lib/utils/index.d.ts
CHANGED
package/lib/utils/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acala-network/chopsticks",
|
|
3
|
-
"version": "0.8.5-
|
|
3
|
+
"version": "0.8.5-3",
|
|
4
4
|
"author": "Acala Developers <hello@acala.network>",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"bin": "./chopsticks.js",
|
|
@@ -17,10 +17,9 @@
|
|
|
17
17
|
"docs:prep": "typedoc"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@acala-network/chopsticks-core": "0.8.5-
|
|
21
|
-
"@acala-network/chopsticks-db": "0.8.5-
|
|
20
|
+
"@acala-network/chopsticks-core": "0.8.5-3",
|
|
21
|
+
"@acala-network/chopsticks-db": "0.8.5-3",
|
|
22
22
|
"@pnpm/npm-conf": "^2.2.2",
|
|
23
|
-
"@polkadot/api": "^10.9.1",
|
|
24
23
|
"axios": "^1.5.1",
|
|
25
24
|
"dotenv": "^16.3.1",
|
|
26
25
|
"global-agent": "^3.0.0",
|
|
@@ -58,6 +57,10 @@
|
|
|
58
57
|
"types": "./lib/*.d.ts",
|
|
59
58
|
"default": "./lib/*.js"
|
|
60
59
|
},
|
|
60
|
+
"./plugins/*": {
|
|
61
|
+
"types": "./lib/plugins/*.d.ts",
|
|
62
|
+
"default": "./lib/plugins/*.js"
|
|
63
|
+
},
|
|
61
64
|
"./package.json": "./package.json"
|
|
62
65
|
}
|
|
63
66
|
}
|
package/lib/utils/signFake.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { ApiPromise } from '@polkadot/api';
|
|
2
|
-
import { GenericExtrinsic } from '@polkadot/types';
|
|
3
|
-
import { SignatureOptions } from '@polkadot/types/types';
|
|
4
|
-
export type SignFakeOptions = Partial<SignatureOptions>;
|
|
5
|
-
export declare const signFakeWithApi: (api: ApiPromise, tx: GenericExtrinsic, addr: string, options?: SignFakeOptions) => Promise<void>;
|
|
6
|
-
export declare const signFake: (tx: GenericExtrinsic, addr: string, options: SignatureOptions) => void;
|
package/lib/utils/signFake.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.signFake = exports.signFakeWithApi = void 0;
|
|
4
|
-
const signFakeWithApi = async (api, tx, addr, options = {}) => {
|
|
5
|
-
const nonce = options.nonce ?? (await api.query.system.account(addr)).nonce;
|
|
6
|
-
(0, exports.signFake)(tx, addr, {
|
|
7
|
-
nonce,
|
|
8
|
-
genesisHash: api.genesisHash,
|
|
9
|
-
runtimeVersion: api.runtimeVersion,
|
|
10
|
-
blockHash: api.genesisHash,
|
|
11
|
-
...options,
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
exports.signFakeWithApi = signFakeWithApi;
|
|
15
|
-
const signFake = (tx, addr, options) => {
|
|
16
|
-
const mockSignature = new Uint8Array(64);
|
|
17
|
-
mockSignature.fill(0xcd);
|
|
18
|
-
mockSignature.set([0xde, 0xad, 0xbe, 0xef]);
|
|
19
|
-
tx.signFake(addr, options);
|
|
20
|
-
tx.signature.set(mockSignature);
|
|
21
|
-
};
|
|
22
|
-
exports.signFake = signFake;
|