@acala-network/chopsticks-core 0.8.0-0 → 0.8.0-2

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.
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -19,18 +20,20 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
19
20
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
20
21
  };
21
22
  var _Blockchain_instances, _Blockchain_txpool, _Blockchain_inherentProvider, _Blockchain_head, _Blockchain_blocksByNumber, _Blockchain_blocksByHash, _Blockchain_loadingBlocks, _Blockchain_maxMemoryBlockCount, _Blockchain_registerBlock;
22
- import { blake2AsHex } from '@polkadot/util-crypto';
23
- import { u8aConcat, u8aToHex } from '@polkadot/util';
24
- import { Block } from './block';
25
- import { BlockEntity } from '../db/entities';
26
- import { TxPool } from './txpool';
27
- import { HeadState } from './head-state';
28
- import { OffchainWorker } from '../offchain';
29
- import { compactHex } from '../utils';
30
- import { defaultLogger } from '../logger';
31
- import { dryRunExtrinsic, dryRunInherents } from './block-builder';
32
- const logger = defaultLogger.child({ name: 'blockchain' });
33
- export class Blockchain {
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.Blockchain = void 0;
25
+ const util_crypto_1 = require("@polkadot/util-crypto");
26
+ const util_1 = require("@polkadot/util");
27
+ const block_1 = require("./block");
28
+ const entities_1 = require("../db/entities");
29
+ const txpool_1 = require("./txpool");
30
+ const head_state_1 = require("./head-state");
31
+ const offchain_1 = require("../offchain");
32
+ const utils_1 = require("../utils");
33
+ const logger_1 = require("../logger");
34
+ const block_builder_1 = require("./block-builder");
35
+ const logger = logger_1.defaultLogger.child({ name: 'blockchain' });
36
+ class Blockchain {
34
37
  constructor({ api, buildBlockMode, inherentProvider, db, header, mockSignatureHost = false, allowUnresolvedImports = false, runtimeLogLevel = 0, registeredTypes = {}, offchainWorker = false, maxMemoryBlockCount = 2000, }) {
35
38
  _Blockchain_instances.add(this);
36
39
  this.uid = Math.random().toString(36).substring(2);
@@ -47,13 +50,13 @@ export class Blockchain {
47
50
  this.allowUnresolvedImports = allowUnresolvedImports;
48
51
  this.runtimeLogLevel = runtimeLogLevel;
49
52
  this.registeredTypes = registeredTypes;
50
- __classPrivateFieldSet(this, _Blockchain_head, new Block(this, header.number, header.hash), "f");
53
+ __classPrivateFieldSet(this, _Blockchain_head, new block_1.Block(this, header.number, header.hash), "f");
51
54
  __classPrivateFieldGet(this, _Blockchain_instances, "m", _Blockchain_registerBlock).call(this, __classPrivateFieldGet(this, _Blockchain_head, "f"));
52
- __classPrivateFieldSet(this, _Blockchain_txpool, new TxPool(this, inherentProvider, buildBlockMode), "f");
55
+ __classPrivateFieldSet(this, _Blockchain_txpool, new txpool_1.TxPool(this, inherentProvider, buildBlockMode), "f");
53
56
  __classPrivateFieldSet(this, _Blockchain_inherentProvider, inherentProvider, "f");
54
- this.headState = new HeadState(__classPrivateFieldGet(this, _Blockchain_head, "f"));
57
+ this.headState = new head_state_1.HeadState(__classPrivateFieldGet(this, _Blockchain_head, "f"));
55
58
  if (offchainWorker) {
56
- this.offchainWorker = new OffchainWorker();
59
+ this.offchainWorker = new offchain_1.OffchainWorker();
57
60
  }
58
61
  __classPrivateFieldSet(this, _Blockchain_maxMemoryBlockCount, maxMemoryBlockCount, "f");
59
62
  }
@@ -70,8 +73,8 @@ export class Blockchain {
70
73
  // delete old ones with the same block number if any, keep the latest one
71
74
  yield this.db.transaction((transactionalEntityManager) => __awaiter(this, void 0, void 0, function* () {
72
75
  var _a;
73
- yield transactionalEntityManager.getRepository(BlockEntity).delete({ number });
74
- yield transactionalEntityManager.getRepository(BlockEntity).upsert({
76
+ yield transactionalEntityManager.getRepository(entities_1.BlockEntity).delete({ number });
77
+ yield transactionalEntityManager.getRepository(entities_1.BlockEntity).upsert({
75
78
  hash,
76
79
  number,
77
80
  header: yield header,
@@ -91,12 +94,12 @@ export class Blockchain {
91
94
  return __awaiter(this, void 0, void 0, function* () {
92
95
  if (this.db) {
93
96
  const blockData = yield this.db
94
- .getRepository(BlockEntity)
97
+ .getRepository(entities_1.BlockEntity)
95
98
  .findOne({ where: { [typeof key === 'number' ? 'number' : 'hash']: key } });
96
99
  if (blockData) {
97
100
  const { hash, number, header, extrinsics, parentHash, storageDiff } = blockData;
98
101
  const parentBlock = parentHash ? __classPrivateFieldGet(this, _Blockchain_blocksByHash, "f")[parentHash] : undefined;
99
- const block = new Block(this, number, hash, parentBlock, { header, extrinsics, storageDiff });
102
+ const block = new block_1.Block(this, number, hash, parentBlock, { header, extrinsics, storageDiff });
100
103
  __classPrivateFieldGet(this, _Blockchain_instances, "m", _Blockchain_registerBlock).call(this, block);
101
104
  return block;
102
105
  }
@@ -118,7 +121,7 @@ export class Blockchain {
118
121
  return blockFromDB;
119
122
  }
120
123
  const hash = yield this.api.getBlockHash(number);
121
- const block = new Block(this, number, hash);
124
+ const block = new block_1.Block(this, number, hash);
122
125
  __classPrivateFieldGet(this, _Blockchain_instances, "m", _Blockchain_registerBlock).call(this, block);
123
126
  }
124
127
  return __classPrivateFieldGet(this, _Blockchain_blocksByNumber, "f").get(number);
@@ -141,7 +144,7 @@ export class Blockchain {
141
144
  const blockFromDB = yield this.loadBlockFromDB(hash);
142
145
  if (!blockFromDB) {
143
146
  const header = yield this.api.getHeader(hash);
144
- const block = new Block(this, Number(header.number), hash);
147
+ const block = new block_1.Block(this, Number(header.number), hash);
145
148
  __classPrivateFieldGet(this, _Blockchain_instances, "m", _Blockchain_registerBlock).call(this, block);
146
149
  }
147
150
  }
@@ -172,7 +175,7 @@ export class Blockchain {
172
175
  delete __classPrivateFieldGet(this, _Blockchain_blocksByHash, "f")[block.hash];
173
176
  // delete from db
174
177
  if (this.db) {
175
- yield this.db.getRepository(BlockEntity).delete({ hash: block.hash });
178
+ yield this.db.getRepository(entities_1.BlockEntity).delete({ hash: block.hash });
176
179
  }
177
180
  });
178
181
  }
@@ -201,14 +204,14 @@ export class Blockchain {
201
204
  const validity = yield this.validateExtrinsic(extrinsic);
202
205
  if (validity.isOk) {
203
206
  yield __classPrivateFieldGet(this, _Blockchain_txpool, "f").submitExtrinsic(extrinsic);
204
- return blake2AsHex(extrinsic, 256);
207
+ return (0, util_crypto_1.blake2AsHex)(extrinsic, 256);
205
208
  }
206
209
  throw validity.asErr;
207
210
  });
208
211
  }
209
212
  validateExtrinsic(extrinsic, source = '0x02' /** External */) {
210
213
  return __awaiter(this, void 0, void 0, function* () {
211
- const args = u8aToHex(u8aConcat(source, extrinsic, this.head.hash));
214
+ const args = (0, util_1.u8aToHex)((0, util_1.u8aConcat)(source, extrinsic, this.head.hash));
212
215
  const res = yield this.head.call('TaggedTransactionQueue_validate_transaction', [args]);
213
216
  const registry = yield this.head.registry;
214
217
  return registry.createType('TransactionValidity', res.result);
@@ -257,7 +260,7 @@ export class Blockchain {
257
260
  upwardMessages: [],
258
261
  horizontalMessages: {},
259
262
  });
260
- const { result, storageDiff } = yield dryRunExtrinsic(head, inherents, extrinsic);
263
+ const { result, storageDiff } = yield (0, block_builder_1.dryRunExtrinsic)(head, inherents, extrinsic);
261
264
  const outcome = registry.createType('ApplyExtrinsicResult', result);
262
265
  return { outcome, storageDiff };
263
266
  });
@@ -275,7 +278,7 @@ export class Blockchain {
275
278
  upwardMessages: [],
276
279
  horizontalMessages: hrmp,
277
280
  });
278
- return dryRunInherents(head, inherents);
281
+ return (0, block_builder_1.dryRunInherents)(head, inherents);
279
282
  });
280
283
  }
281
284
  dryRunDmp(dmp, at) {
@@ -291,7 +294,7 @@ export class Blockchain {
291
294
  upwardMessages: [],
292
295
  horizontalMessages: {},
293
296
  });
294
- return dryRunInherents(head, inherents);
297
+ return (0, block_builder_1.dryRunInherents)(head, inherents);
295
298
  });
296
299
  }
297
300
  dryRunUmp(ump, at) {
@@ -304,7 +307,7 @@ export class Blockchain {
304
307
  const meta = yield head.meta;
305
308
  const needsDispatch = meta.registry.createType('Vec<u32>', Object.keys(ump));
306
309
  const storageValues = [
307
- [compactHex(meta.query.ump.needsDispatch()), needsDispatch.toHex()],
310
+ [(0, utils_1.compactHex)(meta.query.ump.needsDispatch()), needsDispatch.toHex()],
308
311
  ];
309
312
  for (const [paraId, messages] of Object.entries(ump)) {
310
313
  const upwardMessages = meta.registry.createType('Vec<Bytes>', messages);
@@ -314,8 +317,8 @@ export class Blockchain {
314
317
  upwardMessages.length,
315
318
  upwardMessages.map((x) => x.byteLength).reduce((s, i) => s + i, 0),
316
319
  ]);
317
- storageValues.push([compactHex(meta.query.ump.relayDispatchQueues(paraId)), upwardMessages.toHex()]);
318
- storageValues.push([compactHex(meta.query.ump.relayDispatchQueueSize(paraId)), queueSize.toHex()]);
320
+ storageValues.push([(0, utils_1.compactHex)(meta.query.ump.relayDispatchQueues(paraId)), upwardMessages.toHex()]);
321
+ storageValues.push([(0, utils_1.compactHex)(meta.query.ump.relayDispatchQueueSize(paraId)), queueSize.toHex()]);
319
322
  }
320
323
  head.pushStorageLayer().setAll(storageValues);
321
324
  const inherents = yield __classPrivateFieldGet(this, _Blockchain_inherentProvider, "f").createInherents(head, {
@@ -324,7 +327,7 @@ export class Blockchain {
324
327
  upwardMessages: [],
325
328
  horizontalMessages: {},
326
329
  });
327
- return dryRunInherents(head, inherents);
330
+ return (0, block_builder_1.dryRunInherents)(head, inherents);
328
331
  });
329
332
  }
330
333
  getInherents() {
@@ -340,6 +343,7 @@ export class Blockchain {
340
343
  });
341
344
  }
342
345
  }
346
+ exports.Blockchain = Blockchain;
343
347
  _Blockchain_txpool = new WeakMap(), _Blockchain_inherentProvider = new WeakMap(), _Blockchain_head = new WeakMap(), _Blockchain_blocksByNumber = new WeakMap(), _Blockchain_blocksByHash = new WeakMap(), _Blockchain_loadingBlocks = new WeakMap(), _Blockchain_maxMemoryBlockCount = new WeakMap(), _Blockchain_instances = new WeakSet(), _Blockchain_registerBlock = function _Blockchain_registerBlock(block) {
344
348
  // if exceed max memory block count, delete the oldest block
345
349
  if (__classPrivateFieldGet(this, _Blockchain_blocksByNumber, "f").size === __classPrivateFieldGet(this, _Blockchain_maxMemoryBlockCount, "f")) {
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -19,23 +20,30 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
19
20
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
20
21
  };
21
22
  var _InherentProviders_base, _InherentProviders_providers;
22
- import { GenericExtrinsic } from '@polkadot/types';
23
- import { getCurrentTimestamp, getSlotDuration } from '../../utils/time-travel';
24
- export { SetValidationData } from './parachain/validation-data';
25
- export { ParaInherentEnter } from './para-enter';
26
- export { SetBabeRandomness } from './parachain/babe-randomness';
27
- export { SetNimbusAuthorInherent } from './parachain/nimbus-author-inherent';
28
- export class SetTimestamp {
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.InherentProviders = exports.SetTimestamp = exports.SetNimbusAuthorInherent = exports.SetBabeRandomness = exports.ParaInherentEnter = exports.SetValidationData = void 0;
25
+ const types_1 = require("@polkadot/types");
26
+ const time_travel_1 = require("../../utils/time-travel");
27
+ var validation_data_1 = require("./parachain/validation-data");
28
+ Object.defineProperty(exports, "SetValidationData", { enumerable: true, get: function () { return validation_data_1.SetValidationData; } });
29
+ var para_enter_1 = require("./para-enter");
30
+ Object.defineProperty(exports, "ParaInherentEnter", { enumerable: true, get: function () { return para_enter_1.ParaInherentEnter; } });
31
+ var babe_randomness_1 = require("./parachain/babe-randomness");
32
+ Object.defineProperty(exports, "SetBabeRandomness", { enumerable: true, get: function () { return babe_randomness_1.SetBabeRandomness; } });
33
+ var nimbus_author_inherent_1 = require("./parachain/nimbus-author-inherent");
34
+ Object.defineProperty(exports, "SetNimbusAuthorInherent", { enumerable: true, get: function () { return nimbus_author_inherent_1.SetNimbusAuthorInherent; } });
35
+ class SetTimestamp {
29
36
  createInherents(parent) {
30
37
  return __awaiter(this, void 0, void 0, function* () {
31
38
  const meta = yield parent.meta;
32
- const slotDuration = yield getSlotDuration(parent.chain);
33
- const currentTimestamp = yield getCurrentTimestamp(parent.chain);
34
- return [new GenericExtrinsic(meta.registry, meta.tx.timestamp.set(currentTimestamp + slotDuration)).toHex()];
39
+ const slotDuration = yield (0, time_travel_1.getSlotDuration)(parent.chain);
40
+ const currentTimestamp = yield (0, time_travel_1.getCurrentTimestamp)(parent.chain);
41
+ return [new types_1.GenericExtrinsic(meta.registry, meta.tx.timestamp.set(currentTimestamp + slotDuration)).toHex()];
35
42
  });
36
43
  }
37
44
  }
38
- export class InherentProviders {
45
+ exports.SetTimestamp = SetTimestamp;
46
+ class InherentProviders {
39
47
  constructor(base, providers) {
40
48
  _InherentProviders_base.set(this, void 0);
41
49
  _InherentProviders_providers.set(this, void 0);
@@ -50,4 +58,5 @@ export class InherentProviders {
50
58
  });
51
59
  }
52
60
  }
61
+ exports.InherentProviders = InherentProviders;
53
62
  _InherentProviders_base = new WeakMap(), _InherentProviders_providers = new WeakMap();
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -7,8 +8,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
9
  });
9
10
  };
10
- import { GenericExtrinsic } from '@polkadot/types';
11
- export class ParaInherentEnter {
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ParaInherentEnter = void 0;
13
+ const types_1 = require("@polkadot/types");
14
+ class ParaInherentEnter {
12
15
  createInherents(parent, _params) {
13
16
  var _a;
14
17
  return __awaiter(this, void 0, void 0, function* () {
@@ -31,7 +34,8 @@ export class ParaInherentEnter {
31
34
  const parentHeader = (yield parent.header).toJSON();
32
35
  const newData = Object.assign(Object.assign({}, extrinsic), { bitfields: [], backedCandidates: [], parentHeader });
33
36
  // TODO: fill with data
34
- return [new GenericExtrinsic(meta.registry, meta.tx.paraInherent.enter(newData)).toHex()];
37
+ return [new types_1.GenericExtrinsic(meta.registry, meta.tx.paraInherent.enter(newData)).toHex()];
35
38
  });
36
39
  }
37
40
  }
41
+ exports.ParaInherentEnter = ParaInherentEnter;
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -7,9 +8,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
9
  });
9
10
  };
10
- import { GenericExtrinsic } from '@polkadot/types';
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.SetBabeRandomness = void 0;
13
+ const types_1 = require("@polkadot/types");
11
14
  // Support for Moonbeam pallet-randomness mandatory inherent
12
- export class SetBabeRandomness {
15
+ class SetBabeRandomness {
13
16
  createInherents(parent, _params) {
14
17
  var _a;
15
18
  return __awaiter(this, void 0, void 0, function* () {
@@ -17,7 +20,8 @@ export class SetBabeRandomness {
17
20
  if (!((_a = meta.tx.randomness) === null || _a === void 0 ? void 0 : _a.setBabeRandomnessResults)) {
18
21
  return [];
19
22
  }
20
- return [new GenericExtrinsic(meta.registry, meta.tx.randomness.setBabeRandomnessResults()).toHex()];
23
+ return [new types_1.GenericExtrinsic(meta.registry, meta.tx.randomness.setBabeRandomnessResults()).toHex()];
21
24
  });
22
25
  }
23
26
  }
27
+ exports.SetBabeRandomness = SetBabeRandomness;
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -7,9 +8,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
9
  });
9
10
  };
10
- import { GenericExtrinsic } from '@polkadot/types';
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.SetNimbusAuthorInherent = void 0;
13
+ const types_1 = require("@polkadot/types");
11
14
  // Support for Nimbus Author Inherent
12
- export class SetNimbusAuthorInherent {
15
+ class SetNimbusAuthorInherent {
13
16
  createInherents(parent, _params) {
14
17
  var _a;
15
18
  return __awaiter(this, void 0, void 0, function* () {
@@ -17,7 +20,8 @@ export class SetNimbusAuthorInherent {
17
20
  if (!((_a = meta.tx.authorInherent) === null || _a === void 0 ? void 0 : _a.kickOffAuthorshipValidation)) {
18
21
  return [];
19
22
  }
20
- return [new GenericExtrinsic(meta.registry, meta.tx.authorInherent.kickOffAuthorshipValidation()).toHex()];
23
+ return [new types_1.GenericExtrinsic(meta.registry, meta.tx.authorInherent.kickOffAuthorshipValidation()).toHex()];
21
24
  });
22
25
  }
23
26
  }
27
+ exports.SetNimbusAuthorInherent = SetNimbusAuthorInherent;
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -7,13 +8,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
9
  });
9
10
  };
10
- import { GenericExtrinsic } from '@polkadot/types';
11
- import { hexToU8a, u8aConcat } from '@polkadot/util';
12
- import _ from 'lodash';
13
- import { WELL_KNOWN_KEYS, dmqMqcHead, hrmpChannels, hrmpEgressChannelIndex, hrmpIngressChannelIndex, upgradeGoAheadSignal, } from '../../../utils/proof';
14
- import { blake2AsHex, blake2AsU8a } from '@polkadot/util-crypto';
15
- import { compactHex, getParaId } from '../../../utils';
16
- import { createProof, decodeProof } from '../../../executor';
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.SetValidationData = void 0;
16
+ const types_1 = require("@polkadot/types");
17
+ const util_1 = require("@polkadot/util");
18
+ const lodash_1 = __importDefault(require("lodash"));
19
+ const proof_1 = require("../../../utils/proof");
20
+ const util_crypto_1 = require("@polkadot/util-crypto");
21
+ const utils_1 = require("../../../utils");
22
+ const executor_1 = require("../../../executor");
17
23
  const MOCK_VALIDATION_DATA = {
18
24
  validationData: {
19
25
  relayParentNumber: 1000,
@@ -38,7 +44,7 @@ const MOCK_VALIDATION_DATA = {
38
44
  ],
39
45
  },
40
46
  };
41
- export class SetValidationData {
47
+ class SetValidationData {
42
48
  createInherents(parent, params) {
43
49
  var _a;
44
50
  return __awaiter(this, void 0, void 0, function* () {
@@ -67,13 +73,13 @@ export class SetValidationData {
67
73
  const newEntries = [];
68
74
  const downwardMessages = [];
69
75
  const horizontalMessages = {};
70
- const paraId = yield getParaId(parent.chain);
71
- const dmqMqcHeadKey = dmqMqcHead(paraId);
72
- const hrmpIngressChannelIndexKey = hrmpIngressChannelIndex(paraId);
73
- const hrmpEgressChannelIndexKey = hrmpEgressChannelIndex(paraId);
76
+ const paraId = yield (0, utils_1.getParaId)(parent.chain);
77
+ const dmqMqcHeadKey = (0, proof_1.dmqMqcHead)(paraId);
78
+ const hrmpIngressChannelIndexKey = (0, proof_1.hrmpIngressChannelIndex)(paraId);
79
+ const hrmpEgressChannelIndexKey = (0, proof_1.hrmpEgressChannelIndex)(paraId);
74
80
  // TODO: refactor this to have a single decodeProof
75
- const decoded = yield decodeProof(extrinsic.validationData.relayParentStorageRoot, [...Object.values(WELL_KNOWN_KEYS), dmqMqcHeadKey, hrmpIngressChannelIndexKey, hrmpEgressChannelIndexKey], extrinsic.relayChainState.trieNodes);
76
- for (const key of Object.values(WELL_KNOWN_KEYS)) {
81
+ const decoded = yield (0, executor_1.decodeProof)(extrinsic.validationData.relayParentStorageRoot, [...Object.values(proof_1.WELL_KNOWN_KEYS), dmqMqcHeadKey, hrmpIngressChannelIndexKey, hrmpEgressChannelIndexKey], extrinsic.relayChainState.trieNodes);
82
+ for (const key of Object.values(proof_1.WELL_KNOWN_KEYS)) {
77
83
  newEntries.push([key, decoded[key]]);
78
84
  }
79
85
  newEntries.push([hrmpIngressChannelIndexKey, decoded[hrmpIngressChannelIndexKey]]);
@@ -83,7 +89,7 @@ export class SetValidationData {
83
89
  if (dmqMqcHeadHash) {
84
90
  for (const { msg, sentAt } of params.downwardMessages) {
85
91
  // calculate new hash
86
- dmqMqcHeadHash = blake2AsHex(u8aConcat(meta.registry.createType('Hash', dmqMqcHeadHash).toU8a(), meta.registry.createType('BlockNumber', sentAt).toU8a(), blake2AsU8a(meta.registry.createType('Bytes', msg).toU8a(), 256)), 256);
92
+ 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);
87
93
  downwardMessages.push({
88
94
  msg,
89
95
  sentAt,
@@ -97,7 +103,7 @@ export class SetValidationData {
97
103
  const hrmpEgressChannels = meta.registry
98
104
  .createType('Vec<ParaId>', decoded[hrmpEgressChannelIndexKey])
99
105
  .toJSON();
100
- const hrmpMessages = Object.assign(Object.assign({}, _.mapValues(extrinsic.horizontalMessages, () => [])), params.horizontalMessages);
106
+ const hrmpMessages = Object.assign(Object.assign({}, lodash_1.default.mapValues(extrinsic.horizontalMessages, () => [])), params.horizontalMessages);
101
107
  // inject horizontal messages
102
108
  for (const id of hrmpIngressChannels) {
103
109
  const messages = hrmpMessages[id];
@@ -106,19 +112,19 @@ export class SetValidationData {
106
112
  sender,
107
113
  receiver: paraId.toNumber(),
108
114
  });
109
- const hrmpChannelKey = hrmpChannels(channelId);
110
- const decoded = yield decodeProof(extrinsic.validationData.relayParentStorageRoot, [hrmpChannelKey], extrinsic.relayChainState.trieNodes);
115
+ const hrmpChannelKey = (0, proof_1.hrmpChannels)(channelId);
116
+ const decoded = yield (0, executor_1.decodeProof)(extrinsic.validationData.relayParentStorageRoot, [hrmpChannelKey], extrinsic.relayChainState.trieNodes);
111
117
  const abridgedHrmpRaw = decoded[hrmpChannelKey];
112
118
  if (!abridgedHrmpRaw)
113
119
  throw new Error('Canoot find hrmp channels from validation data');
114
120
  const abridgedHrmp = meta.registry
115
- .createType('AbridgedHrmpChannel', hexToU8a(abridgedHrmpRaw))
121
+ .createType('AbridgedHrmpChannel', (0, util_1.hexToU8a)(abridgedHrmpRaw))
116
122
  .toJSON();
117
123
  const paraMessages = [];
118
124
  for (const { data, sentAt } of messages) {
119
125
  // calculate new hash
120
126
  const bytes = meta.registry.createType('Bytes', data);
121
- abridgedHrmp.mqcHead = blake2AsHex(u8aConcat(meta.registry.createType('Hash', abridgedHrmp.mqcHead).toU8a(), meta.registry.createType('BlockNumber', sentAt).toU8a(), blake2AsU8a(bytes.toU8a(), 256)), 256);
127
+ 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);
122
128
  abridgedHrmp.msgCount = abridgedHrmp.msgCount + 1;
123
129
  abridgedHrmp.totalSize = abridgedHrmp.totalSize + bytes.length;
124
130
  paraMessages.push({
@@ -137,12 +143,12 @@ export class SetValidationData {
137
143
  sender: paraId.toNumber(),
138
144
  receiver,
139
145
  });
140
- const hrmpChannelKey = hrmpChannels(channelId);
141
- const decoded = yield decodeProof(extrinsic.validationData.relayParentStorageRoot, [hrmpChannelKey], extrinsic.relayChainState.trieNodes);
146
+ const hrmpChannelKey = (0, proof_1.hrmpChannels)(channelId);
147
+ const decoded = yield (0, executor_1.decodeProof)(extrinsic.validationData.relayParentStorageRoot, [hrmpChannelKey], extrinsic.relayChainState.trieNodes);
142
148
  newEntries.push([hrmpChannelKey, decoded[hrmpChannelKey]]);
143
149
  }
144
- const upgradeKey = upgradeGoAheadSignal(paraId);
145
- const pendingUpgrade = yield parent.get(compactHex(meta.query.parachainSystem.pendingValidationCode()));
150
+ const upgradeKey = (0, proof_1.upgradeGoAheadSignal)(paraId);
151
+ const pendingUpgrade = yield parent.get((0, utils_1.compactHex)(meta.query.parachainSystem.pendingValidationCode()));
146
152
  if (pendingUpgrade) {
147
153
  // send goAhead signal
148
154
  const goAhead = meta.registry.createType('UpgradeGoAhead', 'GoAhead');
@@ -152,14 +158,15 @@ export class SetValidationData {
152
158
  // make sure previous goAhead is removed
153
159
  newEntries.push([upgradeKey, null]);
154
160
  }
155
- const { trieRootHash, nodes } = yield createProof(extrinsic.relayChainState.trieNodes, newEntries);
161
+ const { trieRootHash, nodes } = yield (0, executor_1.createProof)(extrinsic.relayChainState.trieNodes, newEntries);
156
162
  newData = Object.assign(Object.assign({}, extrinsic), { downwardMessages,
157
163
  horizontalMessages, validationData: Object.assign(Object.assign({}, extrinsic.validationData), { relayParentStorageRoot: trieRootHash, relayParentNumber: extrinsic.validationData.relayParentNumber + 2 }), relayChainState: {
158
164
  trieNodes: nodes,
159
165
  } });
160
166
  }
161
- const inherent = new GenericExtrinsic(meta.registry, meta.tx.parachainSystem.setValidationData(newData));
167
+ const inherent = new types_1.GenericExtrinsic(meta.registry, meta.tx.parachainSystem.setValidationData(newData));
162
168
  return [inherent.toHex()];
163
169
  });
164
170
  }
165
171
  }
172
+ exports.SetValidationData = SetValidationData;
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -18,24 +19,29 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
18
19
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
19
20
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
20
21
  };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
21
25
  var _RemoteStorageLayer_api, _RemoteStorageLayer_at, _RemoteStorageLayer_db, _RemoteStorageLayer_keyCache, _StorageLayer_instances, _StorageLayer_store, _StorageLayer_keys, _StorageLayer_deletedPrefix, _StorageLayer_parent, _StorageLayer_addKey, _StorageLayer_removeKey;
22
- import _ from 'lodash';
23
- import { KeyValuePair } from '../db/entities';
24
- import { defaultLogger } from '../logger';
25
- import KeyCache from '../utils/key-cache';
26
- const logger = defaultLogger.child({ name: 'layer' });
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.StorageLayer = exports.RemoteStorageLayer = exports.StorageValueKind = void 0;
28
+ const lodash_1 = __importDefault(require("lodash"));
29
+ const entities_1 = require("../db/entities");
30
+ const logger_1 = require("../logger");
31
+ const key_cache_1 = __importDefault(require("../utils/key-cache"));
32
+ const logger = logger_1.defaultLogger.child({ name: 'layer' });
27
33
  const BATCH_SIZE = 1000;
28
- export var StorageValueKind;
34
+ var StorageValueKind;
29
35
  (function (StorageValueKind) {
30
36
  StorageValueKind["Deleted"] = "Deleted";
31
37
  StorageValueKind["DeletedPrefix"] = "DeletedPrefix";
32
- })(StorageValueKind || (StorageValueKind = {}));
33
- export class RemoteStorageLayer {
38
+ })(StorageValueKind || (exports.StorageValueKind = StorageValueKind = {}));
39
+ class RemoteStorageLayer {
34
40
  constructor(api, at, db) {
35
41
  _RemoteStorageLayer_api.set(this, void 0);
36
42
  _RemoteStorageLayer_at.set(this, void 0);
37
43
  _RemoteStorageLayer_db.set(this, void 0);
38
- _RemoteStorageLayer_keyCache.set(this, new KeyCache());
44
+ _RemoteStorageLayer_keyCache.set(this, new key_cache_1.default());
39
45
  __classPrivateFieldSet(this, _RemoteStorageLayer_api, api, "f");
40
46
  __classPrivateFieldSet(this, _RemoteStorageLayer_at, at, "f");
41
47
  __classPrivateFieldSet(this, _RemoteStorageLayer_db, db, "f");
@@ -43,7 +49,7 @@ export class RemoteStorageLayer {
43
49
  get(key) {
44
50
  var _a;
45
51
  return __awaiter(this, void 0, void 0, function* () {
46
- const keyValuePair = (_a = __classPrivateFieldGet(this, _RemoteStorageLayer_db, "f")) === null || _a === void 0 ? void 0 : _a.getRepository(KeyValuePair);
52
+ const keyValuePair = (_a = __classPrivateFieldGet(this, _RemoteStorageLayer_db, "f")) === null || _a === void 0 ? void 0 : _a.getRepository(entities_1.KeyValuePair);
47
53
  if (__classPrivateFieldGet(this, _RemoteStorageLayer_db, "f")) {
48
54
  const res = yield (keyValuePair === null || keyValuePair === void 0 ? void 0 : keyValuePair.findOne({ where: { key, blockHash: __classPrivateFieldGet(this, _RemoteStorageLayer_at, "f") } }));
49
55
  if (res) {
@@ -102,8 +108,9 @@ export class RemoteStorageLayer {
102
108
  });
103
109
  }
104
110
  }
111
+ exports.RemoteStorageLayer = RemoteStorageLayer;
105
112
  _RemoteStorageLayer_api = new WeakMap(), _RemoteStorageLayer_at = new WeakMap(), _RemoteStorageLayer_db = new WeakMap(), _RemoteStorageLayer_keyCache = new WeakMap();
106
- export class StorageLayer {
113
+ class StorageLayer {
107
114
  constructor(parent) {
108
115
  _StorageLayer_instances.add(this);
109
116
  _StorageLayer_store.set(this, {});
@@ -196,7 +203,7 @@ export class StorageLayer {
196
203
  __classPrivateFieldGet(this, _StorageLayer_instances, "m", _StorageLayer_addKey).call(this, key);
197
204
  }
198
205
  }
199
- let idx = _.sortedIndex(__classPrivateFieldGet(this, _StorageLayer_keys, "f"), startKey);
206
+ let idx = lodash_1.default.sortedIndex(__classPrivateFieldGet(this, _StorageLayer_keys, "f"), startKey);
200
207
  if (__classPrivateFieldGet(this, _StorageLayer_keys, "f")[idx] === startKey) {
201
208
  ++idx;
202
209
  }
@@ -226,15 +233,16 @@ export class StorageLayer {
226
233
  });
227
234
  }
228
235
  }
236
+ exports.StorageLayer = StorageLayer;
229
237
  _StorageLayer_store = new WeakMap(), _StorageLayer_keys = new WeakMap(), _StorageLayer_deletedPrefix = new WeakMap(), _StorageLayer_parent = new WeakMap(), _StorageLayer_instances = new WeakSet(), _StorageLayer_addKey = function _StorageLayer_addKey(key) {
230
- const idx = _.sortedIndex(__classPrivateFieldGet(this, _StorageLayer_keys, "f"), key);
238
+ const idx = lodash_1.default.sortedIndex(__classPrivateFieldGet(this, _StorageLayer_keys, "f"), key);
231
239
  const key2 = __classPrivateFieldGet(this, _StorageLayer_keys, "f")[idx];
232
240
  if (key === key2) {
233
241
  return;
234
242
  }
235
243
  __classPrivateFieldGet(this, _StorageLayer_keys, "f").splice(idx, 0, key);
236
244
  }, _StorageLayer_removeKey = function _StorageLayer_removeKey(key) {
237
- const idx = _.sortedIndex(__classPrivateFieldGet(this, _StorageLayer_keys, "f"), key);
245
+ const idx = lodash_1.default.sortedIndex(__classPrivateFieldGet(this, _StorageLayer_keys, "f"), key);
238
246
  const key2 = __classPrivateFieldGet(this, _StorageLayer_keys, "f")[idx];
239
247
  if (key === key2) {
240
248
  __classPrivateFieldGet(this, _StorageLayer_keys, "f").splice(idx, 1);