@acala-network/chopsticks 0.7.3 → 0.8.0-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.
Files changed (115) hide show
  1. package/lib/cli-options.d.ts +40 -0
  2. package/lib/cli-options.js +43 -0
  3. package/lib/cli.js +19 -146
  4. package/lib/context.d.ts +5 -0
  5. package/lib/context.js +37 -0
  6. package/lib/index.d.ts +2 -7
  7. package/lib/index.js +2 -13
  8. package/lib/logger.d.ts +1 -7
  9. package/lib/logger.js +3 -38
  10. package/lib/plugins/decode-key/index.d.ts +2 -0
  11. package/lib/plugins/decode-key/index.js +27 -0
  12. package/lib/plugins/dry-run/cli.d.ts +2 -0
  13. package/lib/plugins/dry-run/cli.js +46 -0
  14. package/lib/plugins/dry-run/dry-run-extrinsic.d.ts +2 -0
  15. package/lib/{dry-run.js → plugins/dry-run/dry-run-extrinsic.js} +8 -8
  16. package/lib/{dry-run-preimage.d.ts → plugins/dry-run/dry-run-preimage.d.ts} +1 -1
  17. package/lib/{dry-run-preimage.js → plugins/dry-run/dry-run-preimage.js} +10 -12
  18. package/lib/plugins/dry-run/index.d.ts +2 -0
  19. package/lib/plugins/dry-run/index.js +18 -0
  20. package/lib/plugins/dry-run/rpc.d.ts +3 -0
  21. package/lib/{rpc/dev/dry-run.js → plugins/dry-run/rpc.js} +10 -7
  22. package/lib/plugins/index.d.ts +4 -0
  23. package/lib/plugins/index.js +52 -0
  24. package/lib/plugins/new-block/index.d.ts +2 -0
  25. package/lib/plugins/new-block/index.js +28 -0
  26. package/lib/plugins/run-block/index.d.ts +2 -0
  27. package/lib/plugins/run-block/index.js +67 -0
  28. package/lib/plugins/set-block-build-mode/index.d.ts +2 -0
  29. package/lib/plugins/set-block-build-mode/index.js +14 -0
  30. package/lib/plugins/set-head/index.d.ts +2 -0
  31. package/lib/plugins/set-head/index.js +20 -0
  32. package/lib/plugins/set-storage/index.d.ts +2 -0
  33. package/lib/plugins/set-storage/index.js +18 -0
  34. package/lib/plugins/time-travel/index.d.ts +2 -0
  35. package/lib/plugins/time-travel/index.js +13 -0
  36. package/lib/plugins/try-runtime/index.d.ts +2 -0
  37. package/lib/plugins/try-runtime/index.js +58 -0
  38. package/lib/rpc/index.d.ts +1 -1
  39. package/lib/rpc/index.js +11 -4
  40. package/lib/rpc/shared.d.ts +1 -1
  41. package/lib/rpc/shared.js +1 -1
  42. package/lib/rpc/substrate/author.js +3 -3
  43. package/lib/schema/index.d.ts +8 -66
  44. package/lib/schema/index.js +7 -18
  45. package/lib/server.js +2 -1
  46. package/lib/setup-with-server.d.ts +1 -3
  47. package/lib/setup-with-server.js +2 -2
  48. package/lib/utils/decoder.d.ts +1 -1
  49. package/lib/utils/generate-html-diff.d.ts +1 -1
  50. package/lib/utils/override.d.ts +4 -0
  51. package/lib/utils/{import-storage.js → override.js} +6 -6
  52. package/package.json +13 -16
  53. package/lib/api.d.ts +0 -43
  54. package/lib/api.js +0 -79
  55. package/lib/blockchain/block-builder.d.ts +0 -10
  56. package/lib/blockchain/block-builder.js +0 -297
  57. package/lib/blockchain/block.d.ts +0 -45
  58. package/lib/blockchain/block.js +0 -194
  59. package/lib/blockchain/head-state.d.ts +0 -15
  60. package/lib/blockchain/head-state.js +0 -71
  61. package/lib/blockchain/index.d.ts +0 -64
  62. package/lib/blockchain/index.js +0 -243
  63. package/lib/blockchain/inherent/index.d.ts +0 -19
  64. package/lib/blockchain/inherent/index.js +0 -36
  65. package/lib/blockchain/inherent/para-enter.d.ts +0 -7
  66. package/lib/blockchain/inherent/para-enter.js +0 -33
  67. package/lib/blockchain/inherent/parachain/babe-randomness.d.ts +0 -7
  68. package/lib/blockchain/inherent/parachain/babe-randomness.js +0 -15
  69. package/lib/blockchain/inherent/parachain/nimbus-author-inherent.d.ts +0 -7
  70. package/lib/blockchain/inherent/parachain/nimbus-author-inherent.js +0 -15
  71. package/lib/blockchain/inherent/parachain/validation-data.d.ts +0 -19
  72. package/lib/blockchain/inherent/parachain/validation-data.js +0 -172
  73. package/lib/blockchain/storage-layer.d.ts +0 -32
  74. package/lib/blockchain/storage-layer.js +0 -200
  75. package/lib/blockchain/txpool.d.ts +0 -45
  76. package/lib/blockchain/txpool.js +0 -184
  77. package/lib/db/entities.d.ts +0 -5
  78. package/lib/db/entities.js +0 -33
  79. package/lib/db/index.d.ts +0 -3
  80. package/lib/db/index.js +0 -41
  81. package/lib/dry-run.d.ts +0 -2
  82. package/lib/executor.d.ts +0 -40
  83. package/lib/executor.js +0 -131
  84. package/lib/genesis-provider.d.ts +0 -44
  85. package/lib/genesis-provider.js +0 -155
  86. package/lib/offchain.d.ts +0 -10
  87. package/lib/offchain.js +0 -37
  88. package/lib/rpc/dev/dry-run.d.ts +0 -2
  89. package/lib/rpc/dev/index.d.ts +0 -3
  90. package/lib/rpc/dev/index.js +0 -75
  91. package/lib/run-block.d.ts +0 -2
  92. package/lib/run-block.js +0 -51
  93. package/lib/setup.d.ts +0 -11
  94. package/lib/setup.js +0 -86
  95. package/lib/try-runtime.d.ts +0 -2
  96. package/lib/try-runtime.js +0 -36
  97. package/lib/utils/import-storage.d.ts +0 -5
  98. package/lib/utils/index.d.ts +0 -16
  99. package/lib/utils/index.js +0 -59
  100. package/lib/utils/key-cache.d.ts +0 -10
  101. package/lib/utils/key-cache.js +0 -66
  102. package/lib/utils/proof.d.ts +0 -15
  103. package/lib/utils/proof.js +0 -41
  104. package/lib/utils/set-storage.d.ts +0 -7
  105. package/lib/utils/set-storage.js +0 -59
  106. package/lib/utils/time-travel.d.ts +0 -5
  107. package/lib/utils/time-travel.js +0 -65
  108. package/lib/xcm/downward.d.ts +0 -2
  109. package/lib/xcm/downward.js +0 -29
  110. package/lib/xcm/horizontal.d.ts +0 -2
  111. package/lib/xcm/horizontal.js +0 -29
  112. package/lib/xcm/index.d.ts +0 -9
  113. package/lib/xcm/index.js +0 -25
  114. package/lib/xcm/upward.d.ts +0 -2
  115. 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.js CHANGED
@@ -5,172 +5,44 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const dotenv_1 = require("dotenv");
7
7
  const helpers_1 = require("yargs/helpers");
8
+ const lodash_1 = __importDefault(require("lodash"));
8
9
  const yargs_1 = __importDefault(require("yargs"));
9
- const _1 = require(".");
10
- const decoder_1 = require("./utils/decoder");
11
- const dry_run_1 = require("./dry-run");
12
- const dry_run_preimage_1 = require("./dry-run-preimage");
10
+ const chopsticks_core_1 = require("@acala-network/chopsticks-core");
13
11
  const schema_1 = require("./schema");
14
- const run_block_1 = require("./run-block");
15
- 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(".");
16
15
  (0, dotenv_1.config)();
17
16
  const processArgv = async (argv) => {
18
17
  if (argv.config) {
19
- argv = { ...(await (0, schema_1.fetchConfig)(argv.config)), ...argv };
18
+ Object.assign(argv, lodash_1.default.defaults(argv, await (0, schema_1.fetchConfig)(argv.config)));
20
19
  }
21
20
  argv.port = argv.port ?? (process.env.PORT ? Number(process.env.PORT) : 8000);
22
- return argv;
23
- };
24
- const defaultOptions = {
25
- endpoint: {
26
- desc: 'Endpoint to connect to',
27
- string: true,
28
- },
29
- block: {
30
- desc: 'Block hash or block number. Default to latest block',
31
- string: true,
32
- },
33
- 'wasm-override': {
34
- desc: 'Path to wasm override',
35
- string: true,
36
- },
37
- db: {
38
- desc: 'Path to database',
39
- string: true,
40
- },
41
- config: {
42
- desc: 'Path to config file',
43
- string: true,
44
- },
45
- 'runtime-log-level': {
46
- desc: 'Runtime maximum log level [off = 0; error = 1; warn = 2; info = 3; debug = 4; trace = 5]',
47
- number: true,
48
- },
49
- 'offchain-worker': {
50
- desc: 'Enable offchain worker',
51
- boolean: true,
52
- },
53
- };
54
- const mockOptions = {
55
- 'import-storage': {
56
- desc: 'Pre-defined JSON/YAML storage file path',
57
- string: true,
58
- },
59
- 'mock-signature-host': {
60
- desc: 'Mock signature host so any signature starts with 0xdeadbeef and filled by 0xcd is considered valid',
61
- boolean: true,
62
- },
63
21
  };
64
- (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
22
+ const commands = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
65
23
  .scriptName('chopsticks')
24
+ .middleware(processArgv, true)
66
25
  .command('*', 'Dev mode, fork off a chain', (yargs) => yargs.options({
67
- ...defaultOptions,
68
- ...mockOptions,
26
+ ...cli_options_1.defaultOptions,
27
+ ...cli_options_1.mockOptions,
69
28
  port: {
70
29
  desc: 'Port to listen on',
71
30
  number: true,
72
31
  },
73
32
  'build-block-mode': {
74
33
  desc: 'Build block mode. Default to Batch',
75
- 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],
76
35
  },
77
36
  'allow-unresolved-imports': {
78
37
  desc: 'Allow wasm unresolved imports',
79
38
  boolean: true,
80
39
  },
81
- }), async (argv) => {
82
- await (0, _1.setupWithServer)(await processArgv(argv));
83
- })
84
- .command('run-block', 'Replay a block', (yargs) => yargs.options({
85
- ...defaultOptions,
86
- ...mockOptions,
87
- 'output-path': {
88
- desc: 'File path to print output',
89
- string: true,
90
- },
91
- html: {
92
- desc: 'Generate html with storage diff',
93
- },
94
- open: {
95
- desc: 'Open generated html',
96
- },
97
- }), async (argv) => {
98
- await (0, run_block_1.runBlock)(await processArgv(argv));
99
- })
100
- .command('try-runtime', 'Runs runtime upgrade', (yargs) => yargs.options({
101
- ...defaultOptions,
102
- 'wasm-override': {
103
- desc: 'Path to WASM built with feature `try-runtime` enabled',
104
- string: true,
105
- required: true,
106
- },
107
- 'output-path': {
108
- desc: 'File path to print output',
109
- string: true,
110
- },
111
- html: {
112
- desc: 'Generate html with storage diff',
113
- },
114
- open: {
115
- desc: 'Open generated html',
116
- },
117
- }), async (argv) => {
118
- await (0, try_runtime_1.tryRuntime)(await processArgv(argv));
119
- })
120
- .command('dry-run', 'Dry run an extrinsic', (yargs) => yargs.options({
121
- ...defaultOptions,
122
- extrinsic: {
123
- desc: 'Extrinsic or call to dry run. If you pass call here then address is required to fake signature',
124
- string: true,
125
- },
126
- address: {
127
- desc: 'Address to fake sign extrinsic',
128
- string: true,
129
- },
130
- preimage: {
131
- desc: 'Preimage to dry run',
132
- string: true,
133
- },
134
- at: {
135
- desc: 'Block hash to dry run',
136
- string: true,
137
- },
138
- 'output-path': {
139
- desc: 'File path to print output',
140
- string: true,
141
- },
142
- html: {
143
- desc: 'Generate html with storage diff',
144
- },
145
- open: {
146
- desc: 'Open generated html',
40
+ 'max-memory-block-count': {
41
+ desc: 'Max memory block count',
42
+ number: true,
147
43
  },
148
44
  }), async (argv) => {
149
- const config = await processArgv(argv);
150
- if (config.preimage) {
151
- await (0, dry_run_preimage_1.dryRunPreimage)(config);
152
- }
153
- else {
154
- await (0, dry_run_1.dryRun)(config);
155
- }
156
- })
157
- .command('decode-key <key>', 'Deocde a key', (yargs) => yargs
158
- .positional('key', {
159
- desc: 'Key to decode',
160
- type: 'string',
161
- })
162
- .options({
163
- ...defaultOptions,
164
- }), async (argv) => {
165
- const context = await (0, _1.setup)(await processArgv(argv));
166
- const { storage, decodedKey } = (0, decoder_1.decodeKey)(await context.chain.head.meta, context.chain.head, argv.key);
167
- if (storage && decodedKey) {
168
- console.log(`${storage.section}.${storage.method}`, decodedKey.args.map((x) => JSON.stringify(x.toHuman())).join(', '));
169
- }
170
- else {
171
- console.log('Unknown');
172
- }
173
- process.exit(0);
45
+ await (0, _1.setupWithServer)(argv);
174
46
  })
175
47
  .command('xcm', 'XCM setup with relaychain and parachains', (yargs) => yargs
176
48
  .options({
@@ -193,12 +65,12 @@ const mockOptions = {
193
65
  parachains.push(chain);
194
66
  }
195
67
  if (parachains.length > 1) {
196
- await (0, _1.connectParachains)(parachains);
68
+ await (0, chopsticks_core_1.connectParachains)(parachains);
197
69
  }
198
70
  if (argv.relaychain) {
199
71
  const { chain: relaychain } = await (0, _1.setupWithServer)(await (0, schema_1.fetchConfig)(argv.relaychain));
200
72
  for (const parachain of parachains) {
201
- await (0, _1.connectVertical)(relaychain, parachain);
73
+ await (0, chopsticks_core_1.connectVertical)(relaychain, parachain);
202
74
  }
203
75
  }
204
76
  })
@@ -213,4 +85,5 @@ const mockOptions = {
213
85
  .alias('import-storage', 's')
214
86
  .alias('wasm-override', 'w')
215
87
  .usage('Usage: $0 <command> [options]')
216
- .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 { Config, fetchConfig } from './schema';
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
21
  var schema_1 = require("./schema");
32
22
  Object.defineProperty(exports, "fetchConfig", { enumerable: true, get: function () { return schema_1.fetchConfig; } });
33
- __exportStar(require("./blockchain/inherent"), exports);
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';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./cli"), exports);
18
+ __exportStar(require("./rpc"), exports);
@@ -0,0 +1,3 @@
1
+ import { Handler } from '../../rpc/shared';
2
+ export declare const name = "dryRun";
3
+ export declare const rpc: Handler;