@acala-network/chopsticks-core 0.9.7 → 0.9.8-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.
Files changed (71) hide show
  1. package/dist/cjs/api.d.ts +1 -0
  2. package/dist/cjs/api.js +26 -0
  3. package/dist/cjs/blockchain/block-builder.d.ts +6 -4
  4. package/dist/cjs/blockchain/block-builder.js +25 -20
  5. package/dist/cjs/blockchain/block.js +1 -3
  6. package/dist/cjs/blockchain/index.d.ts +4 -4
  7. package/dist/cjs/blockchain/index.js +19 -26
  8. package/dist/cjs/blockchain/inherent/index.d.ts +8 -15
  9. package/dist/cjs/blockchain/inherent/index.js +13 -100
  10. package/dist/cjs/blockchain/inherent/para-enter.d.ts +3 -3
  11. package/dist/cjs/blockchain/inherent/para-enter.js +3 -1
  12. package/dist/cjs/blockchain/inherent/parachain/babe-randomness.d.ts +3 -3
  13. package/dist/cjs/blockchain/inherent/parachain/babe-randomness.js +3 -1
  14. package/dist/cjs/blockchain/inherent/parachain/nimbus-author-inherent.d.ts +3 -3
  15. package/dist/cjs/blockchain/inherent/parachain/nimbus-author-inherent.js +20 -1
  16. package/dist/cjs/blockchain/inherent/parachain/validation-data.d.ts +3 -3
  17. package/dist/cjs/blockchain/inherent/parachain/validation-data.js +3 -1
  18. package/dist/cjs/blockchain/inherent/timestamp.d.ts +6 -0
  19. package/dist/cjs/blockchain/inherent/timestamp.js +24 -0
  20. package/dist/cjs/blockchain/storage-layer.js +125 -69
  21. package/dist/cjs/blockchain/txpool.d.ts +1 -1
  22. package/dist/cjs/blockchain/txpool.js +6 -8
  23. package/dist/cjs/logger.d.ts +2 -12
  24. package/dist/cjs/logger.js +8 -2
  25. package/dist/cjs/rpc/shared.d.ts +1 -6
  26. package/dist/cjs/setup.js +7 -13
  27. package/dist/cjs/utils/decoder.js +1 -1
  28. package/dist/cjs/utils/index.d.ts +5 -0
  29. package/dist/cjs/utils/index.js +46 -5
  30. package/dist/cjs/utils/key-cache.d.ts +2 -1
  31. package/dist/cjs/utils/key-cache.js +27 -25
  32. package/dist/cjs/utils/time-travel.d.ts +0 -3
  33. package/dist/cjs/utils/time-travel.js +4 -37
  34. package/dist/cjs/wasm-executor/index.js +2 -3
  35. package/dist/cjs/xcm/index.d.ts +1 -6
  36. package/dist/esm/api.d.ts +1 -0
  37. package/dist/esm/api.js +21 -0
  38. package/dist/esm/blockchain/block-builder.d.ts +6 -4
  39. package/dist/esm/blockchain/block-builder.js +24 -19
  40. package/dist/esm/blockchain/block.js +1 -3
  41. package/dist/esm/blockchain/index.d.ts +4 -4
  42. package/dist/esm/blockchain/index.js +19 -26
  43. package/dist/esm/blockchain/inherent/index.d.ts +8 -15
  44. package/dist/esm/blockchain/inherent/index.js +12 -32
  45. package/dist/esm/blockchain/inherent/para-enter.d.ts +3 -3
  46. package/dist/esm/blockchain/inherent/para-enter.js +3 -1
  47. package/dist/esm/blockchain/inherent/parachain/babe-randomness.d.ts +3 -3
  48. package/dist/esm/blockchain/inherent/parachain/babe-randomness.js +3 -1
  49. package/dist/esm/blockchain/inherent/parachain/nimbus-author-inherent.d.ts +3 -3
  50. package/dist/esm/blockchain/inherent/parachain/nimbus-author-inherent.js +20 -1
  51. package/dist/esm/blockchain/inherent/parachain/validation-data.d.ts +3 -3
  52. package/dist/esm/blockchain/inherent/parachain/validation-data.js +3 -1
  53. package/dist/esm/blockchain/inherent/timestamp.d.ts +6 -0
  54. package/dist/esm/blockchain/inherent/timestamp.js +14 -0
  55. package/dist/esm/blockchain/storage-layer.js +121 -27
  56. package/dist/esm/blockchain/txpool.d.ts +1 -1
  57. package/dist/esm/blockchain/txpool.js +5 -7
  58. package/dist/esm/logger.d.ts +2 -12
  59. package/dist/esm/logger.js +8 -2
  60. package/dist/esm/rpc/shared.d.ts +1 -6
  61. package/dist/esm/setup.js +2 -8
  62. package/dist/esm/utils/decoder.js +1 -1
  63. package/dist/esm/utils/index.d.ts +5 -0
  64. package/dist/esm/utils/index.js +33 -5
  65. package/dist/esm/utils/key-cache.d.ts +2 -1
  66. package/dist/esm/utils/key-cache.js +25 -14
  67. package/dist/esm/utils/time-travel.d.ts +0 -3
  68. package/dist/esm/utils/time-travel.js +2 -21
  69. package/dist/esm/wasm-executor/index.js +1 -2
  70. package/dist/esm/xcm/index.d.ts +1 -6
  71. package/package.json +13 -13
package/dist/cjs/api.d.ts CHANGED
@@ -50,6 +50,7 @@ export declare class Api {
50
50
  getBlock(hash?: string): Promise<SignedBlock | null>;
51
51
  getStorage(key: string, hash?: string): Promise<`0x${string}` | null>;
52
52
  getKeysPaged(prefix: string, pageSize: number, startKey: string, hash?: string): Promise<string[]>;
53
+ getStorageBatch(prefix: HexString, keys: HexString[], hash?: HexString): Promise<[`0x${string}`, `0x${string}` | null][]>;
53
54
  subscribeRemoteNewHeads(cb: ProviderInterfaceCallback): Promise<string | number>;
54
55
  subscribeRemoteFinalizedHeads(cb: ProviderInterfaceCallback): Promise<string | number>;
55
56
  }
package/dist/cjs/api.js CHANGED
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "Api", {
9
9
  }
10
10
  });
11
11
  const _index = require("./utils/index.js");
12
+ const _lodash = /*#__PURE__*/ _interop_require_default(require("lodash"));
12
13
  function _check_private_redeclaration(obj, privateCollection) {
13
14
  if (privateCollection.has(obj)) {
14
15
  throw new TypeError("Cannot initialize the same private elements twice on an object");
@@ -62,6 +63,11 @@ function _define_property(obj, key, value) {
62
63
  }
63
64
  return obj;
64
65
  }
66
+ function _interop_require_default(obj) {
67
+ return obj && obj.__esModule ? obj : {
68
+ default: obj
69
+ };
70
+ }
65
71
  var _provider = /*#__PURE__*/ new WeakMap(), _ready = /*#__PURE__*/ new WeakMap(), _chain = /*#__PURE__*/ new WeakMap(), _chainProperties = /*#__PURE__*/ new WeakMap();
66
72
  class Api {
67
73
  async disconnect() {
@@ -163,6 +169,26 @@ class Api {
163
169
  return _class_private_field_get(this, _provider).send('state_getKeysPaged', params, !!hash);
164
170
  }
165
171
  }
172
+ async getStorageBatch(prefix, keys, hash) {
173
+ const [child] = (0, _index.splitChildKey)(prefix);
174
+ if (child) {
175
+ // child storage key, use childstate_getStorageEntries
176
+ // strip child prefix from keys
177
+ const params = [
178
+ child,
179
+ keys.map((key)=>(0, _index.stripChildPrefix)(key))
180
+ ];
181
+ if (hash) params.push(hash);
182
+ return _class_private_field_get(this, _provider).send('childstate_getStorageEntries', params, !!hash).then((values)=>_lodash.default.zip(keys, values));
183
+ } else {
184
+ // main storage key, use state_getStorageAt
185
+ const params = [
186
+ keys
187
+ ];
188
+ if (hash) params.push(hash);
189
+ return _class_private_field_get(this, _provider).send('state_queryStorageAt', params, !!hash).then((result)=>result[0]?.['changes'] || []);
190
+ }
191
+ }
166
192
  async subscribeRemoteNewHeads(cb) {
167
193
  if (!_class_private_field_get(this, _provider).hasSubscriptions) {
168
194
  throw new Error('subscribeRemoteNewHeads only works with subscriptions');
@@ -1,15 +1,17 @@
1
1
  import { Header, TransactionValidityError } from '@polkadot/types/interfaces';
2
2
  import { Block } from './block.js';
3
+ import { BuildBlockParams } from './txpool.js';
3
4
  import { HexString } from '@polkadot/util/types';
5
+ import { InherentProvider } from './inherent/index.js';
4
6
  import { TaskCallResponse } from '../wasm-executor/index.js';
5
7
  export declare const newHeader: (head: Block, unsafeBlockHeight?: number) => Promise<Header>;
6
8
  export type BuildBlockCallbacks = {
7
9
  onApplyExtrinsicError?: (extrinsic: HexString, error: TransactionValidityError) => void;
8
10
  onPhaseApplied?: (phase: 'initialize' | 'finalize' | number, resp: TaskCallResponse) => void;
9
11
  };
10
- export declare const buildBlock: (head: Block, inherents: HexString[], extrinsics: HexString[], ump: Record<number, HexString[]>, callbacks?: BuildBlockCallbacks, unsafeBlockHeight?: number) => Promise<[Block, HexString[]]>;
11
- export declare const dryRunExtrinsic: (head: Block, inherents: HexString[], extrinsic: HexString | {
12
+ export declare const buildBlock: (head: Block, inherentProviders: InherentProvider[], params: BuildBlockParams, callbacks?: BuildBlockCallbacks) => Promise<[Block, HexString[]]>;
13
+ export declare const dryRunExtrinsic: (head: Block, inherentProviders: InherentProvider[], extrinsic: HexString | {
12
14
  call: HexString;
13
15
  address: string;
14
- }) => Promise<TaskCallResponse>;
15
- export declare const dryRunInherents: (head: Block, inherents: HexString[]) => Promise<[HexString, HexString | null][]>;
16
+ }, params: BuildBlockParams) => Promise<TaskCallResponse>;
17
+ export declare const dryRunInherents: (head: Block, inherentProviders: InherentProvider[], params: BuildBlockParams) => Promise<[HexString, HexString | null][]>;
@@ -27,7 +27,6 @@ const _storagelayer = require("./storage-layer.js");
27
27
  const _util = require("@polkadot/util");
28
28
  const _index = require("../utils/index.js");
29
29
  const _logger = require("../logger.js");
30
- const _timetravel = require("../utils/time-travel.js");
31
30
  const logger = _logger.defaultLogger.child({
32
31
  name: 'block-builder'
33
32
  });
@@ -74,7 +73,7 @@ const newHeader = async (head, unsafeBlockHeight)=>{
74
73
  let newLogs = parentHeader.digest.logs;
75
74
  const consensus = getConsensus(parentHeader);
76
75
  if (consensus?.consensusEngine.isAura) {
77
- const slot = await (0, _timetravel.getCurrentSlot)(head.chain);
76
+ const slot = await (0, _index.getCurrentSlot)(head.chain);
78
77
  const newSlot = (0, _util.compactAddLength)(meta.registry.createType('Slot', slot + 1).toU8a());
79
78
  newLogs = [
80
79
  {
@@ -86,7 +85,7 @@ const newHeader = async (head, unsafeBlockHeight)=>{
86
85
  ...consensus.rest
87
86
  ];
88
87
  } else if (consensus?.consensusEngine.isBabe) {
89
- const slot = await (0, _timetravel.getCurrentSlot)(head.chain);
88
+ const slot = await (0, _index.getCurrentSlot)(head.chain);
90
89
  const digest = meta.registry.createType('RawBabePreDigest', consensus.slot);
91
90
  const newSlot = (0, _util.compactAddLength)(meta.registry.createType('RawBabePreDigest', getNewSlot(digest, slot + 1)).toU8a());
92
91
  newLogs = [
@@ -127,7 +126,7 @@ const newHeader = async (head, unsafeBlockHeight)=>{
127
126
  });
128
127
  return header;
129
128
  };
130
- const initNewBlock = async (head, header, inherents, storageLayer, callback)=>{
129
+ const initNewBlock = async (head, header, inherentProviders, params, storageLayer, callback)=>{
131
130
  const blockNumber = header.number.toNumber();
132
131
  const hash = `0x${Math.round(Math.random() * 100000000).toString(16).padEnd(64, '0')}`;
133
132
  const newBlock = new _block.Block(head.chain, blockNumber, hash, head, {
@@ -155,16 +154,20 @@ const initNewBlock = async (head, header, inherents, storageLayer, callback)=>{
155
154
  }
156
155
  callback?.onPhaseApplied?.('initialize', resp);
157
156
  }
157
+ const inherents = [];
158
158
  const layers = [];
159
159
  // apply inherents
160
- for (const extrinsic of inherents){
160
+ for (const inherentProvider of inherentProviders){
161
161
  try {
162
- const resp = await newBlock.call('BlockBuilder_apply_extrinsic', [
163
- extrinsic
164
- ]);
162
+ const extrinsics = await inherentProvider.createInherents(newBlock, params);
163
+ if (extrinsics.length === 0) {
164
+ continue;
165
+ }
166
+ const resp = await newBlock.call('BlockBuilder_apply_extrinsic', extrinsics);
165
167
  const layer = newBlock.pushStorageLayer();
166
168
  layer.setAll(resp.storageDiff);
167
169
  layers.push(layer);
170
+ inherents.push(...extrinsics);
168
171
  callback?.onPhaseApplied?.(layers.length - 1, resp);
169
172
  } catch (e) {
170
173
  logger.warn('Failed to apply inherents %o %s', e, e);
@@ -173,18 +176,20 @@ const initNewBlock = async (head, header, inherents, storageLayer, callback)=>{
173
176
  }
174
177
  return {
175
178
  block: newBlock,
176
- layers: layers
179
+ layers,
180
+ inherents
177
181
  };
178
182
  };
179
- const buildBlock = async (head, inherents, extrinsics, ump, callbacks, unsafeBlockHeight)=>{
183
+ const buildBlock = async (head, inherentProviders, params, callbacks)=>{
184
+ const { transactions: extrinsics, upwardMessages: ump, unsafeBlockHeight } = params;
180
185
  const registry = await head.registry;
181
186
  const header = await newHeader(head, unsafeBlockHeight);
182
187
  const newBlockNumber = header.number.toNumber();
183
188
  logger.info({
184
189
  number: newBlockNumber,
185
- extrinsicsCount: extrinsics.length,
190
+ extrinsics: extrinsics.map(_logger.truncate),
186
191
  umpCount: Object.keys(ump).length
187
- }, `Try building block #${newBlockNumber.toLocaleString()}`);
192
+ }, `${await head.chain.api.getSystemChain()} building #${newBlockNumber.toLocaleString()}`);
188
193
  let layer;
189
194
  // apply ump via storage override hack
190
195
  if (Object.keys(ump).length > 0) {
@@ -273,7 +278,7 @@ const buildBlock = async (head, inherents, extrinsics, ump, callbacks, unsafeBlo
273
278
  layer.set((0, _index.compactHex)(meta.query.ump.needsDispatch()), needsDispatch.toHex());
274
279
  }
275
280
  }
276
- const { block: newBlock } = await initNewBlock(head, header, inherents, layer);
281
+ const { block: newBlock, inherents } = await initNewBlock(head, header, inherentProviders, params, layer);
277
282
  const pendingExtrinsics = [];
278
283
  const includedExtrinsic = [];
279
284
  // apply extrinsics
@@ -322,21 +327,21 @@ const buildBlock = async (head, inherents, extrinsics, ump, callbacks, unsafeBlo
322
327
  storageDiff
323
328
  });
324
329
  logger.info({
325
- number: newBlock.number,
330
+ number: finalBlock.number,
326
331
  hash: finalBlock.hash,
327
332
  extrinsics: (0, _logger.truncate)(includedExtrinsic),
328
- pendingExtrinsicsCount: pendingExtrinsics.length,
333
+ pendingExtrinsics: pendingExtrinsics.map(_logger.truncate),
329
334
  ump: (0, _logger.truncate)(ump)
330
- }, 'Block built');
335
+ }, `${await head.chain.api.getSystemChain()} new head #${finalBlock.number.toLocaleString()}`);
331
336
  return [
332
337
  finalBlock,
333
338
  pendingExtrinsics
334
339
  ];
335
340
  };
336
- const dryRunExtrinsic = async (head, inherents, extrinsic)=>{
341
+ const dryRunExtrinsic = async (head, inherentProviders, extrinsic, params)=>{
337
342
  const registry = await head.registry;
338
343
  const header = await newHeader(head);
339
- const { block: newBlock } = await initNewBlock(head, header, inherents);
344
+ const { block: newBlock } = await initNewBlock(head, header, inherentProviders, params);
340
345
  if (typeof extrinsic !== 'string') {
341
346
  if (!head.chain.mockSignatureHost) {
342
347
  throw new Error('Cannot fake signature because mock signature host is not enabled. Start chain with `mockSignatureHost: true`');
@@ -375,9 +380,9 @@ const dryRunExtrinsic = async (head, inherents, extrinsic)=>{
375
380
  extrinsic
376
381
  ]);
377
382
  };
378
- const dryRunInherents = async (head, inherents)=>{
383
+ const dryRunInherents = async (head, inherentProviders, params)=>{
379
384
  const header = await newHeader(head);
380
- const { layers } = await initNewBlock(head, header, inherents);
385
+ const { layers } = await initNewBlock(head, header, inherentProviders, params);
381
386
  const storage = {};
382
387
  for (const layer of layers){
383
388
  await layer.mergeInto(storage);
@@ -139,12 +139,10 @@ class Block {
139
139
  /**
140
140
  * Get paged storage keys.
141
141
  */ async getKeysPaged(options) {
142
- const layer = new _storagelayer.StorageLayer(this.storage);
143
- await layer.fold();
144
142
  const prefix = options.prefix ?? '0x';
145
143
  const startKey = options.startKey ?? '0x';
146
144
  const pageSize = options.pageSize;
147
- return layer.getKeysPaged(prefix, pageSize, startKey);
145
+ return this.storage.getKeysPaged(prefix, pageSize, startKey);
148
146
  }
149
147
  /**
150
148
  * Push a layer to the storage stack.
@@ -17,7 +17,7 @@ export interface Options {
17
17
  /** Build block mode. Default to Batch. */
18
18
  buildBlockMode?: BuildBlockMode;
19
19
  /** Inherent provider, for creating inherents. */
20
- inherentProvider: InherentProvider;
20
+ inherentProviders: InherentProvider[];
21
21
  /** Datasource for caching storage and blocks data. */
22
22
  db?: Database;
23
23
  /** Used to create the initial head. */
@@ -48,7 +48,7 @@ export interface Options {
48
48
  * const chain = new Blockchain({
49
49
  * api,
50
50
  * buildBlockMode: BuildBlockMode.Manual,
51
- * inherentProvider: inherents,
51
+ * inherentProviders,
52
52
  * header: {
53
53
  * hash: blockHash,
54
54
  * number: Number(header.number),
@@ -79,7 +79,7 @@ export declare class Blockchain {
79
79
  /**
80
80
  * @param options - Options for instantiating the blockchain
81
81
  */
82
- constructor({ api, buildBlockMode, inherentProvider, db, header, mockSignatureHost, allowUnresolvedImports, runtimeLogLevel, registeredTypes, offchainWorker, maxMemoryBlockCount, }: Options);
82
+ constructor({ api, buildBlockMode, inherentProviders, db, header, mockSignatureHost, allowUnresolvedImports, runtimeLogLevel, registeredTypes, offchainWorker, maxMemoryBlockCount, }: Options);
83
83
  get head(): Block;
84
84
  get txPool(): TxPool;
85
85
  get runtimeLogLevel(): number;
@@ -163,7 +163,7 @@ export declare class Blockchain {
163
163
  /**
164
164
  * Get inherents of head.
165
165
  */
166
- getInherents(): Promise<HexString[]>;
166
+ getInherents(): InherentProvider[];
167
167
  /**
168
168
  * Close the db and disconnect api.
169
169
  */
@@ -91,7 +91,7 @@ function _interop_require_default(obj) {
91
91
  const logger = _logger.defaultLogger.child({
92
92
  name: 'blockchain'
93
93
  });
94
- var _runtimeLogLevel = /*#__PURE__*/ new WeakMap(), _txpool1 = /*#__PURE__*/ new WeakMap(), _inherentProvider = /*#__PURE__*/ new WeakMap(), _head = /*#__PURE__*/ new WeakMap(), _blocksByNumber = /*#__PURE__*/ new WeakMap(), _blocksByHash = /*#__PURE__*/ new WeakMap(), _loadingBlocks = /*#__PURE__*/ new WeakMap(), _maxMemoryBlockCount = /*#__PURE__*/ new WeakMap(), _registryBuilder = /*#__PURE__*/ new WeakMap(), _registerBlock = /*#__PURE__*/ new WeakSet();
94
+ var _runtimeLogLevel = /*#__PURE__*/ new WeakMap(), _txpool1 = /*#__PURE__*/ new WeakMap(), _inherentProviders = /*#__PURE__*/ new WeakMap(), _head = /*#__PURE__*/ new WeakMap(), _blocksByNumber = /*#__PURE__*/ new WeakMap(), _blocksByHash = /*#__PURE__*/ new WeakMap(), _loadingBlocks = /*#__PURE__*/ new WeakMap(), _maxMemoryBlockCount = /*#__PURE__*/ new WeakMap(), _registryBuilder = /*#__PURE__*/ new WeakMap(), _registerBlock = /*#__PURE__*/ new WeakSet();
95
95
  class Blockchain {
96
96
  get head() {
97
97
  return _class_private_field_get(this, _head);
@@ -312,13 +312,13 @@ class Blockchain {
312
312
  throw new Error(`Cannot find block ${at}`);
313
313
  }
314
314
  const registry = await head.registry;
315
- const inherents = await _class_private_field_get(this, _inherentProvider).createInherents(head, {
315
+ const params = {
316
316
  transactions: [],
317
317
  downwardMessages: [],
318
318
  upwardMessages: [],
319
319
  horizontalMessages: {}
320
- });
321
- const { result, storageDiff } = await (0, _blockbuilder.dryRunExtrinsic)(head, inherents, extrinsic);
320
+ };
321
+ const { result, storageDiff } = await (0, _blockbuilder.dryRunExtrinsic)(head, _class_private_field_get(this, _inherentProviders), extrinsic, params);
322
322
  const outcome = registry.createType('ApplyExtrinsicResult', result);
323
323
  return {
324
324
  outcome,
@@ -334,13 +334,13 @@ class Blockchain {
334
334
  if (!head) {
335
335
  throw new Error(`Cannot find block ${at}`);
336
336
  }
337
- const inherents = await _class_private_field_get(this, _inherentProvider).createInherents(head, {
337
+ const params = {
338
338
  transactions: [],
339
339
  downwardMessages: [],
340
340
  upwardMessages: [],
341
341
  horizontalMessages: hrmp
342
- });
343
- return (0, _blockbuilder.dryRunInherents)(head, inherents);
342
+ };
343
+ return (0, _blockbuilder.dryRunInherents)(head, _class_private_field_get(this, _inherentProviders), params);
344
344
  }
345
345
  /**
346
346
  * Dry run dmp messages in block `at`.
@@ -351,13 +351,13 @@ class Blockchain {
351
351
  if (!head) {
352
352
  throw new Error(`Cannot find block ${at}`);
353
353
  }
354
- const inherents = await _class_private_field_get(this, _inherentProvider).createInherents(head, {
354
+ const params = {
355
355
  transactions: [],
356
356
  downwardMessages: dmp,
357
357
  upwardMessages: [],
358
358
  horizontalMessages: {}
359
- });
360
- return (0, _blockbuilder.dryRunInherents)(head, inherents);
359
+ };
360
+ return (0, _blockbuilder.dryRunInherents)(head, _class_private_field_get(this, _inherentProviders), params);
361
361
  }
362
362
  /**
363
363
  * Dry run ump messages in block `at`.
@@ -393,25 +393,18 @@ class Blockchain {
393
393
  ]);
394
394
  }
395
395
  head.pushStorageLayer().setAll(storageValues);
396
- const inherents = await _class_private_field_get(this, _inherentProvider).createInherents(head, {
396
+ const params = {
397
397
  transactions: [],
398
398
  downwardMessages: [],
399
399
  upwardMessages: [],
400
400
  horizontalMessages: {}
401
- });
402
- return (0, _blockbuilder.dryRunInherents)(head, inherents);
401
+ };
402
+ return (0, _blockbuilder.dryRunInherents)(head, _class_private_field_get(this, _inherentProviders), params);
403
403
  }
404
404
  /**
405
405
  * Get inherents of head.
406
- */ async getInherents() {
407
- await this.api.isReady;
408
- const inherents = await _class_private_field_get(this, _inherentProvider).createInherents(this.head, {
409
- transactions: [],
410
- downwardMessages: [],
411
- upwardMessages: [],
412
- horizontalMessages: {}
413
- });
414
- return inherents;
406
+ */ getInherents() {
407
+ return _class_private_field_get(this, _inherentProviders);
415
408
  }
416
409
  /**
417
410
  * Close the db and disconnect api.
@@ -421,7 +414,7 @@ class Blockchain {
421
414
  }
422
415
  /**
423
416
  * @param options - Options for instantiating the blockchain
424
- */ constructor({ api, buildBlockMode, inherentProvider, db, header, mockSignatureHost = false, allowUnresolvedImports = false, runtimeLogLevel = 0, registeredTypes = {}, offchainWorker = false, maxMemoryBlockCount = 500 }){
417
+ */ constructor({ api, buildBlockMode, inherentProviders, db, header, mockSignatureHost = false, allowUnresolvedImports = false, runtimeLogLevel = 0, registeredTypes = {}, offchainWorker = false, maxMemoryBlockCount = 500 }){
425
418
  _class_private_method_init(this, _registerBlock);
426
419
  /** API instance, for getting on-chain data. */ _define_property(this, "api", void 0);
427
420
  /** Datasource for caching storage and blocks data. */ _define_property(this, "db", void 0);
@@ -436,7 +429,7 @@ class Blockchain {
436
429
  writable: true,
437
430
  value: void 0
438
431
  });
439
- _class_private_field_init(this, _inherentProvider, {
432
+ _class_private_field_init(this, _inherentProviders, {
440
433
  writable: true,
441
434
  value: void 0
442
435
  });
@@ -485,8 +478,8 @@ class Blockchain {
485
478
  this.registeredTypes = registeredTypes;
486
479
  _class_private_field_set(this, _head, new _block.Block(this, header.number, header.hash));
487
480
  _class_private_method_get(this, _registerBlock, registerBlock).call(this, _class_private_field_get(this, _head));
488
- _class_private_field_set(this, _txpool1, new _txpool.TxPool(this, inherentProvider, buildBlockMode));
489
- _class_private_field_set(this, _inherentProvider, inherentProvider);
481
+ _class_private_field_set(this, _txpool1, new _txpool.TxPool(this, inherentProviders, buildBlockMode));
482
+ _class_private_field_set(this, _inherentProviders, inherentProviders);
490
483
  this.headState = new _headstate.HeadState(_class_private_field_get(this, _head));
491
484
  if (offchainWorker) {
492
485
  this.offchainWorker = new _offchain.OffchainWorker();
@@ -1,19 +1,12 @@
1
1
  import { Block } from '../block.js';
2
2
  import { BuildBlockParams } from '../txpool.js';
3
3
  import { HexString } from '@polkadot/util/types';
4
- export { SetValidationData } from './parachain/validation-data.js';
5
- export { ParaInherentEnter } from './para-enter.js';
6
- export { SetBabeRandomness } from './parachain/babe-randomness.js';
7
- export { SetNimbusAuthorInherent } from './parachain/nimbus-author-inherent.js';
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[]>;
4
+ import { ParaInherentEnter } from './para-enter.js';
5
+ import { SetBabeRandomness } from './parachain/babe-randomness.js';
6
+ import { SetNimbusAuthorInherent } from './parachain/nimbus-author-inherent.js';
7
+ import { SetTimestamp } from './timestamp.js';
8
+ import { SetValidationData } from './parachain/validation-data.js';
9
+ export interface InherentProvider {
10
+ createInherents(newBlock: Block, params: BuildBlockParams): Promise<HexString[]>;
19
11
  }
12
+ export declare const inherentProviders: (ParaInherentEnter | SetBabeRandomness | SetNimbusAuthorInherent | SetTimestamp | SetValidationData)[];
@@ -2,108 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- InherentProviders: function() {
13
- return InherentProviders;
14
- },
15
- ParaInherentEnter: function() {
16
- return _paraenter.ParaInherentEnter;
17
- },
18
- SetBabeRandomness: function() {
19
- return _baberandomness.SetBabeRandomness;
20
- },
21
- SetNimbusAuthorInherent: function() {
22
- return _nimbusauthorinherent.SetNimbusAuthorInherent;
23
- },
24
- SetTimestamp: function() {
25
- return SetTimestamp;
26
- },
27
- SetValidationData: function() {
28
- return _validationdata.SetValidationData;
5
+ Object.defineProperty(exports, "inherentProviders", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return inherentProviders;
29
9
  }
30
10
  });
31
- const _types = require("@polkadot/types");
32
- const _timetravel = require("../../utils/time-travel.js");
33
- const _validationdata = require("./parachain/validation-data.js");
34
11
  const _paraenter = require("./para-enter.js");
35
12
  const _baberandomness = require("./parachain/babe-randomness.js");
36
13
  const _nimbusauthorinherent = require("./parachain/nimbus-author-inherent.js");
37
- function _check_private_redeclaration(obj, privateCollection) {
38
- if (privateCollection.has(obj)) {
39
- throw new TypeError("Cannot initialize the same private elements twice on an object");
40
- }
41
- }
42
- function _class_apply_descriptor_get(receiver, descriptor) {
43
- if (descriptor.get) {
44
- return descriptor.get.call(receiver);
45
- }
46
- return descriptor.value;
47
- }
48
- function _class_apply_descriptor_set(receiver, descriptor, value) {
49
- if (descriptor.set) {
50
- descriptor.set.call(receiver, value);
51
- } else {
52
- if (!descriptor.writable) {
53
- throw new TypeError("attempted to set read only private field");
54
- }
55
- descriptor.value = value;
56
- }
57
- }
58
- function _class_extract_field_descriptor(receiver, privateMap, action) {
59
- if (!privateMap.has(receiver)) {
60
- throw new TypeError("attempted to " + action + " private field on non-instance");
61
- }
62
- return privateMap.get(receiver);
63
- }
64
- function _class_private_field_get(receiver, privateMap) {
65
- var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
66
- return _class_apply_descriptor_get(receiver, descriptor);
67
- }
68
- function _class_private_field_init(obj, privateMap, value) {
69
- _check_private_redeclaration(obj, privateMap);
70
- privateMap.set(obj, value);
71
- }
72
- function _class_private_field_set(receiver, privateMap, value) {
73
- var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
74
- _class_apply_descriptor_set(receiver, descriptor, value);
75
- return value;
76
- }
77
- class SetTimestamp {
78
- async createInherents(parent) {
79
- const meta = await parent.meta;
80
- const slotDuration = await (0, _timetravel.getSlotDuration)(parent.chain);
81
- const currentTimestamp = await (0, _timetravel.getCurrentTimestamp)(parent.chain);
82
- return [
83
- new _types.GenericExtrinsic(meta.registry, meta.tx.timestamp.set(currentTimestamp + BigInt(slotDuration))).toHex()
84
- ];
85
- }
86
- }
87
- var _base = /*#__PURE__*/ new WeakMap(), _providers = /*#__PURE__*/ new WeakMap();
88
- class InherentProviders {
89
- async createInherents(parent, params) {
90
- const base = await _class_private_field_get(this, _base).createInherents(parent, params);
91
- const extra = await Promise.all(_class_private_field_get(this, _providers).map((provider)=>provider.createInherents(parent, params)));
92
- return [
93
- ...base,
94
- ...extra.flat()
95
- ];
96
- }
97
- constructor(base, providers){
98
- _class_private_field_init(this, _base, {
99
- writable: true,
100
- value: void 0
101
- });
102
- _class_private_field_init(this, _providers, {
103
- writable: true,
104
- value: void 0
105
- });
106
- _class_private_field_set(this, _base, base);
107
- _class_private_field_set(this, _providers, providers);
108
- }
109
- }
14
+ const _timestamp = require("./timestamp.js");
15
+ const _validationdata = require("./parachain/validation-data.js");
16
+ const inherentProviders = [
17
+ new _timestamp.SetTimestamp(),
18
+ new _validationdata.SetValidationData(),
19
+ new _paraenter.ParaInherentEnter(),
20
+ new _nimbusauthorinherent.SetNimbusAuthorInherent(),
21
+ new _baberandomness.SetBabeRandomness()
22
+ ];
@@ -1,7 +1,7 @@
1
1
  import { HexString } from '@polkadot/util/types';
2
2
  import { Block } from '../block.js';
3
3
  import { BuildBlockParams } from '../txpool.js';
4
- import { CreateInherents } from './index.js';
5
- export declare class ParaInherentEnter implements CreateInherents {
6
- createInherents(parent: Block, _params: BuildBlockParams): Promise<HexString[]>;
4
+ import { InherentProvider } from './index.js';
5
+ export declare class ParaInherentEnter implements InherentProvider {
6
+ createInherents(newBlock: Block, _params: BuildBlockParams): Promise<HexString[]>;
7
7
  }
@@ -10,7 +10,9 @@ Object.defineProperty(exports, "ParaInherentEnter", {
10
10
  });
11
11
  const _types = require("@polkadot/types");
12
12
  class ParaInherentEnter {
13
- async createInherents(parent, _params) {
13
+ async createInherents(newBlock, _params) {
14
+ const parent = await newBlock.parentBlock;
15
+ if (!parent) throw new Error('parent block not found');
14
16
  const meta = await parent.meta;
15
17
  if (!meta.tx.paraInherent?.enter) {
16
18
  return [];
@@ -1,7 +1,7 @@
1
1
  import { HexString } from '@polkadot/util/types';
2
2
  import { Block } from '../../block.js';
3
3
  import { BuildBlockParams } from '../../txpool.js';
4
- import { CreateInherents } from '../index.js';
5
- export declare class SetBabeRandomness implements CreateInherents {
6
- createInherents(parent: Block, _params: BuildBlockParams): Promise<HexString[]>;
4
+ import { InherentProvider } from '../index.js';
5
+ export declare class SetBabeRandomness implements InherentProvider {
6
+ createInherents(newBlock: Block, _params: BuildBlockParams): Promise<HexString[]>;
7
7
  }
@@ -10,7 +10,9 @@ Object.defineProperty(exports, "SetBabeRandomness", {
10
10
  });
11
11
  const _types = require("@polkadot/types");
12
12
  class SetBabeRandomness {
13
- async createInherents(parent, _params) {
13
+ async createInherents(newBlock, _params) {
14
+ const parent = await newBlock.parentBlock;
15
+ if (!parent) throw new Error('parent block not found');
14
16
  const meta = await parent.meta;
15
17
  if (!meta.tx.randomness?.setBabeRandomnessResults) {
16
18
  return [];
@@ -1,7 +1,7 @@
1
1
  import { HexString } from '@polkadot/util/types';
2
2
  import { Block } from '../../block.js';
3
3
  import { BuildBlockParams } from '../../txpool.js';
4
- import { CreateInherents } from '../index.js';
5
- export declare class SetNimbusAuthorInherent implements CreateInherents {
6
- createInherents(parent: Block, _params: BuildBlockParams): Promise<HexString[]>;
4
+ import { InherentProvider } from '../index.js';
5
+ export declare class SetNimbusAuthorInherent implements InherentProvider {
6
+ createInherents(newBlock: Block, _params: BuildBlockParams): Promise<HexString[]>;
7
7
  }
@@ -9,12 +9,31 @@ Object.defineProperty(exports, "SetNimbusAuthorInherent", {
9
9
  }
10
10
  });
11
11
  const _types = require("@polkadot/types");
12
+ const _index = require("../../../utils/index.js");
12
13
  class SetNimbusAuthorInherent {
13
- async createInherents(parent, _params) {
14
+ async createInherents(newBlock, _params) {
15
+ const parent = await newBlock.parentBlock;
16
+ if (!parent) throw new Error('parent block not found');
14
17
  const meta = await parent.meta;
15
18
  if (!meta.tx.authorInherent?.kickOffAuthorshipValidation) {
16
19
  return [];
17
20
  }
21
+ // mock author inherent data and authorities noting data
22
+ const layer = newBlock.pushStorageLayer();
23
+ const accountType = meta.registry.hasType('NimbusPrimitivesNimbusCryptoPublic') ? 'NimbusPrimitivesNimbusCryptoPublic' : 'AccountId';
24
+ const alice = meta.registry.hasType('NimbusPrimitivesNimbusCryptoPublic') ? '0x567b6ddb05396c0a83853b6f40d27450534c7963df8619b8c6064480c4db9703' : '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
25
+ layer.set((0, _index.compactHex)(meta.query.authorInherent.author()), meta.registry.createType(accountType, alice).toHex());
26
+ if (meta.query.authoritiesNoting) {
27
+ layer.set((0, _index.compactHex)(meta.query.authoritiesNoting.authorities()), meta.registry.createType(`Vec<${accountType}>`, [
28
+ alice
29
+ ]).toHex());
30
+ layer.set((0, _index.compactHex)(meta.query.authoritiesNoting.didSetOrchestratorAuthorityData()), meta.registry.createType('bool', true).toHex());
31
+ }
32
+ if (meta.query.parachainStaking) {
33
+ layer.set((0, _index.compactHex)(meta.query.parachainStaking.selectedCandidates()), meta.registry.createType(`Vec<${accountType}>`, [
34
+ alice
35
+ ]).toHex());
36
+ }
18
37
  return [
19
38
  new _types.GenericExtrinsic(meta.registry, meta.tx.authorInherent.kickOffAuthorshipValidation()).toHex()
20
39
  ];
@@ -1,7 +1,7 @@
1
1
  import { HexString } from '@polkadot/util/types';
2
2
  import { Block } from '../../block.js';
3
3
  import { BuildBlockParams, DownwardMessage, HorizontalMessage } from '../../txpool.js';
4
- import { CreateInherents } from '../index.js';
4
+ import { InherentProvider } from '../index.js';
5
5
  export type ValidationData = {
6
6
  downwardMessages: DownwardMessage[];
7
7
  horizontalMessages: Record<number, HorizontalMessage[]>;
@@ -14,6 +14,6 @@ export type ValidationData = {
14
14
  trieNodes: HexString[];
15
15
  };
16
16
  };
17
- export declare class SetValidationData implements CreateInherents {
18
- createInherents(parent: Block, params: BuildBlockParams): Promise<HexString[]>;
17
+ export declare class SetValidationData implements InherentProvider {
18
+ createInherents(newBlock: Block, params: BuildBlockParams): Promise<HexString[]>;
19
19
  }