@acala-network/chopsticks 0.9.1-2 → 0.9.1-4

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 (81) hide show
  1. package/dist/cjs/cli-options.js +30 -15
  2. package/dist/cjs/cli.js +69 -80
  3. package/dist/cjs/context.js +94 -65
  4. package/dist/cjs/index.js +32 -20
  5. package/dist/cjs/logger.js +18 -5
  6. package/dist/cjs/package.json +1 -0
  7. package/dist/cjs/plugins/decode-key/index.js +23 -20
  8. package/dist/cjs/plugins/dry-run/cli.js +46 -41
  9. package/dist/cjs/plugins/dry-run/dry-run-extrinsic.js +37 -21
  10. package/dist/cjs/plugins/dry-run/dry-run-preimage.js +102 -48
  11. package/dist/cjs/plugins/dry-run/index.js +18 -17
  12. package/dist/cjs/plugins/dry-run/rpc.js +48 -74
  13. package/dist/cjs/plugins/follow-chain/index.js +78 -46
  14. package/dist/cjs/plugins/index.js +76 -40
  15. package/dist/cjs/plugins/new-block/index.js +21 -53
  16. package/dist/cjs/plugins/run-block/__snapshots__/index.test.ts.snap +16745 -0
  17. package/dist/cjs/plugins/run-block/index.js +145 -104
  18. package/dist/cjs/plugins/set-block-build-mode/index.js +17 -25
  19. package/dist/cjs/plugins/set-head/index.js +13 -23
  20. package/dist/cjs/plugins/set-runtime-log-level/index.js +16 -23
  21. package/dist/cjs/plugins/set-storage/index.js +16 -35
  22. package/dist/cjs/plugins/time-travel/index.js +13 -23
  23. package/dist/cjs/plugins/try-runtime/index.js +51 -42
  24. package/dist/cjs/plugins/types.js +43 -18
  25. package/dist/cjs/rpc/index.js +30 -21
  26. package/dist/cjs/schema/index.js +77 -48
  27. package/dist/cjs/server.js +89 -65
  28. package/dist/cjs/setup-with-server.js +19 -13
  29. package/dist/cjs/types.js +30 -18
  30. package/dist/cjs/utils/decoder.js +32 -16
  31. package/dist/cjs/utils/generate-html-diff.js +38 -19
  32. package/dist/cjs/utils/index.js +20 -19
  33. package/dist/cjs/utils/open-html.js +12 -6
  34. package/dist/cjs/utils/override.js +40 -27
  35. package/dist/cjs/utils/tunnel.js +11 -14
  36. package/dist/esm/cli-options.js +11 -11
  37. package/dist/esm/cli.js +49 -64
  38. package/dist/esm/context.js +22 -26
  39. package/dist/esm/index.js +2 -2
  40. package/dist/esm/plugins/decode-key/index.js +11 -14
  41. package/dist/esm/plugins/dry-run/cli.js +35 -36
  42. package/dist/esm/plugins/dry-run/dry-run-extrinsic.js +22 -12
  43. package/dist/esm/plugins/dry-run/dry-run-preimage.js +77 -29
  44. package/dist/esm/plugins/dry-run/index.js +2 -2
  45. package/dist/esm/plugins/dry-run/rpc.js +16 -26
  46. package/dist/esm/plugins/follow-chain/index.js +56 -32
  47. package/dist/esm/plugins/index.js +9 -7
  48. package/dist/esm/plugins/new-block/index.js +9 -10
  49. package/dist/esm/plugins/run-block/__snapshots__/index.test.ts.snap +16745 -0
  50. package/dist/esm/plugins/run-block/index.js +101 -69
  51. package/dist/esm/plugins/set-block-build-mode/index.js +5 -4
  52. package/dist/esm/plugins/set-head/index.js +2 -4
  53. package/dist/esm/plugins/set-runtime-log-level/index.js +5 -4
  54. package/dist/esm/plugins/set-storage/index.js +4 -5
  55. package/dist/esm/plugins/time-travel/index.js +2 -4
  56. package/dist/esm/plugins/try-runtime/index.js +37 -34
  57. package/dist/esm/plugins/types.js +8 -8
  58. package/dist/esm/rpc/index.js +19 -16
  59. package/dist/esm/schema/index.js +31 -18
  60. package/dist/esm/server.js +71 -53
  61. package/dist/esm/setup-with-server.js +6 -6
  62. package/dist/esm/types.js +13 -2
  63. package/dist/esm/utils/decoder.js +12 -4
  64. package/dist/esm/utils/generate-html-diff.js +11 -7
  65. package/dist/esm/utils/index.js +4 -4
  66. package/dist/esm/utils/open-html.js +1 -1
  67. package/dist/esm/utils/override.js +12 -14
  68. package/dist/esm/utils/tunnel.js +1 -8
  69. package/dist/types/context.d.ts +2 -2
  70. package/dist/types/index.d.ts +2 -2
  71. package/dist/types/plugins/dry-run/dry-run-extrinsic.d.ts +1 -1
  72. package/dist/types/plugins/dry-run/dry-run-preimage.d.ts +1 -1
  73. package/dist/types/plugins/dry-run/index.d.ts +2 -2
  74. package/dist/types/plugins/run-block/index.d.ts +1 -1
  75. package/dist/types/plugins/types.d.ts +11 -11
  76. package/dist/types/setup-with-server.d.ts +1 -1
  77. package/dist/types/types.d.ts +2 -2
  78. package/dist/types/utils/index.d.ts +4 -4
  79. package/package.json +17 -21
  80. package/dist/esm/package.json +0 -1
  81. /package/{chopsticks.js → chopsticks.cjs} +0 -0
@@ -1,46 +1,51 @@
1
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) => {
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "cli", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return cli;
9
+ }
10
+ });
11
+ const _clioptions = require("../../cli-options.js");
12
+ const _dryrunextrinsic = require("./dry-run-extrinsic.js");
13
+ const _dryrunpreimage = require("./dry-run-preimage.js");
14
+ const cli = (y)=>{
15
+ y.command('dry-run', 'Dry run an extrinsic', (yargs)=>yargs.options({
16
+ ..._clioptions.defaultOptions,
17
+ ..._clioptions.mockOptions,
18
+ extrinsic: {
19
+ desc: 'Extrinsic or call to dry run. If you pass call here then address is required to fake signature',
20
+ string: true
21
+ },
22
+ address: {
23
+ desc: 'Address to fake sign extrinsic',
24
+ string: true
25
+ },
26
+ preimage: {
27
+ desc: 'Preimage to dry run',
28
+ string: true
29
+ },
30
+ at: {
31
+ desc: 'Block hash to dry run',
32
+ string: true
33
+ },
34
+ 'output-path': {
35
+ desc: 'File path to print output',
36
+ string: true
37
+ },
38
+ html: {
39
+ desc: 'Generate html with storage diff'
40
+ },
41
+ open: {
42
+ desc: 'Open generated html'
43
+ }
44
+ }), async (argv)=>{
38
45
  if (argv.preimage) {
39
- await (0, dry_run_preimage_1.dryRunPreimage)(argv);
40
- }
41
- else {
42
- await (0, dry_run_extrinsic_1.dryRunExtrinsic)(argv);
46
+ await (0, _dryrunpreimage.dryRunPreimage)(argv);
47
+ } else {
48
+ await (0, _dryrunextrinsic.dryRunExtrinsic)(argv);
43
49
  }
44
50
  });
45
51
  };
46
- exports.cli = cli;
@@ -1,33 +1,49 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dryRunExtrinsic = void 0;
4
- const util_crypto_1 = require("@polkadot/util-crypto");
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 context_1 = require("../../context");
10
- const dryRunExtrinsic = async (argv) => {
11
- const context = await (0, context_1.setupContext)(argv);
12
- const input = argv['address'] ? { call: argv['extrinsic'], address: argv['address'] } : argv['extrinsic'];
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "dryRunExtrinsic", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return dryRunExtrinsic;
9
+ }
10
+ });
11
+ const _utilcrypto = require("@polkadot/util-crypto");
12
+ const _nodefs = require("node:fs");
13
+ const _logger = require("../../logger.js");
14
+ const _generatehtmldiff = require("../../utils/generate-html-diff.js");
15
+ const _openhtml = require("../../utils/open-html.js");
16
+ const _context = require("../../context.js");
17
+ const dryRunExtrinsic = async (argv)=>{
18
+ const context = await (0, _context.setupContext)(argv);
19
+ const input = argv['address'] ? {
20
+ call: argv['extrinsic'],
21
+ address: argv['address']
22
+ } : argv['extrinsic'];
13
23
  const { outcome, storageDiff } = await context.chain.dryRunExtrinsic(input, argv['at']);
14
24
  if (outcome.isErr) {
15
25
  throw new Error(outcome.asErr.toString());
16
26
  }
17
- logger_1.defaultLogger.info(outcome.toHuman(), 'dry_run_outcome');
27
+ _logger.defaultLogger.info(outcome.toHuman(), 'dry_run_outcome');
18
28
  if (argv['html']) {
19
- const filePath = await (0, generate_html_diff_1.generateHtmlDiffPreviewFile)(context.chain.head, storageDiff, (0, util_crypto_1.blake2AsHex)(argv['extrinsic'], 256));
29
+ const filePath = await (0, _generatehtmldiff.generateHtmlDiffPreviewFile)(context.chain.head, storageDiff, (0, _utilcrypto.blake2AsHex)(argv['extrinsic'], 256));
20
30
  console.log(`Generated preview ${filePath}`);
21
31
  if (argv['open']) {
22
- (0, open_html_1.openHtml)(filePath);
32
+ (0, _openhtml.openHtml)(filePath);
23
33
  }
24
- }
25
- else if (argv['output-path']) {
26
- (0, node_fs_1.writeFileSync)(argv['output-path'], JSON.stringify({ outcome: outcome.toHuman(), storageDiff }, null, 2));
27
- }
28
- else {
29
- console.dir({ outcome: outcome.toHuman(), storageDiff }, { depth: null, colors: false });
34
+ } else if (argv['output-path']) {
35
+ (0, _nodefs.writeFileSync)(argv['output-path'], JSON.stringify({
36
+ outcome: outcome.toHuman(),
37
+ storageDiff
38
+ }, null, 2));
39
+ } else {
40
+ console.dir({
41
+ outcome: outcome.toHuman(),
42
+ storageDiff
43
+ }, {
44
+ depth: null,
45
+ colors: false
46
+ });
30
47
  }
31
48
  process.exit(0);
32
49
  };
33
- exports.dryRunExtrinsic = dryRunExtrinsic;
@@ -1,40 +1,61 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dryRunPreimage = void 0;
4
- const util_crypto_1 = require("@polkadot/util-crypto");
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 chopsticks_core_1 = require("@acala-network/chopsticks-core");
9
- const open_html_1 = require("../../utils/open-html");
10
- const context_1 = require("../../context");
11
- const dryRunPreimage = async (argv) => {
12
- const context = await (0, context_1.setupContext)(argv);
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "dryRunPreimage", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return dryRunPreimage;
9
+ }
10
+ });
11
+ const _utilcrypto = require("@polkadot/util-crypto");
12
+ const _util = require("@polkadot/util");
13
+ const _logger = require("../../logger.js");
14
+ const _generatehtmldiff = require("../../utils/generate-html-diff.js");
15
+ const _chopstickscore = require("@acala-network/chopsticks-core");
16
+ const _openhtml = require("../../utils/open-html.js");
17
+ const _context = require("../../context.js");
18
+ const dryRunPreimage = async (argv)=>{
19
+ const context = await (0, _context.setupContext)(argv);
13
20
  const extrinsic = argv['preimage'];
14
21
  const block = context.chain.head;
15
22
  const registry = await block.registry;
16
- const header = await (0, chopsticks_core_1.newHeader)(block);
17
- const data = (0, util_1.hexToU8a)(extrinsic);
18
- const hash = (0, util_crypto_1.blake2AsHex)(data, 256);
19
- await (0, chopsticks_core_1.setStorage)(context.chain, {
23
+ const header = await (0, _chopstickscore.newHeader)(block);
24
+ const data = (0, _util.hexToU8a)(extrinsic);
25
+ const hash = (0, _utilcrypto.blake2AsHex)(data, 256);
26
+ await (0, _chopstickscore.setStorage)(context.chain, {
20
27
  Preimage: {
21
- PreimageFor: [[[[hash, data.byteLength]], extrinsic]],
28
+ PreimageFor: [
29
+ [
30
+ [
31
+ [
32
+ hash,
33
+ data.byteLength
34
+ ]
35
+ ],
36
+ extrinsic
37
+ ]
38
+ ],
22
39
  StatusFor: [
23
40
  [
24
- [hash],
41
+ [
42
+ hash
43
+ ],
25
44
  {
26
45
  Requested: {
27
46
  count: 1,
28
- len: data.byteLength,
29
- },
30
- },
31
- ],
32
- ],
47
+ len: data.byteLength
48
+ }
49
+ }
50
+ ]
51
+ ]
33
52
  },
34
53
  Scheduler: {
35
54
  Agenda: [
36
55
  [
37
- [block.number + 1],
56
+ [
57
+ block.number + 1
58
+ ],
38
59
  [
39
60
  {
40
61
  maybeId: '0x64656d6f637261633a0000000000000000000000000000000000000000000000',
@@ -42,55 +63,88 @@ const dryRunPreimage = async (argv) => {
42
63
  call: {
43
64
  Lookup: {
44
65
  hash: hash,
45
- len: data.byteLength,
46
- },
66
+ len: data.byteLength
67
+ }
47
68
  },
48
- origin: { system: { Root: null } },
49
- },
50
- ],
51
- ],
69
+ origin: {
70
+ system: {
71
+ Root: null
72
+ }
73
+ }
74
+ }
75
+ ]
76
+ ]
52
77
  ],
53
- Lookup: [[['0x64656d6f637261633a0000000000000000000000000000000000000000000000'], [block.number + 1, 0]]],
54
- },
78
+ Lookup: [
79
+ [
80
+ [
81
+ '0x64656d6f637261633a0000000000000000000000000000000000000000000000'
82
+ ],
83
+ [
84
+ block.number + 1,
85
+ 0
86
+ ]
87
+ ]
88
+ ]
89
+ }
55
90
  });
56
- const calls = [['Core_initialize_block', [header.toHex()]]];
57
- for (const inherent of await block.chain.getInherents()) {
58
- calls.push(['BlockBuilder_apply_extrinsic', [inherent]]);
91
+ const calls = [
92
+ [
93
+ 'Core_initialize_block',
94
+ [
95
+ header.toHex()
96
+ ]
97
+ ]
98
+ ];
99
+ for (const inherent of (await block.chain.getInherents())){
100
+ calls.push([
101
+ 'BlockBuilder_apply_extrinsic',
102
+ [
103
+ inherent
104
+ ]
105
+ ]);
59
106
  }
60
- calls.push(['BlockBuilder_finalize_block', []]);
61
- logger_1.defaultLogger.info({ preimage: registry.createType('Call', data).toHuman() }, 'Dry run preimage');
62
- const result = await (0, chopsticks_core_1.runTask)({
107
+ calls.push([
108
+ 'BlockBuilder_finalize_block',
109
+ []
110
+ ]);
111
+ _logger.defaultLogger.info({
112
+ preimage: registry.createType('Call', data).toHuman()
113
+ }, 'Dry run preimage');
114
+ const result = await (0, _chopstickscore.runTask)({
63
115
  wasm: await block.wasm,
64
116
  calls,
65
117
  mockSignatureHost: false,
66
118
  allowUnresolvedImports: false,
67
- runtimeLogLevel: argv['runtime-log-level'] || 0,
68
- }, (0, chopsticks_core_1.taskHandler)(block));
119
+ runtimeLogLevel: argv['runtime-log-level'] || 0
120
+ }, (0, _chopstickscore.taskHandler)(block));
69
121
  if ('Error' in result) {
70
122
  throw new Error(result.Error);
71
123
  }
72
- (0, chopsticks_core_1.printRuntimeLogs)(result.Call.runtimeLogs);
73
- const filePath = await (0, generate_html_diff_1.generateHtmlDiffPreviewFile)(block, result.Call.storageDiff, hash);
124
+ (0, _chopstickscore.printRuntimeLogs)(result.Call.runtimeLogs);
125
+ const filePath = await (0, _generatehtmldiff.generateHtmlDiffPreviewFile)(block, result.Call.storageDiff, hash);
74
126
  console.log(`Generated preview ${filePath}`);
75
127
  if (argv['open']) {
76
- (0, open_html_1.openHtml)(filePath);
128
+ (0, _openhtml.openHtml)(filePath);
77
129
  }
78
130
  // if dry-run preimage has extrinsic arguments then dry-run extrinsic
79
- // this is usefull to test something after preimage is applied
131
+ // this is useful to test something after preimage is applied
80
132
  if (argv['extrinsic']) {
81
133
  await context.chain.newBlock();
82
- const input = argv['address'] ? { call: argv['extrinsic'], address: argv['address'] } : argv['extrinsic'];
134
+ const input = argv['address'] ? {
135
+ call: argv['extrinsic'],
136
+ address: argv['address']
137
+ } : argv['extrinsic'];
83
138
  const { outcome, storageDiff } = await context.chain.dryRunExtrinsic(input);
84
139
  if (outcome.isErr) {
85
140
  throw new Error(outcome.asErr.toString());
86
141
  }
87
- logger_1.defaultLogger.info(outcome.toHuman(), 'dry_run_outcome');
88
- const filePath = await (0, generate_html_diff_1.generateHtmlDiffPreviewFile)(context.chain.head, storageDiff, (0, util_crypto_1.blake2AsHex)(argv['extrinsic'], 256));
142
+ _logger.defaultLogger.info(outcome.toHuman(), 'dry_run_outcome');
143
+ const filePath = await (0, _generatehtmldiff.generateHtmlDiffPreviewFile)(context.chain.head, storageDiff, (0, _utilcrypto.blake2AsHex)(argv['extrinsic'], 256));
89
144
  console.log(`Generated preview ${filePath}`);
90
145
  if (argv['open']) {
91
- (0, open_html_1.openHtml)(filePath);
146
+ (0, _openhtml.openHtml)(filePath);
92
147
  }
93
148
  }
94
149
  process.exit(0);
95
150
  };
96
- exports.dryRunPreimage = dryRunPreimage;
@@ -1,18 +1,19 @@
1
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);
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ _export_star(require("./cli.js"), exports);
6
+ _export_star(require("./rpc.js"), exports);
7
+ function _export_star(from, to) {
8
+ Object.keys(from).forEach(function(k) {
9
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
10
+ Object.defineProperty(to, k, {
11
+ enumerable: true,
12
+ get: function() {
13
+ return from[k];
14
+ }
15
+ });
16
+ }
17
+ });
18
+ return from;
19
+ }
@@ -1,79 +1,54 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rpc = exports.name = void 0;
4
- const zod_1 = require("zod");
5
- const chopsticks_core_1 = require("@acala-network/chopsticks-core");
6
- const decoder_1 = require("../../utils/decoder");
7
- const generate_html_diff_1 = require("../../utils/generate-html-diff");
8
- const zHex = zod_1.z.custom((val) => /^0x\w+$/.test(val));
9
- const zHash = zod_1.z.string().length(66).and(zHex);
10
- const zParaId = zod_1.z.string().regex(/^\d+$/).transform(Number);
11
- const schema = zod_1.z.object({
12
- raw: zod_1.z.boolean().optional(),
13
- html: zod_1.z.boolean().optional(),
14
- extrinsic: zHex
15
- .or(zod_1.z.object({
16
- call: zHex,
17
- address: zHex,
18
- }))
19
- .optional(),
20
- hrmp: zod_1.z
21
- .record(zParaId, zod_1.z
22
- .array(zod_1.z.object({
23
- sentAt: zod_1.z.number(),
24
- data: zHex,
25
- }))
26
- .min(1))
27
- .optional(),
28
- dmp: zod_1.z
29
- .array(zod_1.z.object({
30
- sentAt: zod_1.z.number(),
31
- msg: zHex,
32
- }))
33
- .min(1)
34
- .optional(),
35
- ump: zod_1.z.record(zParaId, zod_1.z.array(zHex).min(1)).optional(),
36
- at: zHash.optional(),
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
37
4
  });
38
- // custom rpc name (optional). e.g. dryRun will be called as dev_dryRun
39
- exports.name = 'dryRun';
40
- /**
41
- * Dry run an extrinsic or messages.
42
- * If `html` is true, return the generated storage diff html string.
43
- * If `raw` is true, return the raw storage diff.
44
- * Otherwise, return `{ oldState, newState, delta }`.
45
- *
46
- * This function is a dev rpc handler. Use `dev_dryRun` as the method name when calling it.
47
- *
48
- * @param context - The context object of the rpc handler
49
- * @param params - The parameters of the rpc handler
50
- *
51
- * @example Dry run an dmp
52
- * ```ts
53
- * import { WsProvider } from '@polkadot/rpc-provider'
54
- * const ws = new WsProvider(`ws://localhost:8000`)
55
- * const params = [
56
- {
57
- raw: false,
58
- dmp: [
59
- // https://acala.subscan.io/xcm_message/polkadot-2ab22918c567455af3563989d852f307f4cc1250
60
- {
61
- sentAt: 14471353,
62
- msg: '0x02100104000100000b00280b9bba030a13000100000b00280b9bba03010300286bee0d0100040001010070c53d8e216f9c0f2e3b11c53f5f4bf3e078b995d5f0ed590f889f41e20e6531',
63
- },
64
- ],
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ name: function() {
13
+ return name;
65
14
  },
66
- ]
67
- * await ws.send('dev_dryRun', params)
68
- * ```
69
- */
70
- const rpc = async (context, [params]) => {
15
+ rpc: function() {
16
+ return rpc;
17
+ }
18
+ });
19
+ const _zod = require("zod");
20
+ const _chopstickscore = require("@acala-network/chopsticks-core");
21
+ const _decoder = require("../../utils/decoder.js");
22
+ const _generatehtmldiff = require("../../utils/generate-html-diff.js");
23
+ const zHex = _zod.z.custom((val)=>/^0x\w+$/.test(val));
24
+ const zHash = _zod.z.string().length(66).and(zHex);
25
+ const zParaId = _zod.z.string().regex(/^\d+$/).transform(Number);
26
+ const schema = _zod.z.object({
27
+ raw: _zod.z.boolean().optional(),
28
+ html: _zod.z.boolean().optional(),
29
+ extrinsic: zHex.or(_zod.z.object({
30
+ call: zHex,
31
+ address: zHex
32
+ })).optional(),
33
+ hrmp: _zod.z.record(zParaId, _zod.z.array(_zod.z.object({
34
+ sentAt: _zod.z.number(),
35
+ data: zHex
36
+ })).min(1)).optional(),
37
+ dmp: _zod.z.array(_zod.z.object({
38
+ sentAt: _zod.z.number(),
39
+ msg: zHex
40
+ })).min(1).optional(),
41
+ ump: _zod.z.record(zParaId, _zod.z.array(zHex).min(1)).optional(),
42
+ at: zHash.optional()
43
+ });
44
+ const name = 'dryRun';
45
+ const rpc = async (context, [params])=>{
71
46
  const { html, extrinsic, hrmp, dmp, ump, raw, at } = schema.parse(params);
72
- const dryRun = async () => {
47
+ const dryRun = async ()=>{
73
48
  if (extrinsic) {
74
49
  const { outcome, storageDiff } = await context.chain.dryRunExtrinsic(extrinsic, at);
75
50
  if (outcome.isErr) {
76
- throw new chopsticks_core_1.ResponseError(1, outcome.asErr.toString());
51
+ throw new _chopstickscore.ResponseError(1, outcome.asErr.toString());
77
52
  }
78
53
  return storageDiff;
79
54
  }
@@ -86,20 +61,19 @@ const rpc = async (context, [params]) => {
86
61
  if (ump) {
87
62
  return context.chain.dryRunUmp(ump, at);
88
63
  }
89
- throw new chopsticks_core_1.ResponseError(1, 'No extrinsic to run');
64
+ throw new _chopstickscore.ResponseError(1, 'No extrinsic to run');
90
65
  };
91
66
  const storageDiff = await dryRun();
92
67
  if (html) {
93
- return (0, generate_html_diff_1.generateHtmlDiff)(context.chain.head, storageDiff);
68
+ return (0, _generatehtmldiff.generateHtmlDiff)(context.chain.head, storageDiff);
94
69
  }
95
70
  if (raw) {
96
71
  return storageDiff;
97
72
  }
98
- const { oldState, newState, delta } = await (0, decoder_1.decodeStorageDiff)(context.chain.head, storageDiff);
73
+ const { oldState, newState, delta } = await (0, _decoder.decodeStorageDiff)(context.chain.head, storageDiff);
99
74
  return {
100
75
  old: oldState,
101
76
  new: newState,
102
- delta,
77
+ delta
103
78
  };
104
79
  };
105
- exports.rpc = rpc;