@acala-network/chopsticks 0.16.2 → 1.0.1-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 +2 -2
- package/dist/cjs/context.js +3 -1
- package/dist/cjs/plugins/dry-run/index.d.ts +5 -2
- package/dist/cjs/plugins/follow-chain/cli.js +10 -9
- package/dist/cjs/plugins/index.js +6 -6
- package/dist/cjs/plugins/trace-transaction/index.js +3 -3
- package/dist/cjs/plugins/try-runtime/index.js +1 -1
- package/dist/cjs/schema/index.d.ts +11 -8
- package/dist/cjs/schema/index.js +5 -1
- package/dist/cjs/server.d.ts +2 -1
- package/dist/cjs/server.js +12 -10
- package/dist/cjs/setup-with-server.d.ts +0 -1
- package/dist/cjs/setup-with-server.js +7 -5
- package/dist/cjs/utils/fetch-storages.d.ts +1 -1
- package/dist/cjs/utils/fetch-storages.js +2 -1
- package/dist/cjs/utils/tunnel.js +1 -1
- package/dist/esm/cli.js +2 -2
- package/dist/esm/context.js +3 -1
- package/dist/esm/plugins/dry-run/index.d.ts +5 -2
- package/dist/esm/plugins/follow-chain/cli.js +10 -9
- package/dist/esm/plugins/index.js +3 -3
- package/dist/esm/plugins/trace-transaction/index.js +1 -1
- package/dist/esm/plugins/try-runtime/index.js +1 -1
- package/dist/esm/schema/index.d.ts +11 -8
- package/dist/esm/schema/index.js +5 -1
- package/dist/esm/server.d.ts +2 -1
- package/dist/esm/server.js +12 -10
- package/dist/esm/setup-with-server.d.ts +0 -1
- package/dist/esm/setup-with-server.js +7 -5
- package/dist/esm/utils/fetch-storages.d.ts +1 -1
- package/dist/esm/utils/fetch-storages.js +2 -1
- package/dist/esm/utils/tunnel.js +1 -1
- package/package.json +20 -20
package/dist/cjs/cli.js
CHANGED
|
@@ -38,7 +38,7 @@ const processArgv = async (argv)=>{
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
|
-
const commands = (0, _yargs.default)((0, _helpers.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((0, _index.getYargsOptions)(_index.configSchema.shape)), async (argv)=>{
|
|
41
|
+
const commands = (0, _yargs.default)((0, _helpers.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((0, _index.getYargsOptions)(_index.configSchema.shape)).deprecateOption('addr', '⚠️ Use --host instead.'), async (argv)=>{
|
|
42
42
|
await (0, _index2.setupWithServer)(_index.configSchema.parse(argv));
|
|
43
43
|
}).command('xcm', 'XCM setup with relaychain and parachains', (yargs)=>yargs.options({
|
|
44
44
|
relaychain: {
|
|
@@ -66,7 +66,7 @@ const commands = (0, _yargs.default)((0, _helpers.hideBin)(process.argv)).script
|
|
|
66
66
|
await (0, _chopstickscore.connectVertical)(relaychain, parachain);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
}).strict().help().alias('help', 'h').alias('version', 'v').alias('config', 'c').alias('endpoint', 'e').alias('port', 'p').alias('block', 'b').alias('unsafe-rpc-methods', 'ur').alias('import-storage', 's').alias('wasm-override', 'w').usage('Usage: $0 <command> [options]').example('$0', '-c acala');
|
|
69
|
+
}).strict().help().alias('help', 'h').alias('version', 'v').alias('config', 'c').alias('endpoint', 'e').alias('port', 'p').alias('block', 'b').alias('unsafe-rpc-methods', 'ur').alias('import-storage', 's').alias('wasm-override', 'w').usage('Usage: $0 <command> [options]').example('$0', '-c acala').showHelpOnFail(false);
|
|
70
70
|
if (!_chopstickscore.environment.DISABLE_PLUGINS) {
|
|
71
71
|
(0, _index1.pluginExtendCli)(commands.config('config', 'Path to config file with default options', ()=>({}))).then(()=>commands.parse());
|
|
72
72
|
} else {
|
package/dist/cjs/context.js
CHANGED
|
@@ -128,7 +128,9 @@ const setupContext = async (argv, overrideParent = false)=>{
|
|
|
128
128
|
}
|
|
129
129
|
if (blockData) {
|
|
130
130
|
const block = await chain.loadBlockFromDB(blockData.number);
|
|
131
|
-
|
|
131
|
+
if (block) {
|
|
132
|
+
await chain.setHead(block);
|
|
133
|
+
}
|
|
132
134
|
logger.info(`Resume from block ${blockData.number}, hash: ${blockData.hash}`);
|
|
133
135
|
} else {
|
|
134
136
|
throw new Error(`Resume failed. Cannot find block ${argv.resume}`);
|
|
@@ -7,7 +7,8 @@ export declare const dryRunSchema: z.ZodObject<{
|
|
|
7
7
|
"output-path": z.ZodOptional<z.ZodString>;
|
|
8
8
|
html: z.ZodOptional<z.ZodBoolean>;
|
|
9
9
|
open: z.ZodOptional<z.ZodBoolean>;
|
|
10
|
-
addr: z.
|
|
10
|
+
addr: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"localhost">, z.ZodString]>>;
|
|
11
|
+
host: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"localhost">, z.ZodString]>>;
|
|
11
12
|
port: z.ZodDefault<z.ZodNumber>;
|
|
12
13
|
endpoint: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
13
14
|
block: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodNull]>>;
|
|
@@ -146,10 +147,11 @@ export declare const dryRunSchema: z.ZodObject<{
|
|
|
146
147
|
'process-queued-messages': z.ZodOptional<z.ZodBoolean>;
|
|
147
148
|
'prefetch-storages': z.ZodOptional<z.ZodAny>;
|
|
148
149
|
}, "strip", z.ZodTypeAny, {
|
|
149
|
-
addr: string;
|
|
150
150
|
port: number;
|
|
151
151
|
'build-block-mode': import("@acala-network/chopsticks-core").BuildBlockMode;
|
|
152
152
|
at?: string | undefined;
|
|
153
|
+
addr?: string | undefined;
|
|
154
|
+
host?: string | undefined;
|
|
153
155
|
endpoint?: string | string[] | undefined;
|
|
154
156
|
block?: string | number | null | undefined;
|
|
155
157
|
'import-storage'?: any;
|
|
@@ -202,6 +204,7 @@ export declare const dryRunSchema: z.ZodObject<{
|
|
|
202
204
|
}, {
|
|
203
205
|
at?: string | undefined;
|
|
204
206
|
addr?: string | undefined;
|
|
207
|
+
host?: string | undefined;
|
|
205
208
|
port?: number | undefined;
|
|
206
209
|
endpoint?: string | string[] | undefined;
|
|
207
210
|
block?: string | number | null | undefined;
|
|
@@ -23,11 +23,11 @@ function _interop_require_default(obj) {
|
|
|
23
23
|
const logger = _chopstickscore.defaultLogger.child({
|
|
24
24
|
name: 'follow-chain'
|
|
25
25
|
});
|
|
26
|
-
var HeadMode
|
|
27
|
-
(function(HeadMode) {
|
|
26
|
+
var HeadMode = /*#__PURE__*/ function(HeadMode) {
|
|
28
27
|
HeadMode["Latest"] = "Latest";
|
|
29
28
|
HeadMode["Finalized"] = "Finalized";
|
|
30
|
-
|
|
29
|
+
return HeadMode;
|
|
30
|
+
}(HeadMode || {});
|
|
31
31
|
const schema = _zod.z.object({
|
|
32
32
|
..._lodash.default.pick(_index.configSchema.shape, [
|
|
33
33
|
'endpoint',
|
|
@@ -41,16 +41,17 @@ const schema = _zod.z.object({
|
|
|
41
41
|
const cli = (y)=>{
|
|
42
42
|
y.command('follow-chain', 'Always follow the latest block on upstream', (yargs)=>yargs.options((0, _index.getYargsOptions)(schema.shape)), async (argv)=>{
|
|
43
43
|
const config = schema.parse(argv);
|
|
44
|
-
Array.isArray(config.endpoint) ? config.endpoint : [
|
|
45
|
-
config.endpoint
|
|
46
|
-
]
|
|
44
|
+
const endpoints = Array.isArray(config.endpoint) ? config.endpoint : [
|
|
45
|
+
config.endpoint ?? ''
|
|
46
|
+
];
|
|
47
|
+
for (const endpoint of endpoints){
|
|
47
48
|
if (/^(https|http):\/\//.test(endpoint)) {
|
|
48
49
|
throw Error('http provider is not supported');
|
|
49
50
|
}
|
|
50
|
-
}
|
|
51
|
+
}
|
|
51
52
|
const context = await (0, _context.setupContext)(config, true);
|
|
52
|
-
const { close,
|
|
53
|
-
logger.info(`${await context.chain.api.getSystemChain()} RPC listening on
|
|
53
|
+
const { close, addr } = await (0, _server.createServer)((0, _index1.handler)(context), config.port, config.host);
|
|
54
|
+
logger.info(`${await context.chain.api.getSystemChain()} RPC listening on http://${addr} and ws://${addr}`);
|
|
54
55
|
const chain = context.chain;
|
|
55
56
|
chain.api[config['head-mode'] === "Latest" ? 'subscribeRemoteNewHeads' : 'subscribeRemoteFinalizedHeads'](async (error, data)=>{
|
|
56
57
|
try {
|
|
@@ -29,10 +29,10 @@ _export(exports, {
|
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
31
|
const _chopstickscore = require("@acala-network/chopsticks-core");
|
|
32
|
-
const
|
|
32
|
+
const _nodefs = require("node:fs");
|
|
33
33
|
const _lodash = /*#__PURE__*/ _interop_require_default(require("lodash"));
|
|
34
34
|
const _logger = require("../logger.js");
|
|
35
|
-
const
|
|
35
|
+
const _nodepath = require("node:path");
|
|
36
36
|
function _interop_require_default(obj) {
|
|
37
37
|
return obj && obj.__esModule ? obj : {
|
|
38
38
|
default: obj
|
|
@@ -84,8 +84,8 @@ const logger = _logger.defaultLogger.child({
|
|
|
84
84
|
});
|
|
85
85
|
const rpcPluginHandlers = {};
|
|
86
86
|
// list of plugins directory
|
|
87
|
-
const plugins = (0,
|
|
88
|
-
const rpcPluginMethods = plugins.filter((name)=>(0,
|
|
87
|
+
const plugins = (0, _nodefs.readdirSync)(new URL('.', require("url").pathToFileURL(__filename).toString())).filter((file)=>(0, _nodefs.lstatSync)(new URL(file, require("url").pathToFileURL(__filename).toString())).isDirectory());
|
|
88
|
+
const rpcPluginMethods = plugins.filter((name)=>(0, _nodefs.readdirSync)(new URL(name, require("url").pathToFileURL(__filename).toString())).some((file)=>file.startsWith('rpc'))).map((name)=>`dev_${_lodash.default.camelCase(name)}`);
|
|
89
89
|
const loadRpcPlugin = async (method)=>{
|
|
90
90
|
if (_chopstickscore.environment.DISABLE_PLUGINS) {
|
|
91
91
|
return undefined;
|
|
@@ -104,11 +104,11 @@ const loadRpcPlugin = async (method)=>{
|
|
|
104
104
|
let rpcScriptMethods = {};
|
|
105
105
|
const loadRpcMethodsByScripts = async (path)=>{
|
|
106
106
|
try {
|
|
107
|
-
const scriptContent = (0,
|
|
107
|
+
const scriptContent = (0, _nodefs.readFileSync)((0, _nodepath.resolve)(path), 'utf8');
|
|
108
108
|
rpcScriptMethods = new Function(scriptContent)();
|
|
109
109
|
logger.info(`${Object.keys(rpcScriptMethods).length} extension rpc methods loaded from ${path}`);
|
|
110
110
|
} catch (error) {
|
|
111
|
-
console.log('Failed to load rpc extension methods');
|
|
111
|
+
console.log('Failed to load rpc extension methods', error);
|
|
112
112
|
}
|
|
113
113
|
};
|
|
114
114
|
const getRpcExtensionMethods = ()=>{
|
|
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "cli", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _chopstickscore = require("@acala-network/chopsticks-core");
|
|
12
|
-
const
|
|
12
|
+
const _nodefs = require("node:fs");
|
|
13
13
|
const _zod = require("zod");
|
|
14
14
|
const _index = require("../../schema/index.js");
|
|
15
15
|
const _utils = require("./utils.js");
|
|
@@ -54,11 +54,11 @@ const cli = (y)=>{
|
|
|
54
54
|
if (config.vm) {
|
|
55
55
|
_chopstickscore.pinoLogger.info('Running EVM opcode trace ...');
|
|
56
56
|
const steps = await (0, _utils.traceVM)(tracingBlock, extrinsic, config['page-size'], config['disable-stack'], config['enable-memory']);
|
|
57
|
-
(0,
|
|
57
|
+
(0, _nodefs.writeFileSync)(argv.output, JSON.stringify(steps, null, 2));
|
|
58
58
|
} else {
|
|
59
59
|
_chopstickscore.pinoLogger.info('Running EVM call trace ...');
|
|
60
60
|
const calls = await (0, _utils.traceCalls)(tracingBlock, extrinsic);
|
|
61
|
-
(0,
|
|
61
|
+
(0, _nodefs.writeFileSync)(argv.output, JSON.stringify(calls, null, 2));
|
|
62
62
|
}
|
|
63
63
|
_chopstickscore.pinoLogger.info(`Trace logs: ${argv.output}`);
|
|
64
64
|
process.exit(0);
|
|
@@ -4,7 +4,8 @@ import { ZodNativeEnum, ZodRawShape, ZodTypeAny, z } from 'zod';
|
|
|
4
4
|
export declare const zHex: z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>;
|
|
5
5
|
export declare const zHash: z.ZodIntersection<z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>>;
|
|
6
6
|
export declare const configSchema: z.ZodObject<{
|
|
7
|
-
addr: z.
|
|
7
|
+
addr: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"localhost">, z.ZodString]>>;
|
|
8
|
+
host: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"localhost">, z.ZodString]>>;
|
|
8
9
|
port: z.ZodDefault<z.ZodNumber>;
|
|
9
10
|
endpoint: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
10
11
|
block: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodNull]>>;
|
|
@@ -22,7 +23,7 @@ export declare const configSchema: z.ZodObject<{
|
|
|
22
23
|
ss58Format: z.ZodOptional<z.ZodNumber>;
|
|
23
24
|
tokenDecimals: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodArray<z.ZodNumber, "many">]>>;
|
|
24
25
|
tokenSymbol: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
25
|
-
}, "strip", ZodTypeAny, {
|
|
26
|
+
}, "strip", z.ZodTypeAny, {
|
|
26
27
|
ss58Format?: number | undefined;
|
|
27
28
|
tokenDecimals?: number | number[] | undefined;
|
|
28
29
|
tokenSymbol?: string | string[] | undefined;
|
|
@@ -34,12 +35,12 @@ export declare const configSchema: z.ZodObject<{
|
|
|
34
35
|
genesis: z.ZodObject<{
|
|
35
36
|
raw: z.ZodObject<{
|
|
36
37
|
top: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
37
|
-
}, "strip", ZodTypeAny, {
|
|
38
|
+
}, "strip", z.ZodTypeAny, {
|
|
38
39
|
top: Record<string, string>;
|
|
39
40
|
}, {
|
|
40
41
|
top: Record<string, string>;
|
|
41
42
|
}>;
|
|
42
|
-
}, "strip", ZodTypeAny, {
|
|
43
|
+
}, "strip", z.ZodTypeAny, {
|
|
43
44
|
raw: {
|
|
44
45
|
top: Record<string, string>;
|
|
45
46
|
};
|
|
@@ -82,7 +83,7 @@ export declare const configSchema: z.ZodObject<{
|
|
|
82
83
|
ss58Format: z.ZodOptional<z.ZodNumber>;
|
|
83
84
|
tokenDecimals: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodArray<z.ZodNumber, "many">]>>;
|
|
84
85
|
tokenSymbol: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
85
|
-
}, "strip", ZodTypeAny, {
|
|
86
|
+
}, "strip", z.ZodTypeAny, {
|
|
86
87
|
ss58Format?: number | undefined;
|
|
87
88
|
tokenDecimals?: number | number[] | undefined;
|
|
88
89
|
tokenSymbol?: string | string[] | undefined;
|
|
@@ -94,12 +95,12 @@ export declare const configSchema: z.ZodObject<{
|
|
|
94
95
|
genesis: z.ZodObject<{
|
|
95
96
|
raw: z.ZodObject<{
|
|
96
97
|
top: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
97
|
-
}, "strip", ZodTypeAny, {
|
|
98
|
+
}, "strip", z.ZodTypeAny, {
|
|
98
99
|
top: Record<string, string>;
|
|
99
100
|
}, {
|
|
100
101
|
top: Record<string, string>;
|
|
101
102
|
}>;
|
|
102
|
-
}, "strip", ZodTypeAny, {
|
|
103
|
+
}, "strip", z.ZodTypeAny, {
|
|
103
104
|
raw: {
|
|
104
105
|
top: Record<string, string>;
|
|
105
106
|
};
|
|
@@ -143,9 +144,10 @@ export declare const configSchema: z.ZodObject<{
|
|
|
143
144
|
'process-queued-messages': z.ZodOptional<z.ZodBoolean>;
|
|
144
145
|
'prefetch-storages': z.ZodOptional<z.ZodAny>;
|
|
145
146
|
}, "strip", ZodTypeAny, {
|
|
146
|
-
addr: string;
|
|
147
147
|
port: number;
|
|
148
148
|
'build-block-mode': BuildBlockMode;
|
|
149
|
+
addr?: string | undefined;
|
|
150
|
+
host?: string | undefined;
|
|
149
151
|
endpoint?: string | string[] | undefined;
|
|
150
152
|
block?: string | number | null | undefined;
|
|
151
153
|
'import-storage'?: any;
|
|
@@ -191,6 +193,7 @@ export declare const configSchema: z.ZodObject<{
|
|
|
191
193
|
'prefetch-storages'?: any;
|
|
192
194
|
}, {
|
|
193
195
|
addr?: string | undefined;
|
|
196
|
+
host?: string | undefined;
|
|
194
197
|
port?: number | undefined;
|
|
195
198
|
endpoint?: string | string[] | undefined;
|
|
196
199
|
block?: string | number | null | undefined;
|
package/dist/cjs/schema/index.js
CHANGED
|
@@ -43,9 +43,13 @@ const configSchema = _zod.z.object({
|
|
|
43
43
|
addr: _zod.z.union([
|
|
44
44
|
_zod.z.literal('localhost'),
|
|
45
45
|
_zod.z.string().ip()
|
|
46
|
+
]).optional(),
|
|
47
|
+
host: _zod.z.union([
|
|
48
|
+
_zod.z.literal('localhost'),
|
|
49
|
+
_zod.z.string().ip()
|
|
46
50
|
], {
|
|
47
51
|
description: 'Server listening interface'
|
|
48
|
-
}).
|
|
52
|
+
}).optional(),
|
|
49
53
|
port: _zod.z.number({
|
|
50
54
|
description: 'Server listening port'
|
|
51
55
|
}).default(8000),
|
package/dist/cjs/server.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ export type Handler = (data: {
|
|
|
3
3
|
method: string;
|
|
4
4
|
params: string[];
|
|
5
5
|
}, subscriptionManager: SubscriptionManager) => Promise<any>;
|
|
6
|
-
export declare const createServer: (handler: Handler,
|
|
6
|
+
export declare const createServer: (handler: Handler, port: number, host?: string) => Promise<{
|
|
7
|
+
addr: string;
|
|
7
8
|
port: number;
|
|
8
9
|
close: () => Promise<void>;
|
|
9
10
|
}>;
|
package/dist/cjs/server.js
CHANGED
|
@@ -42,7 +42,7 @@ const requestSchema = _zod.z.union([
|
|
|
42
42
|
const parseRequest = (request)=>{
|
|
43
43
|
try {
|
|
44
44
|
return JSON.parse(request);
|
|
45
|
-
} catch (
|
|
45
|
+
} catch (_e) {
|
|
46
46
|
return undefined;
|
|
47
47
|
}
|
|
48
48
|
};
|
|
@@ -66,7 +66,7 @@ const respond = (res, data)=>{
|
|
|
66
66
|
}
|
|
67
67
|
res.end();
|
|
68
68
|
};
|
|
69
|
-
const portInUse = async (port,
|
|
69
|
+
const portInUse = async (port, host)=>{
|
|
70
70
|
const server = _nodehttp.default.createServer();
|
|
71
71
|
const inUse = await new Promise((resolve)=>{
|
|
72
72
|
server.once('error', (e)=>{
|
|
@@ -80,15 +80,16 @@ const portInUse = async (port, addr)=>{
|
|
|
80
80
|
server.close();
|
|
81
81
|
resolve(false);
|
|
82
82
|
});
|
|
83
|
-
server.listen(port,
|
|
83
|
+
server.listen(port, host);
|
|
84
84
|
});
|
|
85
85
|
server.removeAllListeners();
|
|
86
86
|
server.unref();
|
|
87
|
+
await new Promise((r)=>setTimeout(r, 50));
|
|
87
88
|
return inUse;
|
|
88
89
|
};
|
|
89
|
-
const createServer = async (handler,
|
|
90
|
+
const createServer = async (handler, port, host)=>{
|
|
90
91
|
let wss;
|
|
91
|
-
let
|
|
92
|
+
let addressInfo;
|
|
92
93
|
const emptySubscriptionManager = {
|
|
93
94
|
subscribe: ()=>{
|
|
94
95
|
throw new Error('Subscription is not supported');
|
|
@@ -153,7 +154,7 @@ const createServer = async (handler, addr, port)=>{
|
|
|
153
154
|
}
|
|
154
155
|
});
|
|
155
156
|
for(let i = 0; i < 10; i++){
|
|
156
|
-
if (port && await portInUse(port + i,
|
|
157
|
+
if (port && await portInUse(port + i, host)) {
|
|
157
158
|
continue;
|
|
158
159
|
}
|
|
159
160
|
const preferPort = port ? port + i : undefined;
|
|
@@ -164,19 +165,19 @@ const createServer = async (handler, addr, port)=>{
|
|
|
164
165
|
reject(e);
|
|
165
166
|
};
|
|
166
167
|
server.once('error', onError);
|
|
167
|
-
server.listen(preferPort,
|
|
168
|
+
server.listen(preferPort, host, ()=>{
|
|
168
169
|
wss = new _ws.WebSocketServer({
|
|
169
170
|
server,
|
|
170
171
|
maxPayload: 1024 * 1024 * 100
|
|
171
172
|
});
|
|
172
|
-
|
|
173
|
+
addressInfo = server.address();
|
|
173
174
|
server.removeListener('error', onError);
|
|
174
175
|
resolve();
|
|
175
176
|
});
|
|
176
177
|
});
|
|
177
178
|
break;
|
|
178
179
|
}
|
|
179
|
-
if (!wss || !
|
|
180
|
+
if (!wss || !addressInfo) {
|
|
180
181
|
throw new Error(`Failed to create WebsocketServer at port ${port}`);
|
|
181
182
|
}
|
|
182
183
|
wss.on('connection', (ws)=>{
|
|
@@ -289,7 +290,8 @@ const createServer = async (handler, addr, port)=>{
|
|
|
289
290
|
});
|
|
290
291
|
});
|
|
291
292
|
return {
|
|
292
|
-
|
|
293
|
+
addr: `${addressInfo.family === 'IPv6' ? `[${addressInfo.address}]` : addressInfo.address}:${addressInfo.port}`,
|
|
294
|
+
port: addressInfo.port,
|
|
293
295
|
close: async ()=>{
|
|
294
296
|
server.close();
|
|
295
297
|
server.closeAllConnections();
|
|
@@ -13,14 +13,16 @@ const _chopstickscore = require("@acala-network/chopsticks-core");
|
|
|
13
13
|
const _index = require("./rpc/index.js");
|
|
14
14
|
const _context = require("./context.js");
|
|
15
15
|
const setupWithServer = async (argv)=>{
|
|
16
|
+
if (argv.addr) {
|
|
17
|
+
_chopstickscore.defaultLogger.warn({}, `⚠️ Option --addr is deprecated, please use --host instead.`);
|
|
18
|
+
argv.host ??= argv.addr;
|
|
19
|
+
}
|
|
16
20
|
const context = await (0, _context.setupContext)(argv);
|
|
17
|
-
const addr = argv.
|
|
18
|
-
|
|
19
|
-
_chopstickscore.defaultLogger.info(`${await context.chain.api.getSystemChain()} RPC listening on ${addr}:${listenPort}`);
|
|
21
|
+
const { close, addr } = await (0, _server.createServer)((0, _index.handler)(context), argv.port, argv.host);
|
|
22
|
+
_chopstickscore.defaultLogger.info(`${await context.chain.api.getSystemChain()} RPC listening on http://${addr} and ws://${addr}`);
|
|
20
23
|
return {
|
|
21
24
|
...context,
|
|
22
|
-
addr
|
|
23
|
-
listenPort,
|
|
25
|
+
addr,
|
|
24
26
|
async close () {
|
|
25
27
|
await context.chain.close();
|
|
26
28
|
await context.fetchStorageWorker?.terminate();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ApiPromise } from '@polkadot/api';
|
|
2
2
|
import { HexString } from '@polkadot/util/types';
|
|
3
|
-
export declare const logger: import("pino").default.Logger<never>;
|
|
3
|
+
export declare const logger: import("pino").default.Logger<never, boolean>;
|
|
4
4
|
type FetchStorageConfigItem = HexString | string | Record<string, string | Record<string, any[]> | Record<string, any>[] | (string | any)[]>;
|
|
5
5
|
export type FetchStorageConfig = FetchStorageConfigItem[];
|
|
6
6
|
/**
|
|
@@ -120,7 +120,8 @@ const fetchStorages = async ({ block, endpoint, dbPath, config })=>{
|
|
|
120
120
|
if (!endpoint) throw new Error('endpoint is required');
|
|
121
121
|
const provider = new _rpcprovider.WsProvider(endpoint, 3_000);
|
|
122
122
|
const apiPromise = new _api.ApiPromise({
|
|
123
|
-
provider
|
|
123
|
+
provider,
|
|
124
|
+
noInitWarn: true
|
|
124
125
|
});
|
|
125
126
|
await apiPromise.isReady;
|
|
126
127
|
let blockHash;
|
package/dist/cjs/utils/tunnel.js
CHANGED
|
@@ -12,4 +12,4 @@ function _interop_require_default(obj) {
|
|
|
12
12
|
}
|
|
13
13
|
(0, _globalagent.bootstrap)();
|
|
14
14
|
const npmConfig = (0, _npmconf.default)().config;
|
|
15
|
-
|
|
15
|
+
globalThis.GLOBAL_AGENT.HTTP_PROXY = _chopstickscore.environment.HTTP_PROXY || _chopstickscore.environment.http_proxy || _chopstickscore.environment.HTTPS_PROXY || _chopstickscore.environment.https_proxy || npmConfig.get('proxy') || npmConfig.get('https-proxy') || globalThis.GLOBAL_AGENT.HTTP_PROXY;
|
package/dist/esm/cli.js
CHANGED
|
@@ -29,7 +29,7 @@ const processArgv = async (argv)=>{
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
|
-
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)=>{
|
|
32
|
+
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)).deprecateOption('addr', '⚠️ Use --host instead.'), async (argv)=>{
|
|
33
33
|
await setupWithServer(configSchema.parse(argv));
|
|
34
34
|
}).command('xcm', 'XCM setup with relaychain and parachains', (yargs)=>yargs.options({
|
|
35
35
|
relaychain: {
|
|
@@ -57,7 +57,7 @@ const commands = yargs(hideBin(process.argv)).scriptName('chopsticks').middlewar
|
|
|
57
57
|
await connectVertical(relaychain, parachain);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
}).strict().help().alias('help', 'h').alias('version', 'v').alias('config', 'c').alias('endpoint', 'e').alias('port', 'p').alias('block', 'b').alias('unsafe-rpc-methods', 'ur').alias('import-storage', 's').alias('wasm-override', 'w').usage('Usage: $0 <command> [options]').example('$0', '-c acala');
|
|
60
|
+
}).strict().help().alias('help', 'h').alias('version', 'v').alias('config', 'c').alias('endpoint', 'e').alias('port', 'p').alias('block', 'b').alias('unsafe-rpc-methods', 'ur').alias('import-storage', 's').alias('wasm-override', 'w').usage('Usage: $0 <command> [options]').example('$0', '-c acala').showHelpOnFail(false);
|
|
61
61
|
if (!environment.DISABLE_PLUGINS) {
|
|
62
62
|
pluginExtendCli(commands.config('config', 'Path to config file with default options', ()=>({}))).then(()=>commands.parse());
|
|
63
63
|
} else {
|
package/dist/esm/context.js
CHANGED
|
@@ -64,7 +64,9 @@ export const setupContext = async (argv, overrideParent = false)=>{
|
|
|
64
64
|
}
|
|
65
65
|
if (blockData) {
|
|
66
66
|
const block = await chain.loadBlockFromDB(blockData.number);
|
|
67
|
-
|
|
67
|
+
if (block) {
|
|
68
|
+
await chain.setHead(block);
|
|
69
|
+
}
|
|
68
70
|
logger.info(`Resume from block ${blockData.number}, hash: ${blockData.hash}`);
|
|
69
71
|
} else {
|
|
70
72
|
throw new Error(`Resume failed. Cannot find block ${argv.resume}`);
|
|
@@ -7,7 +7,8 @@ export declare const dryRunSchema: z.ZodObject<{
|
|
|
7
7
|
"output-path": z.ZodOptional<z.ZodString>;
|
|
8
8
|
html: z.ZodOptional<z.ZodBoolean>;
|
|
9
9
|
open: z.ZodOptional<z.ZodBoolean>;
|
|
10
|
-
addr: z.
|
|
10
|
+
addr: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"localhost">, z.ZodString]>>;
|
|
11
|
+
host: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"localhost">, z.ZodString]>>;
|
|
11
12
|
port: z.ZodDefault<z.ZodNumber>;
|
|
12
13
|
endpoint: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
13
14
|
block: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodNull]>>;
|
|
@@ -146,10 +147,11 @@ export declare const dryRunSchema: z.ZodObject<{
|
|
|
146
147
|
'process-queued-messages': z.ZodOptional<z.ZodBoolean>;
|
|
147
148
|
'prefetch-storages': z.ZodOptional<z.ZodAny>;
|
|
148
149
|
}, "strip", z.ZodTypeAny, {
|
|
149
|
-
addr: string;
|
|
150
150
|
port: number;
|
|
151
151
|
'build-block-mode': import("@acala-network/chopsticks-core").BuildBlockMode;
|
|
152
152
|
at?: string | undefined;
|
|
153
|
+
addr?: string | undefined;
|
|
154
|
+
host?: string | undefined;
|
|
153
155
|
endpoint?: string | string[] | undefined;
|
|
154
156
|
block?: string | number | null | undefined;
|
|
155
157
|
'import-storage'?: any;
|
|
@@ -202,6 +204,7 @@ export declare const dryRunSchema: z.ZodObject<{
|
|
|
202
204
|
}, {
|
|
203
205
|
at?: string | undefined;
|
|
204
206
|
addr?: string | undefined;
|
|
207
|
+
host?: string | undefined;
|
|
205
208
|
port?: number | undefined;
|
|
206
209
|
endpoint?: string | string[] | undefined;
|
|
207
210
|
block?: string | number | null | undefined;
|
|
@@ -8,11 +8,11 @@ import { setupContext } from '../../context.js';
|
|
|
8
8
|
const logger = defaultLogger.child({
|
|
9
9
|
name: 'follow-chain'
|
|
10
10
|
});
|
|
11
|
-
var HeadMode
|
|
12
|
-
(function(HeadMode) {
|
|
11
|
+
var HeadMode = /*#__PURE__*/ function(HeadMode) {
|
|
13
12
|
HeadMode["Latest"] = "Latest";
|
|
14
13
|
HeadMode["Finalized"] = "Finalized";
|
|
15
|
-
|
|
14
|
+
return HeadMode;
|
|
15
|
+
}(HeadMode || {});
|
|
16
16
|
const schema = z.object({
|
|
17
17
|
..._.pick(configSchema.shape, [
|
|
18
18
|
'endpoint',
|
|
@@ -26,16 +26,17 @@ const schema = z.object({
|
|
|
26
26
|
export const cli = (y)=>{
|
|
27
27
|
y.command('follow-chain', 'Always follow the latest block on upstream', (yargs)=>yargs.options(getYargsOptions(schema.shape)), async (argv)=>{
|
|
28
28
|
const config = schema.parse(argv);
|
|
29
|
-
Array.isArray(config.endpoint) ? config.endpoint : [
|
|
30
|
-
config.endpoint
|
|
31
|
-
]
|
|
29
|
+
const endpoints = Array.isArray(config.endpoint) ? config.endpoint : [
|
|
30
|
+
config.endpoint ?? ''
|
|
31
|
+
];
|
|
32
|
+
for (const endpoint of endpoints){
|
|
32
33
|
if (/^(https|http):\/\//.test(endpoint)) {
|
|
33
34
|
throw Error('http provider is not supported');
|
|
34
35
|
}
|
|
35
|
-
}
|
|
36
|
+
}
|
|
36
37
|
const context = await setupContext(config, true);
|
|
37
|
-
const { close,
|
|
38
|
-
logger.info(`${await context.chain.api.getSystemChain()} RPC listening on
|
|
38
|
+
const { close, addr } = await createServer(handler(context), config.port, config.host);
|
|
39
|
+
logger.info(`${await context.chain.api.getSystemChain()} RPC listening on http://${addr} and ws://${addr}`);
|
|
39
40
|
const chain = context.chain;
|
|
40
41
|
chain.api[config['head-mode'] === "Latest" ? 'subscribeRemoteNewHeads' : 'subscribeRemoteFinalizedHeads'](async (error, data)=>{
|
|
41
42
|
try {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { environment } from '@acala-network/chopsticks-core';
|
|
2
|
-
import { lstatSync, readFileSync, readdirSync } from 'fs';
|
|
2
|
+
import { lstatSync, readFileSync, readdirSync } from 'node:fs';
|
|
3
3
|
import _ from 'lodash';
|
|
4
4
|
import { defaultLogger } from '../logger.js';
|
|
5
|
-
import { resolve } from 'path';
|
|
5
|
+
import { resolve } from 'node:path';
|
|
6
6
|
const logger = defaultLogger.child({
|
|
7
7
|
name: 'plugin'
|
|
8
8
|
});
|
|
@@ -34,7 +34,7 @@ export const loadRpcMethodsByScripts = async (path)=>{
|
|
|
34
34
|
rpcScriptMethods = new Function(scriptContent)();
|
|
35
35
|
logger.info(`${Object.keys(rpcScriptMethods).length} extension rpc methods loaded from ${path}`);
|
|
36
36
|
} catch (error) {
|
|
37
|
-
console.log('Failed to load rpc extension methods');
|
|
37
|
+
console.log('Failed to load rpc extension methods', error);
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
40
|
export const getRpcExtensionMethods = ()=>{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { pinoLogger } from '@acala-network/chopsticks-core';
|
|
2
|
-
import { writeFileSync } from 'fs';
|
|
2
|
+
import { writeFileSync } from 'node:fs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { configSchema, getYargsOptions } from '../../schema/index.js';
|
|
5
5
|
import { fetchEVMTransaction, prepareBlock, traceCalls, traceVM } from './utils.js';
|
|
@@ -4,7 +4,8 @@ import { ZodNativeEnum, ZodRawShape, ZodTypeAny, z } from 'zod';
|
|
|
4
4
|
export declare const zHex: z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>;
|
|
5
5
|
export declare const zHash: z.ZodIntersection<z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>>;
|
|
6
6
|
export declare const configSchema: z.ZodObject<{
|
|
7
|
-
addr: z.
|
|
7
|
+
addr: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"localhost">, z.ZodString]>>;
|
|
8
|
+
host: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"localhost">, z.ZodString]>>;
|
|
8
9
|
port: z.ZodDefault<z.ZodNumber>;
|
|
9
10
|
endpoint: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
10
11
|
block: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodNull]>>;
|
|
@@ -22,7 +23,7 @@ export declare const configSchema: z.ZodObject<{
|
|
|
22
23
|
ss58Format: z.ZodOptional<z.ZodNumber>;
|
|
23
24
|
tokenDecimals: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodArray<z.ZodNumber, "many">]>>;
|
|
24
25
|
tokenSymbol: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
25
|
-
}, "strip", ZodTypeAny, {
|
|
26
|
+
}, "strip", z.ZodTypeAny, {
|
|
26
27
|
ss58Format?: number | undefined;
|
|
27
28
|
tokenDecimals?: number | number[] | undefined;
|
|
28
29
|
tokenSymbol?: string | string[] | undefined;
|
|
@@ -34,12 +35,12 @@ export declare const configSchema: z.ZodObject<{
|
|
|
34
35
|
genesis: z.ZodObject<{
|
|
35
36
|
raw: z.ZodObject<{
|
|
36
37
|
top: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
37
|
-
}, "strip", ZodTypeAny, {
|
|
38
|
+
}, "strip", z.ZodTypeAny, {
|
|
38
39
|
top: Record<string, string>;
|
|
39
40
|
}, {
|
|
40
41
|
top: Record<string, string>;
|
|
41
42
|
}>;
|
|
42
|
-
}, "strip", ZodTypeAny, {
|
|
43
|
+
}, "strip", z.ZodTypeAny, {
|
|
43
44
|
raw: {
|
|
44
45
|
top: Record<string, string>;
|
|
45
46
|
};
|
|
@@ -82,7 +83,7 @@ export declare const configSchema: z.ZodObject<{
|
|
|
82
83
|
ss58Format: z.ZodOptional<z.ZodNumber>;
|
|
83
84
|
tokenDecimals: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodArray<z.ZodNumber, "many">]>>;
|
|
84
85
|
tokenSymbol: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
85
|
-
}, "strip", ZodTypeAny, {
|
|
86
|
+
}, "strip", z.ZodTypeAny, {
|
|
86
87
|
ss58Format?: number | undefined;
|
|
87
88
|
tokenDecimals?: number | number[] | undefined;
|
|
88
89
|
tokenSymbol?: string | string[] | undefined;
|
|
@@ -94,12 +95,12 @@ export declare const configSchema: z.ZodObject<{
|
|
|
94
95
|
genesis: z.ZodObject<{
|
|
95
96
|
raw: z.ZodObject<{
|
|
96
97
|
top: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
97
|
-
}, "strip", ZodTypeAny, {
|
|
98
|
+
}, "strip", z.ZodTypeAny, {
|
|
98
99
|
top: Record<string, string>;
|
|
99
100
|
}, {
|
|
100
101
|
top: Record<string, string>;
|
|
101
102
|
}>;
|
|
102
|
-
}, "strip", ZodTypeAny, {
|
|
103
|
+
}, "strip", z.ZodTypeAny, {
|
|
103
104
|
raw: {
|
|
104
105
|
top: Record<string, string>;
|
|
105
106
|
};
|
|
@@ -143,9 +144,10 @@ export declare const configSchema: z.ZodObject<{
|
|
|
143
144
|
'process-queued-messages': z.ZodOptional<z.ZodBoolean>;
|
|
144
145
|
'prefetch-storages': z.ZodOptional<z.ZodAny>;
|
|
145
146
|
}, "strip", ZodTypeAny, {
|
|
146
|
-
addr: string;
|
|
147
147
|
port: number;
|
|
148
148
|
'build-block-mode': BuildBlockMode;
|
|
149
|
+
addr?: string | undefined;
|
|
150
|
+
host?: string | undefined;
|
|
149
151
|
endpoint?: string | string[] | undefined;
|
|
150
152
|
block?: string | number | null | undefined;
|
|
151
153
|
'import-storage'?: any;
|
|
@@ -191,6 +193,7 @@ export declare const configSchema: z.ZodObject<{
|
|
|
191
193
|
'prefetch-storages'?: any;
|
|
192
194
|
}, {
|
|
193
195
|
addr?: string | undefined;
|
|
196
|
+
host?: string | undefined;
|
|
194
197
|
port?: number | undefined;
|
|
195
198
|
endpoint?: string | string[] | undefined;
|
|
196
199
|
block?: string | number | null | undefined;
|
package/dist/esm/schema/index.js
CHANGED
|
@@ -11,9 +11,13 @@ export const configSchema = z.object({
|
|
|
11
11
|
addr: z.union([
|
|
12
12
|
z.literal('localhost'),
|
|
13
13
|
z.string().ip()
|
|
14
|
+
]).optional(),
|
|
15
|
+
host: z.union([
|
|
16
|
+
z.literal('localhost'),
|
|
17
|
+
z.string().ip()
|
|
14
18
|
], {
|
|
15
19
|
description: 'Server listening interface'
|
|
16
|
-
}).
|
|
20
|
+
}).optional(),
|
|
17
21
|
port: z.number({
|
|
18
22
|
description: 'Server listening port'
|
|
19
23
|
}).default(8000),
|
package/dist/esm/server.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ export type Handler = (data: {
|
|
|
3
3
|
method: string;
|
|
4
4
|
params: string[];
|
|
5
5
|
}, subscriptionManager: SubscriptionManager) => Promise<any>;
|
|
6
|
-
export declare const createServer: (handler: Handler,
|
|
6
|
+
export declare const createServer: (handler: Handler, port: number, host?: string) => Promise<{
|
|
7
|
+
addr: string;
|
|
7
8
|
port: number;
|
|
8
9
|
close: () => Promise<void>;
|
|
9
10
|
}>;
|
package/dist/esm/server.js
CHANGED
|
@@ -27,7 +27,7 @@ const requestSchema = z.union([
|
|
|
27
27
|
const parseRequest = (request)=>{
|
|
28
28
|
try {
|
|
29
29
|
return JSON.parse(request);
|
|
30
|
-
} catch (
|
|
30
|
+
} catch (_e) {
|
|
31
31
|
return undefined;
|
|
32
32
|
}
|
|
33
33
|
};
|
|
@@ -51,7 +51,7 @@ const respond = (res, data)=>{
|
|
|
51
51
|
}
|
|
52
52
|
res.end();
|
|
53
53
|
};
|
|
54
|
-
const portInUse = async (port,
|
|
54
|
+
const portInUse = async (port, host)=>{
|
|
55
55
|
const server = http.createServer();
|
|
56
56
|
const inUse = await new Promise((resolve)=>{
|
|
57
57
|
server.once('error', (e)=>{
|
|
@@ -65,15 +65,16 @@ const portInUse = async (port, addr)=>{
|
|
|
65
65
|
server.close();
|
|
66
66
|
resolve(false);
|
|
67
67
|
});
|
|
68
|
-
server.listen(port,
|
|
68
|
+
server.listen(port, host);
|
|
69
69
|
});
|
|
70
70
|
server.removeAllListeners();
|
|
71
71
|
server.unref();
|
|
72
|
+
await new Promise((r)=>setTimeout(r, 50));
|
|
72
73
|
return inUse;
|
|
73
74
|
};
|
|
74
|
-
export const createServer = async (handler,
|
|
75
|
+
export const createServer = async (handler, port, host)=>{
|
|
75
76
|
let wss;
|
|
76
|
-
let
|
|
77
|
+
let addressInfo;
|
|
77
78
|
const emptySubscriptionManager = {
|
|
78
79
|
subscribe: ()=>{
|
|
79
80
|
throw new Error('Subscription is not supported');
|
|
@@ -138,7 +139,7 @@ export const createServer = async (handler, addr, port)=>{
|
|
|
138
139
|
}
|
|
139
140
|
});
|
|
140
141
|
for(let i = 0; i < 10; i++){
|
|
141
|
-
if (port && await portInUse(port + i,
|
|
142
|
+
if (port && await portInUse(port + i, host)) {
|
|
142
143
|
continue;
|
|
143
144
|
}
|
|
144
145
|
const preferPort = port ? port + i : undefined;
|
|
@@ -149,19 +150,19 @@ export const createServer = async (handler, addr, port)=>{
|
|
|
149
150
|
reject(e);
|
|
150
151
|
};
|
|
151
152
|
server.once('error', onError);
|
|
152
|
-
server.listen(preferPort,
|
|
153
|
+
server.listen(preferPort, host, ()=>{
|
|
153
154
|
wss = new WebSocketServer({
|
|
154
155
|
server,
|
|
155
156
|
maxPayload: 1024 * 1024 * 100
|
|
156
157
|
});
|
|
157
|
-
|
|
158
|
+
addressInfo = server.address();
|
|
158
159
|
server.removeListener('error', onError);
|
|
159
160
|
resolve();
|
|
160
161
|
});
|
|
161
162
|
});
|
|
162
163
|
break;
|
|
163
164
|
}
|
|
164
|
-
if (!wss || !
|
|
165
|
+
if (!wss || !addressInfo) {
|
|
165
166
|
throw new Error(`Failed to create WebsocketServer at port ${port}`);
|
|
166
167
|
}
|
|
167
168
|
wss.on('connection', (ws)=>{
|
|
@@ -274,7 +275,8 @@ export const createServer = async (handler, addr, port)=>{
|
|
|
274
275
|
});
|
|
275
276
|
});
|
|
276
277
|
return {
|
|
277
|
-
|
|
278
|
+
addr: `${addressInfo.family === 'IPv6' ? `[${addressInfo.address}]` : addressInfo.address}:${addressInfo.port}`,
|
|
279
|
+
port: addressInfo.port,
|
|
278
280
|
close: async ()=>{
|
|
279
281
|
server.close();
|
|
280
282
|
server.closeAllConnections();
|
|
@@ -3,14 +3,16 @@ import { defaultLogger } from '@acala-network/chopsticks-core';
|
|
|
3
3
|
import { handler } from './rpc/index.js';
|
|
4
4
|
import { setupContext } from './context.js';
|
|
5
5
|
export const setupWithServer = async (argv)=>{
|
|
6
|
+
if (argv.addr) {
|
|
7
|
+
defaultLogger.warn({}, `⚠️ Option --addr is deprecated, please use --host instead.`);
|
|
8
|
+
argv.host ??= argv.addr;
|
|
9
|
+
}
|
|
6
10
|
const context = await setupContext(argv);
|
|
7
|
-
const addr = argv.
|
|
8
|
-
|
|
9
|
-
defaultLogger.info(`${await context.chain.api.getSystemChain()} RPC listening on ${addr}:${listenPort}`);
|
|
11
|
+
const { close, addr } = await createServer(handler(context), argv.port, argv.host);
|
|
12
|
+
defaultLogger.info(`${await context.chain.api.getSystemChain()} RPC listening on http://${addr} and ws://${addr}`);
|
|
10
13
|
return {
|
|
11
14
|
...context,
|
|
12
|
-
addr
|
|
13
|
-
listenPort,
|
|
15
|
+
addr,
|
|
14
16
|
async close () {
|
|
15
17
|
await context.chain.close();
|
|
16
18
|
await context.fetchStorageWorker?.terminate();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ApiPromise } from '@polkadot/api';
|
|
2
2
|
import { HexString } from '@polkadot/util/types';
|
|
3
|
-
export declare const logger: import("pino").default.Logger<never>;
|
|
3
|
+
export declare const logger: import("pino").default.Logger<never, boolean>;
|
|
4
4
|
type FetchStorageConfigItem = HexString | string | Record<string, string | Record<string, any[]> | Record<string, any>[] | (string | any)[]>;
|
|
5
5
|
export type FetchStorageConfig = FetchStorageConfigItem[];
|
|
6
6
|
/**
|
|
@@ -95,7 +95,8 @@ const checkPalletStorageByName = (meta, palletName, storageName)=>{
|
|
|
95
95
|
if (!endpoint) throw new Error('endpoint is required');
|
|
96
96
|
const provider = new WsProvider(endpoint, 3_000);
|
|
97
97
|
const apiPromise = new ApiPromise({
|
|
98
|
-
provider
|
|
98
|
+
provider,
|
|
99
|
+
noInitWarn: true
|
|
99
100
|
});
|
|
100
101
|
await apiPromise.isReady;
|
|
101
102
|
let blockHash;
|
package/dist/esm/utils/tunnel.js
CHANGED
|
@@ -3,4 +3,4 @@ bootstrap();
|
|
|
3
3
|
import { environment } from '@acala-network/chopsticks-core';
|
|
4
4
|
import npmConf from '@pnpm/npm-conf';
|
|
5
5
|
const npmConfig = npmConf().config;
|
|
6
|
-
|
|
6
|
+
globalThis.GLOBAL_AGENT.HTTP_PROXY = environment.HTTP_PROXY || environment.http_proxy || environment.HTTPS_PROXY || environment.https_proxy || npmConfig.get('proxy') || npmConfig.get('https-proxy') || globalThis.GLOBAL_AGENT.HTTP_PROXY;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acala-network/chopsticks",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1-1",
|
|
4
4
|
"author": "Acala Developers <hello@acala.network>",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"bin": "./chopsticks.cjs",
|
|
@@ -12,36 +12,36 @@
|
|
|
12
12
|
"depcheck": "npx depcheck --ignore-patterns='*.test.ts'"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@acala-network/chopsticks-core": "0.
|
|
16
|
-
"@acala-network/chopsticks-db": "0.
|
|
17
|
-
"@pnpm/npm-conf": "^2.
|
|
18
|
-
"@polkadot/api": "^
|
|
19
|
-
"@polkadot/api-augment": "^
|
|
20
|
-
"@polkadot/rpc-provider": "^
|
|
21
|
-
"@polkadot/types": "^
|
|
22
|
-
"@polkadot/util": "^13.
|
|
23
|
-
"@polkadot/util-crypto": "^13.
|
|
24
|
-
"axios": "^1.7.
|
|
15
|
+
"@acala-network/chopsticks-core": "1.0.1-1",
|
|
16
|
+
"@acala-network/chopsticks-db": "1.0.1-1",
|
|
17
|
+
"@pnpm/npm-conf": "^2.3.1",
|
|
18
|
+
"@polkadot/api": "^14.0.1",
|
|
19
|
+
"@polkadot/api-augment": "^14.0.1",
|
|
20
|
+
"@polkadot/rpc-provider": "^14.0.1",
|
|
21
|
+
"@polkadot/types": "^14.0.1",
|
|
22
|
+
"@polkadot/util": "^13.2.2",
|
|
23
|
+
"@polkadot/util-crypto": "^13.2.2",
|
|
24
|
+
"axios": "^1.7.7",
|
|
25
25
|
"comlink": "^4.4.1",
|
|
26
26
|
"dotenv": "^16.4.5",
|
|
27
27
|
"global-agent": "^3.0.0",
|
|
28
28
|
"js-yaml": "^4.1.0",
|
|
29
29
|
"jsondiffpatch": "^0.5.0",
|
|
30
30
|
"lodash": "^4.17.21",
|
|
31
|
-
"ws": "^8.
|
|
31
|
+
"ws": "^8.18.0",
|
|
32
32
|
"yargs": "^17.7.2",
|
|
33
|
-
"zod": "^3.
|
|
33
|
+
"zod": "^3.23.8"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@swc/cli": "0.
|
|
37
|
-
"@swc/core": "^1.7.
|
|
36
|
+
"@swc/cli": "0.5.0",
|
|
37
|
+
"@swc/core": "^1.7.40",
|
|
38
38
|
"@types/global-agent": "^2.1.3",
|
|
39
39
|
"@types/js-yaml": "^4.0.9",
|
|
40
|
-
"@types/lodash": "^4.17.
|
|
41
|
-
"@types/node": "^
|
|
42
|
-
"@types/ws": "^8.5.
|
|
43
|
-
"@types/yargs": "^17.0.
|
|
44
|
-
"typescript": "^5.
|
|
40
|
+
"@types/lodash": "^4.17.13",
|
|
41
|
+
"@types/node": "^22.8.4",
|
|
42
|
+
"@types/ws": "^8.5.12",
|
|
43
|
+
"@types/yargs": "^17.0.33",
|
|
44
|
+
"typescript": "^5.6.3"
|
|
45
45
|
},
|
|
46
46
|
"files": [
|
|
47
47
|
"dist/esm/**",
|