@acala-network/chopsticks 0.5.5 → 0.5.6

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,10 +1,16 @@
1
- import { GenericExtrinsic } from '@polkadot/types';
2
- import { hexToU8a, u8aConcat } from '@polkadot/util';
3
- import _ from 'lodash';
4
- import { WELL_KNOWN_KEYS, dmqMqcHead, hrmpChannels, hrmpEgressChannelIndex, hrmpIngressChannelIndex, upgradeGoAheadSignal, } from '../../../utils/proof';
5
- import { blake2AsHex, blake2AsU8a } from '@polkadot/util-crypto';
6
- import { compactHex, getParaId } from '../../../utils';
7
- import { createProof, decodeProof } from '../../../executor';
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.SetValidationData = void 0;
7
+ const types_1 = require("@polkadot/types");
8
+ const util_1 = require("@polkadot/util");
9
+ const lodash_1 = __importDefault(require("lodash"));
10
+ const proof_1 = require("../../../utils/proof");
11
+ const util_crypto_1 = require("@polkadot/util-crypto");
12
+ const utils_1 = require("../../../utils");
13
+ const executor_1 = require("../../../executor");
8
14
  const MOCK_VALIDATION_DATA = {
9
15
  validationData: {
10
16
  relayParentNumber: 1000,
@@ -29,7 +35,7 @@ const MOCK_VALIDATION_DATA = {
29
35
  ],
30
36
  },
31
37
  };
32
- export class SetValidationData {
38
+ class SetValidationData {
33
39
  async createInherents(parent, params) {
34
40
  const meta = await parent.meta;
35
41
  if (!meta.tx.parachainSystem?.setValidationData) {
@@ -55,13 +61,13 @@ export class SetValidationData {
55
61
  const newEntries = [];
56
62
  const downwardMessages = [];
57
63
  const horizontalMessages = {};
58
- const paraId = await getParaId(parent.chain);
59
- const dmqMqcHeadKey = dmqMqcHead(paraId);
60
- const hrmpIngressChannelIndexKey = hrmpIngressChannelIndex(paraId);
61
- const hrmpEgressChannelIndexKey = hrmpEgressChannelIndex(paraId);
64
+ const paraId = await (0, utils_1.getParaId)(parent.chain);
65
+ const dmqMqcHeadKey = (0, proof_1.dmqMqcHead)(paraId);
66
+ const hrmpIngressChannelIndexKey = (0, proof_1.hrmpIngressChannelIndex)(paraId);
67
+ const hrmpEgressChannelIndexKey = (0, proof_1.hrmpEgressChannelIndex)(paraId);
62
68
  // TODO: refactor this to have a single decodeProof
63
- const decoded = await decodeProof(extrinsic.validationData.relayParentStorageRoot, [...Object.values(WELL_KNOWN_KEYS), dmqMqcHeadKey, hrmpIngressChannelIndexKey, hrmpEgressChannelIndexKey], extrinsic.relayChainState.trieNodes);
64
- for (const key of Object.values(WELL_KNOWN_KEYS)) {
69
+ const decoded = await (0, executor_1.decodeProof)(extrinsic.validationData.relayParentStorageRoot, [...Object.values(proof_1.WELL_KNOWN_KEYS), dmqMqcHeadKey, hrmpIngressChannelIndexKey, hrmpEgressChannelIndexKey], extrinsic.relayChainState.trieNodes);
70
+ for (const key of Object.values(proof_1.WELL_KNOWN_KEYS)) {
65
71
  newEntries.push([key, decoded[key]]);
66
72
  }
67
73
  newEntries.push([hrmpIngressChannelIndexKey, decoded[hrmpIngressChannelIndexKey]]);
@@ -71,7 +77,7 @@ export class SetValidationData {
71
77
  if (dmqMqcHeadHash) {
72
78
  for (const { msg, sentAt } of params.downwardMessages) {
73
79
  // calculate new hash
74
- dmqMqcHeadHash = blake2AsHex(u8aConcat(meta.registry.createType('Hash', dmqMqcHeadHash).toU8a(), meta.registry.createType('BlockNumber', sentAt).toU8a(), blake2AsU8a(meta.registry.createType('Bytes', msg).toU8a(), 256)), 256);
80
+ dmqMqcHeadHash = (0, util_crypto_1.blake2AsHex)((0, util_1.u8aConcat)(meta.registry.createType('Hash', dmqMqcHeadHash).toU8a(), meta.registry.createType('BlockNumber', sentAt).toU8a(), (0, util_crypto_1.blake2AsU8a)(meta.registry.createType('Bytes', msg).toU8a(), 256)), 256);
75
81
  downwardMessages.push({
76
82
  msg,
77
83
  sentAt,
@@ -87,7 +93,7 @@ export class SetValidationData {
87
93
  .toJSON();
88
94
  const hrmpMessages = {
89
95
  // reset values, we just need the keys
90
- ..._.mapValues(extrinsic.horizontalMessages, () => []),
96
+ ...lodash_1.default.mapValues(extrinsic.horizontalMessages, () => []),
91
97
  ...params.horizontalMessages,
92
98
  };
93
99
  // inject horizontal messages
@@ -98,19 +104,19 @@ export class SetValidationData {
98
104
  sender,
99
105
  receiver: paraId.toNumber(),
100
106
  });
101
- const hrmpChannelKey = hrmpChannels(channelId);
102
- const decoded = await decodeProof(extrinsic.validationData.relayParentStorageRoot, [hrmpChannelKey], extrinsic.relayChainState.trieNodes);
107
+ const hrmpChannelKey = (0, proof_1.hrmpChannels)(channelId);
108
+ const decoded = await (0, executor_1.decodeProof)(extrinsic.validationData.relayParentStorageRoot, [hrmpChannelKey], extrinsic.relayChainState.trieNodes);
103
109
  const abridgedHrmpRaw = decoded[hrmpChannelKey];
104
110
  if (!abridgedHrmpRaw)
105
111
  throw new Error('Canoot find hrmp channels from validation data');
106
112
  const abridgedHrmp = meta.registry
107
- .createType('AbridgedHrmpChannel', hexToU8a(abridgedHrmpRaw))
113
+ .createType('AbridgedHrmpChannel', (0, util_1.hexToU8a)(abridgedHrmpRaw))
108
114
  .toJSON();
109
115
  const paraMessages = [];
110
116
  for (const { data, sentAt } of messages) {
111
117
  // calculate new hash
112
118
  const bytes = meta.registry.createType('Bytes', data);
113
- abridgedHrmp.mqcHead = blake2AsHex(u8aConcat(meta.registry.createType('Hash', abridgedHrmp.mqcHead).toU8a(), meta.registry.createType('BlockNumber', sentAt).toU8a(), blake2AsU8a(bytes.toU8a(), 256)), 256);
119
+ abridgedHrmp.mqcHead = (0, util_crypto_1.blake2AsHex)((0, util_1.u8aConcat)(meta.registry.createType('Hash', abridgedHrmp.mqcHead).toU8a(), meta.registry.createType('BlockNumber', sentAt).toU8a(), (0, util_crypto_1.blake2AsU8a)(bytes.toU8a(), 256)), 256);
114
120
  abridgedHrmp.msgCount = abridgedHrmp.msgCount + 1;
115
121
  abridgedHrmp.totalSize = abridgedHrmp.totalSize + bytes.length;
116
122
  paraMessages.push({
@@ -129,12 +135,12 @@ export class SetValidationData {
129
135
  sender: paraId.toNumber(),
130
136
  receiver,
131
137
  });
132
- const hrmpChannelKey = hrmpChannels(channelId);
133
- const decoded = await decodeProof(extrinsic.validationData.relayParentStorageRoot, [hrmpChannelKey], extrinsic.relayChainState.trieNodes);
138
+ const hrmpChannelKey = (0, proof_1.hrmpChannels)(channelId);
139
+ const decoded = await (0, executor_1.decodeProof)(extrinsic.validationData.relayParentStorageRoot, [hrmpChannelKey], extrinsic.relayChainState.trieNodes);
134
140
  newEntries.push([hrmpChannelKey, decoded[hrmpChannelKey]]);
135
141
  }
136
- const upgradeKey = upgradeGoAheadSignal(paraId);
137
- const pendingUpgrade = await parent.get(compactHex(meta.query.parachainSystem.pendingValidationCode()));
142
+ const upgradeKey = (0, proof_1.upgradeGoAheadSignal)(paraId);
143
+ const pendingUpgrade = await parent.get((0, utils_1.compactHex)(meta.query.parachainSystem.pendingValidationCode()));
138
144
  if (pendingUpgrade) {
139
145
  // send goAhead signal
140
146
  const goAhead = meta.registry.createType('UpgradeGoAhead', 'GoAhead');
@@ -144,7 +150,7 @@ export class SetValidationData {
144
150
  // make sure previous goAhead is removed
145
151
  newEntries.push([upgradeKey, null]);
146
152
  }
147
- const { trieRootHash, nodes } = await createProof(extrinsic.validationData.relayParentStorageRoot, extrinsic.relayChainState.trieNodes, newEntries);
153
+ const { trieRootHash, nodes } = await (0, executor_1.createProof)(extrinsic.validationData.relayParentStorageRoot, extrinsic.relayChainState.trieNodes, newEntries);
148
154
  newData = {
149
155
  ...extrinsic,
150
156
  downwardMessages,
@@ -159,7 +165,8 @@ export class SetValidationData {
159
165
  },
160
166
  };
161
167
  }
162
- const inherent = new GenericExtrinsic(meta.registry, meta.tx.parachainSystem.setValidationData(newData));
168
+ const inherent = new types_1.GenericExtrinsic(meta.registry, meta.tx.parachainSystem.setValidationData(newData));
163
169
  return [inherent.toHex()];
164
170
  }
165
171
  }
172
+ exports.SetValidationData = SetValidationData;
@@ -1,7 +1,13 @@
1
- import _ from 'lodash';
2
- import { defaultLogger } from '../logger';
3
- const logger = defaultLogger.child({ name: 'layer' });
4
- export class RemoteStorageLayer {
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.StorageLayer = exports.RemoteStorageLayer = void 0;
7
+ const lodash_1 = __importDefault(require("lodash"));
8
+ const logger_1 = require("../logger");
9
+ const logger = logger_1.defaultLogger.child({ name: 'layer' });
10
+ class RemoteStorageLayer {
5
11
  #api;
6
12
  #at;
7
13
  #db;
@@ -31,7 +37,8 @@ export class RemoteStorageLayer {
31
37
  return this.#api.getKeysPaged(prefix, pageSize, startKey, this.#at);
32
38
  }
33
39
  }
34
- export class StorageLayer {
40
+ exports.RemoteStorageLayer = RemoteStorageLayer;
41
+ class StorageLayer {
35
42
  #store = {};
36
43
  #keys = [];
37
44
  #deletedPrefix = [];
@@ -40,7 +47,7 @@ export class StorageLayer {
40
47
  this.#parent = parent;
41
48
  }
42
49
  #addKey(key) {
43
- const idx = _.sortedIndex(this.#keys, key);
50
+ const idx = lodash_1.default.sortedIndex(this.#keys, key);
44
51
  const key2 = this.#keys[idx];
45
52
  if (key === key2) {
46
53
  return;
@@ -48,7 +55,7 @@ export class StorageLayer {
48
55
  this.#keys.splice(idx, 0, key);
49
56
  }
50
57
  #removeKey(key) {
51
- const idx = _.sortedIndex(this.#keys, key);
58
+ const idx = lodash_1.default.sortedIndex(this.#keys, key);
52
59
  const key2 = this.#keys[idx];
53
60
  if (key === key2) {
54
61
  this.#keys.splice(idx, 1);
@@ -130,7 +137,7 @@ export class StorageLayer {
130
137
  this.#addKey(key);
131
138
  }
132
139
  }
133
- let idx = _.sortedIndex(this.#keys, startKey);
140
+ let idx = lodash_1.default.sortedIndex(this.#keys, startKey);
134
141
  if (this.#keys[idx] === startKey) {
135
142
  ++idx;
136
143
  }
@@ -157,3 +164,4 @@ export class StorageLayer {
157
164
  }
158
165
  }
159
166
  }
167
+ exports.StorageLayer = StorageLayer;
@@ -1,15 +1,21 @@
1
- import { EventEmitter } from 'node:stream';
2
- import _ from 'lodash';
3
- import { defer } from '../utils';
4
- import { buildBlock } from './block-builder';
5
- export const APPLY_EXTRINSIC_ERROR = 'TxPool::ApplyExtrinsicError';
6
- export var BuildBlockMode;
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.TxPool = exports.BuildBlockMode = exports.APPLY_EXTRINSIC_ERROR = void 0;
7
+ const node_stream_1 = require("node:stream");
8
+ const lodash_1 = __importDefault(require("lodash"));
9
+ const utils_1 = require("../utils");
10
+ const block_builder_1 = require("./block-builder");
11
+ exports.APPLY_EXTRINSIC_ERROR = 'TxPool::ApplyExtrinsicError';
12
+ var BuildBlockMode;
7
13
  (function (BuildBlockMode) {
8
14
  BuildBlockMode[BuildBlockMode["Batch"] = 0] = "Batch";
9
15
  BuildBlockMode[BuildBlockMode["Instant"] = 1] = "Instant";
10
16
  BuildBlockMode[BuildBlockMode["Manual"] = 2] = "Manual";
11
- })(BuildBlockMode || (BuildBlockMode = {}));
12
- export class TxPool {
17
+ })(BuildBlockMode = exports.BuildBlockMode || (exports.BuildBlockMode = {}));
18
+ class TxPool {
13
19
  #chain;
14
20
  #pool = [];
15
21
  #ump = {};
@@ -18,7 +24,7 @@ export class TxPool {
18
24
  #mode;
19
25
  #inherentProvider;
20
26
  #pendingBlocks = [];
21
- event = new EventEmitter();
27
+ event = new node_stream_1.EventEmitter();
22
28
  #isBuilding = false;
23
29
  constructor(chain, inherentProvider, mode = BuildBlockMode.Batch) {
24
30
  this.#chain = chain;
@@ -71,11 +77,11 @@ export class TxPool {
71
77
  break;
72
78
  }
73
79
  }
74
- #batchBuildBlock = _.debounce(this.buildBlock, 100, { maxWait: 1000 });
80
+ #batchBuildBlock = lodash_1.default.debounce(this.buildBlock, 100, { maxWait: 1000 });
75
81
  async buildBlockWithParams(params) {
76
82
  this.#pendingBlocks.push({
77
83
  params,
78
- deferred: defer(),
84
+ deferred: (0, utils_1.defer)(),
79
85
  });
80
86
  this.#buildBlockIfNeeded();
81
87
  await this.upcomingBlocks();
@@ -132,8 +138,8 @@ export class TxPool {
132
138
  const { params, deferred } = pending;
133
139
  const head = this.#chain.head;
134
140
  const inherents = await this.#inherentProvider.createInherents(head, params);
135
- const [newBlock, pendingExtrinsics] = await buildBlock(head, inherents, params.transactions, params.upwardMessages, (extrinsic, error) => {
136
- this.event.emit(APPLY_EXTRINSIC_ERROR, [extrinsic, error]);
141
+ const [newBlock, pendingExtrinsics] = await (0, block_builder_1.buildBlock)(head, inherents, params.transactions, params.upwardMessages, (extrinsic, error) => {
142
+ this.event.emit(exports.APPLY_EXTRINSIC_ERROR, [extrinsic, error]);
137
143
  });
138
144
  for (const extrinsic of pendingExtrinsics) {
139
145
  this.#pool.push({ extrinsic, signer: await this.#getSigner(extrinsic) });
@@ -143,3 +149,4 @@ export class TxPool {
143
149
  deferred.resolve();
144
150
  }
145
151
  }
152
+ exports.TxPool = TxPool;
package/lib/cli.js CHANGED
@@ -1,25 +1,30 @@
1
- import { hideBin } from 'yargs/helpers';
2
- import { readFileSync } from 'node:fs';
3
- import axios from 'axios';
4
- import yaml from 'js-yaml';
5
- import yargs from 'yargs';
6
- import { BuildBlockMode, connectParachains, connectVertical, setup, setupWithServer } from '.';
7
- import { configSchema } from './schema';
8
- import { decodeKey } from './utils/decoder';
9
- import { dryRun } from './dry-run';
10
- import { dryRunPreimage } from './dry-run-preimage';
11
- import { isUrl } from './utils';
12
- import { runBlock } from './run-block';
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 helpers_1 = require("yargs/helpers");
7
+ const node_fs_1 = require("node:fs");
8
+ const axios_1 = __importDefault(require("axios"));
9
+ const js_yaml_1 = __importDefault(require("js-yaml"));
10
+ const yargs_1 = __importDefault(require("yargs"));
11
+ const _1 = require(".");
12
+ const schema_1 = require("./schema");
13
+ const decoder_1 = require("./utils/decoder");
14
+ const dry_run_1 = require("./dry-run");
15
+ const dry_run_preimage_1 = require("./dry-run-preimage");
16
+ const utils_1 = require("./utils");
17
+ const run_block_1 = require("./run-block");
13
18
  const processConfig = async (path) => {
14
19
  let file;
15
- if (isUrl(path)) {
16
- file = await axios.get(path).then((x) => x.data);
20
+ if ((0, utils_1.isUrl)(path)) {
21
+ file = await axios_1.default.get(path).then((x) => x.data);
17
22
  }
18
23
  else {
19
- file = readFileSync(path, 'utf8');
24
+ file = (0, node_fs_1.readFileSync)(path, 'utf8');
20
25
  }
21
- const config = yaml.load(file);
22
- return configSchema.parse(config);
26
+ const config = js_yaml_1.default.load(file);
27
+ return schema_1.configSchema.parse(config);
23
28
  };
24
29
  const processArgv = async (argv) => {
25
30
  if (argv.config) {
@@ -50,7 +55,7 @@ const defaultOptions = {
50
55
  string: true,
51
56
  },
52
57
  };
53
- yargs(hideBin(process.argv))
58
+ (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
54
59
  .scriptName('chopsticks')
55
60
  .command('run-block', 'Replay a block', (yargs) => yargs.options({
56
61
  ...defaultOptions,
@@ -69,7 +74,7 @@ yargs(hideBin(process.argv))
69
74
  desc: 'Open generated html',
70
75
  },
71
76
  }), async (argv) => {
72
- await runBlock(await processArgv(argv));
77
+ await (0, run_block_1.runBlock)(await processArgv(argv));
73
78
  })
74
79
  .command('dry-run', 'Dry run an extrinsic', (yargs) => yargs.options({
75
80
  ...defaultOptions,
@@ -102,10 +107,10 @@ yargs(hideBin(process.argv))
102
107
  }), async (argv) => {
103
108
  const config = await processArgv(argv);
104
109
  if (config.preimage) {
105
- await dryRunPreimage(config);
110
+ await (0, dry_run_preimage_1.dryRunPreimage)(config);
106
111
  }
107
112
  else {
108
- await dryRun(config);
113
+ await (0, dry_run_1.dryRun)(config);
109
114
  }
110
115
  })
111
116
  .command('dev', 'Dev mode', (yargs) => yargs.options({
@@ -116,7 +121,7 @@ yargs(hideBin(process.argv))
116
121
  },
117
122
  'build-block-mode': {
118
123
  desc: 'Build block mode. Default to Batch',
119
- enum: [BuildBlockMode.Batch, BuildBlockMode.Manual, BuildBlockMode.Instant],
124
+ enum: [_1.BuildBlockMode.Batch, _1.BuildBlockMode.Manual, _1.BuildBlockMode.Instant],
120
125
  },
121
126
  'import-storage': {
122
127
  desc: 'Pre-defined JSON/YAML storage file path',
@@ -131,7 +136,7 @@ yargs(hideBin(process.argv))
131
136
  boolean: true,
132
137
  },
133
138
  }), async (argv) => {
134
- await setupWithServer(await processArgv(argv));
139
+ await (0, _1.setupWithServer)(await processArgv(argv));
135
140
  })
136
141
  .command('decode-key <key>', 'Deocde a key', (yargs) => yargs
137
142
  .positional('key', {
@@ -141,8 +146,8 @@ yargs(hideBin(process.argv))
141
146
  .options({
142
147
  ...defaultOptions,
143
148
  }), async (argv) => {
144
- const context = await setup(await processArgv(argv));
145
- const { storage, decodedKey } = decodeKey(await context.chain.head.meta, context.chain.head, argv.key);
149
+ const context = await (0, _1.setup)(await processArgv(argv));
150
+ const { storage, decodedKey } = (0, decoder_1.decodeKey)(await context.chain.head.meta, context.chain.head, argv.key);
146
151
  if (storage && decodedKey) {
147
152
  console.log(`${storage.section}.${storage.method}`, decodedKey.args.map((x) => JSON.stringify(x.toHuman())).join(', '));
148
153
  }
@@ -165,23 +170,23 @@ yargs(hideBin(process.argv))
165
170
  }), async (argv) => {
166
171
  const parachains = [];
167
172
  for (const config of argv.parachain) {
168
- const { chain } = await setupWithServer(await processConfig(config));
173
+ const { chain } = await (0, _1.setupWithServer)(await processConfig(config));
169
174
  parachains.push(chain);
170
175
  }
171
176
  if (parachains.length > 1) {
172
- await connectParachains(parachains);
177
+ await (0, _1.connectParachains)(parachains);
173
178
  }
174
179
  if (argv.relaychain) {
175
- const { chain: relaychain } = await setupWithServer(await processConfig(argv.relaychain));
180
+ const { chain: relaychain } = await (0, _1.setupWithServer)(await processConfig(argv.relaychain));
176
181
  for (const parachain of parachains) {
177
- await connectVertical(relaychain, parachain);
182
+ await (0, _1.connectVertical)(relaychain, parachain);
178
183
  }
179
184
  }
180
185
  })
181
186
  .command({
182
187
  command: '*',
183
188
  handler() {
184
- yargs.showHelp();
189
+ yargs_1.default.showHelp();
185
190
  },
186
191
  })
187
192
  .strict()
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
3
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
4
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -7,25 +8,27 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
8
  var __metadata = (this && this.__metadata) || function (k, v) {
8
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
10
  };
10
- import { Column, Entity, PrimaryColumn } from 'typeorm';
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.KeyValuePair = void 0;
13
+ const typeorm_1 = require("typeorm");
11
14
  let KeyValuePair = class KeyValuePair {
12
15
  blockHash;
13
16
  key;
14
17
  value;
15
18
  };
16
19
  __decorate([
17
- PrimaryColumn(),
20
+ (0, typeorm_1.PrimaryColumn)(),
18
21
  __metadata("design:type", String)
19
22
  ], KeyValuePair.prototype, "blockHash", void 0);
20
23
  __decorate([
21
- PrimaryColumn(),
24
+ (0, typeorm_1.PrimaryColumn)(),
22
25
  __metadata("design:type", String)
23
26
  ], KeyValuePair.prototype, "key", void 0);
24
27
  __decorate([
25
- Column({ nullable: true }),
28
+ (0, typeorm_1.Column)({ nullable: true }),
26
29
  __metadata("design:type", String)
27
30
  ], KeyValuePair.prototype, "value", void 0);
28
31
  KeyValuePair = __decorate([
29
- Entity()
32
+ (0, typeorm_1.Entity)()
30
33
  ], KeyValuePair);
31
- export { KeyValuePair };
34
+ exports.KeyValuePair = KeyValuePair;
package/lib/db/index.js CHANGED
@@ -1,8 +1,34 @@
1
- import 'reflect-metadata';
2
- import { DataSource } from 'typeorm';
3
- import * as entities from './entities';
4
- export const openDb = async (dbPath) => {
5
- const source = new DataSource({
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.openDb = void 0;
27
+ require("reflect-metadata");
28
+ const typeorm_1 = require("typeorm");
29
+ const entities = __importStar(require("./entities"));
30
+ const openDb = async (dbPath) => {
31
+ const source = new typeorm_1.DataSource({
6
32
  type: 'sqlite',
7
33
  database: dbPath,
8
34
  entities: Object.values(entities),
@@ -12,3 +38,4 @@ export const openDb = async (dbPath) => {
12
38
  await source.initialize();
13
39
  return source;
14
40
  };
41
+ exports.openDb = openDb;
@@ -1,21 +1,24 @@
1
- import { blake2AsHex } from '@polkadot/util-crypto';
2
- import { hexToU8a } from '@polkadot/util';
3
- import { defaultLogger } from './logger';
4
- import { generateHtmlDiffPreviewFile } from './utils/generate-html-diff';
5
- import { newHeader } from './blockchain/block-builder';
6
- import { openHtml } from './utils/open-html';
7
- import { runTask, taskHandler } from './executor';
8
- import { setStorage } from './utils/set-storage';
9
- import { setup } from './setup';
10
- export const dryRunPreimage = async (argv) => {
11
- const context = await setup(argv);
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 block_builder_1 = require("./blockchain/block-builder");
9
+ const open_html_1 = require("./utils/open-html");
10
+ const executor_1 = require("./executor");
11
+ const set_storage_1 = require("./utils/set-storage");
12
+ const setup_1 = require("./setup");
13
+ const dryRunPreimage = async (argv) => {
14
+ const context = await (0, setup_1.setup)(argv);
12
15
  const extrinsic = argv['preimage'];
13
16
  const block = context.chain.head;
14
17
  const registry = await block.registry;
15
- const header = await newHeader(block);
16
- const data = hexToU8a(extrinsic);
17
- const hash = blake2AsHex(data, 256);
18
- await setStorage(context.chain, {
18
+ const header = await (0, block_builder_1.newHeader)(block);
19
+ const data = (0, util_1.hexToU8a)(extrinsic);
20
+ const hash = (0, util_crypto_1.blake2AsHex)(data, 256);
21
+ await (0, set_storage_1.setStorage)(context.chain, {
19
22
  Preimage: {
20
23
  PreimageFor: [[[[hash, data.byteLength]], extrinsic]],
21
24
  StatusFor: [
@@ -57,21 +60,21 @@ export const dryRunPreimage = async (argv) => {
57
60
  calls.push(['BlockBuilder_apply_extrinsic', [inherent]]);
58
61
  }
59
62
  calls.push(['BlockBuilder_finalize_block', []]);
60
- defaultLogger.info({ preimage: registry.createType('Call', data).toHuman() }, 'Dry run preimage');
61
- const result = await runTask({
63
+ logger_1.defaultLogger.info({ preimage: registry.createType('Call', data).toHuman() }, 'Dry run preimage');
64
+ const result = await (0, executor_1.runTask)({
62
65
  wasm: await block.wasm,
63
66
  calls,
64
67
  storage: [],
65
68
  mockSignatureHost: false,
66
69
  allowUnresolvedImports: false,
67
- }, taskHandler(block));
70
+ }, (0, executor_1.taskHandler)(block));
68
71
  if (result.Error) {
69
72
  throw new Error(result.Error);
70
73
  }
71
- const filePath = await generateHtmlDiffPreviewFile(block, result.Call.storageDiff, hash);
74
+ const filePath = await (0, generate_html_diff_1.generateHtmlDiffPreviewFile)(block, result.Call.storageDiff, hash);
72
75
  console.log(`Generated preview ${filePath}`);
73
76
  if (argv['open']) {
74
- openHtml(filePath);
77
+ (0, open_html_1.openHtml)(filePath);
75
78
  }
76
79
  // if dry-run preimage has extrinsic arguments then dry-run extrinsic
77
80
  // this is usefull to test something after preimage is applied
@@ -83,13 +86,14 @@ export const dryRunPreimage = async (argv) => {
83
86
  throw new Error(outcome.asErr.toString());
84
87
  }
85
88
  else {
86
- defaultLogger.info(outcome.toHuman(), 'dry_run_outcome');
89
+ logger_1.defaultLogger.info(outcome.toHuman(), 'dry_run_outcome');
87
90
  }
88
- const filePath = await generateHtmlDiffPreviewFile(context.chain.head, storageDiff, blake2AsHex(argv['extrinsic'], 256));
91
+ const filePath = await (0, generate_html_diff_1.generateHtmlDiffPreviewFile)(context.chain.head, storageDiff, (0, util_crypto_1.blake2AsHex)(argv['extrinsic'], 256));
89
92
  console.log(`Generated preview ${filePath}`);
90
93
  if (argv['open']) {
91
- openHtml(filePath);
94
+ (0, open_html_1.openHtml)(filePath);
92
95
  }
93
96
  }
94
97
  process.exit(0);
95
98
  };
99
+ exports.dryRunPreimage = dryRunPreimage;
package/lib/dry-run.js CHANGED
@@ -1,31 +1,35 @@
1
- import { blake2AsHex } from '@polkadot/util-crypto';
2
- import { writeFileSync } from 'node:fs';
3
- import { defaultLogger } from './logger';
4
- import { generateHtmlDiffPreviewFile } from './utils/generate-html-diff';
5
- import { openHtml } from './utils/open-html';
6
- import { setup } from './setup';
7
- export const dryRun = async (argv) => {
8
- const context = await setup(argv);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dryRun = 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 setup_1 = require("./setup");
10
+ const dryRun = async (argv) => {
11
+ const context = await (0, setup_1.setup)(argv);
9
12
  const input = argv['address'] ? { call: argv['extrinsic'], address: argv['address'] } : argv['extrinsic'];
10
13
  const { outcome, storageDiff } = await context.chain.dryRunExtrinsic(input, argv['at']);
11
14
  if (outcome.isErr) {
12
15
  throw new Error(outcome.asErr.toString());
13
16
  }
14
17
  else {
15
- defaultLogger.info(outcome.toHuman(), 'dry_run_outcome');
18
+ logger_1.defaultLogger.info(outcome.toHuman(), 'dry_run_outcome');
16
19
  }
17
20
  if (argv['html']) {
18
- const filePath = await generateHtmlDiffPreviewFile(context.chain.head, storageDiff, blake2AsHex(argv['extrinsic'], 256));
21
+ const filePath = await (0, generate_html_diff_1.generateHtmlDiffPreviewFile)(context.chain.head, storageDiff, (0, util_crypto_1.blake2AsHex)(argv['extrinsic'], 256));
19
22
  console.log(`Generated preview ${filePath}`);
20
23
  if (argv['open']) {
21
- openHtml(filePath);
24
+ (0, open_html_1.openHtml)(filePath);
22
25
  }
23
26
  }
24
27
  else if (argv['output-path']) {
25
- writeFileSync(argv['output-path'], JSON.stringify({ outcome: outcome.toHuman(), storageDiff }, null, 2));
28
+ (0, node_fs_1.writeFileSync)(argv['output-path'], JSON.stringify({ outcome: outcome.toHuman(), storageDiff }, null, 2));
26
29
  }
27
30
  else {
28
31
  console.dir({ outcome: outcome.toHuman(), storageDiff }, { depth: null, colors: false });
29
32
  }
30
33
  process.exit(0);
31
34
  };
35
+ exports.dryRun = dryRun;