@acala-network/chopsticks 0.9.4-5 → 0.9.4
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 +3 -5
- 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/cli.js +16 -16
- 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 +27 -16
- package/dist/cjs/schema/index.js +86 -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 +3 -5
- 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/cli.js +16 -16
- 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 +27 -16
- package/dist/esm/schema/index.js +83 -16
- package/dist/esm/setup-with-server.js +3 -4
- package/package.json +3 -3
- 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
|
@@ -1,49 +1,48 @@
|
|
|
1
1
|
import { Block, defaultLogger, runTask, taskHandler } from '@acala-network/chopsticks-core';
|
|
2
|
+
import { z } from 'zod';
|
|
2
3
|
import _ from 'lodash';
|
|
4
|
+
import { configSchema, getYargsOptions } from '../../schema/index.js';
|
|
3
5
|
import { createServer } from '../../server.js';
|
|
4
|
-
import { defaultOptions } from '../../cli-options.js';
|
|
5
6
|
import { handler } from '../../rpc/index.js';
|
|
6
7
|
import { setupContext } from '../../context.js';
|
|
7
8
|
const logger = defaultLogger.child({
|
|
8
9
|
name: 'follow-chain'
|
|
9
10
|
});
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
var HeadMode;
|
|
12
|
+
(function(HeadMode) {
|
|
13
|
+
HeadMode["Latest"] = "Latest";
|
|
14
|
+
HeadMode["Finalized"] = "Finalized";
|
|
15
|
+
})(HeadMode || (HeadMode = {}));
|
|
16
|
+
const schema = z.object({
|
|
17
|
+
..._.pick(configSchema.shape, [
|
|
18
|
+
'endpoint',
|
|
19
|
+
'port',
|
|
20
|
+
'wasm-override',
|
|
21
|
+
'runtime-log-level',
|
|
22
|
+
'offchain-worker'
|
|
23
|
+
]),
|
|
24
|
+
'head-mode': z.nativeEnum(HeadMode).default("Latest")
|
|
25
|
+
});
|
|
16
26
|
export const cli = (y)=>{
|
|
17
|
-
y.command('follow-chain', 'Always follow the latest block on upstream', (yargs)=>yargs.options({
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
desc: 'Head mode',
|
|
25
|
-
choices: [
|
|
26
|
-
'latest',
|
|
27
|
-
'finalized'
|
|
28
|
-
],
|
|
29
|
-
default: 'finalized'
|
|
27
|
+
y.command('follow-chain', 'Always follow the latest block on upstream', (yargs)=>yargs.options(getYargsOptions(schema.shape)), async (argv)=>{
|
|
28
|
+
const config = schema.parse(argv);
|
|
29
|
+
Array.isArray(config.endpoint) ? config.endpoint : [
|
|
30
|
+
config.endpoint || ''
|
|
31
|
+
].forEach((endpoint)=>{
|
|
32
|
+
if (/^(https|http):\/\//.test(endpoint)) {
|
|
33
|
+
throw Error('http provider is not supported');
|
|
30
34
|
}
|
|
31
|
-
})
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
if (/^(https|http):\/\//.test(endpoint || '')) {
|
|
35
|
-
throw Error('http provider is not supported');
|
|
36
|
-
}
|
|
37
|
-
const context = await setupContext(argv, true);
|
|
38
|
-
const { close, port: listenPort } = await createServer(handler(context), port);
|
|
35
|
+
});
|
|
36
|
+
const context = await setupContext(config, true);
|
|
37
|
+
const { close, port: listenPort } = await createServer(handler(context), config.port);
|
|
39
38
|
logger.info(`${await context.chain.api.getSystemChain()} RPC listening on port ${listenPort}`);
|
|
40
39
|
const chain = context.chain;
|
|
41
|
-
chain.api[
|
|
40
|
+
chain.api[config['head-mode'] === "Latest" ? 'subscribeRemoteNewHeads' : 'subscribeRemoteFinalizedHeads'](async (error, data)=>{
|
|
42
41
|
try {
|
|
43
42
|
if (error) throw error;
|
|
44
43
|
logger.info({
|
|
45
44
|
header: data
|
|
46
|
-
}, `Follow ${
|
|
45
|
+
}, `Follow ${config['head-mode']} head from upstream`);
|
|
47
46
|
const parent = await chain.getBlock(data.parentHash);
|
|
48
47
|
if (!parent) throw Error(`Cannot find parent', ${data.parentHash}`);
|
|
49
48
|
const registry = await parent.registry;
|
|
@@ -76,7 +75,7 @@ export const cli = (y)=>{
|
|
|
76
75
|
calls,
|
|
77
76
|
mockSignatureHost: false,
|
|
78
77
|
allowUnresolvedImports: false,
|
|
79
|
-
runtimeLogLevel:
|
|
78
|
+
runtimeLogLevel: config['runtime-log-level'] || 0
|
|
80
79
|
}, taskHandler(parent));
|
|
81
80
|
if ('Error' in result) {
|
|
82
81
|
throw new Error(result.Error);
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import { writeFileSync } from 'node:fs';
|
|
2
|
+
import { z } from 'zod';
|
|
2
3
|
import { runTask, taskHandler } from '@acala-network/chopsticks-core';
|
|
3
|
-
import {
|
|
4
|
+
import { configSchema, getYargsOptions } from '../../schema/index.js';
|
|
4
5
|
import { generateHtmlDiffPreviewFile } from '../../utils/generate-html-diff.js';
|
|
5
6
|
import { openHtml } from '../../utils/open-html.js';
|
|
6
7
|
import { setupContext } from '../../context.js';
|
|
8
|
+
const schema = z.object({
|
|
9
|
+
...configSchema.shape,
|
|
10
|
+
['output-path']: z.string({
|
|
11
|
+
description: 'File path to print output'
|
|
12
|
+
}).optional(),
|
|
13
|
+
html: z.boolean({
|
|
14
|
+
description: 'Generate html with storage diff'
|
|
15
|
+
}).optional(),
|
|
16
|
+
open: z.boolean({
|
|
17
|
+
description: 'Open generated html'
|
|
18
|
+
}).optional()
|
|
19
|
+
});
|
|
7
20
|
export const cli = (y)=>{
|
|
8
|
-
y.command('run-block', 'Replay a block', (yargs)=>yargs.options({
|
|
9
|
-
|
|
10
|
-
...mockOptions,
|
|
11
|
-
'output-path': {
|
|
12
|
-
desc: 'File path to print output',
|
|
13
|
-
string: true
|
|
14
|
-
},
|
|
15
|
-
html: {
|
|
16
|
-
desc: 'Generate html with storage diff'
|
|
17
|
-
},
|
|
18
|
-
open: {
|
|
19
|
-
desc: 'Open generated html'
|
|
20
|
-
}
|
|
21
|
-
}), async (argv)=>{
|
|
22
|
-
const context = await setupContext(argv, true);
|
|
21
|
+
y.command('run-block', 'Replay a block', (yargs)=>yargs.options(getYargsOptions(schema.shape)), async (argv)=>{
|
|
22
|
+
const context = await setupContext(schema.parse(argv), true);
|
|
23
23
|
const header = await context.chain.head.header;
|
|
24
24
|
const block = context.chain.head;
|
|
25
25
|
const parent = await block.parentBlock;
|
|
@@ -1,30 +1,32 @@
|
|
|
1
1
|
import { writeFileSync } from 'node:fs';
|
|
2
|
-
import {
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { configSchema, getYargsOptions } from '../../schema/index.js';
|
|
3
4
|
import { generateHtmlDiffPreviewFile } from '../../utils/generate-html-diff.js';
|
|
4
5
|
import { openHtml } from '../../utils/open-html.js';
|
|
5
6
|
import { setupContext } from '../../context.js';
|
|
7
|
+
const schema = z.object({
|
|
8
|
+
endpoint: configSchema.shape.endpoint,
|
|
9
|
+
port: configSchema.shape.port,
|
|
10
|
+
['build-block-mode']: configSchema.shape['build-block-mode'],
|
|
11
|
+
block: configSchema.shape.block,
|
|
12
|
+
db: configSchema.shape.db,
|
|
13
|
+
['runtime-log-level']: configSchema.shape['runtime-log-level'],
|
|
14
|
+
['wasm-override']: z.string({
|
|
15
|
+
description: 'Path to WASM built with feature `try-runtime` enabled'
|
|
16
|
+
}),
|
|
17
|
+
['output-path']: z.string({
|
|
18
|
+
description: 'File path to print output'
|
|
19
|
+
}).optional(),
|
|
20
|
+
html: z.boolean({
|
|
21
|
+
description: 'Generate html with storage diff'
|
|
22
|
+
}).optional(),
|
|
23
|
+
open: z.boolean({
|
|
24
|
+
description: 'Open generated html'
|
|
25
|
+
}).optional()
|
|
26
|
+
});
|
|
6
27
|
export const cli = (y)=>{
|
|
7
|
-
y.command('try-runtime', 'Runs runtime upgrade', (yargs)=>yargs.options({
|
|
8
|
-
|
|
9
|
-
'wasm-override': {
|
|
10
|
-
desc: 'Path to WASM built with feature `try-runtime` enabled',
|
|
11
|
-
string: true,
|
|
12
|
-
required: true
|
|
13
|
-
},
|
|
14
|
-
'output-path': {
|
|
15
|
-
desc: 'File path to print output',
|
|
16
|
-
string: true
|
|
17
|
-
},
|
|
18
|
-
html: {
|
|
19
|
-
desc: 'Generate html with storage diff',
|
|
20
|
-
boolean: true
|
|
21
|
-
},
|
|
22
|
-
open: {
|
|
23
|
-
desc: 'Open generated html',
|
|
24
|
-
boolean: true
|
|
25
|
-
}
|
|
26
|
-
}), async (argv)=>{
|
|
27
|
-
const context = await setupContext(argv);
|
|
28
|
+
y.command('try-runtime', 'Runs runtime upgrade', (yargs)=>yargs.options(getYargsOptions(schema.shape)), async (argv)=>{
|
|
29
|
+
const context = await setupContext(schema.parse(argv));
|
|
28
30
|
const block = context.chain.head;
|
|
29
31
|
const registry = await block.registry;
|
|
30
32
|
registry.register({
|
package/dist/esm/rpc/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { ResponseError,
|
|
1
|
+
import { ResponseError, defaultLogger, substrate } from '@acala-network/chopsticks-core';
|
|
2
2
|
import { loadRpcPlugin, rpcPluginMethods } from '../plugins/index.js';
|
|
3
|
+
const rpcLogger = defaultLogger.child({
|
|
4
|
+
module: 'rpc'
|
|
5
|
+
});
|
|
3
6
|
const allHandlers = {
|
|
4
7
|
...substrate,
|
|
5
8
|
rpc_methods: async ()=>Promise.resolve({
|
|
@@ -19,10 +22,10 @@ const getHandler = async (method)=>{
|
|
|
19
22
|
return handler;
|
|
20
23
|
};
|
|
21
24
|
export const handler = (context)=>async ({ method, params }, subscriptionManager)=>{
|
|
22
|
-
|
|
25
|
+
rpcLogger.trace('Handling %s', method);
|
|
23
26
|
const handler = await getHandler(method);
|
|
24
27
|
if (!handler) {
|
|
25
|
-
|
|
28
|
+
rpcLogger.warn('Method not found %s', method);
|
|
26
29
|
throw new ResponseError(-32601, `Method not found: ${method}`);
|
|
27
30
|
}
|
|
28
31
|
return handler(context, params, subscriptionManager);
|
|
@@ -1,13 +1,14 @@
|
|
|
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
|
+
'allow-unresolved-imports': z.ZodOptional<z.ZodBoolean>;
|
|
11
12
|
'mock-signature-host': z.ZodOptional<z.ZodBoolean>;
|
|
12
13
|
'max-memory-block-count': z.ZodOptional<z.ZodNumber>;
|
|
13
14
|
db: z.ZodOptional<z.ZodString>;
|
|
@@ -19,7 +20,7 @@ export declare const configSchema: z.ZodObject<{
|
|
|
19
20
|
ss58Format: z.ZodOptional<z.ZodNumber>;
|
|
20
21
|
tokenDecimals: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodArray<z.ZodNumber, "many">]>>;
|
|
21
22
|
tokenSymbol: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
22
|
-
}, "strip",
|
|
23
|
+
}, "strip", ZodTypeAny, {
|
|
23
24
|
ss58Format?: number | undefined;
|
|
24
25
|
tokenDecimals?: number | number[] | undefined;
|
|
25
26
|
tokenSymbol?: string | string[] | undefined;
|
|
@@ -31,12 +32,12 @@ export declare const configSchema: z.ZodObject<{
|
|
|
31
32
|
genesis: z.ZodObject<{
|
|
32
33
|
raw: z.ZodObject<{
|
|
33
34
|
top: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
34
|
-
}, "strip",
|
|
35
|
+
}, "strip", ZodTypeAny, {
|
|
35
36
|
top: Record<string, string>;
|
|
36
37
|
}, {
|
|
37
38
|
top: Record<string, string>;
|
|
38
39
|
}>;
|
|
39
|
-
}, "strip",
|
|
40
|
+
}, "strip", ZodTypeAny, {
|
|
40
41
|
raw: {
|
|
41
42
|
top: Record<string, string>;
|
|
42
43
|
};
|
|
@@ -45,7 +46,7 @@ export declare const configSchema: z.ZodObject<{
|
|
|
45
46
|
top: Record<string, string>;
|
|
46
47
|
};
|
|
47
48
|
}>;
|
|
48
|
-
}, "strip",
|
|
49
|
+
}, "strip", ZodTypeAny, {
|
|
49
50
|
name: string;
|
|
50
51
|
id: string;
|
|
51
52
|
properties: {
|
|
@@ -76,13 +77,14 @@ export declare const configSchema: z.ZodObject<{
|
|
|
76
77
|
'registered-types': z.ZodOptional<z.ZodAny>;
|
|
77
78
|
'runtime-log-level': z.ZodOptional<z.ZodNumber>;
|
|
78
79
|
'offchain-worker': z.ZodOptional<z.ZodBoolean>;
|
|
79
|
-
resume: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
80
|
-
}, "
|
|
81
|
-
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;
|
|
82
84
|
endpoint?: string | string[] | undefined;
|
|
83
|
-
block?:
|
|
84
|
-
'build-block-mode'?: BuildBlockMode | undefined;
|
|
85
|
+
block?: number | `0x${string}` | null | undefined;
|
|
85
86
|
'import-storage'?: any;
|
|
87
|
+
'allow-unresolved-imports'?: boolean | undefined;
|
|
86
88
|
'mock-signature-host'?: boolean | undefined;
|
|
87
89
|
'max-memory-block-count'?: number | undefined;
|
|
88
90
|
db?: string | undefined;
|
|
@@ -105,13 +107,14 @@ export declare const configSchema: z.ZodObject<{
|
|
|
105
107
|
'registered-types'?: any;
|
|
106
108
|
'runtime-log-level'?: number | undefined;
|
|
107
109
|
'offchain-worker'?: boolean | undefined;
|
|
108
|
-
resume?:
|
|
110
|
+
resume?: number | boolean | `0x${string}` | undefined;
|
|
109
111
|
}, {
|
|
110
112
|
port?: number | undefined;
|
|
111
113
|
endpoint?: string | string[] | undefined;
|
|
112
|
-
block?:
|
|
114
|
+
block?: number | `0x${string}` | null | undefined;
|
|
113
115
|
'build-block-mode'?: BuildBlockMode | undefined;
|
|
114
116
|
'import-storage'?: any;
|
|
117
|
+
'allow-unresolved-imports'?: boolean | undefined;
|
|
115
118
|
'mock-signature-host'?: boolean | undefined;
|
|
116
119
|
'max-memory-block-count'?: number | undefined;
|
|
117
120
|
db?: string | undefined;
|
|
@@ -134,7 +137,15 @@ export declare const configSchema: z.ZodObject<{
|
|
|
134
137
|
'registered-types'?: any;
|
|
135
138
|
'runtime-log-level'?: number | undefined;
|
|
136
139
|
'offchain-worker'?: boolean | undefined;
|
|
137
|
-
resume?:
|
|
140
|
+
resume?: number | boolean | `0x${string}` | undefined;
|
|
138
141
|
}>;
|
|
139
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
|
+
};
|
|
140
151
|
export declare const fetchConfig: (path: string) => Promise<Config>;
|
package/dist/esm/schema/index.js
CHANGED
|
@@ -1,43 +1,110 @@
|
|
|
1
1
|
import { BuildBlockMode, defaultLogger, genesisSchema, isUrl } from '@acala-network/chopsticks-core';
|
|
2
|
+
import { ZodNativeEnum, z } from 'zod';
|
|
2
3
|
import { basename, extname } from 'node:path';
|
|
3
4
|
import { readFileSync } from 'node:fs';
|
|
4
|
-
import { z } from 'zod';
|
|
5
5
|
import _ from 'lodash';
|
|
6
6
|
import axios from 'axios';
|
|
7
7
|
import yaml from 'js-yaml';
|
|
8
8
|
export const zHex = z.custom((val)=>/^0x\w+$/.test(val));
|
|
9
9
|
export const zHash = z.string().length(66).and(zHex);
|
|
10
10
|
export const configSchema = z.object({
|
|
11
|
-
port: z.number(
|
|
11
|
+
port: z.number({
|
|
12
|
+
description: 'Port to listen on'
|
|
13
|
+
}).default(8000),
|
|
12
14
|
endpoint: z.union([
|
|
13
15
|
z.string(),
|
|
14
16
|
z.array(z.string())
|
|
15
|
-
]
|
|
17
|
+
], {
|
|
18
|
+
description: 'Endpoint to connect to'
|
|
19
|
+
}).optional(),
|
|
16
20
|
block: z.union([
|
|
17
|
-
|
|
21
|
+
zHash,
|
|
18
22
|
z.number(),
|
|
19
23
|
z.null()
|
|
20
|
-
]
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
'
|
|
24
|
+
], {
|
|
25
|
+
description: 'Block hash or block number. Default to latest block'
|
|
26
|
+
}).optional(),
|
|
27
|
+
'build-block-mode': z.nativeEnum(BuildBlockMode).default(BuildBlockMode.Batch),
|
|
28
|
+
'import-storage': z.any({
|
|
29
|
+
description: 'Pre-defined JSON/YAML storage file path'
|
|
30
|
+
}).optional(),
|
|
31
|
+
'allow-unresolved-imports': z.boolean().optional(),
|
|
32
|
+
'mock-signature-host': z.boolean({
|
|
33
|
+
description: 'Mock signature host so any signature starts with 0xdeadbeef and filled by 0xcd is considered valid'
|
|
34
|
+
}).optional(),
|
|
24
35
|
'max-memory-block-count': z.number().optional(),
|
|
25
|
-
db: z.string(
|
|
26
|
-
|
|
36
|
+
db: z.string({
|
|
37
|
+
description: 'Path to database'
|
|
38
|
+
}).optional(),
|
|
39
|
+
'wasm-override': z.string({
|
|
40
|
+
description: 'Path to wasm override'
|
|
41
|
+
}).optional(),
|
|
27
42
|
genesis: z.union([
|
|
28
43
|
z.string(),
|
|
29
44
|
genesisSchema
|
|
30
45
|
]).optional(),
|
|
31
46
|
timestamp: z.number().optional(),
|
|
32
47
|
'registered-types': z.any().optional(),
|
|
33
|
-
'runtime-log-level': z.number(
|
|
34
|
-
|
|
48
|
+
'runtime-log-level': z.number({
|
|
49
|
+
description: 'Runtime maximum log level [off = 0; error = 1; warn = 2; info = 3; debug = 4; trace = 5]'
|
|
50
|
+
}).min(0).max(5).optional(),
|
|
51
|
+
'offchain-worker': z.boolean({
|
|
52
|
+
description: 'Enable offchain worker'
|
|
53
|
+
}).optional(),
|
|
35
54
|
resume: z.union([
|
|
36
|
-
|
|
55
|
+
zHash,
|
|
37
56
|
z.number(),
|
|
38
57
|
z.boolean()
|
|
39
|
-
]
|
|
40
|
-
|
|
58
|
+
], {
|
|
59
|
+
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'
|
|
60
|
+
}).optional()
|
|
61
|
+
});
|
|
62
|
+
const getZodType = (option)=>{
|
|
63
|
+
switch(option._def.typeName){
|
|
64
|
+
case 'ZodString':
|
|
65
|
+
return 'string';
|
|
66
|
+
case 'ZodNumber':
|
|
67
|
+
return 'number';
|
|
68
|
+
case 'ZodBoolean':
|
|
69
|
+
return 'boolean';
|
|
70
|
+
default:
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
if (option._def.innerType) {
|
|
74
|
+
return getZodType(option._def.innerType);
|
|
75
|
+
}
|
|
76
|
+
return undefined;
|
|
77
|
+
};
|
|
78
|
+
const getZodChoices = (option)=>{
|
|
79
|
+
if (option._def.innerType instanceof ZodNativeEnum) {
|
|
80
|
+
return Object.values(option._def.innerType._def.values).filter((x)=>typeof x === 'string');
|
|
81
|
+
}
|
|
82
|
+
if (option._def.innerType) {
|
|
83
|
+
return getZodChoices(option._def.innerType);
|
|
84
|
+
}
|
|
85
|
+
return undefined;
|
|
86
|
+
};
|
|
87
|
+
const getZodFirstOption = (option)=>{
|
|
88
|
+
const options = option._def.options;
|
|
89
|
+
if (options) {
|
|
90
|
+
for (const option of options){
|
|
91
|
+
const type = getZodType(option);
|
|
92
|
+
if (type) return type;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (option._def.innerType) {
|
|
96
|
+
return getZodFirstOption(option._def.innerType);
|
|
97
|
+
}
|
|
98
|
+
return undefined;
|
|
99
|
+
};
|
|
100
|
+
export const getYargsOptions = (zodShape)=>{
|
|
101
|
+
return _.mapValues(zodShape, (option)=>({
|
|
102
|
+
demandOption: !option.isOptional(),
|
|
103
|
+
description: option._def.description,
|
|
104
|
+
type: getZodType(option) || getZodFirstOption(option),
|
|
105
|
+
choices: getZodChoices(option)
|
|
106
|
+
}));
|
|
107
|
+
};
|
|
41
108
|
const CONFIGS_BASE_URL = 'https://raw.githubusercontent.com/AcalaNetwork/chopsticks/master/configs/';
|
|
42
109
|
export const fetchConfig = async (path)=>{
|
|
43
110
|
let file;
|
|
@@ -67,5 +134,5 @@ export const fetchConfig = async (path)=>{
|
|
|
67
134
|
const config = yaml.load(_.template(file, {
|
|
68
135
|
variable: 'env'
|
|
69
136
|
})(process.env));
|
|
70
|
-
return configSchema.parse(config);
|
|
137
|
+
return configSchema.strict().parse(config);
|
|
71
138
|
};
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { createServer } from './server.js';
|
|
2
|
+
import { defaultLogger } from '@acala-network/chopsticks-core';
|
|
2
3
|
import { handler } from './rpc/index.js';
|
|
3
|
-
import { logger } from '@acala-network/chopsticks-core';
|
|
4
4
|
import { setupContext } from './context.js';
|
|
5
5
|
export const setupWithServer = async (argv)=>{
|
|
6
6
|
const context = await setupContext(argv);
|
|
7
|
-
const port = argv.port ?? 8000;
|
|
8
7
|
if (argv.genesis) {
|
|
9
8
|
// mine 1st block when starting from genesis to set some mock validation data
|
|
10
9
|
await context.chain.newBlock();
|
|
11
10
|
}
|
|
12
|
-
const { close, port: listenPort } = await createServer(handler(context), port);
|
|
13
|
-
|
|
11
|
+
const { close, port: listenPort } = await createServer(handler(context), argv.port);
|
|
12
|
+
defaultLogger.info(`${await context.chain.api.getSystemChain()} RPC listening on port ${listenPort}`);
|
|
14
13
|
return {
|
|
15
14
|
...context,
|
|
16
15
|
listenPort,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acala-network/chopsticks",
|
|
3
|
-
"version": "0.9.4
|
|
3
|
+
"version": "0.9.4",
|
|
4
4
|
"author": "Acala Developers <hello@acala.network>",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"bin": "./chopsticks.cjs",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"docs:prep": "typedoc"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@acala-network/chopsticks-core": "0.9.4
|
|
17
|
-
"@acala-network/chopsticks-db": "0.9.4
|
|
16
|
+
"@acala-network/chopsticks-core": "0.9.4",
|
|
17
|
+
"@acala-network/chopsticks-db": "0.9.4",
|
|
18
18
|
"@pnpm/npm-conf": "^2.2.2",
|
|
19
19
|
"@polkadot/api-augment": "^10.10.1",
|
|
20
20
|
"@polkadot/types": "^10.10.1",
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export declare const defaultOptions: {
|
|
2
|
-
endpoint: {
|
|
3
|
-
desc: string;
|
|
4
|
-
string: boolean;
|
|
5
|
-
};
|
|
6
|
-
block: {
|
|
7
|
-
desc: string;
|
|
8
|
-
string: boolean;
|
|
9
|
-
};
|
|
10
|
-
'wasm-override': {
|
|
11
|
-
desc: string;
|
|
12
|
-
string: boolean;
|
|
13
|
-
};
|
|
14
|
-
db: {
|
|
15
|
-
desc: string;
|
|
16
|
-
string: boolean;
|
|
17
|
-
};
|
|
18
|
-
config: {
|
|
19
|
-
desc: string;
|
|
20
|
-
string: boolean;
|
|
21
|
-
};
|
|
22
|
-
'runtime-log-level': {
|
|
23
|
-
desc: string;
|
|
24
|
-
number: boolean;
|
|
25
|
-
};
|
|
26
|
-
'offchain-worker': {
|
|
27
|
-
desc: string;
|
|
28
|
-
boolean: boolean;
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
export declare const mockOptions: {
|
|
32
|
-
'import-storage': {
|
|
33
|
-
desc: string;
|
|
34
|
-
string: boolean;
|
|
35
|
-
};
|
|
36
|
-
'mock-signature-host': {
|
|
37
|
-
desc: string;
|
|
38
|
-
boolean: boolean;
|
|
39
|
-
};
|
|
40
|
-
};
|
package/dist/cjs/cli-options.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
defaultOptions: function() {
|
|
13
|
-
return defaultOptions;
|
|
14
|
-
},
|
|
15
|
-
mockOptions: function() {
|
|
16
|
-
return mockOptions;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const defaultOptions = {
|
|
20
|
-
endpoint: {
|
|
21
|
-
desc: 'Endpoint to connect to',
|
|
22
|
-
string: true
|
|
23
|
-
},
|
|
24
|
-
block: {
|
|
25
|
-
desc: 'Block hash or block number. Default to latest block',
|
|
26
|
-
string: true
|
|
27
|
-
},
|
|
28
|
-
'wasm-override': {
|
|
29
|
-
desc: 'Path to wasm override',
|
|
30
|
-
string: true
|
|
31
|
-
},
|
|
32
|
-
db: {
|
|
33
|
-
desc: 'Path to database',
|
|
34
|
-
string: true
|
|
35
|
-
},
|
|
36
|
-
config: {
|
|
37
|
-
desc: 'Path to config file with default options',
|
|
38
|
-
string: true
|
|
39
|
-
},
|
|
40
|
-
'runtime-log-level': {
|
|
41
|
-
desc: 'Runtime maximum log level [off = 0; error = 1; warn = 2; info = 3; debug = 4; trace = 5]',
|
|
42
|
-
number: true
|
|
43
|
-
},
|
|
44
|
-
'offchain-worker': {
|
|
45
|
-
desc: 'Enable offchain worker',
|
|
46
|
-
boolean: true
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
const mockOptions = {
|
|
50
|
-
'import-storage': {
|
|
51
|
-
desc: 'Pre-defined JSON/YAML storage file path',
|
|
52
|
-
string: true
|
|
53
|
-
},
|
|
54
|
-
'mock-signature-host': {
|
|
55
|
-
desc: 'Mock signature host so any signature starts with 0xdeadbeef and filled by 0xcd is considered valid',
|
|
56
|
-
boolean: true
|
|
57
|
-
}
|
|
58
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export declare const defaultOptions: {
|
|
2
|
-
endpoint: {
|
|
3
|
-
desc: string;
|
|
4
|
-
string: boolean;
|
|
5
|
-
};
|
|
6
|
-
block: {
|
|
7
|
-
desc: string;
|
|
8
|
-
string: boolean;
|
|
9
|
-
};
|
|
10
|
-
'wasm-override': {
|
|
11
|
-
desc: string;
|
|
12
|
-
string: boolean;
|
|
13
|
-
};
|
|
14
|
-
db: {
|
|
15
|
-
desc: string;
|
|
16
|
-
string: boolean;
|
|
17
|
-
};
|
|
18
|
-
config: {
|
|
19
|
-
desc: string;
|
|
20
|
-
string: boolean;
|
|
21
|
-
};
|
|
22
|
-
'runtime-log-level': {
|
|
23
|
-
desc: string;
|
|
24
|
-
number: boolean;
|
|
25
|
-
};
|
|
26
|
-
'offchain-worker': {
|
|
27
|
-
desc: string;
|
|
28
|
-
boolean: boolean;
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
export declare const mockOptions: {
|
|
32
|
-
'import-storage': {
|
|
33
|
-
desc: string;
|
|
34
|
-
string: boolean;
|
|
35
|
-
};
|
|
36
|
-
'mock-signature-host': {
|
|
37
|
-
desc: string;
|
|
38
|
-
boolean: boolean;
|
|
39
|
-
};
|
|
40
|
-
};
|
package/dist/esm/cli-options.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export const defaultOptions = {
|
|
2
|
-
endpoint: {
|
|
3
|
-
desc: 'Endpoint to connect to',
|
|
4
|
-
string: true
|
|
5
|
-
},
|
|
6
|
-
block: {
|
|
7
|
-
desc: 'Block hash or block number. Default to latest block',
|
|
8
|
-
string: true
|
|
9
|
-
},
|
|
10
|
-
'wasm-override': {
|
|
11
|
-
desc: 'Path to wasm override',
|
|
12
|
-
string: true
|
|
13
|
-
},
|
|
14
|
-
db: {
|
|
15
|
-
desc: 'Path to database',
|
|
16
|
-
string: true
|
|
17
|
-
},
|
|
18
|
-
config: {
|
|
19
|
-
desc: 'Path to config file with default options',
|
|
20
|
-
string: true
|
|
21
|
-
},
|
|
22
|
-
'runtime-log-level': {
|
|
23
|
-
desc: 'Runtime maximum log level [off = 0; error = 1; warn = 2; info = 3; debug = 4; trace = 5]',
|
|
24
|
-
number: true
|
|
25
|
-
},
|
|
26
|
-
'offchain-worker': {
|
|
27
|
-
desc: 'Enable offchain worker',
|
|
28
|
-
boolean: true
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
export const mockOptions = {
|
|
32
|
-
'import-storage': {
|
|
33
|
-
desc: 'Pre-defined JSON/YAML storage file path',
|
|
34
|
-
string: true
|
|
35
|
-
},
|
|
36
|
-
'mock-signature-host': {
|
|
37
|
-
desc: 'Mock signature host so any signature starts with 0xdeadbeef and filled by 0xcd is considered valid',
|
|
38
|
-
boolean: true
|
|
39
|
-
}
|
|
40
|
-
};
|