@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
package/lib/api.js CHANGED
@@ -1,4 +1,7 @@
1
- export class Api {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Api = void 0;
4
+ class Api {
2
5
  #provider;
3
6
  #ready;
4
7
  #chain;
@@ -73,3 +76,4 @@ export class Api {
73
76
  return this.#provider.send('state_getKeysPaged', [prefix, pageSize, startKey]);
74
77
  }
75
78
  }
79
+ exports.Api = Api;
@@ -1,10 +1,13 @@
1
- import { Block } from './block';
2
- import { blake2AsHex } from '@polkadot/util-crypto';
3
- import { compactAddLength, hexToU8a, stringToHex } from '@polkadot/util';
4
- import { compactHex } from '../utils';
5
- import { defaultLogger, truncate } from '../logger';
6
- import { getCurrentSlot } from '../utils/time-travel';
7
- const logger = defaultLogger.child({ name: 'block-builder' });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dryRunInherents = exports.dryRunExtrinsic = exports.buildBlock = exports.newHeader = void 0;
4
+ const block_1 = require("./block");
5
+ const util_crypto_1 = require("@polkadot/util-crypto");
6
+ const util_1 = require("@polkadot/util");
7
+ const utils_1 = require("../utils");
8
+ const logger_1 = require("../logger");
9
+ const time_travel_1 = require("../utils/time-travel");
10
+ const logger = logger_1.defaultLogger.child({ name: 'block-builder' });
8
11
  const getConsensus = (header) => {
9
12
  if (header.digest.logs.length === 0)
10
13
  return;
@@ -39,24 +42,24 @@ const getNewSlot = (digest, slotNumber) => {
39
42
  }
40
43
  return digest.toJSON();
41
44
  };
42
- export const newHeader = async (head) => {
45
+ const newHeader = async (head) => {
43
46
  const meta = await head.meta;
44
47
  const parentHeader = await head.header;
45
48
  let newLogs = parentHeader.digest.logs;
46
49
  const consensus = getConsensus(parentHeader);
47
50
  if (consensus?.consensusEngine.isAura) {
48
- const slot = await getCurrentSlot(head.chain);
49
- const newSlot = compactAddLength(meta.registry.createType('Slot', slot + 1).toU8a());
51
+ const slot = await (0, time_travel_1.getCurrentSlot)(head.chain);
52
+ const newSlot = (0, util_1.compactAddLength)(meta.registry.createType('Slot', slot + 1).toU8a());
50
53
  newLogs = [{ PreRuntime: [consensus.consensusEngine, newSlot] }, ...consensus.rest];
51
54
  }
52
55
  else if (consensus?.consensusEngine.isBabe) {
53
- const slot = await getCurrentSlot(head.chain);
56
+ const slot = await (0, time_travel_1.getCurrentSlot)(head.chain);
54
57
  const digest = meta.registry.createType('RawBabePreDigest', consensus.slot);
55
- const newSlot = compactAddLength(meta.registry.createType('RawBabePreDigest', getNewSlot(digest, slot + 1)).toU8a());
58
+ const newSlot = (0, util_1.compactAddLength)(meta.registry.createType('RawBabePreDigest', getNewSlot(digest, slot + 1)).toU8a());
56
59
  newLogs = [{ PreRuntime: [consensus.consensusEngine, newSlot] }, ...consensus.rest];
57
60
  }
58
61
  else if (consensus?.consensusEngine?.toString() == 'nmbs') {
59
- const nmbsKey = stringToHex('nmbs');
62
+ const nmbsKey = (0, util_1.stringToHex)('nmbs');
60
63
  newLogs = [
61
64
  {
62
65
  // Using previous block author
@@ -72,7 +75,7 @@ export const newHeader = async (head) => {
72
75
  if (meta.query.randomness) {
73
76
  // TODO: shouldn't modify existing head
74
77
  // reset notFirstBlock so randomness will skip validation
75
- head.pushStorageLayer().set(compactHex(meta.query.randomness.notFirstBlock()), "Deleted" /* StorageValueKind.Deleted */);
78
+ head.pushStorageLayer().set((0, utils_1.compactHex)(meta.query.randomness.notFirstBlock()), "Deleted" /* StorageValueKind.Deleted */);
76
79
  }
77
80
  }
78
81
  const header = meta.registry.createType('Header', {
@@ -86,17 +89,18 @@ export const newHeader = async (head) => {
86
89
  });
87
90
  return header;
88
91
  };
92
+ exports.newHeader = newHeader;
89
93
  const initNewBlock = async (head, header, inherents) => {
90
94
  const blockNumber = header.number.toNumber();
91
95
  const hash = `0x${Math.round(Math.random() * 100000000)
92
96
  .toString(16)
93
97
  .padEnd(64, '0')}`;
94
- const newBlock = new Block(head.chain, blockNumber, hash, head, { header, extrinsics: [], storage: head.storage });
98
+ const newBlock = new block_1.Block(head.chain, blockNumber, hash, head, { header, extrinsics: [], storage: head.storage });
95
99
  {
96
100
  // initialize block
97
101
  const { storageDiff } = await newBlock.call('Core_initialize_block', [header.toHex()]);
98
102
  newBlock.pushStorageLayer().setAll(storageDiff);
99
- logger.trace(truncate(storageDiff), 'Initialize block');
103
+ logger.trace((0, logger_1.truncate)(storageDiff), 'Initialize block');
100
104
  }
101
105
  const layers = [];
102
106
  // apply inherents
@@ -106,7 +110,7 @@ const initNewBlock = async (head, header, inherents) => {
106
110
  const layer = newBlock.pushStorageLayer();
107
111
  layer.setAll(storageDiff);
108
112
  layers.push(layer);
109
- logger.trace(truncate(storageDiff), 'Applied inherent');
113
+ logger.trace((0, logger_1.truncate)(storageDiff), 'Applied inherent');
110
114
  }
111
115
  catch (e) {
112
116
  logger.warn('Failed to apply inherents %o %s', e, e);
@@ -118,9 +122,9 @@ const initNewBlock = async (head, header, inherents) => {
118
122
  layers: layers,
119
123
  };
120
124
  };
121
- export const buildBlock = async (head, inherents, extrinsics, ump, onApplyExtrinsicError) => {
125
+ const buildBlock = async (head, inherents, extrinsics, ump, onApplyExtrinsicError) => {
122
126
  const registry = await head.registry;
123
- const header = await newHeader(head);
127
+ const header = await (0, exports.newHeader)(head);
124
128
  const { block: newBlock } = await initNewBlock(head, header, inherents);
125
129
  logger.info({
126
130
  number: newBlock.number,
@@ -141,8 +145,8 @@ export const buildBlock = async (head, inherents, extrinsics, ump, onApplyExtrin
141
145
  const messages = meta.registry.createType('Vec<Bytes>', upwardMessages);
142
146
  // TODO: make sure we append instead of replace
143
147
  layer.setAll([
144
- [compactHex(meta.query.ump.relayDispatchQueues(paraId)), messages.toHex()],
145
- [compactHex(meta.query.ump.relayDispatchQueueSize(paraId)), queueSize.toHex()],
148
+ [(0, utils_1.compactHex)(meta.query.ump.relayDispatchQueues(paraId)), messages.toHex()],
149
+ [(0, utils_1.compactHex)(meta.query.ump.relayDispatchQueueSize(paraId)), queueSize.toHex()],
146
150
  ]);
147
151
  }
148
152
  logger.trace({
@@ -151,7 +155,7 @@ export const buildBlock = async (head, inherents, extrinsics, ump, onApplyExtrin
151
155
  ump,
152
156
  }, 'Upward messages');
153
157
  const needsDispatch = meta.registry.createType('Vec<u32>', Object.keys(ump));
154
- layer.set(compactHex(meta.query.ump.needsDispatch()), needsDispatch.toHex());
158
+ layer.set((0, utils_1.compactHex)(meta.query.ump.needsDispatch()), needsDispatch.toHex());
155
159
  }
156
160
  // apply extrinsics
157
161
  for (const extrinsic of extrinsics) {
@@ -163,7 +167,7 @@ export const buildBlock = async (head, inherents, extrinsics, ump, onApplyExtrin
163
167
  continue;
164
168
  }
165
169
  newBlock.pushStorageLayer().setAll(storageDiff);
166
- logger.trace(truncate(storageDiff), 'Applied extrinsic');
170
+ logger.trace((0, logger_1.truncate)(storageDiff), 'Applied extrinsic');
167
171
  includedExtrinsic.push(extrinsic);
168
172
  }
169
173
  catch (e) {
@@ -175,15 +179,15 @@ export const buildBlock = async (head, inherents, extrinsics, ump, onApplyExtrin
175
179
  // finalize block
176
180
  const { storageDiff } = await newBlock.call('BlockBuilder_finalize_block', []);
177
181
  newBlock.pushStorageLayer().setAll(storageDiff);
178
- logger.trace(truncate(storageDiff), 'Finalize block');
182
+ logger.trace((0, logger_1.truncate)(storageDiff), 'Finalize block');
179
183
  }
180
184
  const blockData = registry.createType('Block', {
181
185
  header,
182
186
  extrinsics: includedExtrinsic,
183
187
  });
184
188
  const storageDiff = await newBlock.storageDiff();
185
- logger.trace(Object.entries(storageDiff).map(([key, value]) => [key, truncate(value)]), 'Final block');
186
- const finalBlock = new Block(head.chain, newBlock.number, blockData.hash.toHex(), head, {
189
+ logger.trace(Object.entries(storageDiff).map(([key, value]) => [key, (0, logger_1.truncate)(value)]), 'Final block');
190
+ const finalBlock = new block_1.Block(head.chain, newBlock.number, blockData.hash.toHex(), head, {
187
191
  header,
188
192
  extrinsics: [...inherents, ...includedExtrinsic],
189
193
  storage: head.storage,
@@ -191,25 +195,26 @@ export const buildBlock = async (head, inherents, extrinsics, ump, onApplyExtrin
191
195
  });
192
196
  logger.info({
193
197
  hash: finalBlock.hash,
194
- extrinsics: includedExtrinsic.map((x) => blake2AsHex(x, 256)),
198
+ extrinsics: includedExtrinsic.map((x) => (0, util_crypto_1.blake2AsHex)(x, 256)),
195
199
  pendingExtrinsics: pendingExtrinsics.length,
196
200
  number: newBlock.number,
197
201
  }, `Block built #${newBlock.number.toLocaleString()} hash ${finalBlock.hash}`);
198
202
  return [finalBlock, pendingExtrinsics];
199
203
  };
200
- export const dryRunExtrinsic = async (head, inherents, extrinsic) => {
204
+ exports.buildBlock = buildBlock;
205
+ const dryRunExtrinsic = async (head, inherents, extrinsic) => {
201
206
  const registry = await head.registry;
202
- const header = await newHeader(head);
207
+ const header = await (0, exports.newHeader)(head);
203
208
  const { block: newBlock } = await initNewBlock(head, header, inherents);
204
209
  if (typeof extrinsic !== 'string') {
205
210
  if (!head.chain.mockSignatureHost) {
206
211
  throw new Error('Cannot fake signature because mock signature host is not enabled. Start chain with `mockSignatureHost: true`');
207
212
  }
208
213
  const meta = await head.meta;
209
- const call = registry.createType('Call', hexToU8a(extrinsic.call));
214
+ const call = registry.createType('Call', (0, util_1.hexToU8a)(extrinsic.call));
210
215
  const generic = registry.createType('GenericExtrinsic', call);
211
- const accountRaw = await head.get(compactHex(meta.query.system.account(extrinsic.address)));
212
- const account = registry.createType('AccountInfo', hexToU8a(accountRaw));
216
+ const accountRaw = await head.get((0, utils_1.compactHex)(meta.query.system.account(extrinsic.address)));
217
+ const account = registry.createType('AccountInfo', (0, util_1.hexToU8a)(accountRaw));
213
218
  generic.signFake(extrinsic.address, {
214
219
  blockHash: head.hash,
215
220
  genesisHash: head.hash,
@@ -220,14 +225,15 @@ export const dryRunExtrinsic = async (head, inherents, extrinsic) => {
220
225
  mockSignature.fill(0xcd);
221
226
  mockSignature.set([0xde, 0xad, 0xbe, 0xef]);
222
227
  generic.signature.set(mockSignature);
223
- defaultLogger.info({ call: call.toHuman() }, 'dry_run_call');
228
+ logger_1.defaultLogger.info({ call: call.toHuman() }, 'dry_run_call');
224
229
  return newBlock.call('BlockBuilder_apply_extrinsic', [generic.toHex()]);
225
230
  }
226
- defaultLogger.info({ call: registry.createType('GenericExtrinsic', hexToU8a(extrinsic)).toHuman() }, 'dry_run_extrinsic');
231
+ logger_1.defaultLogger.info({ call: registry.createType('GenericExtrinsic', (0, util_1.hexToU8a)(extrinsic)).toHuman() }, 'dry_run_extrinsic');
227
232
  return newBlock.call('BlockBuilder_apply_extrinsic', [extrinsic]);
228
233
  };
229
- export const dryRunInherents = async (head, inherents) => {
230
- const header = await newHeader(head);
234
+ exports.dryRunExtrinsic = dryRunExtrinsic;
235
+ const dryRunInherents = async (head, inherents) => {
236
+ const header = await (0, exports.newHeader)(head);
231
237
  const { layers } = await initNewBlock(head, header, inherents);
232
238
  const stoarge = {};
233
239
  for (const layer of layers) {
@@ -235,3 +241,4 @@ export const dryRunInherents = async (head, inherents) => {
235
241
  }
236
242
  return Object.entries(stoarge);
237
243
  };
244
+ exports.dryRunInherents = dryRunInherents;
@@ -1,11 +1,14 @@
1
- import { Metadata, TypeRegistry } from '@polkadot/types';
2
- import { expandMetadata } from '@polkadot/types/metadata';
3
- import { getSpecExtensions, getSpecHasher, getSpecTypes } from '@polkadot/types-known/util';
4
- import { hexToU8a, objectSpread, stringToHex } from '@polkadot/util';
5
- import { RemoteStorageLayer, StorageLayer } from './storage-layer';
6
- import { compactHex } from '../utils';
7
- import { getRuntimeVersion, runTask, taskHandler } from '../executor';
8
- export class Block {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Block = void 0;
4
+ const types_1 = require("@polkadot/types");
5
+ const metadata_1 = require("@polkadot/types/metadata");
6
+ const util_1 = require("@polkadot/types-known/util");
7
+ const util_2 = require("@polkadot/util");
8
+ const storage_layer_1 = require("./storage-layer");
9
+ const utils_1 = require("../utils");
10
+ const executor_1 = require("../executor");
11
+ class Block {
9
12
  number;
10
13
  hash;
11
14
  #chain;
@@ -26,12 +29,12 @@ export class Block {
26
29
  this.#parentBlock = parentBlock;
27
30
  this.#header = block?.header;
28
31
  this.#extrinsics = block?.extrinsics;
29
- this.#baseStorage = block?.storage ?? new RemoteStorageLayer(chain.api, hash, chain.db);
32
+ this.#baseStorage = block?.storage ?? new storage_layer_1.RemoteStorageLayer(chain.api, hash, chain.db);
30
33
  this.#storages = [];
31
34
  const storageDiff = block?.storageDiff;
32
35
  if (storageDiff) {
33
36
  // if code doesn't change then reuse parent block's meta
34
- if (!storageDiff?.[stringToHex(':code')]) {
37
+ if (!storageDiff?.[(0, util_2.stringToHex)(':code')]) {
35
38
  this.#runtimeVersion = parentBlock?.runtimeVersion;
36
39
  this.#metadata = parentBlock?.metadata;
37
40
  this.#registry = parentBlock?.registry;
@@ -77,7 +80,7 @@ export class Block {
77
80
  }
78
81
  }
79
82
  async getKeysPaged(options) {
80
- const layer = new StorageLayer(this.storage);
83
+ const layer = new storage_layer_1.StorageLayer(this.storage);
81
84
  await layer.fold();
82
85
  const prefix = options.prefix ?? '0x';
83
86
  const startKey = options.startKey ?? prefix;
@@ -85,7 +88,7 @@ export class Block {
85
88
  return layer.getKeysPaged(prefix, pageSize, startKey);
86
89
  }
87
90
  pushStorageLayer() {
88
- const layer = new StorageLayer(this.storage);
91
+ const layer = new storage_layer_1.StorageLayer(this.storage);
89
92
  this.#storages.push(layer);
90
93
  return layer;
91
94
  }
@@ -102,7 +105,7 @@ export class Block {
102
105
  get wasm() {
103
106
  if (!this.#wasm) {
104
107
  this.#wasm = (async () => {
105
- const wasmKey = stringToHex(':code');
108
+ const wasmKey = (0, util_2.stringToHex)(':code');
106
109
  const wasm = await this.get(wasmKey);
107
110
  if (!wasm) {
108
111
  throw new Error('No wasm found');
@@ -113,7 +116,7 @@ export class Block {
113
116
  return this.#wasm;
114
117
  }
115
118
  setWasm(wasm) {
116
- const wasmKey = stringToHex(':code');
119
+ const wasmKey = (0, util_2.stringToHex)(':code');
117
120
  this.pushStorageLayer().set(wasmKey, wasm);
118
121
  this.#wasm = Promise.resolve(wasm);
119
122
  this.#runtimeVersion = undefined;
@@ -129,12 +132,12 @@ export class Block {
129
132
  this.#chain.api.chain,
130
133
  this.runtimeVersion,
131
134
  ]).then(([data, properties, chain, version]) => {
132
- const registry = new TypeRegistry(this.hash);
135
+ const registry = new types_1.TypeRegistry(this.hash);
133
136
  registry.setKnownTypes(this.chain.registeredTypes);
134
137
  registry.setChainProperties(registry.createType('ChainProperties', properties));
135
- registry.register(getSpecTypes(registry, chain, version.specName, version.specVersion));
136
- registry.setHasher(getSpecHasher(registry, chain, version.specName));
137
- registry.setMetadata(new Metadata(registry, data), undefined, objectSpread({}, getSpecExtensions(registry, chain, version.specName), this.#chain.api.signedExtensions));
138
+ registry.register((0, util_1.getSpecTypes)(registry, chain, version.specName, version.specVersion));
139
+ registry.setHasher((0, util_1.getSpecHasher)(registry, chain, version.specName));
140
+ registry.setMetadata(new types_1.Metadata(registry, data), undefined, (0, util_2.objectSpread)({}, (0, util_1.getSpecExtensions)(registry, chain, version.specName), this.#chain.api.signedExtensions));
138
141
  return registry;
139
142
  });
140
143
  }
@@ -142,34 +145,34 @@ export class Block {
142
145
  }
143
146
  get runtimeVersion() {
144
147
  if (!this.#runtimeVersion) {
145
- this.#runtimeVersion = this.wasm.then(getRuntimeVersion);
148
+ this.#runtimeVersion = this.wasm.then(executor_1.getRuntimeVersion);
146
149
  }
147
150
  return this.#runtimeVersion;
148
151
  }
149
152
  get metadata() {
150
153
  if (!this.#metadata) {
151
- this.#metadata = this.call('Metadata_metadata', []).then((resp) => compactHex(hexToU8a(resp.result)));
154
+ this.#metadata = this.call('Metadata_metadata', []).then((resp) => (0, utils_1.compactHex)((0, util_2.hexToU8a)(resp.result)));
152
155
  }
153
156
  return this.#metadata;
154
157
  }
155
158
  get meta() {
156
159
  if (!this.#meta) {
157
160
  this.#meta = Promise.all([this.registry, this.metadata]).then(([registry, metadataStr]) => {
158
- const metadata = new Metadata(registry, metadataStr);
159
- return expandMetadata(registry, metadata);
161
+ const metadata = new types_1.Metadata(registry, metadataStr);
162
+ return (0, metadata_1.expandMetadata)(registry, metadata);
160
163
  });
161
164
  }
162
165
  return this.#meta;
163
166
  }
164
167
  async call(method, args, storage = []) {
165
168
  const wasm = await this.wasm;
166
- const response = await runTask({
169
+ const response = await (0, executor_1.runTask)({
167
170
  wasm,
168
171
  calls: [[method, args]],
169
172
  storage,
170
173
  mockSignatureHost: this.#chain.mockSignatureHost,
171
174
  allowUnresolvedImports: this.#chain.allowUnresolvedImports,
172
- }, taskHandler(this));
175
+ }, (0, executor_1.taskHandler)(this));
173
176
  if (response.Call)
174
177
  return response.Call;
175
178
  if (response.Error)
@@ -177,3 +180,4 @@ export class Block {
177
180
  throw Error('Unexpected response');
178
181
  }
179
182
  }
183
+ exports.Block = Block;
@@ -1,8 +1,12 @@
1
- import { stringToHex } from '@polkadot/util';
2
- import { defaultLogger } from '../logger';
3
- export const randomId = () => Math.random().toString(36).substring(2);
4
- const logger = defaultLogger.child({ name: 'head-state' });
5
- export class HeadState {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HeadState = exports.randomId = void 0;
4
+ const util_1 = require("@polkadot/util");
5
+ const logger_1 = require("../logger");
6
+ const randomId = () => Math.random().toString(36).substring(2);
7
+ exports.randomId = randomId;
8
+ const logger = logger_1.defaultLogger.child({ name: 'head-state' });
9
+ class HeadState {
6
10
  #headListeners = {};
7
11
  #storageListeners = {};
8
12
  #oldValues = {};
@@ -11,7 +15,7 @@ export class HeadState {
11
15
  this.#head = head;
12
16
  }
13
17
  subscribeHead(cb) {
14
- const id = randomId();
18
+ const id = (0, exports.randomId)();
15
19
  this.#headListeners[id] = cb;
16
20
  return id;
17
21
  }
@@ -19,7 +23,7 @@ export class HeadState {
19
23
  delete this.#headListeners[id];
20
24
  }
21
25
  async subscribeStorage(keys, cb) {
22
- const id = randomId();
26
+ const id = (0, exports.randomId)();
23
27
  this.#storageListeners[id] = [keys, cb];
24
28
  for (const key of keys) {
25
29
  this.#oldValues[key] = await this.#head.get(key);
@@ -30,8 +34,8 @@ export class HeadState {
30
34
  delete this.#storageListeners[id];
31
35
  }
32
36
  async subscrubeRuntimeVersion(cb) {
33
- const id = randomId();
34
- const codeKey = stringToHex(':code');
37
+ const id = (0, exports.randomId)();
38
+ const codeKey = (0, util_1.stringToHex)(':code');
35
39
  this.#storageListeners[id] = [[codeKey], cb];
36
40
  this.#oldValues[codeKey] = await this.#head.get(codeKey);
37
41
  return id;
@@ -64,3 +68,4 @@ export class HeadState {
64
68
  Object.assign(this.#oldValues, diff);
65
69
  }
66
70
  }
71
+ exports.HeadState = HeadState;
@@ -1,13 +1,16 @@
1
- import { blake2AsHex } from '@polkadot/util-crypto';
2
- import { u8aConcat, u8aToHex } from '@polkadot/util';
3
- import { Block } from './block';
4
- import { TxPool } from './txpool';
5
- import { HeadState } from './head-state';
6
- import { compactHex } from '../utils';
7
- import { defaultLogger } from '../logger';
8
- import { dryRunExtrinsic, dryRunInherents } from './block-builder';
9
- const logger = defaultLogger.child({ name: 'blockchain' });
10
- export class Blockchain {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Blockchain = void 0;
4
+ const util_crypto_1 = require("@polkadot/util-crypto");
5
+ const util_1 = require("@polkadot/util");
6
+ const block_1 = require("./block");
7
+ const txpool_1 = require("./txpool");
8
+ const head_state_1 = require("./head-state");
9
+ const utils_1 = require("../utils");
10
+ const logger_1 = require("../logger");
11
+ const block_builder_1 = require("./block-builder");
12
+ const logger = logger_1.defaultLogger.child({ name: 'blockchain' });
13
+ class Blockchain {
11
14
  uid = Math.random().toString(36).substring(2);
12
15
  api;
13
16
  db;
@@ -27,11 +30,11 @@ export class Blockchain {
27
30
  this.mockSignatureHost = mockSignatureHost;
28
31
  this.allowUnresolvedImports = allowUnresolvedImports;
29
32
  this.registeredTypes = registeredTypes;
30
- this.#head = new Block(this, header.number, header.hash);
33
+ this.#head = new block_1.Block(this, header.number, header.hash);
31
34
  this.#registerBlock(this.#head);
32
- this.#txpool = new TxPool(this, inherentProvider, buildBlockMode);
35
+ this.#txpool = new txpool_1.TxPool(this, inherentProvider, buildBlockMode);
33
36
  this.#inherentProvider = inherentProvider;
34
- this.headState = new HeadState(this.#head);
37
+ this.headState = new head_state_1.HeadState(this.#head);
35
38
  }
36
39
  #registerBlock(block) {
37
40
  this.#blocksByNumber[block.number] = block;
@@ -52,7 +55,7 @@ export class Blockchain {
52
55
  }
53
56
  if (!this.#blocksByNumber[number]) {
54
57
  const hash = await this.api.getBlockHash(number);
55
- const block = new Block(this, number, hash);
58
+ const block = new block_1.Block(this, number, hash);
56
59
  this.#registerBlock(block);
57
60
  }
58
61
  return this.#blocksByNumber[number];
@@ -71,7 +74,7 @@ export class Blockchain {
71
74
  const loadingBlock = (async () => {
72
75
  try {
73
76
  const header = await this.api.getHeader(hash);
74
- const block = new Block(this, Number(header.number), hash);
77
+ const block = new block_1.Block(this, Number(header.number), hash);
75
78
  this.#registerBlock(block);
76
79
  }
77
80
  catch (e) {
@@ -105,13 +108,13 @@ export class Blockchain {
105
108
  }
106
109
  async submitExtrinsic(extrinsic) {
107
110
  const source = '0x02'; // External
108
- const args = u8aToHex(u8aConcat(source, extrinsic, this.head.hash));
111
+ const args = (0, util_1.u8aToHex)((0, util_1.u8aConcat)(source, extrinsic, this.head.hash));
109
112
  const res = await this.head.call('TaggedTransactionQueue_validate_transaction', [args]);
110
113
  const registry = await this.head.registry;
111
114
  const validity = registry.createType('TransactionValidity', res.result);
112
115
  if (validity.isOk) {
113
116
  await this.#txpool.submitExtrinsic(extrinsic);
114
- return blake2AsHex(extrinsic, 256);
117
+ return (0, util_crypto_1.blake2AsHex)(extrinsic, 256);
115
118
  }
116
119
  throw validity.asErr;
117
120
  }
@@ -151,7 +154,7 @@ export class Blockchain {
151
154
  upwardMessages: [],
152
155
  horizontalMessages: {},
153
156
  });
154
- const { result, storageDiff } = await dryRunExtrinsic(head, inherents, extrinsic);
157
+ const { result, storageDiff } = await (0, block_builder_1.dryRunExtrinsic)(head, inherents, extrinsic);
155
158
  const outcome = registry.createType('ApplyExtrinsicResult', result);
156
159
  return { outcome, storageDiff };
157
160
  }
@@ -167,7 +170,7 @@ export class Blockchain {
167
170
  upwardMessages: [],
168
171
  horizontalMessages: hrmp,
169
172
  });
170
- return dryRunInherents(head, inherents);
173
+ return (0, block_builder_1.dryRunInherents)(head, inherents);
171
174
  }
172
175
  async dryRunDmp(dmp, at) {
173
176
  await this.api.isReady;
@@ -181,7 +184,7 @@ export class Blockchain {
181
184
  upwardMessages: [],
182
185
  horizontalMessages: {},
183
186
  });
184
- return dryRunInherents(head, inherents);
187
+ return (0, block_builder_1.dryRunInherents)(head, inherents);
185
188
  }
186
189
  async dryRunUmp(ump, at) {
187
190
  await this.api.isReady;
@@ -192,7 +195,7 @@ export class Blockchain {
192
195
  const meta = await head.meta;
193
196
  const needsDispatch = meta.registry.createType('Vec<u32>', Object.keys(ump));
194
197
  const stroageValues = [
195
- [compactHex(meta.query.ump.needsDispatch()), needsDispatch.toHex()],
198
+ [(0, utils_1.compactHex)(meta.query.ump.needsDispatch()), needsDispatch.toHex()],
196
199
  ];
197
200
  for (const [paraId, messages] of Object.entries(ump)) {
198
201
  const upwardMessages = meta.registry.createType('Vec<Bytes>', messages);
@@ -202,8 +205,8 @@ export class Blockchain {
202
205
  upwardMessages.length,
203
206
  upwardMessages.map((x) => x.byteLength).reduce((s, i) => s + i, 0),
204
207
  ]);
205
- stroageValues.push([compactHex(meta.query.ump.relayDispatchQueues(paraId)), upwardMessages.toHex()]);
206
- stroageValues.push([compactHex(meta.query.ump.relayDispatchQueueSize(paraId)), queueSize.toHex()]);
208
+ stroageValues.push([(0, utils_1.compactHex)(meta.query.ump.relayDispatchQueues(paraId)), upwardMessages.toHex()]);
209
+ stroageValues.push([(0, utils_1.compactHex)(meta.query.ump.relayDispatchQueueSize(paraId)), queueSize.toHex()]);
207
210
  }
208
211
  head.pushStorageLayer().setAll(stroageValues);
209
212
  const inherents = await this.#inherentProvider.createInherents(head, {
@@ -212,7 +215,7 @@ export class Blockchain {
212
215
  upwardMessages: [],
213
216
  horizontalMessages: {},
214
217
  });
215
- return dryRunInherents(head, inherents);
218
+ return (0, block_builder_1.dryRunInherents)(head, inherents);
216
219
  }
217
220
  async getInherents() {
218
221
  await this.api.isReady;
@@ -225,3 +228,4 @@ export class Blockchain {
225
228
  return inherents;
226
229
  }
227
230
  }
231
+ exports.Blockchain = Blockchain;
@@ -1,18 +1,26 @@
1
- import { GenericExtrinsic } from '@polkadot/types';
2
- import { getCurrentTimestamp, getSlotDuration } from '../../utils/time-travel';
3
- export { SetValidationData } from './parachain/validation-data';
4
- export { ParaInherentEnter } from './para-enter';
5
- export { SetBabeRandomness } from './parachain/babe-randomness';
6
- export { SetNimbusAuthorInherent } from './parachain/nimbus-author-inherent';
7
- export class SetTimestamp {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InherentProviders = exports.SetTimestamp = exports.SetNimbusAuthorInherent = exports.SetBabeRandomness = exports.ParaInherentEnter = exports.SetValidationData = void 0;
4
+ const types_1 = require("@polkadot/types");
5
+ const time_travel_1 = require("../../utils/time-travel");
6
+ var validation_data_1 = require("./parachain/validation-data");
7
+ Object.defineProperty(exports, "SetValidationData", { enumerable: true, get: function () { return validation_data_1.SetValidationData; } });
8
+ var para_enter_1 = require("./para-enter");
9
+ Object.defineProperty(exports, "ParaInherentEnter", { enumerable: true, get: function () { return para_enter_1.ParaInherentEnter; } });
10
+ var babe_randomness_1 = require("./parachain/babe-randomness");
11
+ Object.defineProperty(exports, "SetBabeRandomness", { enumerable: true, get: function () { return babe_randomness_1.SetBabeRandomness; } });
12
+ var nimbus_author_inherent_1 = require("./parachain/nimbus-author-inherent");
13
+ Object.defineProperty(exports, "SetNimbusAuthorInherent", { enumerable: true, get: function () { return nimbus_author_inherent_1.SetNimbusAuthorInherent; } });
14
+ class SetTimestamp {
8
15
  async createInherents(parent) {
9
16
  const meta = await parent.meta;
10
- const slotDuration = await getSlotDuration(parent.chain);
11
- const currentTimestamp = await getCurrentTimestamp(parent.chain);
12
- return [new GenericExtrinsic(meta.registry, meta.tx.timestamp.set(currentTimestamp + slotDuration)).toHex()];
17
+ const slotDuration = await (0, time_travel_1.getSlotDuration)(parent.chain);
18
+ const currentTimestamp = await (0, time_travel_1.getCurrentTimestamp)(parent.chain);
19
+ return [new types_1.GenericExtrinsic(meta.registry, meta.tx.timestamp.set(currentTimestamp + slotDuration)).toHex()];
13
20
  }
14
21
  }
15
- export class InherentProviders {
22
+ exports.SetTimestamp = SetTimestamp;
23
+ class InherentProviders {
16
24
  #base;
17
25
  #providers;
18
26
  constructor(base, providers) {
@@ -25,3 +33,4 @@ export class InherentProviders {
25
33
  return [...base, ...extra.flat()];
26
34
  }
27
35
  }
36
+ exports.InherentProviders = InherentProviders;
@@ -1,5 +1,8 @@
1
- import { GenericExtrinsic } from '@polkadot/types';
2
- export class ParaInherentEnter {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ParaInherentEnter = void 0;
4
+ const types_1 = require("@polkadot/types");
5
+ class ParaInherentEnter {
3
6
  async createInherents(parent, _params) {
4
7
  const meta = await parent.meta;
5
8
  if (!meta.tx.paraInherent?.enter) {
@@ -24,6 +27,7 @@ export class ParaInherentEnter {
24
27
  parentHeader,
25
28
  };
26
29
  // TODO: fill with data
27
- return [new GenericExtrinsic(meta.registry, meta.tx.paraInherent.enter(newData)).toHex()];
30
+ return [new types_1.GenericExtrinsic(meta.registry, meta.tx.paraInherent.enter(newData)).toHex()];
28
31
  }
29
32
  }
33
+ exports.ParaInherentEnter = ParaInherentEnter;
@@ -1,11 +1,15 @@
1
- import { GenericExtrinsic } from '@polkadot/types';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SetBabeRandomness = void 0;
4
+ const types_1 = require("@polkadot/types");
2
5
  // Support for Moonbeam pallet-randomness mandatory inherent
3
- export class SetBabeRandomness {
6
+ class SetBabeRandomness {
4
7
  async createInherents(parent, _params) {
5
8
  const meta = await parent.meta;
6
9
  if (!meta.tx.randomness?.setBabeRandomnessResults) {
7
10
  return [];
8
11
  }
9
- return [new GenericExtrinsic(meta.registry, meta.tx.randomness.setBabeRandomnessResults()).toHex()];
12
+ return [new types_1.GenericExtrinsic(meta.registry, meta.tx.randomness.setBabeRandomnessResults()).toHex()];
10
13
  }
11
14
  }
15
+ exports.SetBabeRandomness = SetBabeRandomness;
@@ -1,11 +1,15 @@
1
- import { GenericExtrinsic } from '@polkadot/types';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SetNimbusAuthorInherent = void 0;
4
+ const types_1 = require("@polkadot/types");
2
5
  // Support for Nimbus Author Inherent
3
- export class SetNimbusAuthorInherent {
6
+ class SetNimbusAuthorInherent {
4
7
  async createInherents(parent, _params) {
5
8
  const meta = await parent.meta;
6
9
  if (!meta.tx.authorInherent?.kickOffAuthorshipValidation) {
7
10
  return [];
8
11
  }
9
- return [new GenericExtrinsic(meta.registry, meta.tx.authorInherent.kickOffAuthorshipValidation()).toHex()];
12
+ return [new types_1.GenericExtrinsic(meta.registry, meta.tx.authorInherent.kickOffAuthorshipValidation()).toHex()];
10
13
  }
11
14
  }
15
+ exports.SetNimbusAuthorInherent = SetNimbusAuthorInherent;