@acala-network/chopsticks 0.5.5 → 0.5.7

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 (49) hide show
  1. package/lib/api.js +5 -1
  2. package/lib/blockchain/block-builder.js +43 -36
  3. package/lib/blockchain/block.js +28 -24
  4. package/lib/blockchain/head-state.js +14 -9
  5. package/lib/blockchain/index.js +28 -24
  6. package/lib/blockchain/inherent/index.js +20 -11
  7. package/lib/blockchain/inherent/para-enter.js +7 -3
  8. package/lib/blockchain/inherent/parachain/babe-randomness.js +7 -3
  9. package/lib/blockchain/inherent/parachain/nimbus-author-inherent.js +7 -3
  10. package/lib/blockchain/inherent/parachain/validation-data.js +33 -26
  11. package/lib/blockchain/storage-layer.js +16 -8
  12. package/lib/blockchain/txpool.js +20 -13
  13. package/lib/cli.js +35 -30
  14. package/lib/db/entities.js +9 -6
  15. package/lib/db/index.js +32 -5
  16. package/lib/dry-run-preimage.js +27 -23
  17. package/lib/dry-run.js +16 -12
  18. package/lib/executor.js +36 -24
  19. package/lib/genesis-provider.js +24 -17
  20. package/lib/index.js +31 -7
  21. package/lib/logger.js +10 -3
  22. package/lib/rpc/dev/dry-run.js +28 -21
  23. package/lib/rpc/dev/index.js +16 -14
  24. package/lib/rpc/index.js +16 -9
  25. package/lib/rpc/shared.js +7 -3
  26. package/lib/rpc/substrate/author.js +10 -8
  27. package/lib/rpc/substrate/chain.js +7 -5
  28. package/lib/rpc/substrate/index.js +16 -11
  29. package/lib/rpc/substrate/payment.js +9 -7
  30. package/lib/rpc/substrate/state.js +7 -5
  31. package/lib/rpc/substrate/system.js +11 -6
  32. package/lib/run-block.js +16 -12
  33. package/lib/schema/index.js +25 -22
  34. package/lib/server.js +35 -8
  35. package/lib/setup-with-server.js +12 -8
  36. package/lib/setup.js +30 -26
  37. package/lib/utils/decoder.js +25 -16
  38. package/lib/utils/generate-html-diff.js +20 -12
  39. package/lib/utils/import-storage.js +19 -11
  40. package/lib/utils/index.js +19 -10
  41. package/lib/utils/open-html.js +7 -3
  42. package/lib/utils/proof.js +17 -9
  43. package/lib/utils/set-storage.js +14 -10
  44. package/lib/utils/time-travel.js +28 -21
  45. package/lib/xcm/downward.js +15 -11
  46. package/lib/xcm/horizontal.js +11 -7
  47. package/lib/xcm/index.js +19 -14
  48. package/lib/xcm/upward.js +10 -6
  49. package/package.json +2 -2
@@ -1,6 +1,11 @@
1
- import { hexToU8a } from '@polkadot/util';
2
- import { readFileSync } from 'node:fs';
3
- import path from 'node:path';
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
+ const util_1 = require("@polkadot/util");
7
+ const node_fs_1 = require("node:fs");
8
+ const node_path_1 = __importDefault(require("node:path"));
4
9
  const handlers = {
5
10
  system_localPeerId: async () => '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY',
6
11
  system_nodeRoles: async () => ['Full'],
@@ -15,7 +20,7 @@ const handlers = {
15
20
  return context.chain.api.getSystemName();
16
21
  },
17
22
  system_version: async (_context) => {
18
- const { version } = JSON.parse(readFileSync(path.join(__dirname, '../../../package.json'), 'utf-8'));
23
+ const { version } = JSON.parse((0, node_fs_1.readFileSync)(node_path_1.default.join(__dirname, '../../../package.json'), 'utf-8'));
19
24
  return `chopsticks-v${version}`;
20
25
  },
21
26
  system_chainType: async (_context) => {
@@ -37,8 +42,8 @@ const handlers = {
37
42
  const registry = await head.registry;
38
43
  const account = registry.createType('AccountId', address);
39
44
  const result = await head.call('AccountNonceApi_account_nonce', [account.toHex()]);
40
- const nonce = registry.createType('Index', hexToU8a(result.result)).toNumber();
45
+ const nonce = registry.createType('Index', (0, util_1.hexToU8a)(result.result)).toNumber();
41
46
  return nonce + context.chain.txPool.pendingExtrinsicsBy(address).length;
42
47
  },
43
48
  };
44
- export default handlers;
49
+ exports.default = handlers;
package/lib/run-block.js CHANGED
@@ -1,10 +1,13 @@
1
- import { writeFileSync } from 'node:fs';
2
- import { generateHtmlDiffPreviewFile } from './utils/generate-html-diff';
3
- import { openHtml } from './utils/open-html';
4
- import { runTask, taskHandler } from './executor';
5
- import { setup } from './setup';
6
- export const runBlock = async (argv) => {
7
- const context = await setup(argv);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runBlock = void 0;
4
+ const node_fs_1 = require("node:fs");
5
+ const generate_html_diff_1 = require("./utils/generate-html-diff");
6
+ const open_html_1 = require("./utils/open-html");
7
+ const executor_1 = require("./executor");
8
+ const setup_1 = require("./setup");
9
+ const runBlock = async (argv) => {
10
+ const context = await (0, setup_1.setup)(argv);
8
11
  const header = await context.chain.head.header;
9
12
  const wasm = await context.chain.head.wasm;
10
13
  const block = context.chain.head;
@@ -16,28 +19,29 @@ export const runBlock = async (argv) => {
16
19
  calls.push(['BlockBuilder_apply_extrinsic', [extrinsic]]);
17
20
  }
18
21
  calls.push(['BlockBuilder_finalize_block', []]);
19
- const result = await runTask({
22
+ const result = await (0, executor_1.runTask)({
20
23
  wasm,
21
24
  calls,
22
25
  storage: [],
23
26
  mockSignatureHost: false,
24
27
  allowUnresolvedImports: false,
25
- }, taskHandler(parent));
28
+ }, (0, executor_1.taskHandler)(parent));
26
29
  if (result.Error) {
27
30
  throw new Error(result.Error);
28
31
  }
29
32
  if (argv['html']) {
30
- const filePath = await generateHtmlDiffPreviewFile(parent, result.Call.storageDiff, block.hash);
33
+ const filePath = await (0, generate_html_diff_1.generateHtmlDiffPreviewFile)(parent, result.Call.storageDiff, block.hash);
31
34
  console.log(`Generated preview ${filePath}`);
32
35
  if (argv['open']) {
33
- openHtml(filePath);
36
+ (0, open_html_1.openHtml)(filePath);
34
37
  }
35
38
  }
36
39
  else if (argv['output-path']) {
37
- writeFileSync(argv['output-path'], JSON.stringify(result, null, 2));
40
+ (0, node_fs_1.writeFileSync)(argv['output-path'], JSON.stringify(result, null, 2));
38
41
  }
39
42
  else {
40
43
  console.dir(result, { depth: null, colors: false });
41
44
  }
42
45
  process.exit(0);
43
46
  };
47
+ exports.runBlock = runBlock;
@@ -1,27 +1,30 @@
1
- import { BuildBlockMode } from '../blockchain/txpool';
2
- import { z } from 'zod';
3
- export const genesisSchema = z.object({
4
- id: z.string(),
5
- name: z.string(),
6
- properties: z.object({
7
- ss58Format: z.number().optional(),
8
- tokenDecimals: z.union([z.number(), z.array(z.number())]).optional(),
9
- tokenSymbol: z.union([z.string(), z.array(z.string())]).optional(),
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configSchema = exports.genesisSchema = void 0;
4
+ const txpool_1 = require("../blockchain/txpool");
5
+ const zod_1 = require("zod");
6
+ exports.genesisSchema = zod_1.z.object({
7
+ id: zod_1.z.string(),
8
+ name: zod_1.z.string(),
9
+ properties: zod_1.z.object({
10
+ ss58Format: zod_1.z.number().optional(),
11
+ tokenDecimals: zod_1.z.union([zod_1.z.number(), zod_1.z.array(zod_1.z.number())]).optional(),
12
+ tokenSymbol: zod_1.z.union([zod_1.z.string(), zod_1.z.array(zod_1.z.string())]).optional(),
10
13
  }),
11
- genesis: z.object({ raw: z.object({ top: z.record(z.string()) }) }),
14
+ genesis: zod_1.z.object({ raw: zod_1.z.object({ top: zod_1.z.record(zod_1.z.string()) }) }),
12
15
  });
13
- export const configSchema = z
16
+ exports.configSchema = zod_1.z
14
17
  .object({
15
- port: z.number().optional(),
16
- endpoint: z.string().optional(),
17
- block: z.union([z.string().length(66).startsWith('0x'), z.number()]).optional(),
18
- 'build-block-mode': z.nativeEnum(BuildBlockMode).optional(),
19
- 'import-storage': z.any().optional(),
20
- 'mock-signature-host': z.boolean().optional(),
21
- db: z.string().optional(),
22
- 'wasm-override': z.string().optional(),
23
- genesis: z.union([z.string(), genesisSchema]).optional(),
24
- timestamp: z.number().optional(),
25
- 'registered-types': z.any().optional(),
18
+ port: zod_1.z.number().optional(),
19
+ endpoint: zod_1.z.string().optional(),
20
+ block: zod_1.z.union([zod_1.z.string().length(66).startsWith('0x'), zod_1.z.number()]).optional(),
21
+ 'build-block-mode': zod_1.z.nativeEnum(txpool_1.BuildBlockMode).optional(),
22
+ 'import-storage': zod_1.z.any().optional(),
23
+ 'mock-signature-host': zod_1.z.boolean().optional(),
24
+ db: zod_1.z.string().optional(),
25
+ 'wasm-override': zod_1.z.string().optional(),
26
+ genesis: zod_1.z.union([zod_1.z.string(), exports.genesisSchema]).optional(),
27
+ timestamp: zod_1.z.number().optional(),
28
+ 'registered-types': zod_1.z.any().optional(),
26
29
  })
27
30
  .strict();
package/lib/server.js CHANGED
@@ -1,6 +1,32 @@
1
- import WebSocket, { WebSocketServer } from 'ws';
2
- import { defaultLogger, truncate } from './logger';
3
- const logger = defaultLogger.child({ name: 'ws' });
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.createServer = void 0;
27
+ const ws_1 = __importStar(require("ws"));
28
+ const logger_1 = require("./logger");
29
+ const logger = logger_1.defaultLogger.child({ name: 'ws' });
4
30
  const parseRequest = (request) => {
5
31
  try {
6
32
  return JSON.parse(request);
@@ -10,7 +36,7 @@ const parseRequest = (request) => {
10
36
  }
11
37
  };
12
38
  const createWS = async (port) => {
13
- const wss = new WebSocketServer({ port, maxPayload: 1024 * 1024 * 100 });
39
+ const wss = new ws_1.WebSocketServer({ port, maxPayload: 1024 * 1024 * 100 });
14
40
  const promise = new Promise((resolve) => {
15
41
  wss.on('listening', () => {
16
42
  resolve([wss, wss.address().port]);
@@ -21,7 +47,7 @@ const createWS = async (port) => {
21
47
  });
22
48
  return promise;
23
49
  };
24
- export const createServer = async (handler, port) => {
50
+ const createServer = async (handler, port) => {
25
51
  let wss;
26
52
  let listenPort;
27
53
  for (let i = 0; i < 5; i++) {
@@ -40,7 +66,7 @@ export const createServer = async (handler, port) => {
40
66
  wss.on('connection', (ws) => {
41
67
  logger.debug('New connection');
42
68
  const send = (data) => {
43
- if (ws.readyState === WebSocket.OPEN) {
69
+ if (ws.readyState === ws_1.default.OPEN) {
44
70
  ws.send(JSON.stringify(data));
45
71
  }
46
72
  };
@@ -50,7 +76,7 @@ export const createServer = async (handler, port) => {
50
76
  subscriptions[subid] = onCancel;
51
77
  return (data) => {
52
78
  if (subscriptions[subid]) {
53
- logger.trace({ method, subid, data: truncate(data) }, 'Subscription notification');
79
+ logger.trace({ method, subid, data: (0, logger_1.truncate)(data) }, 'Subscription notification');
54
80
  send({
55
81
  jsonrpc: '2.0',
56
82
  method,
@@ -106,7 +132,7 @@ export const createServer = async (handler, port) => {
106
132
  logger.trace({
107
133
  id: req.id,
108
134
  method: req.method,
109
- result: truncate(resp),
135
+ result: (0, logger_1.truncate)(resp),
110
136
  }, 'Sending response for request');
111
137
  send({
112
138
  id: req.id,
@@ -139,3 +165,4 @@ export const createServer = async (handler, port) => {
139
165
  }),
140
166
  };
141
167
  };
168
+ exports.createServer = createServer;
@@ -1,19 +1,23 @@
1
- import { createServer } from './server';
2
- import { handler } from './rpc';
3
- import { logger } from './rpc/shared';
4
- import { setup } from './setup';
5
- export const setupWithServer = async (argv) => {
6
- const context = await setup(argv);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setupWithServer = void 0;
4
+ const server_1 = require("./server");
5
+ const rpc_1 = require("./rpc");
6
+ const shared_1 = require("./rpc/shared");
7
+ const setup_1 = require("./setup");
8
+ const setupWithServer = async (argv) => {
9
+ const context = await (0, setup_1.setup)(argv);
7
10
  const port = argv.port ?? 8000;
8
11
  if (argv.genesis) {
9
12
  // mine 1st block when starting from genesis to set some mock validation data
10
13
  await context.chain.newBlock();
11
14
  }
12
- const { close, port: listenPort } = await createServer(handler(context), port);
13
- logger.info(`${await context.chain.api.getSystemChain()} RPC listening on port ${listenPort}`);
15
+ const { close, port: listenPort } = await (0, server_1.createServer)((0, rpc_1.handler)(context), port);
16
+ shared_1.logger.info(`${await context.chain.api.getSystemChain()} RPC listening on port ${listenPort}`);
14
17
  return {
15
18
  ...context,
16
19
  close,
17
20
  listenPort,
18
21
  };
19
22
  };
23
+ exports.setupWithServer = setupWithServer;
package/lib/setup.js CHANGED
@@ -1,27 +1,30 @@
1
- import '@polkadot/types-codec';
2
- import { WsProvider } from '@polkadot/api';
3
- import { Api } from './api';
4
- import { Blockchain } from './blockchain';
5
- import { GenesisProvider } from './genesis-provider';
6
- import { InherentProviders, ParaInherentEnter, SetBabeRandomness, SetNimbusAuthorInherent, SetTimestamp, SetValidationData, } from './blockchain/inherent';
7
- import { defaultLogger } from './logger';
8
- import { importStorage, overrideWasm } from './utils/import-storage';
9
- import { openDb } from './db';
10
- import { timeTravel } from './utils/time-travel';
11
- export const setup = async (argv) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setup = void 0;
4
+ require("@polkadot/types-codec");
5
+ const api_1 = require("@polkadot/api");
6
+ const api_2 = require("./api");
7
+ const blockchain_1 = require("./blockchain");
8
+ const genesis_provider_1 = require("./genesis-provider");
9
+ const inherent_1 = require("./blockchain/inherent");
10
+ const logger_1 = require("./logger");
11
+ const import_storage_1 = require("./utils/import-storage");
12
+ const db_1 = require("./db");
13
+ const time_travel_1 = require("./utils/time-travel");
14
+ const setup = async (argv) => {
12
15
  let provider;
13
16
  if (argv.genesis) {
14
17
  if (typeof argv.genesis === 'string') {
15
- provider = await GenesisProvider.fromUrl(argv.genesis);
18
+ provider = await genesis_provider_1.GenesisProvider.fromUrl(argv.genesis);
16
19
  }
17
20
  else {
18
- provider = new GenesisProvider(argv.genesis);
21
+ provider = new genesis_provider_1.GenesisProvider(argv.genesis);
19
22
  }
20
23
  }
21
24
  else {
22
- provider = new WsProvider(argv.endpoint);
25
+ provider = new api_1.WsProvider(argv.endpoint);
23
26
  }
24
- const api = new Api(provider);
27
+ const api = new api_2.Api(provider);
25
28
  await api.isReady;
26
29
  let blockHash;
27
30
  if (argv.block == null) {
@@ -36,19 +39,19 @@ export const setup = async (argv) => {
36
39
  else {
37
40
  throw new Error(`Invalid block number or hash: ${argv.block}`);
38
41
  }
39
- defaultLogger.debug({ ...argv, blockHash }, 'Args');
42
+ logger_1.defaultLogger.debug({ ...argv, blockHash }, 'Args');
40
43
  let db;
41
44
  if (argv.db) {
42
- db = await openDb(argv.db);
45
+ db = await (0, db_1.openDb)(argv.db);
43
46
  }
44
47
  const header = await api.getHeader(blockHash);
45
- const inherents = new InherentProviders(new SetTimestamp(), [
46
- new SetValidationData(),
47
- new ParaInherentEnter(),
48
- new SetNimbusAuthorInherent(),
49
- new SetBabeRandomness(),
48
+ const inherents = new inherent_1.InherentProviders(new inherent_1.SetTimestamp(), [
49
+ new inherent_1.SetValidationData(),
50
+ new inherent_1.ParaInherentEnter(),
51
+ new inherent_1.SetNimbusAuthorInherent(),
52
+ new inherent_1.SetBabeRandomness(),
50
53
  ]);
51
- const chain = new Blockchain({
54
+ const chain = new blockchain_1.Blockchain({
52
55
  api,
53
56
  buildBlockMode: argv['build-block-mode'],
54
57
  inherentProvider: inherents,
@@ -62,10 +65,11 @@ export const setup = async (argv) => {
62
65
  registeredTypes: argv['registered-types'],
63
66
  });
64
67
  if (argv.timestamp)
65
- await timeTravel(chain, argv.timestamp);
68
+ await (0, time_travel_1.timeTravel)(chain, argv.timestamp);
66
69
  // override wasm before importing storage, in case new pallets have been
67
70
  // added that have storage imports
68
- await overrideWasm(chain, argv['wasm-override']);
69
- await importStorage(chain, argv['import-storage']);
71
+ await (0, import_storage_1.overrideWasm)(chain, argv['wasm-override']);
72
+ await (0, import_storage_1.importStorage)(chain, argv['import-storage']);
70
73
  return { chain, api, ws: provider };
71
74
  };
75
+ exports.setup = setup;
@@ -1,9 +1,15 @@
1
- import '@polkadot/types-codec';
2
- import { blake2AsHex } from '@polkadot/util-crypto';
3
- import { create } from 'jsondiffpatch';
4
- import { hexToU8a, u8aToHex } from '@polkadot/util';
5
- import _ from 'lodash';
6
- const diffPatcher = create({
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.decodeStorageDiff = exports.decodeKeyValue = exports.decodeKey = void 0;
7
+ require("@polkadot/types-codec");
8
+ const util_crypto_1 = require("@polkadot/util-crypto");
9
+ const jsondiffpatch_1 = require("jsondiffpatch");
10
+ const util_1 = require("@polkadot/util");
11
+ const lodash_1 = __importDefault(require("lodash"));
12
+ const diffPatcher = (0, jsondiffpatch_1.create)({
7
13
  array: { detectMove: false },
8
14
  textDiff: { minLength: Number.MAX_VALUE }, // skip text diff
9
15
  });
@@ -22,7 +28,7 @@ const getStorageEntry = (meta, block, key) => {
22
28
  }
23
29
  for (const module of Object.values(meta.query)) {
24
30
  for (const storage of Object.values(module)) {
25
- const keyPrefix = u8aToHex(storage.keyPrefix());
31
+ const keyPrefix = (0, util_1.u8aToHex)(storage.keyPrefix());
26
32
  if (key.startsWith(keyPrefix)) {
27
33
  cache[keyPrefix] = storage;
28
34
  return storage;
@@ -31,7 +37,7 @@ const getStorageEntry = (meta, block, key) => {
31
37
  }
32
38
  return undefined;
33
39
  };
34
- export const decodeKey = (meta, block, key) => {
40
+ const decodeKey = (meta, block, key) => {
35
41
  const storage = getStorageEntry(meta, block, key);
36
42
  const decodedKey = meta.registry.createType('StorageKey', key);
37
43
  if (storage) {
@@ -40,8 +46,9 @@ export const decodeKey = (meta, block, key) => {
40
46
  }
41
47
  return {};
42
48
  };
43
- export const decodeKeyValue = (meta, block, key, value) => {
44
- const { storage, decodedKey } = decodeKey(meta, block, key);
49
+ exports.decodeKey = decodeKey;
50
+ const decodeKeyValue = (meta, block, key, value) => {
51
+ const { storage, decodedKey } = (0, exports.decodeKey)(meta, block, key);
45
52
  if (!storage || !decodedKey) {
46
53
  return { [key]: value };
47
54
  }
@@ -49,9 +56,9 @@ export const decodeKeyValue = (meta, block, key, value) => {
49
56
  if (!value)
50
57
  return null;
51
58
  if (storage.section === 'substrate' && storage.method === 'code') {
52
- return `:code blake2_256 ${blake2AsHex(value, 256)} (${hexToU8a(value).length} bytes)`;
59
+ return `:code blake2_256 ${(0, util_crypto_1.blake2AsHex)(value, 256)} (${(0, util_1.hexToU8a)(value).length} bytes)`;
53
60
  }
54
- return meta.registry.createType(decodedKey.outputType, hexToU8a(value)).toHuman();
61
+ return meta.registry.createType(decodedKey.outputType, (0, util_1.hexToU8a)(value)).toHuman();
55
62
  };
56
63
  switch (decodedKey.args.length) {
57
64
  case 2: {
@@ -82,17 +89,19 @@ export const decodeKeyValue = (meta, block, key, value) => {
82
89
  };
83
90
  }
84
91
  };
85
- export const decodeStorageDiff = async (block, diff) => {
92
+ exports.decodeKeyValue = decodeKeyValue;
93
+ const decodeStorageDiff = async (block, diff) => {
86
94
  const oldState = {};
87
95
  const newState = {};
88
96
  const meta = await block.meta;
89
97
  for (const [key, value] of diff) {
90
- _.merge(oldState, decodeKeyValue(meta, block, key, (await block.get(key))));
91
- _.merge(newState, decodeKeyValue(meta, block, key, value));
98
+ lodash_1.default.merge(oldState, (0, exports.decodeKeyValue)(meta, block, key, (await block.get(key))));
99
+ lodash_1.default.merge(newState, (0, exports.decodeKeyValue)(meta, block, key, value));
92
100
  }
93
- const oldStateWithoutEvents = _.cloneDeep(oldState);
101
+ const oldStateWithoutEvents = lodash_1.default.cloneDeep(oldState);
94
102
  if (oldStateWithoutEvents['system']?.['events']) {
95
103
  oldStateWithoutEvents['system']['events'] = [];
96
104
  }
97
105
  return [oldState, newState, diffPatcher.diff(oldStateWithoutEvents, newState)];
98
106
  };
107
+ exports.decodeStorageDiff = decodeStorageDiff;
@@ -1,16 +1,24 @@
1
- import { decodeStorageDiff } from './decoder';
2
- import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
3
- import { template } from 'lodash';
4
- import path from 'node:path';
5
- export const generateHtmlDiff = async (block, diff) => {
6
- const [left, _right, delta] = await decodeStorageDiff(block, diff);
7
- const htmlTemplate = readFileSync(path.join(__dirname, '../../template/diff.html'), 'utf-8');
8
- return template(htmlTemplate)({ left: JSON.stringify(left), delta: JSON.stringify(delta) });
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
4
  };
10
- export const generateHtmlDiffPreviewFile = async (block, diff, filename) => {
11
- const html = await generateHtmlDiff(block, diff);
12
- mkdirSync('./preview', { recursive: true });
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.generateHtmlDiffPreviewFile = exports.generateHtmlDiff = void 0;
7
+ const decoder_1 = require("./decoder");
8
+ const node_fs_1 = require("node:fs");
9
+ const lodash_1 = require("lodash");
10
+ const node_path_1 = __importDefault(require("node:path"));
11
+ const generateHtmlDiff = async (block, diff) => {
12
+ const [left, _right, delta] = await (0, decoder_1.decodeStorageDiff)(block, diff);
13
+ const htmlTemplate = (0, node_fs_1.readFileSync)(node_path_1.default.join(__dirname, '../../template/diff.html'), 'utf-8');
14
+ return (0, lodash_1.template)(htmlTemplate)({ left: JSON.stringify(left), delta: JSON.stringify(delta) });
15
+ };
16
+ exports.generateHtmlDiff = generateHtmlDiff;
17
+ const generateHtmlDiffPreviewFile = async (block, diff, filename) => {
18
+ const html = await (0, exports.generateHtmlDiff)(block, diff);
19
+ (0, node_fs_1.mkdirSync)('./preview', { recursive: true });
13
20
  const filePath = `./preview/${filename}.html`;
14
- writeFileSync(filePath, html);
21
+ (0, node_fs_1.writeFileSync)(filePath, html);
15
22
  return filePath;
16
23
  };
24
+ exports.generateHtmlDiffPreviewFile = generateHtmlDiffPreviewFile;
@@ -1,28 +1,35 @@
1
- import { existsSync, readFileSync } from 'node:fs';
2
- import yaml from 'js-yaml';
3
- import { setStorage } from './set-storage';
4
- import { defaultLogger } from '../logger';
5
- export const importStorage = async (chain, storage) => {
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.overrideWasm = exports.importStorage = void 0;
7
+ const node_fs_1 = require("node:fs");
8
+ const js_yaml_1 = __importDefault(require("js-yaml"));
9
+ const set_storage_1 = require("./set-storage");
10
+ const logger_1 = require("../logger");
11
+ const importStorage = async (chain, storage) => {
6
12
  if (storage == null) {
7
13
  return;
8
14
  }
9
15
  let storageValue;
10
16
  if (typeof storage === 'string') {
11
- if (!existsSync(storage))
17
+ if (!(0, node_fs_1.existsSync)(storage))
12
18
  throw Error(`File ${storage} does not exist`);
13
- storageValue = yaml.load(String(readFileSync(storage)));
19
+ storageValue = js_yaml_1.default.load(String((0, node_fs_1.readFileSync)(storage)));
14
20
  }
15
21
  else {
16
22
  storageValue = storage;
17
23
  }
18
- const blockHash = await setStorage(chain, storageValue);
19
- defaultLogger.trace({ blockHash, storage }, 'ImportStorage');
24
+ const blockHash = await (0, set_storage_1.setStorage)(chain, storageValue);
25
+ logger_1.defaultLogger.trace({ blockHash, storage }, 'ImportStorage');
20
26
  };
21
- export const overrideWasm = async (chain, wasmPath) => {
27
+ exports.importStorage = importStorage;
28
+ const overrideWasm = async (chain, wasmPath) => {
22
29
  if (wasmPath == null) {
23
30
  return;
24
31
  }
25
- const wasm = readFileSync(wasmPath);
32
+ const wasm = (0, node_fs_1.readFileSync)(wasmPath);
26
33
  let wasmHex;
27
34
  if (wasm.at(0) === 0x30 && wasm.at(1) === 0x78) {
28
35
  // starts with 0x
@@ -33,3 +40,4 @@ export const overrideWasm = async (chain, wasmPath) => {
33
40
  }
34
41
  chain.head.setWasm(wasmHex);
35
42
  };
43
+ exports.overrideWasm = overrideWasm;
@@ -1,5 +1,8 @@
1
- import { compactStripLength, hexToU8a, u8aToHex } from '@polkadot/util';
2
- export async function fetchKeys(getKeys, processKey) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defer = exports.isUrl = exports.getParaId = exports.compactHex = exports.fetchKeysToArray = exports.fetchKeys = void 0;
4
+ const util_1 = require("@polkadot/util");
5
+ async function fetchKeys(getKeys, processKey) {
3
6
  const processKeys = async (keys) => {
4
7
  for (const key of keys) {
5
8
  await processKey(key);
@@ -16,22 +19,26 @@ export async function fetchKeys(getKeys, processKey) {
16
19
  nextKey = await processKeys(keys);
17
20
  }
18
21
  }
19
- export async function fetchKeysToArray(getKeys) {
22
+ exports.fetchKeys = fetchKeys;
23
+ async function fetchKeysToArray(getKeys) {
20
24
  const res = [];
21
25
  await fetchKeys(getKeys, (key) => res.push(key));
22
26
  return res;
23
27
  }
24
- export const compactHex = (value) => {
25
- return u8aToHex(compactStripLength(value)[1]);
28
+ exports.fetchKeysToArray = fetchKeysToArray;
29
+ const compactHex = (value) => {
30
+ return (0, util_1.u8aToHex)((0, util_1.compactStripLength)(value)[1]);
26
31
  };
27
- export const getParaId = async (chain) => {
32
+ exports.compactHex = compactHex;
33
+ const getParaId = async (chain) => {
28
34
  const meta = await chain.head.meta;
29
- const raw = await chain.head.get(compactHex(meta.query.parachainInfo.parachainId()));
35
+ const raw = await chain.head.get((0, exports.compactHex)(meta.query.parachainInfo.parachainId()));
30
36
  if (!raw)
31
37
  throw new Error('Cannot find parachain id');
32
- return meta.registry.createType('u32', hexToU8a(raw));
38
+ return meta.registry.createType('u32', (0, util_1.hexToU8a)(raw));
33
39
  };
34
- export const isUrl = (url) => {
40
+ exports.getParaId = getParaId;
41
+ const isUrl = (url) => {
35
42
  try {
36
43
  new URL(url);
37
44
  return true;
@@ -40,7 +47,8 @@ export const isUrl = (url) => {
40
47
  return false;
41
48
  }
42
49
  };
43
- export function defer() {
50
+ exports.isUrl = isUrl;
51
+ function defer() {
44
52
  const deferred = {};
45
53
  deferred.promise = new Promise((resolve, reject) => {
46
54
  deferred.resolve = resolve;
@@ -48,3 +56,4 @@ export function defer() {
48
56
  });
49
57
  return deferred;
50
58
  }
59
+ exports.defer = defer;
@@ -1,5 +1,9 @@
1
- import { execSync } from 'node:child_process';
2
- export const openHtml = (filePath) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.openHtml = void 0;
4
+ const node_child_process_1 = require("node:child_process");
5
+ const openHtml = (filePath) => {
3
6
  const start = process.platform == 'darwin' ? 'open' : process.platform == 'win32' ? 'start' : 'xdg-open';
4
- execSync(start + ' ' + filePath);
7
+ (0, node_child_process_1.execSync)(start + ' ' + filePath);
5
8
  };
9
+ exports.openHtml = openHtml;