@acala-network/chopsticks 0.10.1 → 0.11.0
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 +4 -1
- package/dist/cjs/plugins/index.d.ts +3 -1
- package/dist/cjs/plugins/index.js +30 -2
- package/dist/cjs/rpc/index.js +3 -3
- package/dist/esm/cli.js +5 -2
- package/dist/esm/plugins/index.d.ts +3 -1
- package/dist/esm/plugins/index.js +25 -2
- package/dist/esm/rpc/index.js +4 -4
- package/package.json +3 -3
package/dist/cjs/cli.js
CHANGED
|
@@ -17,6 +17,9 @@ function _interop_require_default(obj) {
|
|
|
17
17
|
}
|
|
18
18
|
(0, _dotenv.config)();
|
|
19
19
|
const processArgv = async (argv)=>{
|
|
20
|
+
if (argv.unsafeRpcMethods) {
|
|
21
|
+
await (0, _index1.loadRpcMethodsByScripts)(argv.unsafeRpcMethods);
|
|
22
|
+
}
|
|
20
23
|
if (argv.config) {
|
|
21
24
|
Object.assign(argv, _lodash.default.defaults(argv, await (0, _index.fetchConfig)(argv.config)));
|
|
22
25
|
}
|
|
@@ -52,7 +55,7 @@ const commands = (0, _yargs.default)((0, _helpers.hideBin)(process.argv)).script
|
|
|
52
55
|
await (0, _chopstickscore.connectVertical)(relaychain, parachain);
|
|
53
56
|
}
|
|
54
57
|
}
|
|
55
|
-
}).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');
|
|
58
|
+
}).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');
|
|
56
59
|
if (!_chopstickscore.environment.DISABLE_PLUGINS) {
|
|
57
60
|
(0, _index1.pluginExtendCli)(commands.config('config', 'Path to config file with default options', ()=>({}))).then(()=>commands.parse());
|
|
58
61
|
} else {
|
|
@@ -2,5 +2,7 @@ import { Handlers } from '@acala-network/chopsticks-core';
|
|
|
2
2
|
import type { Argv } from 'yargs';
|
|
3
3
|
export declare const rpcPluginHandlers: Handlers;
|
|
4
4
|
export declare const rpcPluginMethods: string[];
|
|
5
|
-
export declare const
|
|
5
|
+
export declare const loadRpcMethodsByScripts: (path: string) => Promise<void>;
|
|
6
|
+
export declare const getRpcExtensionMethods: () => string[];
|
|
7
|
+
export declare const loadRpcExtensionMethod: (method: string) => Promise<any>;
|
|
6
8
|
export declare const pluginExtendCli: (y: Argv) => Promise<void>;
|
|
@@ -9,8 +9,14 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
|
|
13
|
-
return
|
|
12
|
+
getRpcExtensionMethods: function() {
|
|
13
|
+
return getRpcExtensionMethods;
|
|
14
|
+
},
|
|
15
|
+
loadRpcExtensionMethod: function() {
|
|
16
|
+
return loadRpcExtensionMethod;
|
|
17
|
+
},
|
|
18
|
+
loadRpcMethodsByScripts: function() {
|
|
19
|
+
return loadRpcMethodsByScripts;
|
|
14
20
|
},
|
|
15
21
|
pluginExtendCli: function() {
|
|
16
22
|
return pluginExtendCli;
|
|
@@ -26,6 +32,7 @@ const _chopstickscore = require("@acala-network/chopsticks-core");
|
|
|
26
32
|
const _fs = require("fs");
|
|
27
33
|
const _lodash = /*#__PURE__*/ _interop_require_default(require("lodash"));
|
|
28
34
|
const _logger = require("../logger.js");
|
|
35
|
+
const _path = require("path");
|
|
29
36
|
function _interop_require_default(obj) {
|
|
30
37
|
return obj && obj.__esModule ? obj : {
|
|
31
38
|
default: obj
|
|
@@ -93,6 +100,27 @@ const loadRpcPlugin = async (method)=>{
|
|
|
93
100
|
logger.debug(`Registered plugin ${plugin} RPC`);
|
|
94
101
|
return rpc;
|
|
95
102
|
};
|
|
103
|
+
// store the loaded methods by cli
|
|
104
|
+
let rpcScriptMethods = {};
|
|
105
|
+
const loadRpcMethodsByScripts = async (path)=>{
|
|
106
|
+
try {
|
|
107
|
+
const scriptContent = (0, _fs.readFileSync)((0, _path.resolve)(path), 'utf8');
|
|
108
|
+
rpcScriptMethods = new Function(scriptContent)();
|
|
109
|
+
logger.info(`${Object.keys(rpcScriptMethods).length} extension rpc methods loaded from ${path}`);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
console.log('Failed to load rpc extension methods');
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const getRpcExtensionMethods = ()=>{
|
|
115
|
+
return [
|
|
116
|
+
...Object.keys(rpcScriptMethods),
|
|
117
|
+
...rpcPluginMethods
|
|
118
|
+
];
|
|
119
|
+
};
|
|
120
|
+
const loadRpcExtensionMethod = async (method)=>{
|
|
121
|
+
if (rpcScriptMethods[method]) return rpcScriptMethods[method];
|
|
122
|
+
return loadRpcPlugin(method);
|
|
123
|
+
};
|
|
96
124
|
const pluginExtendCli = async (y)=>{
|
|
97
125
|
for (const plugin of plugins){
|
|
98
126
|
const location = new URL(`${plugin}/index.js`, require("url").pathToFileURL(__filename).toString());
|
package/dist/cjs/rpc/index.js
CHANGED
|
@@ -19,15 +19,15 @@ const allHandlers = {
|
|
|
19
19
|
version: 1,
|
|
20
20
|
methods: [
|
|
21
21
|
...Object.keys(allHandlers),
|
|
22
|
-
..._index.
|
|
22
|
+
...(0, _index.getRpcExtensionMethods)()
|
|
23
23
|
].sort()
|
|
24
24
|
})
|
|
25
25
|
};
|
|
26
26
|
const getHandler = async (method)=>{
|
|
27
27
|
const handler = allHandlers[method];
|
|
28
28
|
if (!handler) {
|
|
29
|
-
// no handler for this method, check if it's a plugin
|
|
30
|
-
return (0, _index.
|
|
29
|
+
// no handler for this method, check if it's a plugin or a script loaded
|
|
30
|
+
return (0, _index.loadRpcExtensionMethod)(method);
|
|
31
31
|
}
|
|
32
32
|
return handler;
|
|
33
33
|
};
|
package/dist/esm/cli.js
CHANGED
|
@@ -4,10 +4,13 @@ import _ from 'lodash';
|
|
|
4
4
|
import yargs from 'yargs';
|
|
5
5
|
import { connectParachains, connectVertical, environment } from '@acala-network/chopsticks-core';
|
|
6
6
|
import { configSchema, fetchConfig, getYargsOptions } from './schema/index.js';
|
|
7
|
-
import { pluginExtendCli } from './plugins/index.js';
|
|
7
|
+
import { loadRpcMethodsByScripts, pluginExtendCli } from './plugins/index.js';
|
|
8
8
|
import { setupWithServer } from './index.js';
|
|
9
9
|
dotenvConfig();
|
|
10
10
|
const processArgv = async (argv)=>{
|
|
11
|
+
if (argv.unsafeRpcMethods) {
|
|
12
|
+
await loadRpcMethodsByScripts(argv.unsafeRpcMethods);
|
|
13
|
+
}
|
|
11
14
|
if (argv.config) {
|
|
12
15
|
Object.assign(argv, _.defaults(argv, await fetchConfig(argv.config)));
|
|
13
16
|
}
|
|
@@ -43,7 +46,7 @@ const commands = yargs(hideBin(process.argv)).scriptName('chopsticks').middlewar
|
|
|
43
46
|
await connectVertical(relaychain, parachain);
|
|
44
47
|
}
|
|
45
48
|
}
|
|
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');
|
|
49
|
+
}).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');
|
|
47
50
|
if (!environment.DISABLE_PLUGINS) {
|
|
48
51
|
pluginExtendCli(commands.config('config', 'Path to config file with default options', ()=>({}))).then(()=>commands.parse());
|
|
49
52
|
} else {
|
|
@@ -2,5 +2,7 @@ import { Handlers } from '@acala-network/chopsticks-core';
|
|
|
2
2
|
import type { Argv } from 'yargs';
|
|
3
3
|
export declare const rpcPluginHandlers: Handlers;
|
|
4
4
|
export declare const rpcPluginMethods: string[];
|
|
5
|
-
export declare const
|
|
5
|
+
export declare const loadRpcMethodsByScripts: (path: string) => Promise<void>;
|
|
6
|
+
export declare const getRpcExtensionMethods: () => string[];
|
|
7
|
+
export declare const loadRpcExtensionMethod: (method: string) => Promise<any>;
|
|
6
8
|
export declare const pluginExtendCli: (y: Argv) => Promise<void>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { environment } from '@acala-network/chopsticks-core';
|
|
2
|
-
import { lstatSync, readdirSync } from 'fs';
|
|
2
|
+
import { lstatSync, readFileSync, readdirSync } from 'fs';
|
|
3
3
|
import _ from 'lodash';
|
|
4
4
|
import { defaultLogger } from '../logger.js';
|
|
5
|
+
import { resolve } from 'path';
|
|
5
6
|
const logger = defaultLogger.child({
|
|
6
7
|
name: 'plugin'
|
|
7
8
|
});
|
|
@@ -10,7 +11,7 @@ export const rpcPluginHandlers = {};
|
|
|
10
11
|
const plugins = readdirSync(new URL('.', import.meta.url)).filter((file)=>lstatSync(new URL(file, import.meta.url)).isDirectory());
|
|
11
12
|
// find all rpc methods
|
|
12
13
|
export const rpcPluginMethods = plugins.filter((name)=>readdirSync(new URL(name, import.meta.url)).some((file)=>file.startsWith('rpc'))).map((name)=>`dev_${_.camelCase(name)}`);
|
|
13
|
-
|
|
14
|
+
const loadRpcPlugin = async (method)=>{
|
|
14
15
|
if (environment.DISABLE_PLUGINS) {
|
|
15
16
|
return undefined;
|
|
16
17
|
}
|
|
@@ -24,6 +25,28 @@ export const loadRpcPlugin = async (method)=>{
|
|
|
24
25
|
logger.debug(`Registered plugin ${plugin} RPC`);
|
|
25
26
|
return rpc;
|
|
26
27
|
};
|
|
28
|
+
// store the loaded methods by cli
|
|
29
|
+
let rpcScriptMethods = {};
|
|
30
|
+
// use cli to load rpc methods of external scripts
|
|
31
|
+
export const loadRpcMethodsByScripts = async (path)=>{
|
|
32
|
+
try {
|
|
33
|
+
const scriptContent = readFileSync(resolve(path), 'utf8');
|
|
34
|
+
rpcScriptMethods = new Function(scriptContent)();
|
|
35
|
+
logger.info(`${Object.keys(rpcScriptMethods).length} extension rpc methods loaded from ${path}`);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.log('Failed to load rpc extension methods');
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
export const getRpcExtensionMethods = ()=>{
|
|
41
|
+
return [
|
|
42
|
+
...Object.keys(rpcScriptMethods),
|
|
43
|
+
...rpcPluginMethods
|
|
44
|
+
];
|
|
45
|
+
};
|
|
46
|
+
export const loadRpcExtensionMethod = async (method)=>{
|
|
47
|
+
if (rpcScriptMethods[method]) return rpcScriptMethods[method];
|
|
48
|
+
return loadRpcPlugin(method);
|
|
49
|
+
};
|
|
27
50
|
export const pluginExtendCli = async (y)=>{
|
|
28
51
|
for (const plugin of plugins){
|
|
29
52
|
const location = new URL(`${plugin}/index.js`, import.meta.url);
|
package/dist/esm/rpc/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ResponseError, allHandlers as coreHandlers, defaultLogger } from '@acala-network/chopsticks-core';
|
|
2
|
-
import {
|
|
2
|
+
import { getRpcExtensionMethods, loadRpcExtensionMethod } from '../plugins/index.js';
|
|
3
3
|
const rpcLogger = defaultLogger.child({
|
|
4
4
|
name: 'rpc'
|
|
5
5
|
});
|
|
@@ -9,15 +9,15 @@ const allHandlers = {
|
|
|
9
9
|
version: 1,
|
|
10
10
|
methods: [
|
|
11
11
|
...Object.keys(allHandlers),
|
|
12
|
-
...
|
|
12
|
+
...getRpcExtensionMethods()
|
|
13
13
|
].sort()
|
|
14
14
|
})
|
|
15
15
|
};
|
|
16
16
|
const getHandler = async (method)=>{
|
|
17
17
|
const handler = allHandlers[method];
|
|
18
18
|
if (!handler) {
|
|
19
|
-
// no handler for this method, check if it's a plugin
|
|
20
|
-
return
|
|
19
|
+
// no handler for this method, check if it's a plugin or a script loaded
|
|
20
|
+
return loadRpcExtensionMethod(method);
|
|
21
21
|
}
|
|
22
22
|
return handler;
|
|
23
23
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acala-network/chopsticks",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
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.
|
|
17
|
-
"@acala-network/chopsticks-db": "0.
|
|
16
|
+
"@acala-network/chopsticks-core": "0.11.0",
|
|
17
|
+
"@acala-network/chopsticks-db": "0.11.0",
|
|
18
18
|
"@pnpm/npm-conf": "^2.2.2",
|
|
19
19
|
"@polkadot/api-augment": "^10.11.2",
|
|
20
20
|
"@polkadot/types": "^10.11.2",
|