@acala-network/chopsticks 0.6.0 → 0.6.2

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.
Files changed (2) hide show
  1. package/lib/cli.js +63 -39
  2. package/package.json +5 -4
package/lib/cli.js CHANGED
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const node_path_1 = require("node:path");
6
7
  const helpers_1 = require("yargs/helpers");
7
8
  const node_fs_1 = require("node:fs");
8
9
  const lodash_1 = __importDefault(require("lodash"));
@@ -16,16 +17,33 @@ const decoder_1 = require("./utils/decoder");
16
17
  const dry_run_1 = require("./dry-run");
17
18
  const dry_run_preimage_1 = require("./dry-run-preimage");
18
19
  const utils_1 = require("./utils");
20
+ const shared_1 = require("./rpc/shared");
19
21
  const run_block_1 = require("./run-block");
20
22
  const try_runtime_1 = require("./try-runtime");
21
23
  dotenv_1.default.config();
24
+ const CONFIGS_BASE_URL = 'https://raw.githubusercontent.com/AcalaNetwork/chopsticks/master/configs/';
22
25
  const processConfig = async (path) => {
23
26
  let file;
24
27
  if ((0, utils_1.isUrl)(path)) {
25
28
  file = await axios_1.default.get(path).then((x) => x.data);
26
29
  }
27
30
  else {
28
- file = (0, node_fs_1.readFileSync)(path, 'utf8');
31
+ try {
32
+ file = (0, node_fs_1.readFileSync)(path, 'utf8');
33
+ }
34
+ catch (err) {
35
+ if ((0, node_path_1.basename)(path) === path && ['', '.yml', '.yaml', '.json'].includes((0, node_path_1.extname)(path))) {
36
+ if ((0, node_path_1.extname)(path) === '') {
37
+ path += '.yml';
38
+ }
39
+ const url = CONFIGS_BASE_URL + path;
40
+ shared_1.logger.info(`Loading config file ${url}`);
41
+ file = await axios_1.default.get(url).then((x) => x.data);
42
+ }
43
+ else {
44
+ throw err;
45
+ }
46
+ }
29
47
  }
30
48
  const config = js_yaml_1.default.load(lodash_1.default.template(file, { variable: 'env' })(process.env));
31
49
  return schema_1.configSchema.parse(config);
@@ -63,18 +81,43 @@ const defaultOptions = {
63
81
  number: true,
64
82
  },
65
83
  };
84
+ const mockOptions = {
85
+ 'import-storage': {
86
+ desc: 'Pre-defined JSON/YAML storage file path',
87
+ string: true,
88
+ },
89
+ 'mock-signature-host': {
90
+ desc: 'Mock signature host so any signature starts with 0xdeadbeef and filled by 0xcd is considered valid',
91
+ boolean: true,
92
+ },
93
+ };
66
94
  (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
67
95
  .scriptName('chopsticks')
96
+ .command('*', 'Dev mode, fork off a chain', (yargs) => yargs.options({
97
+ ...defaultOptions,
98
+ ...mockOptions,
99
+ port: {
100
+ desc: 'Port to listen on',
101
+ number: true,
102
+ },
103
+ 'build-block-mode': {
104
+ desc: 'Build block mode. Default to Batch',
105
+ enum: [_1.BuildBlockMode.Batch, _1.BuildBlockMode.Manual, _1.BuildBlockMode.Instant],
106
+ },
107
+ 'allow-unresolved-imports': {
108
+ desc: 'Allow wasm unresolved imports',
109
+ boolean: true,
110
+ },
111
+ }), async (argv) => {
112
+ await (0, _1.setupWithServer)(await processArgv(argv));
113
+ })
68
114
  .command('run-block', 'Replay a block', (yargs) => yargs.options({
69
115
  ...defaultOptions,
116
+ ...mockOptions,
70
117
  'output-path': {
71
118
  desc: 'File path to print output',
72
119
  string: true,
73
120
  },
74
- 'import-storage': {
75
- desc: 'Pre-defined JSON/YAML storage file path',
76
- string: true,
77
- },
78
121
  html: {
79
122
  desc: 'Generate html with storage diff',
80
123
  },
@@ -140,31 +183,6 @@ const defaultOptions = {
140
183
  else {
141
184
  await (0, dry_run_1.dryRun)(config);
142
185
  }
143
- })
144
- .command('dev', 'Dev mode', (yargs) => yargs.options({
145
- ...defaultOptions,
146
- port: {
147
- desc: 'Port to listen on',
148
- number: true,
149
- },
150
- 'build-block-mode': {
151
- desc: 'Build block mode. Default to Batch',
152
- enum: [_1.BuildBlockMode.Batch, _1.BuildBlockMode.Manual, _1.BuildBlockMode.Instant],
153
- },
154
- 'import-storage': {
155
- desc: 'Pre-defined JSON/YAML storage file path',
156
- string: true,
157
- },
158
- 'mock-signature-host': {
159
- desc: 'Mock signature host so any signature starts with 0xdeadbeef and filled by 0xcd is considered valid',
160
- boolean: true,
161
- },
162
- 'allow-unresolved-imports': {
163
- desc: 'Allow wasm unresolved imports',
164
- boolean: true,
165
- },
166
- }), async (argv) => {
167
- await (0, _1.setupWithServer)(await processArgv(argv));
168
186
  })
169
187
  .command('decode-key <key>', 'Deocde a key', (yargs) => yargs
170
188
  .positional('key', {
@@ -184,7 +202,8 @@ const defaultOptions = {
184
202
  }
185
203
  process.exit(0);
186
204
  })
187
- .command('xcm', 'XCM setup with relaychain and parachains', (yargs) => yargs.options({
205
+ .command('xcm', 'XCM setup with relaychain and parachains', (yargs) => yargs
206
+ .options({
188
207
  relaychain: {
189
208
  desc: 'Relaychain config file path',
190
209
  string: true,
@@ -195,7 +214,9 @@ const defaultOptions = {
195
214
  string: true,
196
215
  required: true,
197
216
  },
198
- }), async (argv) => {
217
+ })
218
+ .alias('relaychain', 'r')
219
+ .alias('parachain', 'p'), async (argv) => {
199
220
  const parachains = [];
200
221
  for (const config of argv.parachain) {
201
222
  const { chain } = await (0, _1.setupWithServer)(await processConfig(config));
@@ -210,13 +231,16 @@ const defaultOptions = {
210
231
  await (0, _1.connectVertical)(relaychain, parachain);
211
232
  }
212
233
  }
213
- })
214
- .command({
215
- command: '*',
216
- handler() {
217
- yargs_1.default.showHelp();
218
- },
219
234
  })
220
235
  .strict()
221
236
  .help()
222
- .alias('help', 'h').argv;
237
+ .alias('help', 'h')
238
+ .alias('version', 'v')
239
+ .alias('config', 'c')
240
+ .alias('endpoint', 'e')
241
+ .alias('port', 'p')
242
+ .alias('block', 'b')
243
+ .alias('import-storage', 's')
244
+ .alias('wasm-override', 'w')
245
+ .usage('Usage: $0 <command> [options]')
246
+ .example('$0', '-c acala').argv;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acala-network/chopsticks",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "author": "Bryan Chen <xlchen1291@gmail.com>",
5
5
  "license": "Apache-2.0",
6
6
  "bin": "./chopsticks.js",
@@ -11,11 +11,12 @@
11
11
  "script:run": "cd ../..; LOG_LEVEL=trace ts-node-dev --transpile-only --inspect --notify=false packages/chopsticks/src/cli.ts -- dev --config=configs/dev.yml",
12
12
  "dev:karura": "cd ../..; ts-node-dev --transpile-only --inspect --notify=false packages/chopsticks/src/cli.ts -- dev --config=configs/karura.yml",
13
13
  "dev:acala": "cd ../..; ts-node-dev --transpile-only --inspect --notify=false packages/chopsticks/src/cli.ts -- dev --config=configs/acala.yml",
14
+ "dev:polkadot": "cd ../..; ts-node-dev --transpile-only --inspect --notify=false packages/chopsticks/src/cli.ts -- dev --config=configs/polkadot.yml",
14
15
  "dev:moonriver": "cd ../..; ts-node-dev --transpile-only --inspect --notify=false packages/chopsticks/src/cli.ts -- dev --config=configs/moonriver.yml",
15
16
  "dev:moonbeam": "cd ../..; ts-node-dev --transpile-only --inspect --notify=false packages/chopsticks/src/cli.ts -- dev --config=configs/moonbeam.yml"
16
17
  },
17
18
  "dependencies": {
18
- "@acala-network/chopsticks-executor": "0.6.0",
19
+ "@acala-network/chopsticks-executor": "0.6.2",
19
20
  "@polkadot/api": "^10.2.1",
20
21
  "@polkadot/rpc-provider": "^10.2.1",
21
22
  "@polkadot/types": "^10.2.1",
@@ -39,12 +40,12 @@
39
40
  "devDependencies": {
40
41
  "@types/js-yaml": "^4.0.5",
41
42
  "@types/lodash": "^4.14.192",
42
- "@types/node": "^18.15.10",
43
+ "@types/node": "^18.15.11",
43
44
  "@types/ws": "^8.5.4",
44
45
  "@types/yargs": "^17.0.24",
45
46
  "ts-node": "^10.9.1",
46
47
  "ts-node-dev": "^2.0.0",
47
- "typescript": "^5.0.2"
48
+ "typescript": "^5.0.3"
48
49
  },
49
50
  "files": [
50
51
  "lib",