@acala-network/chopsticks 0.9.4-6 → 0.9.5-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli.js +6 -34
- package/dist/cjs/context.js +3 -3
- package/dist/cjs/plugins/decode-key/cli.js +4 -6
- package/dist/cjs/plugins/dry-run/cli.js +31 -34
- package/dist/cjs/plugins/dry-run/dry-run-extrinsic.d.ts +2 -2
- package/dist/cjs/plugins/dry-run/dry-run-preimage.d.ts +2 -2
- package/dist/cjs/plugins/dry-run/index.d.ts +160 -0
- package/dist/cjs/plugins/dry-run/index.js +32 -0
- package/dist/cjs/plugins/follow-chain/cli.js +31 -32
- package/dist/cjs/plugins/run-block/__snapshots__/index.test.ts.snap +3301 -0
- package/dist/cjs/plugins/run-block/cli.js +16 -16
- package/dist/cjs/plugins/run-block/rpc.js +2 -1
- package/dist/cjs/plugins/try-runtime/index.js +24 -22
- package/dist/cjs/rpc/index.js +5 -2
- package/dist/cjs/schema/index.d.ts +24 -16
- package/dist/cjs/schema/index.js +85 -16
- package/dist/cjs/setup-with-server.js +3 -4
- package/dist/esm/cli.js +8 -36
- package/dist/esm/context.js +3 -3
- package/dist/esm/plugins/decode-key/cli.js +4 -6
- package/dist/esm/plugins/dry-run/cli.js +31 -34
- package/dist/esm/plugins/dry-run/dry-run-extrinsic.d.ts +2 -2
- package/dist/esm/plugins/dry-run/dry-run-preimage.d.ts +2 -2
- package/dist/esm/plugins/dry-run/index.d.ts +160 -0
- package/dist/esm/plugins/dry-run/index.js +26 -0
- package/dist/esm/plugins/follow-chain/cli.js +30 -31
- package/dist/esm/plugins/run-block/__snapshots__/index.test.ts.snap +3301 -0
- package/dist/esm/plugins/run-block/cli.js +16 -16
- package/dist/esm/plugins/run-block/rpc.js +2 -1
- package/dist/esm/plugins/try-runtime/index.js +24 -22
- package/dist/esm/rpc/index.js +6 -3
- package/dist/esm/schema/index.d.ts +24 -16
- package/dist/esm/schema/index.js +82 -16
- package/dist/esm/setup-with-server.js +3 -4
- package/package.json +8 -8
- package/dist/cjs/cli-options.d.ts +0 -40
- package/dist/cjs/cli-options.js +0 -58
- package/dist/esm/cli-options.d.ts +0 -40
- package/dist/esm/cli-options.js +0 -40
|
@@ -9,27 +9,27 @@ Object.defineProperty(exports, "cli", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _nodefs = require("node:fs");
|
|
12
|
+
const _zod = require("zod");
|
|
12
13
|
const _chopstickscore = require("@acala-network/chopsticks-core");
|
|
13
|
-
const
|
|
14
|
+
const _index = require("../../schema/index.js");
|
|
14
15
|
const _generatehtmldiff = require("../../utils/generate-html-diff.js");
|
|
15
16
|
const _openhtml = require("../../utils/open-html.js");
|
|
16
17
|
const _context = require("../../context.js");
|
|
18
|
+
const schema = _zod.z.object({
|
|
19
|
+
..._index.configSchema.shape,
|
|
20
|
+
['output-path']: _zod.z.string({
|
|
21
|
+
description: 'File path to print output'
|
|
22
|
+
}).optional(),
|
|
23
|
+
html: _zod.z.boolean({
|
|
24
|
+
description: 'Generate html with storage diff'
|
|
25
|
+
}).optional(),
|
|
26
|
+
open: _zod.z.boolean({
|
|
27
|
+
description: 'Open generated html'
|
|
28
|
+
}).optional()
|
|
29
|
+
});
|
|
17
30
|
const cli = (y)=>{
|
|
18
|
-
y.command('run-block', 'Replay a block', (yargs)=>yargs.options({
|
|
19
|
-
|
|
20
|
-
..._clioptions.mockOptions,
|
|
21
|
-
'output-path': {
|
|
22
|
-
desc: 'File path to print output',
|
|
23
|
-
string: true
|
|
24
|
-
},
|
|
25
|
-
html: {
|
|
26
|
-
desc: 'Generate html with storage diff'
|
|
27
|
-
},
|
|
28
|
-
open: {
|
|
29
|
-
desc: 'Open generated html'
|
|
30
|
-
}
|
|
31
|
-
}), async (argv)=>{
|
|
32
|
-
const context = await (0, _context.setupContext)(argv, true);
|
|
31
|
+
y.command('run-block', 'Replay a block', (yargs)=>yargs.options((0, _index.getYargsOptions)(schema.shape)), async (argv)=>{
|
|
32
|
+
const context = await (0, _context.setupContext)(schema.parse(argv), true);
|
|
33
33
|
const header = await context.chain.head.header;
|
|
34
34
|
const block = context.chain.head;
|
|
35
35
|
const parent = await block.parentBlock;
|
|
@@ -78,6 +78,7 @@ const rpc = async ({ chain }, [params])=>{
|
|
|
78
78
|
const raw = result.Call.storageDiff;
|
|
79
79
|
const previousLayer = newBlock.storage;
|
|
80
80
|
newBlock.pushStorageLayer().setAll(raw);
|
|
81
|
+
const newBlockMeta = await newBlock.meta;
|
|
81
82
|
for (const [key, value] of raw){
|
|
82
83
|
if (key === systemEventsKey) {
|
|
83
84
|
continue;
|
|
@@ -97,7 +98,7 @@ const rpc = async ({ chain }, [params])=>{
|
|
|
97
98
|
};
|
|
98
99
|
}
|
|
99
100
|
if (includeParsed) {
|
|
100
|
-
const decoded = (0, _chopstickscore.decodeKeyValue)(
|
|
101
|
+
const decoded = (0, _chopstickscore.decodeKeyValue)(newBlockMeta, key, value, false);
|
|
101
102
|
if (decoded) {
|
|
102
103
|
obj.parsed = {
|
|
103
104
|
section: decoded.section,
|
|
@@ -9,32 +9,34 @@ Object.defineProperty(exports, "cli", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _nodefs = require("node:fs");
|
|
12
|
-
const
|
|
12
|
+
const _zod = require("zod");
|
|
13
|
+
const _index = require("../../schema/index.js");
|
|
13
14
|
const _generatehtmldiff = require("../../utils/generate-html-diff.js");
|
|
14
15
|
const _openhtml = require("../../utils/open-html.js");
|
|
15
16
|
const _context = require("../../context.js");
|
|
17
|
+
const schema = _zod.z.object({
|
|
18
|
+
endpoint: _index.configSchema.shape.endpoint,
|
|
19
|
+
port: _index.configSchema.shape.port,
|
|
20
|
+
['build-block-mode']: _index.configSchema.shape['build-block-mode'],
|
|
21
|
+
block: _index.configSchema.shape.block,
|
|
22
|
+
db: _index.configSchema.shape.db,
|
|
23
|
+
['runtime-log-level']: _index.configSchema.shape['runtime-log-level'],
|
|
24
|
+
['wasm-override']: _zod.z.string({
|
|
25
|
+
description: 'Path to WASM built with feature `try-runtime` enabled'
|
|
26
|
+
}),
|
|
27
|
+
['output-path']: _zod.z.string({
|
|
28
|
+
description: 'File path to print output'
|
|
29
|
+
}).optional(),
|
|
30
|
+
html: _zod.z.boolean({
|
|
31
|
+
description: 'Generate html with storage diff'
|
|
32
|
+
}).optional(),
|
|
33
|
+
open: _zod.z.boolean({
|
|
34
|
+
description: 'Open generated html'
|
|
35
|
+
}).optional()
|
|
36
|
+
});
|
|
16
37
|
const cli = (y)=>{
|
|
17
|
-
y.command('try-runtime', 'Runs runtime upgrade', (yargs)=>yargs.options({
|
|
18
|
-
|
|
19
|
-
'wasm-override': {
|
|
20
|
-
desc: 'Path to WASM built with feature `try-runtime` enabled',
|
|
21
|
-
string: true,
|
|
22
|
-
required: true
|
|
23
|
-
},
|
|
24
|
-
'output-path': {
|
|
25
|
-
desc: 'File path to print output',
|
|
26
|
-
string: true
|
|
27
|
-
},
|
|
28
|
-
html: {
|
|
29
|
-
desc: 'Generate html with storage diff',
|
|
30
|
-
boolean: true
|
|
31
|
-
},
|
|
32
|
-
open: {
|
|
33
|
-
desc: 'Open generated html',
|
|
34
|
-
boolean: true
|
|
35
|
-
}
|
|
36
|
-
}), async (argv)=>{
|
|
37
|
-
const context = await (0, _context.setupContext)(argv);
|
|
38
|
+
y.command('try-runtime', 'Runs runtime upgrade', (yargs)=>yargs.options((0, _index.getYargsOptions)(schema.shape)), async (argv)=>{
|
|
39
|
+
const context = await (0, _context.setupContext)(schema.parse(argv));
|
|
38
40
|
const block = context.chain.head;
|
|
39
41
|
const registry = await block.registry;
|
|
40
42
|
registry.register({
|
package/dist/cjs/rpc/index.js
CHANGED
|
@@ -10,6 +10,9 @@ Object.defineProperty(exports, "handler", {
|
|
|
10
10
|
});
|
|
11
11
|
const _chopstickscore = require("@acala-network/chopsticks-core");
|
|
12
12
|
const _index = require("../plugins/index.js");
|
|
13
|
+
const rpcLogger = _chopstickscore.defaultLogger.child({
|
|
14
|
+
module: 'rpc'
|
|
15
|
+
});
|
|
13
16
|
const allHandlers = {
|
|
14
17
|
..._chopstickscore.substrate,
|
|
15
18
|
rpc_methods: async ()=>Promise.resolve({
|
|
@@ -29,10 +32,10 @@ const getHandler = async (method)=>{
|
|
|
29
32
|
return handler;
|
|
30
33
|
};
|
|
31
34
|
const handler = (context)=>async ({ method, params }, subscriptionManager)=>{
|
|
32
|
-
|
|
35
|
+
rpcLogger.trace('Handling %s', method);
|
|
33
36
|
const handler = await getHandler(method);
|
|
34
37
|
if (!handler) {
|
|
35
|
-
|
|
38
|
+
rpcLogger.warn('Method not found %s', method);
|
|
36
39
|
throw new _chopstickscore.ResponseError(-32601, `Method not found: ${method}`);
|
|
37
40
|
}
|
|
38
41
|
return handler(context, params, subscriptionManager);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { BuildBlockMode } from '@acala-network/chopsticks-core';
|
|
2
|
-
import { z } from 'zod';
|
|
2
|
+
import { ZodNativeEnum, ZodRawShape, ZodTypeAny, z } from 'zod';
|
|
3
3
|
export declare const zHex: z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>;
|
|
4
4
|
export declare const zHash: z.ZodIntersection<z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>>;
|
|
5
5
|
export declare const configSchema: z.ZodObject<{
|
|
6
|
-
port: z.
|
|
6
|
+
port: z.ZodDefault<z.ZodNumber>;
|
|
7
7
|
endpoint: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
8
|
-
block: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodNull]>>;
|
|
9
|
-
'build-block-mode': z.
|
|
8
|
+
block: z.ZodOptional<z.ZodUnion<[z.ZodIntersection<z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>>, z.ZodNumber, z.ZodNull]>>;
|
|
9
|
+
'build-block-mode': z.ZodDefault<ZodNativeEnum<typeof BuildBlockMode>>;
|
|
10
10
|
'import-storage': z.ZodOptional<z.ZodAny>;
|
|
11
11
|
'allow-unresolved-imports': z.ZodOptional<z.ZodBoolean>;
|
|
12
12
|
'mock-signature-host': z.ZodOptional<z.ZodBoolean>;
|
|
@@ -20,7 +20,7 @@ export declare const configSchema: z.ZodObject<{
|
|
|
20
20
|
ss58Format: z.ZodOptional<z.ZodNumber>;
|
|
21
21
|
tokenDecimals: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodArray<z.ZodNumber, "many">]>>;
|
|
22
22
|
tokenSymbol: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
23
|
-
}, "strip",
|
|
23
|
+
}, "strip", ZodTypeAny, {
|
|
24
24
|
ss58Format?: number | undefined;
|
|
25
25
|
tokenDecimals?: number | number[] | undefined;
|
|
26
26
|
tokenSymbol?: string | string[] | undefined;
|
|
@@ -32,12 +32,12 @@ export declare const configSchema: z.ZodObject<{
|
|
|
32
32
|
genesis: z.ZodObject<{
|
|
33
33
|
raw: z.ZodObject<{
|
|
34
34
|
top: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
35
|
-
}, "strip",
|
|
35
|
+
}, "strip", ZodTypeAny, {
|
|
36
36
|
top: Record<string, string>;
|
|
37
37
|
}, {
|
|
38
38
|
top: Record<string, string>;
|
|
39
39
|
}>;
|
|
40
|
-
}, "strip",
|
|
40
|
+
}, "strip", ZodTypeAny, {
|
|
41
41
|
raw: {
|
|
42
42
|
top: Record<string, string>;
|
|
43
43
|
};
|
|
@@ -46,7 +46,7 @@ export declare const configSchema: z.ZodObject<{
|
|
|
46
46
|
top: Record<string, string>;
|
|
47
47
|
};
|
|
48
48
|
}>;
|
|
49
|
-
}, "strip",
|
|
49
|
+
}, "strip", ZodTypeAny, {
|
|
50
50
|
name: string;
|
|
51
51
|
id: string;
|
|
52
52
|
properties: {
|
|
@@ -77,12 +77,12 @@ export declare const configSchema: z.ZodObject<{
|
|
|
77
77
|
'registered-types': z.ZodOptional<z.ZodAny>;
|
|
78
78
|
'runtime-log-level': z.ZodOptional<z.ZodNumber>;
|
|
79
79
|
'offchain-worker': z.ZodOptional<z.ZodBoolean>;
|
|
80
|
-
resume: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
81
|
-
}, "
|
|
82
|
-
port
|
|
80
|
+
resume: z.ZodOptional<z.ZodUnion<[z.ZodIntersection<z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>>, z.ZodNumber, z.ZodBoolean]>>;
|
|
81
|
+
}, "strip", ZodTypeAny, {
|
|
82
|
+
port: number;
|
|
83
|
+
'build-block-mode': BuildBlockMode;
|
|
83
84
|
endpoint?: string | string[] | undefined;
|
|
84
|
-
block?:
|
|
85
|
-
'build-block-mode'?: BuildBlockMode | undefined;
|
|
85
|
+
block?: number | `0x${string}` | null | undefined;
|
|
86
86
|
'import-storage'?: any;
|
|
87
87
|
'allow-unresolved-imports'?: boolean | undefined;
|
|
88
88
|
'mock-signature-host'?: boolean | undefined;
|
|
@@ -107,11 +107,11 @@ export declare const configSchema: z.ZodObject<{
|
|
|
107
107
|
'registered-types'?: any;
|
|
108
108
|
'runtime-log-level'?: number | undefined;
|
|
109
109
|
'offchain-worker'?: boolean | undefined;
|
|
110
|
-
resume?:
|
|
110
|
+
resume?: number | boolean | `0x${string}` | undefined;
|
|
111
111
|
}, {
|
|
112
112
|
port?: number | undefined;
|
|
113
113
|
endpoint?: string | string[] | undefined;
|
|
114
|
-
block?:
|
|
114
|
+
block?: number | `0x${string}` | null | undefined;
|
|
115
115
|
'build-block-mode'?: BuildBlockMode | undefined;
|
|
116
116
|
'import-storage'?: any;
|
|
117
117
|
'allow-unresolved-imports'?: boolean | undefined;
|
|
@@ -137,7 +137,15 @@ export declare const configSchema: z.ZodObject<{
|
|
|
137
137
|
'registered-types'?: any;
|
|
138
138
|
'runtime-log-level'?: number | undefined;
|
|
139
139
|
'offchain-worker'?: boolean | undefined;
|
|
140
|
-
resume?:
|
|
140
|
+
resume?: number | boolean | `0x${string}` | undefined;
|
|
141
141
|
}>;
|
|
142
142
|
export type Config = z.infer<typeof configSchema>;
|
|
143
|
+
export declare const getYargsOptions: (zodShape: ZodRawShape) => {
|
|
144
|
+
[x: string]: {
|
|
145
|
+
demandOption: boolean;
|
|
146
|
+
description: any;
|
|
147
|
+
type: any;
|
|
148
|
+
choices: any;
|
|
149
|
+
};
|
|
150
|
+
};
|
|
143
151
|
export declare const fetchConfig: (path: string) => Promise<Config>;
|
package/dist/cjs/schema/index.js
CHANGED
|
@@ -15,6 +15,9 @@ _export(exports, {
|
|
|
15
15
|
fetchConfig: function() {
|
|
16
16
|
return fetchConfig;
|
|
17
17
|
},
|
|
18
|
+
getYargsOptions: function() {
|
|
19
|
+
return getYargsOptions;
|
|
20
|
+
},
|
|
18
21
|
zHash: function() {
|
|
19
22
|
return zHash;
|
|
20
23
|
},
|
|
@@ -23,9 +26,9 @@ _export(exports, {
|
|
|
23
26
|
}
|
|
24
27
|
});
|
|
25
28
|
const _chopstickscore = require("@acala-network/chopsticks-core");
|
|
29
|
+
const _zod = require("zod");
|
|
26
30
|
const _nodepath = require("node:path");
|
|
27
31
|
const _nodefs = require("node:fs");
|
|
28
|
-
const _zod = require("zod");
|
|
29
32
|
const _lodash = /*#__PURE__*/ _interop_require_default(require("lodash"));
|
|
30
33
|
const _axios = /*#__PURE__*/ _interop_require_default(require("axios"));
|
|
31
34
|
const _jsyaml = /*#__PURE__*/ _interop_require_default(require("js-yaml"));
|
|
@@ -37,37 +40,103 @@ function _interop_require_default(obj) {
|
|
|
37
40
|
const zHex = _zod.z.custom((val)=>/^0x\w+$/.test(val));
|
|
38
41
|
const zHash = _zod.z.string().length(66).and(zHex);
|
|
39
42
|
const configSchema = _zod.z.object({
|
|
40
|
-
port: _zod.z.number(
|
|
43
|
+
port: _zod.z.number({
|
|
44
|
+
description: 'Port to listen on'
|
|
45
|
+
}).default(8000),
|
|
41
46
|
endpoint: _zod.z.union([
|
|
42
47
|
_zod.z.string(),
|
|
43
48
|
_zod.z.array(_zod.z.string())
|
|
44
|
-
]
|
|
49
|
+
], {
|
|
50
|
+
description: 'Endpoint to connect to'
|
|
51
|
+
}).optional(),
|
|
45
52
|
block: _zod.z.union([
|
|
46
|
-
|
|
53
|
+
zHash,
|
|
47
54
|
_zod.z.number(),
|
|
48
55
|
_zod.z.null()
|
|
49
|
-
]
|
|
50
|
-
|
|
51
|
-
|
|
56
|
+
], {
|
|
57
|
+
description: 'Block hash or block number. Default to latest block'
|
|
58
|
+
}).optional(),
|
|
59
|
+
'build-block-mode': _zod.z.nativeEnum(_chopstickscore.BuildBlockMode).default(_chopstickscore.BuildBlockMode.Batch),
|
|
60
|
+
'import-storage': _zod.z.any({
|
|
61
|
+
description: 'Pre-defined JSON/YAML storage file path'
|
|
62
|
+
}).optional(),
|
|
52
63
|
'allow-unresolved-imports': _zod.z.boolean().optional(),
|
|
53
|
-
'mock-signature-host': _zod.z.boolean(
|
|
64
|
+
'mock-signature-host': _zod.z.boolean({
|
|
65
|
+
description: 'Mock signature host so any signature starts with 0xdeadbeef and filled by 0xcd is considered valid'
|
|
66
|
+
}).optional(),
|
|
54
67
|
'max-memory-block-count': _zod.z.number().optional(),
|
|
55
|
-
db: _zod.z.string(
|
|
56
|
-
|
|
68
|
+
db: _zod.z.string({
|
|
69
|
+
description: 'Path to database'
|
|
70
|
+
}).optional(),
|
|
71
|
+
'wasm-override': _zod.z.string({
|
|
72
|
+
description: 'Path to wasm override'
|
|
73
|
+
}).optional(),
|
|
57
74
|
genesis: _zod.z.union([
|
|
58
75
|
_zod.z.string(),
|
|
59
76
|
_chopstickscore.genesisSchema
|
|
60
77
|
]).optional(),
|
|
61
78
|
timestamp: _zod.z.number().optional(),
|
|
62
79
|
'registered-types': _zod.z.any().optional(),
|
|
63
|
-
'runtime-log-level': _zod.z.number(
|
|
64
|
-
|
|
80
|
+
'runtime-log-level': _zod.z.number({
|
|
81
|
+
description: 'Runtime maximum log level [off = 0; error = 1; warn = 2; info = 3; debug = 4; trace = 5]'
|
|
82
|
+
}).min(0).max(5).optional(),
|
|
83
|
+
'offchain-worker': _zod.z.boolean({
|
|
84
|
+
description: 'Enable offchain worker'
|
|
85
|
+
}).optional(),
|
|
65
86
|
resume: _zod.z.union([
|
|
66
|
-
|
|
87
|
+
zHash,
|
|
67
88
|
_zod.z.number(),
|
|
68
89
|
_zod.z.boolean()
|
|
69
|
-
]
|
|
70
|
-
|
|
90
|
+
], {
|
|
91
|
+
description: 'Resume from the specified block hash or block number in db. If true, it will resume from the latest block in db. Note this will override the block option'
|
|
92
|
+
}).optional()
|
|
93
|
+
});
|
|
94
|
+
const getZodType = (option)=>{
|
|
95
|
+
switch(option._def.typeName){
|
|
96
|
+
case 'ZodString':
|
|
97
|
+
return 'string';
|
|
98
|
+
case 'ZodNumber':
|
|
99
|
+
return 'number';
|
|
100
|
+
case 'ZodBoolean':
|
|
101
|
+
return 'boolean';
|
|
102
|
+
default:
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
if (option._def.innerType) {
|
|
106
|
+
return getZodType(option._def.innerType);
|
|
107
|
+
}
|
|
108
|
+
return undefined;
|
|
109
|
+
};
|
|
110
|
+
const getZodChoices = (option)=>{
|
|
111
|
+
if (option._def.innerType instanceof _zod.ZodNativeEnum) {
|
|
112
|
+
return Object.values(option._def.innerType._def.values).filter((x)=>typeof x === 'string');
|
|
113
|
+
}
|
|
114
|
+
if (option._def.innerType) {
|
|
115
|
+
return getZodChoices(option._def.innerType);
|
|
116
|
+
}
|
|
117
|
+
return undefined;
|
|
118
|
+
};
|
|
119
|
+
const getZodFirstOption = (option)=>{
|
|
120
|
+
const options = option._def.options;
|
|
121
|
+
if (options) {
|
|
122
|
+
for (const option of options){
|
|
123
|
+
const type = getZodType(option);
|
|
124
|
+
if (type) return type;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (option._def.innerType) {
|
|
128
|
+
return getZodFirstOption(option._def.innerType);
|
|
129
|
+
}
|
|
130
|
+
return undefined;
|
|
131
|
+
};
|
|
132
|
+
const getYargsOptions = (zodShape)=>{
|
|
133
|
+
return _lodash.default.mapValues(zodShape, (option)=>({
|
|
134
|
+
demandOption: !option.isOptional(),
|
|
135
|
+
description: option._def.description,
|
|
136
|
+
type: getZodType(option) || getZodFirstOption(option),
|
|
137
|
+
choices: getZodChoices(option)
|
|
138
|
+
}));
|
|
139
|
+
};
|
|
71
140
|
const CONFIGS_BASE_URL = 'https://raw.githubusercontent.com/AcalaNetwork/chopsticks/master/configs/';
|
|
72
141
|
const fetchConfig = async (path)=>{
|
|
73
142
|
let file;
|
|
@@ -97,5 +166,5 @@ const fetchConfig = async (path)=>{
|
|
|
97
166
|
const config = _jsyaml.default.load(_lodash.default.template(file, {
|
|
98
167
|
variable: 'env'
|
|
99
168
|
})(process.env));
|
|
100
|
-
return configSchema.parse(config);
|
|
169
|
+
return configSchema.strict().parse(config);
|
|
101
170
|
};
|
|
@@ -9,18 +9,17 @@ Object.defineProperty(exports, "setupWithServer", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _server = require("./server.js");
|
|
12
|
-
const _index = require("./rpc/index.js");
|
|
13
12
|
const _chopstickscore = require("@acala-network/chopsticks-core");
|
|
13
|
+
const _index = require("./rpc/index.js");
|
|
14
14
|
const _context = require("./context.js");
|
|
15
15
|
const setupWithServer = async (argv)=>{
|
|
16
16
|
const context = await (0, _context.setupContext)(argv);
|
|
17
|
-
const port = argv.port ?? 8000;
|
|
18
17
|
if (argv.genesis) {
|
|
19
18
|
// mine 1st block when starting from genesis to set some mock validation data
|
|
20
19
|
await context.chain.newBlock();
|
|
21
20
|
}
|
|
22
|
-
const { close, port: listenPort } = await (0, _server.createServer)((0, _index.handler)(context), port);
|
|
23
|
-
_chopstickscore.
|
|
21
|
+
const { close, port: listenPort } = await (0, _server.createServer)((0, _index.handler)(context), argv.port);
|
|
22
|
+
_chopstickscore.defaultLogger.info(`${await context.chain.api.getSystemChain()} RPC listening on port ${listenPort}`);
|
|
24
23
|
return {
|
|
25
24
|
...context,
|
|
26
25
|
listenPort,
|
package/dist/esm/cli.js
CHANGED
|
@@ -2,9 +2,8 @@ import { config as dotenvConfig } from 'dotenv';
|
|
|
2
2
|
import { hideBin } from 'yargs/helpers';
|
|
3
3
|
import _ from 'lodash';
|
|
4
4
|
import yargs from 'yargs';
|
|
5
|
-
import {
|
|
6
|
-
import { fetchConfig } from './schema/index.js';
|
|
7
|
-
import { defaultOptions, mockOptions } from './cli-options.js';
|
|
5
|
+
import { connectParachains, connectVertical } from '@acala-network/chopsticks-core';
|
|
6
|
+
import { configSchema, fetchConfig, getYargsOptions } from './schema/index.js';
|
|
8
7
|
import { pluginExtendCli } from './plugins/index.js';
|
|
9
8
|
import { setupWithServer } from './index.js';
|
|
10
9
|
dotenvConfig();
|
|
@@ -12,39 +11,12 @@ const processArgv = async (argv)=>{
|
|
|
12
11
|
if (argv.config) {
|
|
13
12
|
Object.assign(argv, _.defaults(argv, await fetchConfig(argv.config)));
|
|
14
13
|
}
|
|
15
|
-
|
|
14
|
+
if (process.env.PORT) {
|
|
15
|
+
argv.port = Number(process.env.PORT);
|
|
16
|
+
}
|
|
16
17
|
};
|
|
17
|
-
const commands = yargs(hideBin(process.argv)).scriptName('chopsticks').middleware(processArgv, false).command('*', 'Dev mode, fork off a chain', (yargs)=>yargs.options({
|
|
18
|
-
|
|
19
|
-
...mockOptions,
|
|
20
|
-
port: {
|
|
21
|
-
desc: 'Port to listen on',
|
|
22
|
-
number: true
|
|
23
|
-
},
|
|
24
|
-
'build-block-mode': {
|
|
25
|
-
desc: 'Build block mode. Default to Batch',
|
|
26
|
-
enum: [
|
|
27
|
-
BuildBlockMode.Batch,
|
|
28
|
-
BuildBlockMode.Manual,
|
|
29
|
-
BuildBlockMode.Instant
|
|
30
|
-
]
|
|
31
|
-
},
|
|
32
|
-
'allow-unresolved-imports': {
|
|
33
|
-
desc: 'Allow wasm unresolved imports',
|
|
34
|
-
boolean: true
|
|
35
|
-
},
|
|
36
|
-
'max-memory-block-count': {
|
|
37
|
-
desc: 'Max memory block count',
|
|
38
|
-
number: true
|
|
39
|
-
},
|
|
40
|
-
resume: {
|
|
41
|
-
desc: `Resume from the specified block hash or block number in db.
|
|
42
|
-
If true, it will resume from the latest block in db.
|
|
43
|
-
Note this will override the block option`,
|
|
44
|
-
string: true
|
|
45
|
-
}
|
|
46
|
-
}), async (argv)=>{
|
|
47
|
-
await setupWithServer(argv);
|
|
18
|
+
const commands = yargs(hideBin(process.argv)).scriptName('chopsticks').middleware(processArgv, false).command('*', 'Dev mode, fork off a chain', (yargs)=>yargs.config('config', 'Path to config file with default options', ()=>({})).options(getYargsOptions(configSchema.shape)), async (argv)=>{
|
|
19
|
+
await setupWithServer(configSchema.parse(argv));
|
|
48
20
|
}).command('xcm', 'XCM setup with relaychain and parachains', (yargs)=>yargs.options({
|
|
49
21
|
relaychain: {
|
|
50
22
|
desc: 'Relaychain config file path',
|
|
@@ -73,7 +45,7 @@ const commands = yargs(hideBin(process.argv)).scriptName('chopsticks').middlewar
|
|
|
73
45
|
}
|
|
74
46
|
}).strict().help().alias('help', 'h').alias('version', 'v').alias('config', 'c').alias('endpoint', 'e').alias('port', 'p').alias('block', 'b').alias('import-storage', 's').alias('wasm-override', 'w').usage('Usage: $0 <command> [options]').example('$0', '-c acala');
|
|
75
47
|
if (!process.env.DISABLE_PLUGINS) {
|
|
76
|
-
pluginExtendCli(commands).then(()=>commands.parse());
|
|
48
|
+
pluginExtendCli(commands.config('config', 'Path to config file with default options', ()=>({}))).then(()=>commands.parse());
|
|
77
49
|
} else {
|
|
78
50
|
commands.parse();
|
|
79
51
|
}
|
package/dist/esm/context.js
CHANGED
|
@@ -48,10 +48,10 @@ export const setupContext = async (argv, overrideParent = false)=>{
|
|
|
48
48
|
let blockData = null;
|
|
49
49
|
if (typeof argv.resume === 'string' && argv.resume.startsWith('0x')) {
|
|
50
50
|
blockData = await chain.db.queryBlock(argv.resume);
|
|
51
|
-
} else if (typeof argv.resume === '
|
|
51
|
+
} else if (typeof argv.resume === 'number') {
|
|
52
|
+
blockData = await chain.db.queryBlockByNumber(argv.resume);
|
|
53
|
+
} else if (argv.resume === true) {
|
|
52
54
|
blockData = await chain.db.queryHighestBlock();
|
|
53
|
-
} else if (Number.isInteger(+argv.resume)) {
|
|
54
|
-
blockData = await chain.db.queryBlockByNumber(+argv.resume);
|
|
55
55
|
} else {
|
|
56
56
|
throw new Error(`Resume failed. Invalid resume option ${argv.resume}`);
|
|
57
57
|
}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
+
import { configSchema, getYargsOptions } from '../../schema/index.js';
|
|
1
2
|
import { decodeKey } from '@acala-network/chopsticks-core';
|
|
2
|
-
import { defaultOptions } from '../../cli-options.js';
|
|
3
3
|
import { setupContext } from '../../context.js';
|
|
4
4
|
export const cli = (y)=>{
|
|
5
|
-
y.command('decode-key <key>', 'Deocde a key', (yargs)=>yargs.positional('key', {
|
|
5
|
+
y.command('decode-key <key>', 'Deocde a key', (yargs)=>yargs.options(getYargsOptions(configSchema.shape)).positional('key', {
|
|
6
6
|
desc: 'Key to decode',
|
|
7
7
|
type: 'string'
|
|
8
|
-
}).options({
|
|
9
|
-
...defaultOptions
|
|
10
8
|
}), async (argv)=>{
|
|
11
|
-
const context = await setupContext(argv);
|
|
12
|
-
const { storage, decodedKey } = decodeKey(await context.chain.head.meta,
|
|
9
|
+
const context = await setupContext(configSchema.parse(argv));
|
|
10
|
+
const { storage, decodedKey } = decodeKey(await context.chain.head.meta, argv.key);
|
|
13
11
|
if (storage && decodedKey) {
|
|
14
12
|
console.log(`${storage.section}.${storage.method}`, decodedKey.args.map((x)=>JSON.stringify(x.toHuman())).join(', '));
|
|
15
13
|
} else {
|
|
@@ -1,41 +1,38 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { configSchema, getYargsOptions } from '../../schema/index.js';
|
|
2
2
|
import { dryRunExtrinsic } from './dry-run-extrinsic.js';
|
|
3
3
|
import { dryRunPreimage } from './dry-run-preimage.js';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
const schema = z.object({
|
|
6
|
+
...configSchema.shape,
|
|
7
|
+
extrinsic: z.string({
|
|
8
|
+
description: 'Extrinsic or call to dry run. If you pass call here then address is required to fake signature'
|
|
9
|
+
}),
|
|
10
|
+
address: z.string({
|
|
11
|
+
description: 'Address to fake sign extrinsic'
|
|
12
|
+
}).optional(),
|
|
13
|
+
preimage: z.string({
|
|
14
|
+
description: 'Preimage to dry run'
|
|
15
|
+
}).optional(),
|
|
16
|
+
at: z.string({
|
|
17
|
+
description: 'Block hash to dry run'
|
|
18
|
+
}).optional(),
|
|
19
|
+
['output-path']: z.string({
|
|
20
|
+
description: 'File path to print output'
|
|
21
|
+
}).optional(),
|
|
22
|
+
html: z.boolean({
|
|
23
|
+
description: 'Generate html with storage diff'
|
|
24
|
+
}).optional(),
|
|
25
|
+
open: z.boolean({
|
|
26
|
+
description: 'Open generated html'
|
|
27
|
+
}).optional()
|
|
28
|
+
});
|
|
4
29
|
export const cli = (y)=>{
|
|
5
|
-
y.command('dry-run', 'Dry run an extrinsic', (yargs)=>yargs.options({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
desc: 'Extrinsic or call to dry run. If you pass call here then address is required to fake signature',
|
|
10
|
-
string: true
|
|
11
|
-
},
|
|
12
|
-
address: {
|
|
13
|
-
desc: 'Address to fake sign extrinsic',
|
|
14
|
-
string: true
|
|
15
|
-
},
|
|
16
|
-
preimage: {
|
|
17
|
-
desc: 'Preimage to dry run',
|
|
18
|
-
string: true
|
|
19
|
-
},
|
|
20
|
-
at: {
|
|
21
|
-
desc: 'Block hash to dry run',
|
|
22
|
-
string: true
|
|
23
|
-
},
|
|
24
|
-
'output-path': {
|
|
25
|
-
desc: 'File path to print output',
|
|
26
|
-
string: true
|
|
27
|
-
},
|
|
28
|
-
html: {
|
|
29
|
-
desc: 'Generate html with storage diff'
|
|
30
|
-
},
|
|
31
|
-
open: {
|
|
32
|
-
desc: 'Open generated html'
|
|
33
|
-
}
|
|
34
|
-
}), async (argv)=>{
|
|
35
|
-
if (argv.preimage) {
|
|
36
|
-
await dryRunPreimage(argv);
|
|
30
|
+
y.command('dry-run', 'Dry run an extrinsic', (yargs)=>yargs.options(getYargsOptions(schema.shape)), async (argv)=>{
|
|
31
|
+
const config = schema.parse(argv);
|
|
32
|
+
if (config.preimage) {
|
|
33
|
+
await dryRunPreimage(config);
|
|
37
34
|
} else {
|
|
38
|
-
await dryRunExtrinsic(
|
|
35
|
+
await dryRunExtrinsic(config);
|
|
39
36
|
}
|
|
40
37
|
});
|
|
41
38
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const dryRunExtrinsic: (argv:
|
|
1
|
+
import { DryRunSchemaType } from './index.js';
|
|
2
|
+
export declare const dryRunExtrinsic: (argv: DryRunSchemaType) => Promise<never>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const dryRunPreimage: (argv:
|
|
1
|
+
import { DryRunSchemaType } from './index.js';
|
|
2
|
+
export declare const dryRunPreimage: (argv: DryRunSchemaType) => Promise<never>;
|