@acala-network/chopsticks-core 0.8.0-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/lib/api.d.ts +43 -0
  2. package/lib/api.js +116 -0
  3. package/lib/blockchain/block-builder.d.ts +10 -0
  4. package/lib/blockchain/block-builder.js +290 -0
  5. package/lib/blockchain/block.d.ts +45 -0
  6. package/lib/blockchain/block.js +221 -0
  7. package/lib/blockchain/head-state.d.ts +15 -0
  8. package/lib/blockchain/head-state.js +94 -0
  9. package/lib/blockchain/index.d.ts +73 -0
  10. package/lib/blockchain/index.js +351 -0
  11. package/lib/blockchain/inherent/index.d.ts +19 -0
  12. package/lib/blockchain/inherent/index.js +53 -0
  13. package/lib/blockchain/inherent/para-enter.d.ts +7 -0
  14. package/lib/blockchain/inherent/para-enter.js +37 -0
  15. package/lib/blockchain/inherent/parachain/babe-randomness.d.ts +7 -0
  16. package/lib/blockchain/inherent/parachain/babe-randomness.js +23 -0
  17. package/lib/blockchain/inherent/parachain/nimbus-author-inherent.d.ts +7 -0
  18. package/lib/blockchain/inherent/parachain/nimbus-author-inherent.js +23 -0
  19. package/lib/blockchain/inherent/parachain/validation-data.d.ts +19 -0
  20. package/lib/blockchain/inherent/parachain/validation-data.js +165 -0
  21. package/lib/blockchain/storage-layer.d.ts +32 -0
  22. package/lib/blockchain/storage-layer.js +242 -0
  23. package/lib/blockchain/txpool.d.ts +44 -0
  24. package/lib/blockchain/txpool.js +210 -0
  25. package/lib/db/browser.d.ts +2 -0
  26. package/lib/db/browser.js +33 -0
  27. package/lib/db/entities.d.ts +16 -0
  28. package/lib/db/entities.js +50 -0
  29. package/lib/db/index.d.ts +1 -0
  30. package/lib/db/index.js +17 -0
  31. package/lib/db/node.d.ts +2 -0
  32. package/lib/db/node.js +22 -0
  33. package/lib/executor.d.ts +41 -0
  34. package/lib/executor.js +160 -0
  35. package/lib/genesis-provider.d.ts +44 -0
  36. package/lib/genesis-provider.js +172 -0
  37. package/lib/index.d.ts +13 -0
  38. package/lib/index.js +13 -0
  39. package/lib/logger.d.ts +7 -0
  40. package/lib/logger.js +34 -0
  41. package/lib/offchain.d.ts +10 -0
  42. package/lib/offchain.js +49 -0
  43. package/lib/schema/index.d.ts +62 -0
  44. package/lib/schema/index.js +11 -0
  45. package/lib/setup.d.ts +20 -0
  46. package/lib/setup.js +74 -0
  47. package/lib/utils/index.d.ts +18 -0
  48. package/lib/utils/index.js +65 -0
  49. package/lib/utils/key-cache.d.ts +10 -0
  50. package/lib/utils/key-cache.js +72 -0
  51. package/lib/utils/proof.d.ts +15 -0
  52. package/lib/utils/proof.js +33 -0
  53. package/lib/utils/set-storage.d.ts +7 -0
  54. package/lib/utils/set-storage.js +65 -0
  55. package/lib/utils/time-travel.d.ts +5 -0
  56. package/lib/utils/time-travel.js +67 -0
  57. package/lib/xcm/downward.d.ts +2 -0
  58. package/lib/xcm/downward.js +34 -0
  59. package/lib/xcm/horizontal.d.ts +2 -0
  60. package/lib/xcm/horizontal.js +34 -0
  61. package/lib/xcm/index.d.ts +9 -0
  62. package/lib/xcm/index.js +29 -0
  63. package/lib/xcm/upward.d.ts +2 -0
  64. package/lib/xcm/upward.js +26 -0
  65. package/package.json +46 -0
@@ -0,0 +1,351 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
11
+ if (kind === "m") throw new TypeError("Private method is not writable");
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
13
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
14
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
15
+ };
16
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
17
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
18
+ 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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
20
+ };
21
+ 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 {
34
+ constructor({ api, buildBlockMode, inherentProvider, db, header, mockSignatureHost = false, allowUnresolvedImports = false, runtimeLogLevel = 0, registeredTypes = {}, offchainWorker = false, maxMemoryBlockCount = 2000, }) {
35
+ _Blockchain_instances.add(this);
36
+ this.uid = Math.random().toString(36).substring(2);
37
+ _Blockchain_txpool.set(this, void 0);
38
+ _Blockchain_inherentProvider.set(this, void 0);
39
+ _Blockchain_head.set(this, void 0);
40
+ _Blockchain_blocksByNumber.set(this, new Map());
41
+ _Blockchain_blocksByHash.set(this, {});
42
+ _Blockchain_loadingBlocks.set(this, {});
43
+ _Blockchain_maxMemoryBlockCount.set(this, void 0);
44
+ this.api = api;
45
+ this.db = db;
46
+ this.mockSignatureHost = mockSignatureHost;
47
+ this.allowUnresolvedImports = allowUnresolvedImports;
48
+ this.runtimeLogLevel = runtimeLogLevel;
49
+ this.registeredTypes = registeredTypes;
50
+ __classPrivateFieldSet(this, _Blockchain_head, new Block(this, header.number, header.hash), "f");
51
+ __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");
53
+ __classPrivateFieldSet(this, _Blockchain_inherentProvider, inherentProvider, "f");
54
+ this.headState = new HeadState(__classPrivateFieldGet(this, _Blockchain_head, "f"));
55
+ if (offchainWorker) {
56
+ this.offchainWorker = new OffchainWorker();
57
+ }
58
+ __classPrivateFieldSet(this, _Blockchain_maxMemoryBlockCount, maxMemoryBlockCount, "f");
59
+ }
60
+ get head() {
61
+ return __classPrivateFieldGet(this, _Blockchain_head, "f");
62
+ }
63
+ get txPool() {
64
+ return __classPrivateFieldGet(this, _Blockchain_txpool, "f");
65
+ }
66
+ saveBlockToDB(block) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ if (this.db) {
69
+ const { hash, number, header, extrinsics } = block;
70
+ // delete old ones with the same block number if any, keep the latest one
71
+ yield this.db.transaction((transactionalEntityManager) => __awaiter(this, void 0, void 0, function* () {
72
+ var _a;
73
+ yield transactionalEntityManager.getRepository(BlockEntity).delete({ number });
74
+ yield transactionalEntityManager.getRepository(BlockEntity).upsert({
75
+ hash,
76
+ number,
77
+ header: yield header,
78
+ extrinsics: yield extrinsics,
79
+ parentHash: (_a = (yield block.parentBlock)) === null || _a === void 0 ? void 0 : _a.hash,
80
+ storageDiff: yield block.storageDiff(),
81
+ }, ['hash']);
82
+ }));
83
+ }
84
+ });
85
+ }
86
+ /**
87
+ * Try to load block from db and register it
88
+ * If pass in number, get block by number, else get block by hash
89
+ */
90
+ loadBlockFromDB(key) {
91
+ return __awaiter(this, void 0, void 0, function* () {
92
+ if (this.db) {
93
+ const blockData = yield this.db
94
+ .getRepository(BlockEntity)
95
+ .findOne({ where: { [typeof key === 'number' ? 'number' : 'hash']: key } });
96
+ if (blockData) {
97
+ const { hash, number, header, extrinsics, parentHash, storageDiff } = blockData;
98
+ const parentBlock = parentHash ? __classPrivateFieldGet(this, _Blockchain_blocksByHash, "f")[parentHash] : undefined;
99
+ const block = new Block(this, number, hash, parentBlock, { header, extrinsics, storageDiff });
100
+ __classPrivateFieldGet(this, _Blockchain_instances, "m", _Blockchain_registerBlock).call(this, block);
101
+ return block;
102
+ }
103
+ }
104
+ return undefined;
105
+ });
106
+ }
107
+ getBlockAt(number) {
108
+ return __awaiter(this, void 0, void 0, function* () {
109
+ if (number === undefined) {
110
+ return this.head;
111
+ }
112
+ if (number > __classPrivateFieldGet(this, _Blockchain_head, "f").number) {
113
+ return undefined;
114
+ }
115
+ if (!__classPrivateFieldGet(this, _Blockchain_blocksByNumber, "f").has(number)) {
116
+ const blockFromDB = yield this.loadBlockFromDB(number);
117
+ if (blockFromDB) {
118
+ return blockFromDB;
119
+ }
120
+ const hash = yield this.api.getBlockHash(number);
121
+ const block = new Block(this, number, hash);
122
+ __classPrivateFieldGet(this, _Blockchain_instances, "m", _Blockchain_registerBlock).call(this, block);
123
+ }
124
+ return __classPrivateFieldGet(this, _Blockchain_blocksByNumber, "f").get(number);
125
+ });
126
+ }
127
+ getBlock(hash) {
128
+ return __awaiter(this, void 0, void 0, function* () {
129
+ yield this.api.isReady;
130
+ if (hash == null) {
131
+ hash = this.head.hash;
132
+ }
133
+ if (!__classPrivateFieldGet(this, _Blockchain_blocksByHash, "f")[hash]) {
134
+ const loadingBlock = __classPrivateFieldGet(this, _Blockchain_loadingBlocks, "f")[hash];
135
+ if (loadingBlock) {
136
+ yield loadingBlock;
137
+ }
138
+ else {
139
+ const loadingBlock = (() => __awaiter(this, void 0, void 0, function* () {
140
+ try {
141
+ const blockFromDB = yield this.loadBlockFromDB(hash);
142
+ if (!blockFromDB) {
143
+ const header = yield this.api.getHeader(hash);
144
+ const block = new Block(this, Number(header.number), hash);
145
+ __classPrivateFieldGet(this, _Blockchain_instances, "m", _Blockchain_registerBlock).call(this, block);
146
+ }
147
+ }
148
+ catch (e) {
149
+ logger.debug(`getBlock(${hash}) failed: ${e}`);
150
+ }
151
+ }))();
152
+ __classPrivateFieldGet(this, _Blockchain_loadingBlocks, "f")[hash] = loadingBlock;
153
+ yield loadingBlock;
154
+ delete __classPrivateFieldGet(this, _Blockchain_loadingBlocks, "f")[hash];
155
+ }
156
+ }
157
+ return __classPrivateFieldGet(this, _Blockchain_blocksByHash, "f")[hash];
158
+ });
159
+ }
160
+ blocksInMemory() {
161
+ return Array.from(__classPrivateFieldGet(this, _Blockchain_blocksByNumber, "f").values());
162
+ }
163
+ unregisterBlock(block) {
164
+ var _a;
165
+ return __awaiter(this, void 0, void 0, function* () {
166
+ if (block.hash === this.head.hash) {
167
+ throw new Error('Cannot unregister head block');
168
+ }
169
+ if (((_a = __classPrivateFieldGet(this, _Blockchain_blocksByNumber, "f").get(block.number)) === null || _a === void 0 ? void 0 : _a.hash) === block.hash) {
170
+ __classPrivateFieldGet(this, _Blockchain_blocksByNumber, "f").delete(block.number);
171
+ }
172
+ delete __classPrivateFieldGet(this, _Blockchain_blocksByHash, "f")[block.hash];
173
+ // delete from db
174
+ if (this.db) {
175
+ yield this.db.getRepository(BlockEntity).delete({ hash: block.hash });
176
+ }
177
+ });
178
+ }
179
+ onNewBlock(block) {
180
+ return __awaiter(this, void 0, void 0, function* () {
181
+ yield this.setHead(block);
182
+ yield this.saveBlockToDB(block);
183
+ });
184
+ }
185
+ setHead(block) {
186
+ return __awaiter(this, void 0, void 0, function* () {
187
+ logger.debug({
188
+ number: block.number,
189
+ hash: block.hash,
190
+ }, 'setHead');
191
+ __classPrivateFieldSet(this, _Blockchain_head, block, "f");
192
+ __classPrivateFieldGet(this, _Blockchain_instances, "m", _Blockchain_registerBlock).call(this, block);
193
+ yield this.headState.setHead(block);
194
+ if (this.offchainWorker) {
195
+ yield this.offchainWorker.run(block);
196
+ }
197
+ });
198
+ }
199
+ submitExtrinsic(extrinsic) {
200
+ return __awaiter(this, void 0, void 0, function* () {
201
+ const validity = yield this.validateExtrinsic(extrinsic);
202
+ if (validity.isOk) {
203
+ yield __classPrivateFieldGet(this, _Blockchain_txpool, "f").submitExtrinsic(extrinsic);
204
+ return blake2AsHex(extrinsic, 256);
205
+ }
206
+ throw validity.asErr;
207
+ });
208
+ }
209
+ validateExtrinsic(extrinsic, source = '0x02' /** External */) {
210
+ return __awaiter(this, void 0, void 0, function* () {
211
+ const args = u8aToHex(u8aConcat(source, extrinsic, this.head.hash));
212
+ const res = yield this.head.call('TaggedTransactionQueue_validate_transaction', [args]);
213
+ const registry = yield this.head.registry;
214
+ return registry.createType('TransactionValidity', res.result);
215
+ });
216
+ }
217
+ submitUpwardMessages(id, ump) {
218
+ __classPrivateFieldGet(this, _Blockchain_txpool, "f").submitUpwardMessages(id, ump);
219
+ logger.debug({ id, ump }, 'submitUpwardMessages');
220
+ }
221
+ submitDownwardMessages(dmp) {
222
+ __classPrivateFieldGet(this, _Blockchain_txpool, "f").submitDownwardMessages(dmp);
223
+ logger.debug({ dmp }, 'submitDownwardMessages');
224
+ }
225
+ submitHorizontalMessages(id, hrmp) {
226
+ __classPrivateFieldGet(this, _Blockchain_txpool, "f").submitHorizontalMessages(id, hrmp);
227
+ logger.debug({ id, hrmp }, 'submitHorizontalMessages');
228
+ }
229
+ newBlock(params) {
230
+ return __awaiter(this, void 0, void 0, function* () {
231
+ yield __classPrivateFieldGet(this, _Blockchain_txpool, "f").buildBlock(params);
232
+ return __classPrivateFieldGet(this, _Blockchain_head, "f");
233
+ });
234
+ }
235
+ newBlockWithParams(params) {
236
+ return __awaiter(this, void 0, void 0, function* () {
237
+ yield __classPrivateFieldGet(this, _Blockchain_txpool, "f").buildBlockWithParams(params);
238
+ return __classPrivateFieldGet(this, _Blockchain_head, "f");
239
+ });
240
+ }
241
+ upcomingBlocks() {
242
+ return __awaiter(this, void 0, void 0, function* () {
243
+ return __classPrivateFieldGet(this, _Blockchain_txpool, "f").upcomingBlocks();
244
+ });
245
+ }
246
+ dryRunExtrinsic(extrinsic, at) {
247
+ return __awaiter(this, void 0, void 0, function* () {
248
+ yield this.api.isReady;
249
+ const head = at ? yield this.getBlock(at) : this.head;
250
+ if (!head) {
251
+ throw new Error(`Cannot find block ${at}`);
252
+ }
253
+ const registry = yield head.registry;
254
+ const inherents = yield __classPrivateFieldGet(this, _Blockchain_inherentProvider, "f").createInherents(head, {
255
+ transactions: [],
256
+ downwardMessages: [],
257
+ upwardMessages: [],
258
+ horizontalMessages: {},
259
+ });
260
+ const { result, storageDiff } = yield dryRunExtrinsic(head, inherents, extrinsic);
261
+ const outcome = registry.createType('ApplyExtrinsicResult', result);
262
+ return { outcome, storageDiff };
263
+ });
264
+ }
265
+ dryRunHrmp(hrmp, at) {
266
+ return __awaiter(this, void 0, void 0, function* () {
267
+ yield this.api.isReady;
268
+ const head = at ? yield this.getBlock(at) : this.head;
269
+ if (!head) {
270
+ throw new Error(`Cannot find block ${at}`);
271
+ }
272
+ const inherents = yield __classPrivateFieldGet(this, _Blockchain_inherentProvider, "f").createInherents(head, {
273
+ transactions: [],
274
+ downwardMessages: [],
275
+ upwardMessages: [],
276
+ horizontalMessages: hrmp,
277
+ });
278
+ return dryRunInherents(head, inherents);
279
+ });
280
+ }
281
+ dryRunDmp(dmp, at) {
282
+ return __awaiter(this, void 0, void 0, function* () {
283
+ yield this.api.isReady;
284
+ const head = at ? yield this.getBlock(at) : this.head;
285
+ if (!head) {
286
+ throw new Error(`Cannot find block ${at}`);
287
+ }
288
+ const inherents = yield __classPrivateFieldGet(this, _Blockchain_inherentProvider, "f").createInherents(head, {
289
+ transactions: [],
290
+ downwardMessages: dmp,
291
+ upwardMessages: [],
292
+ horizontalMessages: {},
293
+ });
294
+ return dryRunInherents(head, inherents);
295
+ });
296
+ }
297
+ dryRunUmp(ump, at) {
298
+ return __awaiter(this, void 0, void 0, function* () {
299
+ yield this.api.isReady;
300
+ const head = at ? yield this.getBlock(at) : this.head;
301
+ if (!head) {
302
+ throw new Error(`Cannot find block ${at}`);
303
+ }
304
+ const meta = yield head.meta;
305
+ const needsDispatch = meta.registry.createType('Vec<u32>', Object.keys(ump));
306
+ const storageValues = [
307
+ [compactHex(meta.query.ump.needsDispatch()), needsDispatch.toHex()],
308
+ ];
309
+ for (const [paraId, messages] of Object.entries(ump)) {
310
+ const upwardMessages = meta.registry.createType('Vec<Bytes>', messages);
311
+ if (upwardMessages.length === 0)
312
+ throw new Error('No upward meesage');
313
+ const queueSize = meta.registry.createType('(u32, u32)', [
314
+ upwardMessages.length,
315
+ upwardMessages.map((x) => x.byteLength).reduce((s, i) => s + i, 0),
316
+ ]);
317
+ storageValues.push([compactHex(meta.query.ump.relayDispatchQueues(paraId)), upwardMessages.toHex()]);
318
+ storageValues.push([compactHex(meta.query.ump.relayDispatchQueueSize(paraId)), queueSize.toHex()]);
319
+ }
320
+ head.pushStorageLayer().setAll(storageValues);
321
+ const inherents = yield __classPrivateFieldGet(this, _Blockchain_inherentProvider, "f").createInherents(head, {
322
+ transactions: [],
323
+ downwardMessages: [],
324
+ upwardMessages: [],
325
+ horizontalMessages: {},
326
+ });
327
+ return dryRunInherents(head, inherents);
328
+ });
329
+ }
330
+ getInherents() {
331
+ return __awaiter(this, void 0, void 0, function* () {
332
+ yield this.api.isReady;
333
+ const inherents = yield __classPrivateFieldGet(this, _Blockchain_inherentProvider, "f").createInherents(this.head, {
334
+ transactions: [],
335
+ downwardMessages: [],
336
+ upwardMessages: [],
337
+ horizontalMessages: {},
338
+ });
339
+ return inherents;
340
+ });
341
+ }
342
+ }
343
+ _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
+ // if exceed max memory block count, delete the oldest block
345
+ if (__classPrivateFieldGet(this, _Blockchain_blocksByNumber, "f").size === __classPrivateFieldGet(this, _Blockchain_maxMemoryBlockCount, "f")) {
346
+ const firstKey = __classPrivateFieldGet(this, _Blockchain_blocksByNumber, "f").keys().next().value;
347
+ __classPrivateFieldGet(this, _Blockchain_blocksByNumber, "f").delete(firstKey);
348
+ }
349
+ __classPrivateFieldGet(this, _Blockchain_blocksByNumber, "f").set(block.number, block);
350
+ __classPrivateFieldGet(this, _Blockchain_blocksByHash, "f")[block.hash] = block;
351
+ };
@@ -0,0 +1,19 @@
1
+ import { Block } from '../block';
2
+ import { BuildBlockParams } from '../txpool';
3
+ import { HexString } from '@polkadot/util/types';
4
+ export { SetValidationData } from './parachain/validation-data';
5
+ export { ParaInherentEnter } from './para-enter';
6
+ export { SetBabeRandomness } from './parachain/babe-randomness';
7
+ export { SetNimbusAuthorInherent } from './parachain/nimbus-author-inherent';
8
+ export interface CreateInherents {
9
+ createInherents(parent: Block, params: BuildBlockParams): Promise<HexString[]>;
10
+ }
11
+ export type InherentProvider = CreateInherents;
12
+ export declare class SetTimestamp implements InherentProvider {
13
+ createInherents(parent: Block): Promise<HexString[]>;
14
+ }
15
+ export declare class InherentProviders implements InherentProvider {
16
+ #private;
17
+ constructor(base: InherentProvider, providers: CreateInherents[]);
18
+ createInherents(parent: Block, params: BuildBlockParams): Promise<HexString[]>;
19
+ }
@@ -0,0 +1,53 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
11
+ if (kind === "m") throw new TypeError("Private method is not writable");
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
13
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
14
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
15
+ };
16
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
17
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
18
+ 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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
20
+ };
21
+ 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 {
29
+ createInherents(parent) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ 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()];
35
+ });
36
+ }
37
+ }
38
+ export class InherentProviders {
39
+ constructor(base, providers) {
40
+ _InherentProviders_base.set(this, void 0);
41
+ _InherentProviders_providers.set(this, void 0);
42
+ __classPrivateFieldSet(this, _InherentProviders_base, base, "f");
43
+ __classPrivateFieldSet(this, _InherentProviders_providers, providers, "f");
44
+ }
45
+ createInherents(parent, params) {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ const base = yield __classPrivateFieldGet(this, _InherentProviders_base, "f").createInherents(parent, params);
48
+ const extra = yield Promise.all(__classPrivateFieldGet(this, _InherentProviders_providers, "f").map((provider) => provider.createInherents(parent, params)));
49
+ return [...base, ...extra.flat()];
50
+ });
51
+ }
52
+ }
53
+ _InherentProviders_base = new WeakMap(), _InherentProviders_providers = new WeakMap();
@@ -0,0 +1,7 @@
1
+ import { HexString } from '@polkadot/util/types';
2
+ import { Block } from '../block';
3
+ import { BuildBlockParams } from '../txpool';
4
+ import { CreateInherents } from '.';
5
+ export declare class ParaInherentEnter implements CreateInherents {
6
+ createInherents(parent: Block, _params: BuildBlockParams): Promise<HexString[]>;
7
+ }
@@ -0,0 +1,37 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { GenericExtrinsic } from '@polkadot/types';
11
+ export class ParaInherentEnter {
12
+ createInherents(parent, _params) {
13
+ var _a;
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ const meta = yield parent.meta;
16
+ if (!((_a = meta.tx.paraInherent) === null || _a === void 0 ? void 0 : _a.enter)) {
17
+ return [];
18
+ }
19
+ const extrinsics = yield parent.extrinsics;
20
+ const paraEnterExtrinsic = extrinsics.find((extrinsic) => {
21
+ var _a, _b;
22
+ const firstArg = (_b = (_a = meta.registry.createType('GenericExtrinsic', extrinsic)) === null || _a === void 0 ? void 0 : _a.args) === null || _b === void 0 ? void 0 : _b[0];
23
+ return firstArg && 'bitfields' in firstArg;
24
+ });
25
+ if (!paraEnterExtrinsic) {
26
+ throw new Error('Missing paraInherent data from block');
27
+ }
28
+ const extrinsic = meta.registry
29
+ .createType('GenericExtrinsic', paraEnterExtrinsic)
30
+ .args[0].toJSON();
31
+ const parentHeader = (yield parent.header).toJSON();
32
+ const newData = Object.assign(Object.assign({}, extrinsic), { bitfields: [], backedCandidates: [], parentHeader });
33
+ // TODO: fill with data
34
+ return [new GenericExtrinsic(meta.registry, meta.tx.paraInherent.enter(newData)).toHex()];
35
+ });
36
+ }
37
+ }
@@ -0,0 +1,7 @@
1
+ import { HexString } from '@polkadot/util/types';
2
+ import { Block } from '../../block';
3
+ import { BuildBlockParams } from '../../txpool';
4
+ import { CreateInherents } from '..';
5
+ export declare class SetBabeRandomness implements CreateInherents {
6
+ createInherents(parent: Block, _params: BuildBlockParams): Promise<HexString[]>;
7
+ }
@@ -0,0 +1,23 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { GenericExtrinsic } from '@polkadot/types';
11
+ // Support for Moonbeam pallet-randomness mandatory inherent
12
+ export class SetBabeRandomness {
13
+ createInherents(parent, _params) {
14
+ var _a;
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const meta = yield parent.meta;
17
+ if (!((_a = meta.tx.randomness) === null || _a === void 0 ? void 0 : _a.setBabeRandomnessResults)) {
18
+ return [];
19
+ }
20
+ return [new GenericExtrinsic(meta.registry, meta.tx.randomness.setBabeRandomnessResults()).toHex()];
21
+ });
22
+ }
23
+ }
@@ -0,0 +1,7 @@
1
+ import { HexString } from '@polkadot/util/types';
2
+ import { Block } from '../../block';
3
+ import { BuildBlockParams } from '../../txpool';
4
+ import { CreateInherents } from '..';
5
+ export declare class SetNimbusAuthorInherent implements CreateInherents {
6
+ createInherents(parent: Block, _params: BuildBlockParams): Promise<HexString[]>;
7
+ }
@@ -0,0 +1,23 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { GenericExtrinsic } from '@polkadot/types';
11
+ // Support for Nimbus Author Inherent
12
+ export class SetNimbusAuthorInherent {
13
+ createInherents(parent, _params) {
14
+ var _a;
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const meta = yield parent.meta;
17
+ if (!((_a = meta.tx.authorInherent) === null || _a === void 0 ? void 0 : _a.kickOffAuthorshipValidation)) {
18
+ return [];
19
+ }
20
+ return [new GenericExtrinsic(meta.registry, meta.tx.authorInherent.kickOffAuthorshipValidation()).toHex()];
21
+ });
22
+ }
23
+ }
@@ -0,0 +1,19 @@
1
+ import { HexString } from '@polkadot/util/types';
2
+ import { Block } from '../../block';
3
+ import { BuildBlockParams, DownwardMessage, HorizontalMessage } from '../../txpool';
4
+ import { CreateInherents } from '..';
5
+ export type ValidationData = {
6
+ downwardMessages: DownwardMessage[];
7
+ horizontalMessages: Record<number, HorizontalMessage[]>;
8
+ validationData: {
9
+ relayParentNumber: number;
10
+ relayParentStorageRoot: HexString;
11
+ maxPovSize: number;
12
+ };
13
+ relayChainState: {
14
+ trieNodes: HexString[];
15
+ };
16
+ };
17
+ export declare class SetValidationData implements CreateInherents {
18
+ createInherents(parent: Block, params: BuildBlockParams): Promise<HexString[]>;
19
+ }