@acala-network/chopsticks 0.7.2 → 0.8.0-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.
Files changed (116) hide show
  1. package/lib/cli-options.d.ts +40 -0
  2. package/lib/cli-options.js +43 -0
  3. package/lib/cli.d.ts +1 -2
  4. package/lib/cli.js +20 -183
  5. package/lib/context.d.ts +5 -0
  6. package/lib/context.js +37 -0
  7. package/lib/index.d.ts +2 -7
  8. package/lib/index.js +4 -15
  9. package/lib/logger.d.ts +1 -7
  10. package/lib/logger.js +3 -38
  11. package/lib/plugins/decode-key/index.d.ts +2 -0
  12. package/lib/plugins/decode-key/index.js +27 -0
  13. package/lib/plugins/dry-run/cli.d.ts +2 -0
  14. package/lib/plugins/dry-run/cli.js +46 -0
  15. package/lib/plugins/dry-run/dry-run-extrinsic.d.ts +2 -0
  16. package/lib/{dry-run.js → plugins/dry-run/dry-run-extrinsic.js} +8 -8
  17. package/lib/{dry-run-preimage.d.ts → plugins/dry-run/dry-run-preimage.d.ts} +1 -1
  18. package/lib/{dry-run-preimage.js → plugins/dry-run/dry-run-preimage.js} +10 -12
  19. package/lib/plugins/dry-run/index.d.ts +2 -0
  20. package/lib/plugins/dry-run/index.js +18 -0
  21. package/lib/plugins/dry-run/rpc.d.ts +3 -0
  22. package/lib/{rpc/dev/dry-run.js → plugins/dry-run/rpc.js} +10 -7
  23. package/lib/plugins/index.d.ts +4 -0
  24. package/lib/plugins/index.js +52 -0
  25. package/lib/plugins/new-block/index.d.ts +2 -0
  26. package/lib/plugins/new-block/index.js +28 -0
  27. package/lib/plugins/run-block/index.d.ts +2 -0
  28. package/lib/plugins/run-block/index.js +67 -0
  29. package/lib/plugins/set-block-build-mode/index.d.ts +2 -0
  30. package/lib/plugins/set-block-build-mode/index.js +14 -0
  31. package/lib/plugins/set-head/index.d.ts +2 -0
  32. package/lib/plugins/set-head/index.js +20 -0
  33. package/lib/plugins/set-storage/index.d.ts +2 -0
  34. package/lib/plugins/set-storage/index.js +18 -0
  35. package/lib/plugins/time-travel/index.d.ts +2 -0
  36. package/lib/plugins/time-travel/index.js +13 -0
  37. package/lib/plugins/try-runtime/index.d.ts +2 -0
  38. package/lib/plugins/try-runtime/index.js +58 -0
  39. package/lib/rpc/index.d.ts +1 -1
  40. package/lib/rpc/index.js +11 -4
  41. package/lib/rpc/shared.d.ts +1 -1
  42. package/lib/rpc/shared.js +1 -1
  43. package/lib/rpc/substrate/author.js +3 -3
  44. package/lib/schema/index.d.ts +9 -66
  45. package/lib/schema/index.js +41 -14
  46. package/lib/server.js +2 -1
  47. package/lib/setup-with-server.d.ts +1 -3
  48. package/lib/setup-with-server.js +2 -2
  49. package/lib/utils/decoder.d.ts +1 -1
  50. package/lib/utils/generate-html-diff.d.ts +1 -1
  51. package/lib/utils/override.d.ts +4 -0
  52. package/lib/utils/{import-storage.js → override.js} +6 -6
  53. package/package.json +13 -16
  54. package/lib/api.d.ts +0 -43
  55. package/lib/api.js +0 -79
  56. package/lib/blockchain/block-builder.d.ts +0 -10
  57. package/lib/blockchain/block-builder.js +0 -297
  58. package/lib/blockchain/block.d.ts +0 -45
  59. package/lib/blockchain/block.js +0 -194
  60. package/lib/blockchain/head-state.d.ts +0 -15
  61. package/lib/blockchain/head-state.js +0 -71
  62. package/lib/blockchain/index.d.ts +0 -64
  63. package/lib/blockchain/index.js +0 -243
  64. package/lib/blockchain/inherent/index.d.ts +0 -19
  65. package/lib/blockchain/inherent/index.js +0 -36
  66. package/lib/blockchain/inherent/para-enter.d.ts +0 -7
  67. package/lib/blockchain/inherent/para-enter.js +0 -33
  68. package/lib/blockchain/inherent/parachain/babe-randomness.d.ts +0 -7
  69. package/lib/blockchain/inherent/parachain/babe-randomness.js +0 -15
  70. package/lib/blockchain/inherent/parachain/nimbus-author-inherent.d.ts +0 -7
  71. package/lib/blockchain/inherent/parachain/nimbus-author-inherent.js +0 -15
  72. package/lib/blockchain/inherent/parachain/validation-data.d.ts +0 -19
  73. package/lib/blockchain/inherent/parachain/validation-data.js +0 -172
  74. package/lib/blockchain/storage-layer.d.ts +0 -32
  75. package/lib/blockchain/storage-layer.js +0 -200
  76. package/lib/blockchain/txpool.d.ts +0 -45
  77. package/lib/blockchain/txpool.js +0 -184
  78. package/lib/db/entities.d.ts +0 -5
  79. package/lib/db/entities.js +0 -33
  80. package/lib/db/index.d.ts +0 -3
  81. package/lib/db/index.js +0 -41
  82. package/lib/dry-run.d.ts +0 -2
  83. package/lib/executor.d.ts +0 -40
  84. package/lib/executor.js +0 -131
  85. package/lib/genesis-provider.d.ts +0 -44
  86. package/lib/genesis-provider.js +0 -155
  87. package/lib/offchain.d.ts +0 -10
  88. package/lib/offchain.js +0 -37
  89. package/lib/rpc/dev/dry-run.d.ts +0 -2
  90. package/lib/rpc/dev/index.d.ts +0 -3
  91. package/lib/rpc/dev/index.js +0 -75
  92. package/lib/run-block.d.ts +0 -2
  93. package/lib/run-block.js +0 -51
  94. package/lib/setup.d.ts +0 -11
  95. package/lib/setup.js +0 -86
  96. package/lib/try-runtime.d.ts +0 -2
  97. package/lib/try-runtime.js +0 -36
  98. package/lib/utils/import-storage.d.ts +0 -5
  99. package/lib/utils/index.d.ts +0 -16
  100. package/lib/utils/index.js +0 -59
  101. package/lib/utils/key-cache.d.ts +0 -10
  102. package/lib/utils/key-cache.js +0 -66
  103. package/lib/utils/proof.d.ts +0 -15
  104. package/lib/utils/proof.js +0 -41
  105. package/lib/utils/set-storage.d.ts +0 -7
  106. package/lib/utils/set-storage.js +0 -59
  107. package/lib/utils/time-travel.d.ts +0 -5
  108. package/lib/utils/time-travel.js +0 -65
  109. package/lib/xcm/downward.d.ts +0 -2
  110. package/lib/xcm/downward.js +0 -29
  111. package/lib/xcm/horizontal.d.ts +0 -2
  112. package/lib/xcm/horizontal.js +0 -29
  113. package/lib/xcm/index.d.ts +0 -9
  114. package/lib/xcm/index.js +0 -25
  115. package/lib/xcm/upward.d.ts +0 -2
  116. package/lib/xcm/upward.js +0 -21
@@ -0,0 +1,40 @@
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
+ };
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mockOptions = exports.defaultOptions = void 0;
4
+ exports.defaultOptions = {
5
+ endpoint: {
6
+ desc: 'Endpoint to connect to',
7
+ string: true,
8
+ },
9
+ block: {
10
+ desc: 'Block hash or block number. Default to latest block',
11
+ string: true,
12
+ },
13
+ 'wasm-override': {
14
+ desc: 'Path to wasm override',
15
+ string: true,
16
+ },
17
+ db: {
18
+ desc: 'Path to database',
19
+ string: true,
20
+ },
21
+ config: {
22
+ desc: 'Path to config file with default options',
23
+ string: true,
24
+ },
25
+ 'runtime-log-level': {
26
+ desc: 'Runtime maximum log level [off = 0; error = 1; warn = 2; info = 3; debug = 4; trace = 5]',
27
+ number: true,
28
+ },
29
+ 'offchain-worker': {
30
+ desc: 'Enable offchain worker',
31
+ boolean: true,
32
+ },
33
+ };
34
+ exports.mockOptions = {
35
+ 'import-storage': {
36
+ desc: 'Pre-defined JSON/YAML storage file path',
37
+ string: true,
38
+ },
39
+ 'mock-signature-host': {
40
+ desc: 'Mock signature host so any signature starts with 0xdeadbeef and filled by 0xcd is considered valid',
41
+ boolean: true,
42
+ },
43
+ };
package/lib/cli.d.ts CHANGED
@@ -1,2 +1 @@
1
- import { Config } from './schema';
2
- export declare const fetchConfig: (path: string) => Promise<Config>;
1
+ export {};
package/lib/cli.js CHANGED
@@ -3,210 +3,46 @@ 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
- exports.fetchConfig = void 0;
7
- const node_path_1 = require("node:path");
8
6
  const dotenv_1 = require("dotenv");
9
7
  const helpers_1 = require("yargs/helpers");
10
- const node_fs_1 = require("node:fs");
11
8
  const lodash_1 = __importDefault(require("lodash"));
12
- const axios_1 = __importDefault(require("axios"));
13
- const js_yaml_1 = __importDefault(require("js-yaml"));
14
9
  const yargs_1 = __importDefault(require("yargs"));
15
- const _1 = require(".");
10
+ const chopsticks_core_1 = require("@acala-network/chopsticks-core");
16
11
  const schema_1 = require("./schema");
17
- const decoder_1 = require("./utils/decoder");
18
- const dry_run_1 = require("./dry-run");
19
- const dry_run_preimage_1 = require("./dry-run-preimage");
20
- const utils_1 = require("./utils");
21
- const shared_1 = require("./rpc/shared");
22
- const run_block_1 = require("./run-block");
23
- const try_runtime_1 = require("./try-runtime");
12
+ const cli_options_1 = require("./cli-options");
13
+ const plugins_1 = require("./plugins");
14
+ const _1 = require(".");
24
15
  (0, dotenv_1.config)();
25
- const CONFIGS_BASE_URL = 'https://raw.githubusercontent.com/AcalaNetwork/chopsticks/master/configs/';
26
- const fetchConfig = async (path) => {
27
- let file;
28
- if ((0, utils_1.isUrl)(path)) {
29
- file = await axios_1.default.get(path).then((x) => x.data);
30
- }
31
- else {
32
- try {
33
- file = (0, node_fs_1.readFileSync)(path, 'utf8');
34
- }
35
- catch (err) {
36
- if ((0, node_path_1.basename)(path) === path && ['', '.yml', '.yaml', '.json'].includes((0, node_path_1.extname)(path))) {
37
- if ((0, node_path_1.extname)(path) === '') {
38
- path += '.yml';
39
- }
40
- const url = CONFIGS_BASE_URL + path;
41
- shared_1.logger.info(`Loading config file ${url}`);
42
- file = await axios_1.default.get(url).then((x) => x.data);
43
- }
44
- else {
45
- throw err;
46
- }
47
- }
48
- }
49
- const config = js_yaml_1.default.load(lodash_1.default.template(file, { variable: 'env' })(process.env));
50
- return schema_1.configSchema.parse(config);
51
- };
52
- exports.fetchConfig = fetchConfig;
53
16
  const processArgv = async (argv) => {
54
17
  if (argv.config) {
55
- argv = { ...(await (0, exports.fetchConfig)(argv.config)), ...argv };
18
+ Object.assign(argv, lodash_1.default.defaults(argv, await (0, schema_1.fetchConfig)(argv.config)));
56
19
  }
57
20
  argv.port = argv.port ?? (process.env.PORT ? Number(process.env.PORT) : 8000);
58
- return argv;
59
- };
60
- const defaultOptions = {
61
- endpoint: {
62
- desc: 'Endpoint to connect to',
63
- string: true,
64
- },
65
- block: {
66
- desc: 'Block hash or block number. Default to latest block',
67
- string: true,
68
- },
69
- 'wasm-override': {
70
- desc: 'Path to wasm override',
71
- string: true,
72
- },
73
- db: {
74
- desc: 'Path to database',
75
- string: true,
76
- },
77
- config: {
78
- desc: 'Path to config file',
79
- string: true,
80
- },
81
- 'runtime-log-level': {
82
- desc: 'Runtime maximum log level [off = 0; error = 1; warn = 2; info = 3; debug = 4; trace = 5]',
83
- number: true,
84
- },
85
- 'offchain-worker': {
86
- desc: 'Enable offchain worker',
87
- boolean: true,
88
- },
89
- };
90
- const mockOptions = {
91
- 'import-storage': {
92
- desc: 'Pre-defined JSON/YAML storage file path',
93
- string: true,
94
- },
95
- 'mock-signature-host': {
96
- desc: 'Mock signature host so any signature starts with 0xdeadbeef and filled by 0xcd is considered valid',
97
- boolean: true,
98
- },
99
21
  };
100
- (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
22
+ const commands = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
101
23
  .scriptName('chopsticks')
24
+ .middleware(processArgv, true)
102
25
  .command('*', 'Dev mode, fork off a chain', (yargs) => yargs.options({
103
- ...defaultOptions,
104
- ...mockOptions,
26
+ ...cli_options_1.defaultOptions,
27
+ ...cli_options_1.mockOptions,
105
28
  port: {
106
29
  desc: 'Port to listen on',
107
30
  number: true,
108
31
  },
109
32
  'build-block-mode': {
110
33
  desc: 'Build block mode. Default to Batch',
111
- enum: [_1.BuildBlockMode.Batch, _1.BuildBlockMode.Manual, _1.BuildBlockMode.Instant],
34
+ enum: [chopsticks_core_1.BuildBlockMode.Batch, chopsticks_core_1.BuildBlockMode.Manual, chopsticks_core_1.BuildBlockMode.Instant],
112
35
  },
113
36
  'allow-unresolved-imports': {
114
37
  desc: 'Allow wasm unresolved imports',
115
38
  boolean: true,
116
39
  },
117
- }), async (argv) => {
118
- await (0, _1.setupWithServer)(await processArgv(argv));
119
- })
120
- .command('run-block', 'Replay a block', (yargs) => yargs.options({
121
- ...defaultOptions,
122
- ...mockOptions,
123
- 'output-path': {
124
- desc: 'File path to print output',
125
- string: true,
126
- },
127
- html: {
128
- desc: 'Generate html with storage diff',
129
- },
130
- open: {
131
- desc: 'Open generated html',
132
- },
133
- }), async (argv) => {
134
- await (0, run_block_1.runBlock)(await processArgv(argv));
135
- })
136
- .command('try-runtime', 'Runs runtime upgrade', (yargs) => yargs.options({
137
- ...defaultOptions,
138
- 'wasm-override': {
139
- desc: 'Path to WASM built with feature `try-runtime` enabled',
140
- string: true,
141
- required: true,
142
- },
143
- 'output-path': {
144
- desc: 'File path to print output',
145
- string: true,
146
- },
147
- html: {
148
- desc: 'Generate html with storage diff',
149
- },
150
- open: {
151
- desc: 'Open generated html',
152
- },
153
- }), async (argv) => {
154
- await (0, try_runtime_1.tryRuntime)(await processArgv(argv));
155
- })
156
- .command('dry-run', 'Dry run an extrinsic', (yargs) => yargs.options({
157
- ...defaultOptions,
158
- extrinsic: {
159
- desc: 'Extrinsic or call to dry run. If you pass call here then address is required to fake signature',
160
- string: true,
161
- },
162
- address: {
163
- desc: 'Address to fake sign extrinsic',
164
- string: true,
165
- },
166
- preimage: {
167
- desc: 'Preimage to dry run',
168
- string: true,
169
- },
170
- at: {
171
- desc: 'Block hash to dry run',
172
- string: true,
173
- },
174
- 'output-path': {
175
- desc: 'File path to print output',
176
- string: true,
177
- },
178
- html: {
179
- desc: 'Generate html with storage diff',
180
- },
181
- open: {
182
- desc: 'Open generated html',
40
+ 'max-memory-block-count': {
41
+ desc: 'Max memory block count',
42
+ number: true,
183
43
  },
184
44
  }), async (argv) => {
185
- const config = await processArgv(argv);
186
- if (config.preimage) {
187
- await (0, dry_run_preimage_1.dryRunPreimage)(config);
188
- }
189
- else {
190
- await (0, dry_run_1.dryRun)(config);
191
- }
192
- })
193
- .command('decode-key <key>', 'Deocde a key', (yargs) => yargs
194
- .positional('key', {
195
- desc: 'Key to decode',
196
- type: 'string',
197
- })
198
- .options({
199
- ...defaultOptions,
200
- }), async (argv) => {
201
- const context = await (0, _1.setup)(await processArgv(argv));
202
- const { storage, decodedKey } = (0, decoder_1.decodeKey)(await context.chain.head.meta, context.chain.head, argv.key);
203
- if (storage && decodedKey) {
204
- console.log(`${storage.section}.${storage.method}`, decodedKey.args.map((x) => JSON.stringify(x.toHuman())).join(', '));
205
- }
206
- else {
207
- console.log('Unknown');
208
- }
209
- process.exit(0);
45
+ await (0, _1.setupWithServer)(argv);
210
46
  })
211
47
  .command('xcm', 'XCM setup with relaychain and parachains', (yargs) => yargs
212
48
  .options({
@@ -225,16 +61,16 @@ const mockOptions = {
225
61
  .alias('parachain', 'p'), async (argv) => {
226
62
  const parachains = [];
227
63
  for (const config of argv.parachain) {
228
- const { chain } = await (0, _1.setupWithServer)(await (0, exports.fetchConfig)(config));
64
+ const { chain } = await (0, _1.setupWithServer)(await (0, schema_1.fetchConfig)(config));
229
65
  parachains.push(chain);
230
66
  }
231
67
  if (parachains.length > 1) {
232
- await (0, _1.connectParachains)(parachains);
68
+ await (0, chopsticks_core_1.connectParachains)(parachains);
233
69
  }
234
70
  if (argv.relaychain) {
235
- const { chain: relaychain } = await (0, _1.setupWithServer)(await (0, exports.fetchConfig)(argv.relaychain));
71
+ const { chain: relaychain } = await (0, _1.setupWithServer)(await (0, schema_1.fetchConfig)(argv.relaychain));
236
72
  for (const parachain of parachains) {
237
- await (0, _1.connectVertical)(relaychain, parachain);
73
+ await (0, chopsticks_core_1.connectVertical)(relaychain, parachain);
238
74
  }
239
75
  }
240
76
  })
@@ -249,4 +85,5 @@ const mockOptions = {
249
85
  .alias('import-storage', 's')
250
86
  .alias('wasm-override', 'w')
251
87
  .usage('Usage: $0 <command> [options]')
252
- .example('$0', '-c acala').argv;
88
+ .example('$0', '-c acala');
89
+ (0, plugins_1.pluginExtendCli)(commands).then(() => commands.parse());
@@ -0,0 +1,5 @@
1
+ import './utils/tunnel';
2
+ import { Config } from './schema';
3
+ export declare const setupContext: (argv: Config, overrideParent?: boolean) => Promise<{
4
+ chain: import("@acala-network/chopsticks-core").Blockchain;
5
+ }>;
package/lib/context.js ADDED
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setupContext = void 0;
4
+ require("./utils/tunnel");
5
+ const override_1 = require("./utils/override");
6
+ const chopsticks_core_1 = require("@acala-network/chopsticks-core");
7
+ const setupContext = async (argv, overrideParent = false) => {
8
+ const chain = await (0, chopsticks_core_1.setup)({
9
+ endpoint: argv.endpoint,
10
+ block: argv.block,
11
+ genesis: argv.genesis,
12
+ buildBlockMode: argv['build-block-mode'],
13
+ db: argv.db,
14
+ mockSignatureHost: argv['mock-signature-host'],
15
+ allowUnresolvedImports: argv['allow-unresolved-imports'],
16
+ runtimeLogLevel: argv['runtime-log-level'],
17
+ registeredTypes: argv['registered-types'],
18
+ offchainWorker: argv['offchain-worker'],
19
+ maxMemoryBlockCount: argv['max-memory-block-count'],
20
+ });
21
+ if (argv.timestamp)
22
+ await (0, chopsticks_core_1.timeTravel)(chain, argv.timestamp);
23
+ let at;
24
+ if (overrideParent) {
25
+ // in case of run block we need to apply wasm-override and import-storage to parent block
26
+ const block = await chain.head.parentBlock;
27
+ if (!block)
28
+ throw new Error('Cannot find parent block');
29
+ at = block.hash;
30
+ }
31
+ // override wasm before importing storage, in case new pallets have been
32
+ // added that have storage imports
33
+ await (0, override_1.overrideStorage)(chain, argv['import-storage'], at);
34
+ await (0, override_1.overrideWasm)(chain, argv['wasm-override'], at);
35
+ return { chain };
36
+ };
37
+ exports.setupContext = setupContext;
package/lib/index.d.ts CHANGED
@@ -1,8 +1,3 @@
1
- export { Api } from './api';
2
- export { Blockchain } from './blockchain';
3
- export { BuildBlockMode } from './blockchain/txpool';
4
- export { connectParachains, connectVertical } from './xcm';
5
- export { setup } from './setup';
1
+ export * from '@acala-network/chopsticks-core';
6
2
  export { setupWithServer } from './setup-with-server';
7
- export { fetchConfig } from './cli';
8
- export * from './blockchain/inherent';
3
+ export { fetchConfig } from './schema';
package/lib/index.js CHANGED
@@ -14,20 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.fetchConfig = exports.setupWithServer = exports.setup = exports.connectVertical = exports.connectParachains = exports.BuildBlockMode = exports.Blockchain = exports.Api = void 0;
18
- var api_1 = require("./api");
19
- Object.defineProperty(exports, "Api", { enumerable: true, get: function () { return api_1.Api; } });
20
- var blockchain_1 = require("./blockchain");
21
- Object.defineProperty(exports, "Blockchain", { enumerable: true, get: function () { return blockchain_1.Blockchain; } });
22
- var txpool_1 = require("./blockchain/txpool");
23
- Object.defineProperty(exports, "BuildBlockMode", { enumerable: true, get: function () { return txpool_1.BuildBlockMode; } });
24
- var xcm_1 = require("./xcm");
25
- Object.defineProperty(exports, "connectParachains", { enumerable: true, get: function () { return xcm_1.connectParachains; } });
26
- Object.defineProperty(exports, "connectVertical", { enumerable: true, get: function () { return xcm_1.connectVertical; } });
27
- var setup_1 = require("./setup");
28
- Object.defineProperty(exports, "setup", { enumerable: true, get: function () { return setup_1.setup; } });
17
+ exports.fetchConfig = exports.setupWithServer = void 0;
18
+ __exportStar(require("@acala-network/chopsticks-core"), exports);
29
19
  var setup_with_server_1 = require("./setup-with-server");
30
20
  Object.defineProperty(exports, "setupWithServer", { enumerable: true, get: function () { return setup_with_server_1.setupWithServer; } });
31
- var cli_1 = require("./cli");
32
- Object.defineProperty(exports, "fetchConfig", { enumerable: true, get: function () { return cli_1.fetchConfig; } });
33
- __exportStar(require("./blockchain/inherent"), exports);
21
+ var schema_1 = require("./schema");
22
+ Object.defineProperty(exports, "fetchConfig", { enumerable: true, get: function () { return schema_1.fetchConfig; } });
package/lib/logger.d.ts CHANGED
@@ -1,7 +1 @@
1
- export declare const defaultLogger: import("pino").Logger<{
2
- level: string;
3
- transport: {
4
- target: string;
5
- };
6
- }>;
7
- export declare const truncate: (val: any) => any;
1
+ export { defaultLogger, truncate } from '@acala-network/chopsticks-core';
package/lib/logger.js CHANGED
@@ -1,41 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.truncate = exports.defaultLogger = void 0;
7
- const pino_1 = __importDefault(require("pino"));
8
- exports.defaultLogger = (0, pino_1.default)({
9
- level: process.env.LOG_LEVEL || 'info',
10
- transport: {
11
- target: 'pino-pretty',
12
- },
13
- });
14
- const innerTruncate = (level = 0) => (val) => {
15
- const verboseLog = !!process.env.VERBOSE_LOG;
16
- const levelLimit = verboseLog ? 10 : 5;
17
- if (val == null) {
18
- return val;
19
- }
20
- if (level > levelLimit) {
21
- return '( Too Deep )';
22
- }
23
- switch (typeof val) {
24
- case 'string':
25
- if (val.length > 66 && !verboseLog) {
26
- return val.slice(0, 34) + '…' + val.slice(-32);
27
- }
28
- else {
29
- return val;
30
- }
31
- case 'object':
32
- if (Array.isArray(val)) {
33
- return val.map(innerTruncate(level + 1));
34
- }
35
- return Object.fromEntries(Object.entries(val.toJSON ? val.toJSON() : val).map(([k, v]) => [k, innerTruncate(level + 1)(v)]));
36
- default:
37
- return val;
38
- }
39
- };
40
- const truncate = (val) => innerTruncate(0)(val);
41
- exports.truncate = truncate;
4
+ var chopsticks_core_1 = require("@acala-network/chopsticks-core");
5
+ Object.defineProperty(exports, "defaultLogger", { enumerable: true, get: function () { return chopsticks_core_1.defaultLogger; } });
6
+ Object.defineProperty(exports, "truncate", { enumerable: true, get: function () { return chopsticks_core_1.truncate; } });
@@ -0,0 +1,2 @@
1
+ import type yargs from 'yargs';
2
+ export declare const cli: (y: yargs.Argv) => void;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cli = void 0;
4
+ const decoder_1 = require("../../utils/decoder");
5
+ const cli_options_1 = require("../../cli-options");
6
+ const context_1 = require("../../context");
7
+ const cli = (y) => {
8
+ y.command('decode-key <key>', 'Deocde a key', (yargs) => yargs
9
+ .positional('key', {
10
+ desc: 'Key to decode',
11
+ type: 'string',
12
+ })
13
+ .options({
14
+ ...cli_options_1.defaultOptions,
15
+ }), async (argv) => {
16
+ const context = await (0, context_1.setupContext)(argv);
17
+ const { storage, decodedKey } = (0, decoder_1.decodeKey)(await context.chain.head.meta, context.chain.head, argv.key);
18
+ if (storage && decodedKey) {
19
+ console.log(`${storage.section}.${storage.method}`, decodedKey.args.map((x) => JSON.stringify(x.toHuman())).join(', '));
20
+ }
21
+ else {
22
+ console.log('Unknown');
23
+ }
24
+ process.exit(0);
25
+ });
26
+ };
27
+ exports.cli = cli;
@@ -0,0 +1,2 @@
1
+ import type yargs from 'yargs';
2
+ export declare const cli: (y: yargs.Argv) => void;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cli = void 0;
4
+ const cli_options_1 = require("../../cli-options");
5
+ const dry_run_extrinsic_1 = require("./dry-run-extrinsic");
6
+ const dry_run_preimage_1 = require("./dry-run-preimage");
7
+ const cli = (y) => {
8
+ y.command('dry-run', 'Dry run an extrinsic', (yargs) => yargs.options({
9
+ ...cli_options_1.defaultOptions,
10
+ ...cli_options_1.mockOptions,
11
+ extrinsic: {
12
+ desc: 'Extrinsic or call to dry run. If you pass call here then address is required to fake signature',
13
+ string: true,
14
+ },
15
+ address: {
16
+ desc: 'Address to fake sign extrinsic',
17
+ string: true,
18
+ },
19
+ preimage: {
20
+ desc: 'Preimage to dry run',
21
+ string: true,
22
+ },
23
+ at: {
24
+ desc: 'Block hash to dry run',
25
+ string: true,
26
+ },
27
+ 'output-path': {
28
+ desc: 'File path to print output',
29
+ string: true,
30
+ },
31
+ html: {
32
+ desc: 'Generate html with storage diff',
33
+ },
34
+ open: {
35
+ desc: 'Open generated html',
36
+ },
37
+ }), async (argv) => {
38
+ if (argv.preimage) {
39
+ await (0, dry_run_preimage_1.dryRunPreimage)(argv);
40
+ }
41
+ else {
42
+ await (0, dry_run_extrinsic_1.dryRunExtrinsic)(argv);
43
+ }
44
+ });
45
+ };
46
+ exports.cli = cli;
@@ -0,0 +1,2 @@
1
+ import { Config } from '../../schema';
2
+ export declare const dryRunExtrinsic: (argv: Config) => Promise<never>;
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dryRun = void 0;
3
+ exports.dryRunExtrinsic = void 0;
4
4
  const util_crypto_1 = require("@polkadot/util-crypto");
5
5
  const node_fs_1 = require("node:fs");
6
- const logger_1 = require("./logger");
7
- const generate_html_diff_1 = require("./utils/generate-html-diff");
8
- const open_html_1 = require("./utils/open-html");
9
- const setup_1 = require("./setup");
10
- const dryRun = async (argv) => {
11
- const context = await (0, setup_1.setup)(argv);
6
+ const logger_1 = require("../../logger");
7
+ const generate_html_diff_1 = require("../../utils/generate-html-diff");
8
+ const open_html_1 = require("../../utils/open-html");
9
+ const context_1 = require("../../context");
10
+ const dryRunExtrinsic = async (argv) => {
11
+ const context = await (0, context_1.setupContext)(argv);
12
12
  const input = argv['address'] ? { call: argv['extrinsic'], address: argv['address'] } : argv['extrinsic'];
13
13
  const { outcome, storageDiff } = await context.chain.dryRunExtrinsic(input, argv['at']);
14
14
  if (outcome.isErr) {
@@ -30,4 +30,4 @@ const dryRun = async (argv) => {
30
30
  }
31
31
  process.exit(0);
32
32
  };
33
- exports.dryRun = dryRun;
33
+ exports.dryRunExtrinsic = dryRunExtrinsic;
@@ -1,2 +1,2 @@
1
- import { Config } from './schema';
1
+ import { Config } from '../../schema';
2
2
  export declare const dryRunPreimage: (argv: Config) => Promise<never>;
@@ -3,22 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.dryRunPreimage = void 0;
4
4
  const util_crypto_1 = require("@polkadot/util-crypto");
5
5
  const util_1 = require("@polkadot/util");
6
- const logger_1 = require("./logger");
7
- const generate_html_diff_1 = require("./utils/generate-html-diff");
8
- const block_builder_1 = require("./blockchain/block-builder");
9
- const open_html_1 = require("./utils/open-html");
10
- const executor_1 = require("./executor");
11
- const set_storage_1 = require("./utils/set-storage");
12
- const setup_1 = require("./setup");
6
+ const logger_1 = require("../../logger");
7
+ const generate_html_diff_1 = require("../../utils/generate-html-diff");
8
+ const chopsticks_core_1 = require("@acala-network/chopsticks-core");
9
+ const open_html_1 = require("../../utils/open-html");
10
+ const context_1 = require("../../context");
13
11
  const dryRunPreimage = async (argv) => {
14
- const context = await (0, setup_1.setup)(argv);
12
+ const context = await (0, context_1.setupContext)(argv);
15
13
  const extrinsic = argv['preimage'];
16
14
  const block = context.chain.head;
17
15
  const registry = await block.registry;
18
- const header = await (0, block_builder_1.newHeader)(block);
16
+ const header = await (0, chopsticks_core_1.newHeader)(block);
19
17
  const data = (0, util_1.hexToU8a)(extrinsic);
20
18
  const hash = (0, util_crypto_1.blake2AsHex)(data, 256);
21
- await (0, set_storage_1.setStorage)(context.chain, {
19
+ await (0, chopsticks_core_1.setStorage)(context.chain, {
22
20
  Preimage: {
23
21
  PreimageFor: [[[[hash, data.byteLength]], extrinsic]],
24
22
  StatusFor: [
@@ -61,13 +59,13 @@ const dryRunPreimage = async (argv) => {
61
59
  }
62
60
  calls.push(['BlockBuilder_finalize_block', []]);
63
61
  logger_1.defaultLogger.info({ preimage: registry.createType('Call', data).toHuman() }, 'Dry run preimage');
64
- const result = await (0, executor_1.runTask)({
62
+ const result = await (0, chopsticks_core_1.runTask)({
65
63
  wasm: await block.wasm,
66
64
  calls,
67
65
  mockSignatureHost: false,
68
66
  allowUnresolvedImports: false,
69
67
  runtimeLogLevel: argv['runtime-log-level'] || 0,
70
- }, (0, executor_1.taskHandler)(block));
68
+ }, (0, chopsticks_core_1.taskHandler)(block));
71
69
  if (result.Error) {
72
70
  throw new Error(result.Error);
73
71
  }
@@ -0,0 +1,2 @@
1
+ export * from './cli';
2
+ export * from './rpc';