@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,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;
@@ -3,14 +3,15 @@ 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.dev_dryRun = void 0;
6
+ exports.rpc = exports.name = void 0;
7
7
  const zod_1 = __importDefault(require("zod"));
8
+ const shared_1 = require("../../rpc/shared");
8
9
  const decoder_1 = require("../../utils/decoder");
9
10
  const generate_html_diff_1 = require("../../utils/generate-html-diff");
10
11
  const zHex = zod_1.default.custom((val) => /^0x\w+$/.test(val));
11
12
  const zHash = zod_1.default.string().length(66).and(zHex);
12
13
  const zParaId = zod_1.default.string().regex(/^\d+$/).transform(Number);
13
- const dryRunSchema = zod_1.default.object({
14
+ const schema = zod_1.default.object({
14
15
  raw: zod_1.default.boolean().optional(),
15
16
  html: zod_1.default.boolean().optional(),
16
17
  extrinsic: zHex
@@ -37,13 +38,15 @@ const dryRunSchema = zod_1.default.object({
37
38
  ump: zod_1.default.record(zParaId, zod_1.default.array(zHex).min(1)).optional(),
38
39
  at: zHash.optional(),
39
40
  });
40
- const dev_dryRun = async (context, [params]) => {
41
- const { html, extrinsic, hrmp, dmp, ump, raw, at } = dryRunSchema.parse(params);
41
+ // custom rpc name (optional). e.g. dryRun will be called as dev_dryRun
42
+ exports.name = 'dryRun';
43
+ const rpc = async (context, [params]) => {
44
+ const { html, extrinsic, hrmp, dmp, ump, raw, at } = schema.parse(params);
42
45
  const dryRun = async () => {
43
46
  if (extrinsic) {
44
47
  const { outcome, storageDiff } = await context.chain.dryRunExtrinsic(extrinsic, at);
45
48
  if (outcome.isErr) {
46
- throw new Error(outcome.asErr.toString());
49
+ throw new shared_1.ResponseError(1, outcome.asErr.toString());
47
50
  }
48
51
  return storageDiff;
49
52
  }
@@ -56,7 +59,7 @@ const dev_dryRun = async (context, [params]) => {
56
59
  if (ump) {
57
60
  return context.chain.dryRunUmp(ump, at);
58
61
  }
59
- throw new Error('No extrinsic to run');
62
+ throw new shared_1.ResponseError(1, 'No extrinsic to run');
60
63
  };
61
64
  const storageDiff = await dryRun();
62
65
  if (html) {
@@ -72,4 +75,4 @@ const dev_dryRun = async (context, [params]) => {
72
75
  delta,
73
76
  };
74
77
  };
75
- exports.dev_dryRun = dev_dryRun;
78
+ exports.rpc = rpc;
@@ -0,0 +1,4 @@
1
+ import type yargs from 'yargs';
2
+ import { Handlers } from '../rpc/shared';
3
+ export declare const pluginHandlers: Handlers;
4
+ export declare const pluginExtendCli: (y: yargs.Argv) => Promise<void>;
@@ -0,0 +1,52 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.pluginExtendCli = exports.pluginHandlers = void 0;
27
+ const lodash_1 = require("lodash");
28
+ const fs_1 = require("fs");
29
+ const logger_1 = require("../logger");
30
+ const logger = logger_1.defaultLogger.child({ name: 'plugin' });
31
+ exports.pluginHandlers = {};
32
+ const plugins = (0, fs_1.readdirSync)(__dirname).filter((file) => (0, fs_1.lstatSync)(`${__dirname}/${file}`).isDirectory());
33
+ (async () => {
34
+ for (const plugin of plugins) {
35
+ const { rpc, name } = await Promise.resolve(`${`./${plugin}`}`).then(s => __importStar(require(s)));
36
+ if (rpc) {
37
+ const methodName = name || (0, lodash_1.camelCase)(plugin);
38
+ exports.pluginHandlers[`dev_${methodName}`] = rpc;
39
+ logger.debug(`Registered plugin ${plugin} RPC`);
40
+ }
41
+ }
42
+ })();
43
+ const pluginExtendCli = async (y) => {
44
+ for (const plugin of plugins) {
45
+ const { cli } = await Promise.resolve(`${`./${plugin}`}`).then(s => __importStar(require(s)));
46
+ if (cli) {
47
+ cli(y);
48
+ logger.debug(`Registered plugin ${plugin} CLI`);
49
+ }
50
+ }
51
+ };
52
+ exports.pluginExtendCli = pluginExtendCli;
@@ -0,0 +1,2 @@
1
+ import { Handler } from '../../rpc/shared';
2
+ export declare const rpc: Handler;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rpc = void 0;
4
+ const shared_1 = require("../../rpc/shared");
5
+ const logger_1 = require("../../logger");
6
+ const rpc = async (context, [param]) => {
7
+ const { count, to, hrmp, ump, dmp, transactions } = param || {};
8
+ const now = context.chain.head.number;
9
+ const diff = to ? to - now : count;
10
+ const finalCount = diff > 0 ? diff : 1;
11
+ let finalHash;
12
+ for (let i = 0; i < finalCount; i++) {
13
+ const block = await context.chain
14
+ .newBlock({
15
+ transactions,
16
+ horizontalMessages: hrmp,
17
+ upwardMessages: ump,
18
+ downwardMessages: dmp,
19
+ })
20
+ .catch((error) => {
21
+ throw new shared_1.ResponseError(1, error.toString());
22
+ });
23
+ logger_1.defaultLogger.debug({ hash: block.hash }, 'dev_newBlock');
24
+ finalHash = block.hash;
25
+ }
26
+ return finalHash;
27
+ };
28
+ exports.rpc = rpc;
@@ -0,0 +1,2 @@
1
+ import type yargs from 'yargs';
2
+ export declare const cli: (y: yargs.Argv) => void;
@@ -0,0 +1,67 @@
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 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 chopsticks_core_1 = require("@acala-network/chopsticks-core");
10
+ const context_1 = require("../../context");
11
+ const cli = (y) => {
12
+ y.command('run-block', 'Replay a block', (yargs) => yargs.options({
13
+ ...cli_options_1.defaultOptions,
14
+ ...cli_options_1.mockOptions,
15
+ 'output-path': {
16
+ desc: 'File path to print output',
17
+ string: true,
18
+ },
19
+ html: {
20
+ desc: 'Generate html with storage diff',
21
+ },
22
+ open: {
23
+ desc: 'Open generated html',
24
+ },
25
+ }), async (argv) => {
26
+ const context = await (0, context_1.setupContext)(argv, true);
27
+ const header = await context.chain.head.header;
28
+ const block = context.chain.head;
29
+ const parent = await block.parentBlock;
30
+ if (!parent)
31
+ throw Error('cant find parent block');
32
+ const wasm = await parent.wasm;
33
+ const calls = [['Core_initialize_block', [header.toHex()]]];
34
+ for (const extrinsic of await block.extrinsics) {
35
+ calls.push(['BlockBuilder_apply_extrinsic', [extrinsic]]);
36
+ }
37
+ calls.push(['BlockBuilder_finalize_block', []]);
38
+ const result = await (0, chopsticks_core_1.runTask)({
39
+ wasm,
40
+ calls,
41
+ mockSignatureHost: false,
42
+ allowUnresolvedImports: false,
43
+ runtimeLogLevel: argv.runtimeLogLevel || 0,
44
+ }, (0, chopsticks_core_1.taskHandler)(parent));
45
+ if (result.Error) {
46
+ throw new Error(result.Error);
47
+ }
48
+ for (const logs of result.Call.runtimeLogs) {
49
+ logger_1.defaultLogger.info(`RuntimeLogs:\n${logs}`);
50
+ }
51
+ if (argv.html) {
52
+ const filePath = await (0, generate_html_diff_1.generateHtmlDiffPreviewFile)(parent, result.Call.storageDiff, block.hash);
53
+ console.log(`Generated preview ${filePath}`);
54
+ if (argv.open) {
55
+ (0, open_html_1.openHtml)(filePath);
56
+ }
57
+ }
58
+ else if (argv.outputPath) {
59
+ (0, node_fs_1.writeFileSync)(argv.outputPath, JSON.stringify(result, null, 2));
60
+ }
61
+ else {
62
+ console.dir(result, { depth: null, colors: false });
63
+ }
64
+ process.exit(0);
65
+ });
66
+ };
67
+ exports.cli = cli;
@@ -0,0 +1,2 @@
1
+ import { Handler } from '../../rpc/shared';
2
+ export declare const rpc: Handler;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rpc = void 0;
4
+ const chopsticks_core_1 = require("@acala-network/chopsticks-core");
5
+ const shared_1 = require("../../rpc/shared");
6
+ const logger_1 = require("../../logger");
7
+ const rpc = async (context, [mode]) => {
8
+ logger_1.defaultLogger.debug({ mode }, 'dev_setBlockBuildMode');
9
+ if (chopsticks_core_1.BuildBlockMode[mode] === undefined) {
10
+ throw new shared_1.ResponseError(1, `Invalid mode ${mode}`);
11
+ }
12
+ context.chain.txPool.mode = mode;
13
+ };
14
+ exports.rpc = rpc;
@@ -0,0 +1,2 @@
1
+ import { Handler } from '../../rpc/shared';
2
+ export declare const rpc: Handler;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rpc = void 0;
4
+ const shared_1 = require("../../rpc/shared");
5
+ const rpc = async (context, [hashOrNumber]) => {
6
+ let block;
7
+ if (typeof hashOrNumber === 'number') {
8
+ const blockNumber = hashOrNumber > 0 ? hashOrNumber : context.chain.head.number + hashOrNumber;
9
+ block = await context.chain.getBlockAt(blockNumber);
10
+ }
11
+ else {
12
+ block = await context.chain.getBlock(hashOrNumber);
13
+ }
14
+ if (!block) {
15
+ throw new shared_1.ResponseError(1, `Block not found ${hashOrNumber}`);
16
+ }
17
+ await context.chain.setHead(block);
18
+ return block.hash;
19
+ };
20
+ exports.rpc = rpc;
@@ -0,0 +1,2 @@
1
+ import { Handler } from '../../rpc/shared';
2
+ export declare const rpc: Handler;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rpc = void 0;
4
+ const shared_1 = require("../../rpc/shared");
5
+ const chopsticks_core_1 = require("@acala-network/chopsticks-core");
6
+ const logger_1 = require("../../logger");
7
+ const rpc = async (context, params) => {
8
+ const [values, blockHash] = params;
9
+ const hash = await (0, chopsticks_core_1.setStorage)(context.chain, values, blockHash).catch((error) => {
10
+ throw new shared_1.ResponseError(1, error.toString());
11
+ });
12
+ logger_1.defaultLogger.debug({
13
+ hash,
14
+ values,
15
+ }, 'dev_setStorage');
16
+ return hash;
17
+ };
18
+ exports.rpc = rpc;
@@ -0,0 +1,2 @@
1
+ import { Handler } from '../../rpc/shared';
2
+ export declare const rpc: Handler;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rpc = void 0;
4
+ const shared_1 = require("../../rpc/shared");
5
+ const chopsticks_core_1 = require("@acala-network/chopsticks-core");
6
+ const rpc = async (context, [date]) => {
7
+ const timestamp = typeof date === 'string' ? Date.parse(date) : date;
8
+ if (Number.isNaN(timestamp))
9
+ throw new shared_1.ResponseError(1, 'Invalid date');
10
+ await (0, chopsticks_core_1.timeTravel)(context.chain, timestamp);
11
+ return timestamp;
12
+ };
13
+ exports.rpc = rpc;
@@ -0,0 +1,2 @@
1
+ import type yargs from 'yargs';
2
+ export declare const cli: (y: yargs.Argv) => void;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cli = void 0;
4
+ const node_fs_1 = require("node:fs");
5
+ const cli_options_1 = require("../../cli-options");
6
+ const generate_html_diff_1 = require("../../utils/generate-html-diff");
7
+ const open_html_1 = require("../../utils/open-html");
8
+ const context_1 = require("../../context");
9
+ const cli = (y) => {
10
+ y.command('try-runtime', 'Runs runtime upgrade', (yargs) => yargs.options({
11
+ ...cli_options_1.defaultOptions,
12
+ 'wasm-override': {
13
+ desc: 'Path to WASM built with feature `try-runtime` enabled',
14
+ string: true,
15
+ required: true,
16
+ },
17
+ 'output-path': {
18
+ desc: 'File path to print output',
19
+ string: true,
20
+ },
21
+ html: {
22
+ desc: 'Generate html with storage diff',
23
+ boolean: true,
24
+ },
25
+ open: {
26
+ desc: 'Open generated html',
27
+ boolean: true,
28
+ },
29
+ }), async (argv) => {
30
+ const context = await (0, context_1.setupContext)(argv);
31
+ const block = context.chain.head;
32
+ const registry = await block.registry;
33
+ registry.register({
34
+ UpgradeCheckSelect: {
35
+ _enum: {
36
+ None: null,
37
+ },
38
+ },
39
+ });
40
+ const select_none = registry.createType('UpgradeCheckSelect', 'None');
41
+ const result = await block.call('TryRuntime_on_runtime_upgrade', [select_none.toHex()]);
42
+ if (argv.html) {
43
+ const filePath = await (0, generate_html_diff_1.generateHtmlDiffPreviewFile)(block, result.storageDiff, block.hash);
44
+ console.log(`Generated preview ${filePath}`);
45
+ if (argv.open) {
46
+ (0, open_html_1.openHtml)(filePath);
47
+ }
48
+ }
49
+ else if (argv.outputPath) {
50
+ (0, node_fs_1.writeFileSync)(argv.outputPath, JSON.stringify(result, null, 2));
51
+ }
52
+ else {
53
+ console.dir(result, { depth: null, colors: false });
54
+ }
55
+ process.exit(0);
56
+ });
57
+ };
58
+ exports.cli = cli;
@@ -1,5 +1,5 @@
1
1
  import { Context, SubscriptionManager } from './shared';
2
2
  export declare const handler: (context: Context) => ({ method, params }: {
3
3
  method: string;
4
- params: string[];
4
+ params: any[];
5
5
  }, subscriptionManager: SubscriptionManager) => Promise<string | number | void | object | null | undefined>;
package/lib/rpc/index.js CHANGED
@@ -5,19 +5,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.handler = void 0;
7
7
  const shared_1 = require("./shared");
8
- const dev_1 = __importDefault(require("./dev"));
8
+ const plugins_1 = require("../plugins");
9
9
  const substrate_1 = __importDefault(require("./substrate"));
10
10
  const allHandlers = {
11
11
  ...substrate_1.default,
12
- ...dev_1.default,
13
12
  rpc_methods: async () => Promise.resolve({
14
13
  version: 1,
15
- methods: Object.keys(allHandlers),
14
+ methods: [...Object.keys(allHandlers), ...Object.keys(plugins_1.pluginHandlers)],
16
15
  }),
17
16
  };
17
+ const getHandler = (method) => {
18
+ const handler = allHandlers[method];
19
+ if (!handler) {
20
+ // no handler for this method, check if it's a plugin
21
+ return plugins_1.pluginHandlers[method];
22
+ }
23
+ return handler;
24
+ };
18
25
  const handler = (context) => ({ method, params }, subscriptionManager) => {
19
26
  shared_1.logger.trace('Handling %s', method);
20
- const handler = allHandlers[method];
27
+ const handler = getHandler(method);
21
28
  if (!handler) {
22
29
  shared_1.logger.warn('Method not found %s', method);
23
30
  throw new shared_1.ResponseError(-32601, `Method not found: ${method}`);
@@ -1,4 +1,4 @@
1
- import { Blockchain } from '../blockchain';
1
+ import { Blockchain } from '@acala-network/chopsticks-core';
2
2
  export declare const logger: import("pino").default.Logger<{
3
3
  level: string;
4
4
  transport: {
package/lib/rpc/shared.js CHANGED
@@ -7,8 +7,8 @@ class ResponseError extends Error {
7
7
  code;
8
8
  constructor(code, message) {
9
9
  super(message);
10
+ this.name = 'ResponseError';
10
11
  this.code = code;
11
- this.message = message;
12
12
  }
13
13
  toJSON() {
14
14
  return {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const txpool_1 = require("../../blockchain/txpool");
3
+ const chopsticks_core_1 = require("@acala-network/chopsticks-core");
4
4
  const shared_1 = require("../shared");
5
5
  const logger_1 = require("../../logger");
6
6
  const logger = logger_1.defaultLogger.child({ name: 'rpc-author' });
@@ -21,9 +21,9 @@ const handlers = {
21
21
  done(id);
22
22
  }
23
23
  };
24
- context.chain.txPool.event.on(txpool_1.APPLY_EXTRINSIC_ERROR, onExtrinsicFail);
24
+ context.chain.txPool.event.on(chopsticks_core_1.APPLY_EXTRINSIC_ERROR, onExtrinsicFail);
25
25
  const done = (id) => {
26
- context.chain.txPool.event.removeListener(txpool_1.APPLY_EXTRINSIC_ERROR, onExtrinsicFail);
26
+ context.chain.txPool.event.removeListener(chopsticks_core_1.APPLY_EXTRINSIC_ERROR, onExtrinsicFail);
27
27
  unsubscribe(id);
28
28
  };
29
29
  update = async (block) => {
@@ -1,66 +1,5 @@
1
- import { BuildBlockMode } from '../blockchain/txpool';
1
+ import { BuildBlockMode } from '@acala-network/chopsticks-core';
2
2
  import { z } from 'zod';
3
- export declare const genesisSchema: z.ZodObject<{
4
- id: z.ZodString;
5
- name: z.ZodString;
6
- properties: z.ZodObject<{
7
- ss58Format: z.ZodOptional<z.ZodNumber>;
8
- tokenDecimals: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodArray<z.ZodNumber, "many">]>>;
9
- tokenSymbol: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
10
- }, "strip", z.ZodTypeAny, {
11
- ss58Format?: number | undefined;
12
- tokenDecimals?: number | number[] | undefined;
13
- tokenSymbol?: string | string[] | undefined;
14
- }, {
15
- ss58Format?: number | undefined;
16
- tokenDecimals?: number | number[] | undefined;
17
- tokenSymbol?: string | string[] | undefined;
18
- }>;
19
- genesis: z.ZodObject<{
20
- raw: z.ZodObject<{
21
- top: z.ZodRecord<z.ZodString, z.ZodString>;
22
- }, "strip", z.ZodTypeAny, {
23
- top: Record<string, string>;
24
- }, {
25
- top: Record<string, string>;
26
- }>;
27
- }, "strip", z.ZodTypeAny, {
28
- raw: {
29
- top: Record<string, string>;
30
- };
31
- }, {
32
- raw: {
33
- top: Record<string, string>;
34
- };
35
- }>;
36
- }, "strip", z.ZodTypeAny, {
37
- name: string;
38
- properties: {
39
- ss58Format?: number | undefined;
40
- tokenDecimals?: number | number[] | undefined;
41
- tokenSymbol?: string | string[] | undefined;
42
- };
43
- id: string;
44
- genesis: {
45
- raw: {
46
- top: Record<string, string>;
47
- };
48
- };
49
- }, {
50
- name: string;
51
- properties: {
52
- ss58Format?: number | undefined;
53
- tokenDecimals?: number | number[] | undefined;
54
- tokenSymbol?: string | string[] | undefined;
55
- };
56
- id: string;
57
- genesis: {
58
- raw: {
59
- top: Record<string, string>;
60
- };
61
- };
62
- }>;
63
- export type Genesis = z.infer<typeof genesisSchema>;
64
3
  export declare const configSchema: z.ZodObject<{
65
4
  port: z.ZodOptional<z.ZodNumber>;
66
5
  endpoint: z.ZodOptional<z.ZodString>;
@@ -68,6 +7,7 @@ export declare const configSchema: z.ZodObject<{
68
7
  'build-block-mode': z.ZodOptional<z.ZodNativeEnum<typeof BuildBlockMode>>;
69
8
  'import-storage': z.ZodOptional<z.ZodAny>;
70
9
  'mock-signature-host': z.ZodOptional<z.ZodBoolean>;
10
+ 'max-memory-block-count': z.ZodOptional<z.ZodNumber>;
71
11
  db: z.ZodOptional<z.ZodString>;
72
12
  'wasm-override': z.ZodOptional<z.ZodString>;
73
13
  genesis: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodObject<{
@@ -105,12 +45,12 @@ export declare const configSchema: z.ZodObject<{
105
45
  }>;
106
46
  }, "strip", z.ZodTypeAny, {
107
47
  name: string;
48
+ id: string;
108
49
  properties: {
109
50
  ss58Format?: number | undefined;
110
51
  tokenDecimals?: number | number[] | undefined;
111
52
  tokenSymbol?: string | string[] | undefined;
112
53
  };
113
- id: string;
114
54
  genesis: {
115
55
  raw: {
116
56
  top: Record<string, string>;
@@ -118,12 +58,12 @@ export declare const configSchema: z.ZodObject<{
118
58
  };
119
59
  }, {
120
60
  name: string;
61
+ id: string;
121
62
  properties: {
122
63
  ss58Format?: number | undefined;
123
64
  tokenDecimals?: number | number[] | undefined;
124
65
  tokenSymbol?: string | string[] | undefined;
125
66
  };
126
- id: string;
127
67
  genesis: {
128
68
  raw: {
129
69
  top: Record<string, string>;
@@ -141,16 +81,17 @@ export declare const configSchema: z.ZodObject<{
141
81
  'build-block-mode'?: BuildBlockMode | undefined;
142
82
  'import-storage'?: any;
143
83
  'mock-signature-host'?: boolean | undefined;
84
+ 'max-memory-block-count'?: number | undefined;
144
85
  db?: string | undefined;
145
86
  'wasm-override'?: string | undefined;
146
87
  genesis?: string | {
147
88
  name: string;
89
+ id: string;
148
90
  properties: {
149
91
  ss58Format?: number | undefined;
150
92
  tokenDecimals?: number | number[] | undefined;
151
93
  tokenSymbol?: string | string[] | undefined;
152
94
  };
153
- id: string;
154
95
  genesis: {
155
96
  raw: {
156
97
  top: Record<string, string>;
@@ -168,16 +109,17 @@ export declare const configSchema: z.ZodObject<{
168
109
  'build-block-mode'?: BuildBlockMode | undefined;
169
110
  'import-storage'?: any;
170
111
  'mock-signature-host'?: boolean | undefined;
112
+ 'max-memory-block-count'?: number | undefined;
171
113
  db?: string | undefined;
172
114
  'wasm-override'?: string | undefined;
173
115
  genesis?: string | {
174
116
  name: string;
117
+ id: string;
175
118
  properties: {
176
119
  ss58Format?: number | undefined;
177
120
  tokenDecimals?: number | number[] | undefined;
178
121
  tokenSymbol?: string | string[] | undefined;
179
122
  };
180
- id: string;
181
123
  genesis: {
182
124
  raw: {
183
125
  top: Record<string, string>;
@@ -190,3 +132,4 @@ export declare const configSchema: z.ZodObject<{
190
132
  'offchain-worker'?: boolean | undefined;
191
133
  }>;
192
134
  export type Config = z.infer<typeof configSchema>;
135
+ export declare const fetchConfig: (path: string) => Promise<Config>;