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

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 (65) 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 +93 -64
  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 +101 -47
  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/index.js +145 -104
  17. package/dist/cjs/plugins/set-block-build-mode/index.js +17 -25
  18. package/dist/cjs/plugins/set-head/index.js +13 -23
  19. package/dist/cjs/plugins/set-runtime-log-level/index.js +16 -23
  20. package/dist/cjs/plugins/set-storage/index.js +16 -35
  21. package/dist/cjs/plugins/time-travel/index.js +13 -23
  22. package/dist/cjs/plugins/try-runtime/index.js +51 -42
  23. package/dist/cjs/plugins/types.js +43 -18
  24. package/dist/cjs/rpc/index.js +30 -21
  25. package/dist/cjs/schema/index.js +77 -48
  26. package/dist/cjs/server.js +89 -65
  27. package/dist/cjs/setup-with-server.js +19 -13
  28. package/dist/cjs/types.js +30 -18
  29. package/dist/cjs/utils/decoder.js +32 -16
  30. package/dist/cjs/utils/generate-html-diff.js +38 -19
  31. package/dist/cjs/utils/index.js +20 -19
  32. package/dist/cjs/utils/open-html.js +12 -6
  33. package/dist/cjs/utils/override.js +40 -27
  34. package/dist/cjs/utils/tunnel.js +11 -14
  35. package/dist/esm/cli-options.js +11 -11
  36. package/dist/esm/cli.js +45 -60
  37. package/dist/esm/context.js +20 -24
  38. package/dist/esm/plugins/decode-key/index.js +9 -12
  39. package/dist/esm/plugins/dry-run/cli.js +32 -33
  40. package/dist/esm/plugins/dry-run/dry-run-extrinsic.js +18 -8
  41. package/dist/esm/plugins/dry-run/dry-run-preimage.js +72 -24
  42. package/dist/esm/plugins/dry-run/rpc.js +14 -24
  43. package/dist/esm/plugins/follow-chain/index.js +52 -28
  44. package/dist/esm/plugins/index.js +8 -6
  45. package/dist/esm/plugins/new-block/index.js +8 -9
  46. package/dist/esm/plugins/run-block/index.js +97 -65
  47. package/dist/esm/plugins/set-block-build-mode/index.js +4 -3
  48. package/dist/esm/plugins/set-head/index.js +2 -4
  49. package/dist/esm/plugins/set-runtime-log-level/index.js +4 -3
  50. package/dist/esm/plugins/set-storage/index.js +3 -4
  51. package/dist/esm/plugins/time-travel/index.js +2 -4
  52. package/dist/esm/plugins/try-runtime/index.js +33 -30
  53. package/dist/esm/rpc/index.js +18 -15
  54. package/dist/esm/schema/index.js +31 -18
  55. package/dist/esm/server.js +70 -52
  56. package/dist/esm/setup-with-server.js +3 -3
  57. package/dist/esm/types.js +12 -1
  58. package/dist/esm/utils/decoder.js +12 -4
  59. package/dist/esm/utils/generate-html-diff.js +10 -6
  60. package/dist/esm/utils/open-html.js +1 -1
  61. package/dist/esm/utils/override.js +11 -13
  62. package/dist/esm/utils/tunnel.js +1 -8
  63. package/package.json +13 -17
  64. package/dist/esm/package.json +0 -1
  65. /package/{chopsticks.js → chopsticks.cjs} +0 -0
@@ -1,70 +1,103 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.cli = void 0;
7
- const chopsticks_core_1 = require("@acala-network/chopsticks-core");
8
- const lodash_1 = __importDefault(require("lodash"));
9
- const server_1 = require("../../server");
10
- const cli_options_1 = require("../../cli-options");
11
- const rpc_1 = require("../../rpc");
12
- const context_1 = require("../../context");
13
- const logger = chopsticks_core_1.defaultLogger.child({ name: 'follow-chain' });
14
- const options = lodash_1.default.pick(cli_options_1.defaultOptions, ['endpoint', 'wasm-override', 'runtime-log-level', 'offchain-worker']);
15
- const cli = (y) => {
16
- y.command('follow-chain', 'Always follow the latest block on upstream', (yargs) => yargs.options({
17
- ...options,
18
- port: {
19
- desc: 'Port to listen on',
20
- number: true,
21
- },
22
- 'head-mode': {
23
- desc: 'Head mode',
24
- choices: ['latest', 'finalized'],
25
- default: 'finalized',
26
- },
27
- }), 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 _chopstickscore = require("@acala-network/chopsticks-core");
12
+ const _lodash = /*#__PURE__*/ _interop_require_default(require("lodash"));
13
+ const _server = require("../../server");
14
+ const _clioptions = require("../../cli-options");
15
+ const _rpc = require("../../rpc");
16
+ const _context = require("../../context");
17
+ function _interop_require_default(obj) {
18
+ return obj && obj.__esModule ? obj : {
19
+ default: obj
20
+ };
21
+ }
22
+ const logger = _chopstickscore.defaultLogger.child({
23
+ name: 'follow-chain'
24
+ });
25
+ const options = _lodash.default.pick(_clioptions.defaultOptions, [
26
+ 'endpoint',
27
+ 'wasm-override',
28
+ 'runtime-log-level',
29
+ 'offchain-worker'
30
+ ]);
31
+ const cli = (y)=>{
32
+ y.command('follow-chain', 'Always follow the latest block on upstream', (yargs)=>yargs.options({
33
+ ...options,
34
+ port: {
35
+ desc: 'Port to listen on',
36
+ number: true
37
+ },
38
+ 'head-mode': {
39
+ desc: 'Head mode',
40
+ choices: [
41
+ 'latest',
42
+ 'finalized'
43
+ ],
44
+ default: 'finalized'
45
+ }
46
+ }), async (argv)=>{
28
47
  const port = argv.port ?? 8000;
29
48
  const endpoint = argv.endpoint;
30
49
  if (/^(https|http):\/\//.test(endpoint || '')) {
31
50
  throw Error('http provider is not supported');
32
51
  }
33
- const context = await (0, context_1.setupContext)(argv, true);
34
- const { close, port: listenPort } = await (0, server_1.createServer)((0, rpc_1.handler)(context), port);
52
+ const context = await (0, _context.setupContext)(argv, true);
53
+ const { close, port: listenPort } = await (0, _server.createServer)((0, _rpc.handler)(context), port);
35
54
  logger.info(`${await context.chain.api.getSystemChain()} RPC listening on port ${listenPort}`);
36
55
  const chain = context.chain;
37
- chain.api[argv.headMode === 'latest' ? 'subscribeRemoteNewHeads' : 'subscribeRemoteFinalizedHeads'](async (error, data) => {
56
+ chain.api[argv.headMode === 'latest' ? 'subscribeRemoteNewHeads' : 'subscribeRemoteFinalizedHeads'](async (error, data)=>{
38
57
  try {
39
- if (error)
40
- throw error;
41
- logger.info({ header: data }, `Follow ${argv.headMode} head from upstream`);
58
+ if (error) throw error;
59
+ logger.info({
60
+ header: data
61
+ }, `Follow ${argv.headMode} head from upstream`);
42
62
  const parent = await chain.getBlock(data.parentHash);
43
- if (!parent)
44
- throw Error(`Cannot find parent', ${data.parentHash}`);
63
+ if (!parent) throw Error(`Cannot find parent', ${data.parentHash}`);
45
64
  const registry = await parent.registry;
46
65
  const header = registry.createType('Header', data);
47
66
  const wasm = await parent.wasm;
48
- const block = new chopsticks_core_1.Block(chain, header.number.toNumber(), header.hash.toHex(), parent);
67
+ const block = new _chopstickscore.Block(chain, header.number.toNumber(), header.hash.toHex(), parent);
49
68
  await chain.setHead(block);
50
- const calls = [['Core_initialize_block', [header.toHex()]]];
51
- for (const extrinsic of await block.extrinsics) {
52
- calls.push(['BlockBuilder_apply_extrinsic', [extrinsic]]);
69
+ const calls = [
70
+ [
71
+ 'Core_initialize_block',
72
+ [
73
+ header.toHex()
74
+ ]
75
+ ]
76
+ ];
77
+ for (const extrinsic of (await block.extrinsics)){
78
+ calls.push([
79
+ 'BlockBuilder_apply_extrinsic',
80
+ [
81
+ extrinsic
82
+ ]
83
+ ]);
53
84
  }
54
- calls.push(['BlockBuilder_finalize_block', []]);
55
- const result = await (0, chopsticks_core_1.runTask)({
85
+ calls.push([
86
+ 'BlockBuilder_finalize_block',
87
+ []
88
+ ]);
89
+ const result = await (0, _chopstickscore.runTask)({
56
90
  wasm,
57
91
  calls,
58
92
  mockSignatureHost: false,
59
93
  allowUnresolvedImports: false,
60
- runtimeLogLevel: argv.runtimeLogLevel || 0,
61
- }, (0, chopsticks_core_1.taskHandler)(parent));
94
+ runtimeLogLevel: argv.runtimeLogLevel || 0
95
+ }, (0, _chopstickscore.taskHandler)(parent));
62
96
  if ('Error' in result) {
63
97
  throw new Error(result.Error);
64
98
  }
65
- (0, chopsticks_core_1.printRuntimeLogs)(result.Call.runtimeLogs);
66
- }
67
- catch (e) {
99
+ (0, _chopstickscore.printRuntimeLogs)(result.Call.runtimeLogs);
100
+ } catch (e) {
68
101
  logger.error(e, 'Error when processing new head');
69
102
  await close();
70
103
  process.exit(1);
@@ -72,4 +105,3 @@ const cli = (y) => {
72
105
  });
73
106
  });
74
107
  };
75
- exports.cli = cli;
@@ -1,36 +1,73 @@
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]; } };
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
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
+ pluginExtendCli: function() {
13
+ return pluginExtendCli;
14
+ },
15
+ pluginHandlers: function() {
16
+ return pluginHandlers;
7
17
  }
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
  });
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.pluginExtendCli = exports.pluginHandlers = void 0;
30
- const lodash_1 = __importDefault(require("lodash"));
31
- const logger_1 = require("../logger");
32
- const logger = logger_1.defaultLogger.child({ name: 'plugin' });
33
- exports.pluginHandlers = {};
19
+ const _lodash = /*#__PURE__*/ _interop_require_default(require("lodash"));
20
+ const _logger = require("../logger");
21
+ function _interop_require_default(obj) {
22
+ return obj && obj.__esModule ? obj : {
23
+ default: obj
24
+ };
25
+ }
26
+ function _getRequireWildcardCache(nodeInterop) {
27
+ if (typeof WeakMap !== "function") return null;
28
+ var cacheBabelInterop = new WeakMap();
29
+ var cacheNodeInterop = new WeakMap();
30
+ return (_getRequireWildcardCache = function(nodeInterop) {
31
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
32
+ })(nodeInterop);
33
+ }
34
+ function _interop_require_wildcard(obj, nodeInterop) {
35
+ if (!nodeInterop && obj && obj.__esModule) {
36
+ return obj;
37
+ }
38
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
39
+ return {
40
+ default: obj
41
+ };
42
+ }
43
+ var cache = _getRequireWildcardCache(nodeInterop);
44
+ if (cache && cache.has(obj)) {
45
+ return cache.get(obj);
46
+ }
47
+ var newObj = {
48
+ __proto__: null
49
+ };
50
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
51
+ for(var key in obj){
52
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
53
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
54
+ if (desc && (desc.get || desc.set)) {
55
+ Object.defineProperty(newObj, key, desc);
56
+ } else {
57
+ newObj[key] = obj[key];
58
+ }
59
+ }
60
+ }
61
+ newObj.default = obj;
62
+ if (cache) {
63
+ cache.set(obj, newObj);
64
+ }
65
+ return newObj;
66
+ }
67
+ const logger = _logger.defaultLogger.child({
68
+ name: 'plugin'
69
+ });
70
+ const pluginHandlers = {};
34
71
  const plugins = [
35
72
  'decode-key',
36
73
  'dry-run',
@@ -42,25 +79,24 @@ const plugins = [
42
79
  'set-runtime-log-level',
43
80
  'set-storage',
44
81
  'time-travel',
45
- 'try-runtime',
82
+ 'try-runtime'
46
83
  ];
47
- (async () => {
48
- for (const plugin of plugins) {
49
- const { rpc, name } = await Promise.resolve(`${`./${plugin}`}`).then(s => __importStar(require(s)));
84
+ (async ()=>{
85
+ for (const plugin of plugins){
86
+ const { rpc, name } = await Promise.resolve(`./${plugin}`).then((p)=>/*#__PURE__*/ _interop_require_wildcard(require(p)));
50
87
  if (rpc) {
51
- const methodName = name || lodash_1.default.camelCase(plugin);
52
- exports.pluginHandlers[`dev_${methodName}`] = rpc;
88
+ const methodName = name || _lodash.default.camelCase(plugin);
89
+ pluginHandlers[`dev_${methodName}`] = rpc;
53
90
  logger.debug(`Registered plugin ${plugin} RPC`);
54
91
  }
55
92
  }
56
93
  })();
57
- const pluginExtendCli = async (y) => {
58
- for (const plugin of plugins) {
59
- const { cli } = await Promise.resolve(`${`./${plugin}`}`).then(s => __importStar(require(s)));
94
+ const pluginExtendCli = async (y)=>{
95
+ for (const plugin of plugins){
96
+ const { cli } = await Promise.resolve(`./${plugin}`).then((p)=>/*#__PURE__*/ _interop_require_wildcard(require(p)));
60
97
  if (cli) {
61
98
  cli(y);
62
99
  logger.debug(`Registered plugin ${plugin} CLI`);
63
100
  }
64
101
  }
65
102
  };
66
- exports.pluginExtendCli = pluginExtendCli;
@@ -1,47 +1,16 @@
1
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 logger_1 = require("../../logger");
6
- /**
7
- * Build new blocks.
8
- *
9
- * This function is a dev rpc handler. Use `dev_newBlock` as the method name when calling it.
10
- *
11
- * @param context - The context object of the rpc handler
12
- * @param params - The parameters of the rpc handler
13
- *
14
- * @example Build 2 blocks
15
- * ```ts
16
- * import { WsProvider } from '@polkadot/rpc-provider'
17
- * const ws = new WsProvider(`ws://localhost:8000`)
18
- * await ws.send('dev_newBlock', [{ count: 2 }])
19
- * ```
20
- * @example Build a block with upward messages
21
- * ```ts
22
- * import { WsProvider } from '@polkadot/rpc-provider'
23
- * const ws = new WsProvider(`ws://localhost:8000`)
24
- * await ws.send('dev_newBlock', [
25
- * {
26
- * ump: {
27
- * // https://acala.subscan.io/xcm_message/polkadot-ff66f28818d0b74573e62db8317e354b253fbc80
28
- * 2000: [
29
- * '0x021000040000000007903fc4db080a130000000007903fc4db08000d010004000101009c4b11a0974cba4a395c94832fba812868a6cb0ba09e8519b3521093ea359905',
30
- * ],
31
- * }
32
- * }
33
- * ])
34
- * ```
35
- *
36
- * @example Build two blocks with unsafeBlockHeight
37
- * ```ts
38
- * import { WsProvider } from '@polkadot/rpc-provider'
39
- * const ws = new WsProvider(`ws://localhost:8000`)
40
- * // this will create two blocks with block height 100000001 and 100000002
41
- * await ws.send('dev_newBlock', [{ count: 2, unsafeBlockHeight: 100000001 }])
42
- * ```
43
- */
44
- const rpc = async (context, params) => {
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "rpc", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return rpc;
9
+ }
10
+ });
11
+ const _chopstickscore = require("@acala-network/chopsticks-core");
12
+ const _logger = require("../../logger");
13
+ const rpc = async (context, params)=>{
45
14
  const [param] = params;
46
15
  const { count, to, hrmp, ump, dmp, transactions, unsafeBlockHeight } = param || {};
47
16
  const now = context.chain.head.number;
@@ -49,23 +18,22 @@ const rpc = async (context, params) => {
49
18
  const finalCount = diff > 0 ? diff : 1;
50
19
  let finalHash;
51
20
  if (unsafeBlockHeight < now) {
52
- throw new chopsticks_core_1.ResponseError(1, 'unsafeBlockHeight must be greater than current block height');
21
+ throw new _chopstickscore.ResponseError(1, 'unsafeBlockHeight must be greater than current block height');
53
22
  }
54
- for (let i = 0; i < finalCount; i++) {
55
- const block = await context.chain
56
- .newBlock({
23
+ for(let i = 0; i < finalCount; i++){
24
+ const block = await context.chain.newBlock({
57
25
  transactions,
58
26
  horizontalMessages: hrmp,
59
27
  upwardMessages: ump,
60
28
  downwardMessages: dmp,
61
- unsafeBlockHeight: i === 0 ? unsafeBlockHeight : undefined,
62
- })
63
- .catch((error) => {
64
- throw new chopsticks_core_1.ResponseError(1, error.toString());
29
+ unsafeBlockHeight: i === 0 ? unsafeBlockHeight : undefined
30
+ }).catch((error)=>{
31
+ throw new _chopstickscore.ResponseError(1, error.toString());
65
32
  });
66
- logger_1.defaultLogger.debug({ hash: block.hash }, 'dev_newBlock');
33
+ _logger.defaultLogger.debug({
34
+ hash: block.hash
35
+ }, 'dev_newBlock');
67
36
  finalHash = block.hash;
68
37
  }
69
38
  return finalHash;
70
39
  };
71
- exports.rpc = rpc;