@acala-network/chopsticks-core 0.9.8 → 0.9.9-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 (57) hide show
  1. package/dist/cjs/blockchain/inherent/parachain/nimbus-author-inherent.d.ts +1 -1
  2. package/dist/cjs/blockchain/inherent/parachain/nimbus-author-inherent.js +17 -0
  3. package/dist/cjs/blockchain/inherent/parachain/validation-data.js +48 -23
  4. package/dist/cjs/chopsticks-provider.js +1 -5
  5. package/dist/cjs/genesis-provider.js +39 -7
  6. package/dist/cjs/rpc/dev/index.d.ts +15 -0
  7. package/dist/cjs/rpc/dev/index.js +38 -0
  8. package/dist/cjs/rpc/dev/new-block.d.ts +128 -0
  9. package/dist/cjs/rpc/dev/new-block.js +57 -0
  10. package/dist/cjs/rpc/dev/set-block-build-mode.d.ts +21 -0
  11. package/dist/cjs/rpc/dev/set-block-build-mode.js +22 -0
  12. package/dist/cjs/rpc/dev/set-head.d.ts +21 -0
  13. package/dist/cjs/rpc/dev/set-head.js +28 -0
  14. package/dist/cjs/rpc/dev/set-runtime-log-level.d.ts +17 -0
  15. package/dist/cjs/rpc/dev/set-runtime-log-level.js +21 -0
  16. package/dist/cjs/rpc/dev/set-storage.d.ts +29 -0
  17. package/dist/cjs/rpc/dev/set-storage.js +24 -0
  18. package/dist/cjs/rpc/dev/time-travel.d.ts +17 -0
  19. package/dist/cjs/rpc/dev/time-travel.js +18 -0
  20. package/dist/cjs/rpc/index.d.ts +3 -1
  21. package/dist/cjs/rpc/index.js +8 -5
  22. package/dist/cjs/rpc/shared.d.ts +3 -0
  23. package/dist/cjs/rpc/shared.js +9 -0
  24. package/dist/cjs/setup.d.ts +16 -0
  25. package/dist/cjs/setup.js +22 -11
  26. package/dist/cjs/utils/index.js +1 -0
  27. package/dist/cjs/wasm-executor/index.d.ts +0 -1
  28. package/dist/cjs/wasm-executor/index.js +0 -7
  29. package/dist/esm/blockchain/inherent/parachain/nimbus-author-inherent.d.ts +1 -1
  30. package/dist/esm/blockchain/inherent/parachain/nimbus-author-inherent.js +17 -0
  31. package/dist/esm/blockchain/inherent/parachain/validation-data.js +48 -23
  32. package/dist/esm/chopsticks-provider.js +1 -5
  33. package/dist/esm/genesis-provider.js +39 -7
  34. package/dist/esm/rpc/dev/index.d.ts +15 -0
  35. package/dist/esm/rpc/dev/index.js +21 -0
  36. package/dist/esm/rpc/dev/new-block.d.ts +128 -0
  37. package/dist/esm/rpc/dev/new-block.js +84 -0
  38. package/dist/esm/rpc/dev/set-block-build-mode.d.ts +21 -0
  39. package/dist/esm/rpc/dev/set-block-build-mode.js +29 -0
  40. package/dist/esm/rpc/dev/set-head.d.ts +21 -0
  41. package/dist/esm/rpc/dev/set-head.js +32 -0
  42. package/dist/esm/rpc/dev/set-runtime-log-level.d.ts +17 -0
  43. package/dist/esm/rpc/dev/set-runtime-log-level.js +25 -0
  44. package/dist/esm/rpc/dev/set-storage.d.ts +29 -0
  45. package/dist/esm/rpc/dev/set-storage.js +38 -0
  46. package/dist/esm/rpc/dev/time-travel.d.ts +17 -0
  47. package/dist/esm/rpc/dev/time-travel.js +22 -0
  48. package/dist/esm/rpc/index.d.ts +3 -1
  49. package/dist/esm/rpc/index.js +4 -4
  50. package/dist/esm/rpc/shared.d.ts +3 -0
  51. package/dist/esm/rpc/shared.js +3 -0
  52. package/dist/esm/setup.d.ts +16 -0
  53. package/dist/esm/setup.js +19 -11
  54. package/dist/esm/utils/index.js +1 -0
  55. package/dist/esm/wasm-executor/index.d.ts +0 -1
  56. package/dist/esm/wasm-executor/index.js +0 -7
  57. package/package.json +2 -2
@@ -1,6 +1,6 @@
1
- import { HexString } from '@polkadot/util/types';
2
1
  import { Block } from '../../block.js';
3
2
  import { BuildBlockParams } from '../../txpool.js';
3
+ import { HexString } from '@polkadot/util/types';
4
4
  import { InherentProvider } from '../index.js';
5
5
  export declare class SetNimbusAuthorInherent implements InherentProvider {
6
6
  createInherents(newBlock: Block, _params: BuildBlockParams): Promise<HexString[]>;
@@ -34,6 +34,23 @@ class SetNimbusAuthorInherent {
34
34
  alice
35
35
  ]).toHex());
36
36
  }
37
+ if (meta.query.authorityAssignment && meta.query.session) {
38
+ const session = await newBlock.chain.head.read('u32', meta.query.session.currentIndex);
39
+ if (session) {
40
+ // We need to set both the assignemnt for current and next sessions
41
+ layer.set((0, _index.compactHex)(meta.query.authorityAssignment.collatorContainerChain(session)), meta.registry.createType(`DpCollatorAssignmentAssignedCollatorsPublic`, {
42
+ orchestratorChain: [
43
+ alice
44
+ ]
45
+ }).toHex());
46
+ layer.set((0, _index.compactHex)(meta.query.authorityAssignment.collatorContainerChain(session.toBigInt() + 1n)), meta.registry.createType(`DpCollatorAssignmentAssignedCollatorsPublic`, {
47
+ orchestratorChain: [
48
+ alice
49
+ ]
50
+ }).toHex());
51
+ }
52
+ layer.set((0, _index.compactHex)(meta.query.authorNoting.didSetContainerAuthorData()), meta.registry.createType('bool', true).toHex());
53
+ }
37
54
  return [
38
55
  new _types.GenericExtrinsic(meta.registry, meta.tx.authorInherent.kickOffAuthorshipValidation()).toHex()
39
56
  ];
@@ -8,8 +8,8 @@ Object.defineProperty(exports, "SetValidationData", {
8
8
  return SetValidationData;
9
9
  }
10
10
  });
11
- const _types = require("@polkadot/types");
12
11
  const _util = require("@polkadot/util");
12
+ const _types = require("@polkadot/types");
13
13
  const _lodash = /*#__PURE__*/ _interop_require_default(require("lodash"));
14
14
  const _proof = require("../../../utils/proof.js");
15
15
  const _utilcrypto = require("@polkadot/util-crypto");
@@ -88,11 +88,13 @@ class SetValidationData {
88
88
  const hrmpIngressChannelIndexKey = (0, _proof.hrmpIngressChannelIndex)(paraId);
89
89
  const hrmpEgressChannelIndexKey = (0, _proof.hrmpEgressChannelIndex)(paraId);
90
90
  const decoded = await (0, _index1.decodeProof)(extrinsic.validationData.relayParentStorageRoot, extrinsic.relayChainState.trieNodes);
91
+ const slotIncrease = meta.consts.timestamp.minimumPeriod.divn(3000) // relaychain min period
92
+ .toNumber();
91
93
  for (const key of Object.values(_proof.WELL_KNOWN_KEYS)){
92
94
  if (key === _proof.WELL_KNOWN_KEYS.CURRENT_SLOT) {
93
95
  // increment current slot
94
- const currentSlot = decoded[key] ? meta.registry.createType('Slot', (0, _util.hexToU8a)(decoded[key])).toNumber() : await (0, _index.getCurrentSlot)(parent.chain) * 2;
95
- const newSlot = meta.registry.createType('Slot', currentSlot + 2);
96
+ const relayCurrentSlot = decoded[key] ? meta.registry.createType('Slot', (0, _util.hexToU8a)(decoded[key])).toNumber() : await (0, _index.getCurrentSlot)(parent.chain) * slotIncrease;
97
+ const newSlot = meta.registry.createType('Slot', relayCurrentSlot + slotIncrease);
96
98
  newEntries.push([
97
99
  key,
98
100
  (0, _util.u8aToHex)(newSlot.toU8a())
@@ -104,13 +106,28 @@ class SetValidationData {
104
106
  ]);
105
107
  }
106
108
  }
109
+ // inject missing hrmpIngressChannel and hrmpEgressChannel
110
+ const hrmpIngressChannels = meta.registry.createType('Vec<u32>', (0, _util.hexToU8a)(decoded[hrmpIngressChannelIndexKey]));
111
+ const hrmpEgressChannels = meta.registry.createType('Vec<u32>', (0, _util.hexToU8a)(decoded[hrmpEgressChannelIndexKey]));
112
+ for(const key in params.horizontalMessages){
113
+ // order is important
114
+ const sender = meta.registry.createType('u32', key);
115
+ if (!hrmpIngressChannels.some((x)=>x.eq(sender))) {
116
+ const idx = _lodash.default.sortedIndexBy(hrmpIngressChannels, sender, (x)=>x.toNumber());
117
+ hrmpIngressChannels.splice(idx, 0, sender);
118
+ }
119
+ if (!hrmpEgressChannels.some((x)=>x.eq(sender))) {
120
+ const idx = _lodash.default.sortedIndexBy(hrmpEgressChannels, sender, (x)=>x.toNumber());
121
+ hrmpEgressChannels.splice(idx, 0, sender);
122
+ }
123
+ }
107
124
  newEntries.push([
108
125
  hrmpIngressChannelIndexKey,
109
- decoded[hrmpIngressChannelIndexKey]
126
+ hrmpIngressChannels.toHex()
110
127
  ]);
111
128
  newEntries.push([
112
129
  hrmpEgressChannelIndexKey,
113
- decoded[hrmpEgressChannelIndexKey]
130
+ hrmpEgressChannels.toHex()
114
131
  ]);
115
132
  // inject paraHead
116
133
  const headData = meta.registry.createType('HeadData', (await parent.header).toHex());
@@ -132,25 +149,26 @@ class SetValidationData {
132
149
  dmqMqcHeadKey,
133
150
  dmqMqcHeadHash
134
151
  ]);
135
- const hrmpIngressChannels = meta.registry.createType('Vec<ParaId>', decoded[hrmpIngressChannelIndexKey]).toJSON();
136
- const hrmpEgressChannels = meta.registry.createType('Vec<ParaId>', decoded[hrmpEgressChannelIndexKey]).toJSON();
137
- const hrmpMessages = {
138
- // reset values, we just need the keys
139
- ..._lodash.default.mapValues(extrinsic.horizontalMessages, ()=>[]),
140
- ...params.horizontalMessages
141
- };
142
152
  // inject horizontal messages
143
- for (const id of hrmpIngressChannels){
144
- const messages = hrmpMessages[id];
145
- const sender = Number(id);
153
+ for (const sender of hrmpIngressChannels){
154
+ // search by number and string just in case key is not a number
155
+ const messages = params.horizontalMessages[sender.toNumber()] || params.horizontalMessages[sender.toString()] || [];
146
156
  const channelId = meta.registry.createType('HrmpChannelId', {
147
157
  sender,
148
158
  receiver: paraId.toNumber()
149
159
  });
150
160
  const hrmpChannelKey = (0, _proof.hrmpChannels)(channelId);
151
161
  const abridgedHrmpRaw = decoded[hrmpChannelKey];
152
- if (!abridgedHrmpRaw) throw new Error('Canoot find hrmp channels from validation data');
153
- const abridgedHrmp = meta.registry.createType('AbridgedHrmpChannel', (0, _util.hexToU8a)(abridgedHrmpRaw)).toJSON();
162
+ const abridgedHrmp = abridgedHrmpRaw ? meta.registry.createType('AbridgedHrmpChannel', (0, _util.hexToU8a)(abridgedHrmpRaw)).toJSON() : {
163
+ maxCapacity: 1000,
164
+ maxTotalSize: 102400,
165
+ maxMessageSize: 102400,
166
+ msgCount: 0,
167
+ totalSize: 0,
168
+ mqcHead: 0x0000000000000000000000000000000000000000000000000000000000000000,
169
+ senderDeposit: 5000000000000,
170
+ recipientDeposit: 5000000000000
171
+ };
154
172
  const paraMessages = [];
155
173
  for (const { data, sentAt: _unused } of messages){
156
174
  // fake relaychain sentAt to make validationData think this msg was sent at previous block
@@ -165,24 +183,31 @@ class SetValidationData {
165
183
  sentAt
166
184
  });
167
185
  }
168
- horizontalMessages[sender] = paraMessages;
186
+ horizontalMessages[sender.toNumber()] = paraMessages;
169
187
  newEntries.push([
170
188
  hrmpChannelKey,
171
189
  meta.registry.createType('AbridgedHrmpChannel', abridgedHrmp).toHex()
172
190
  ]);
173
191
  }
174
192
  // inject hrmpEgressChannels proof
175
- for (const id of hrmpEgressChannels){
176
- // const messages = hrmpMessages[id]
177
- const receiver = Number(id);
193
+ for (const receiver of hrmpEgressChannels){
178
194
  const channelId = meta.registry.createType('HrmpChannelId', {
179
195
  sender: paraId.toNumber(),
180
196
  receiver
181
197
  });
182
198
  const hrmpChannelKey = (0, _proof.hrmpChannels)(channelId);
199
+ const abridgedHrmpRaw = decoded[hrmpChannelKey];
200
+ const abridgedHrmp = abridgedHrmpRaw ? meta.registry.createType('AbridgedHrmpChannel', (0, _util.hexToU8a)(abridgedHrmpRaw)).toJSON() : {
201
+ maxCapacity: 1000,
202
+ maxTotalSize: 102400,
203
+ maxMessageSize: 102400,
204
+ msgCount: 0,
205
+ totalSize: 0,
206
+ mqcHead: 0x0000000000000000000000000000000000000000000000000000000000000000
207
+ };
183
208
  newEntries.push([
184
209
  hrmpChannelKey,
185
- decoded[hrmpChannelKey]
210
+ meta.registry.createType('AbridgedHrmpChannel', abridgedHrmp).toHex()
186
211
  ]);
187
212
  }
188
213
  const upgradeKey = (0, _proof.upgradeGoAheadSignal)(paraId);
@@ -209,7 +234,7 @@ class SetValidationData {
209
234
  validationData: {
210
235
  ...extrinsic.validationData,
211
236
  relayParentStorageRoot: trieRootHash,
212
- relayParentNumber: extrinsic.validationData.relayParentNumber + 2
237
+ relayParentNumber: extrinsic.validationData.relayParentNumber + slotIncrease
213
238
  },
214
239
  relayChainState: {
215
240
  trieNodes: nodes
@@ -66,11 +66,7 @@ function _define_property(obj, key, value) {
66
66
  return obj;
67
67
  }
68
68
  const providerHandlers = {
69
- ..._index.allHandlers,
70
- dev_newBlock: async (context, _params, _subscriptionManager)=>{
71
- const block = await context.chain.newBlock();
72
- return block.hash;
73
- }
69
+ ..._index.allHandlers
74
70
  };
75
71
  const logger = _logger.defaultLogger.child({
76
72
  name: '[Chopsticks provider]'
@@ -11,6 +11,7 @@ Object.defineProperty(exports, "GenesisProvider", {
11
11
  const _eventemitter3 = require("eventemitter3");
12
12
  const _index = require("./schema/index.js");
13
13
  const _index1 = require("./wasm-executor/index.js");
14
+ const _index2 = require("./index.js");
14
15
  function _check_private_redeclaration(obj, privateCollection) {
15
16
  if (privateCollection.has(obj)) {
16
17
  throw new TypeError("Cannot initialize the same private elements twice on an object");
@@ -86,13 +87,29 @@ class GenesisProvider {
86
87
  return {
87
88
  ..._index1.emptyTaskHandler,
88
89
  getStorage: async function(key) {
90
+ if ((0, _index2.isPrefixedChildKey)(key)) {
91
+ _index2.defaultLogger.warn({
92
+ key
93
+ }, 'genesis child storage not supported');
94
+ return undefined;
95
+ }
89
96
  return storage[key];
90
97
  },
91
- getStateRoot: async function() {
92
- return '0x49416764844ff0d8bad851e8abe686dff9dd2de78621180ef8e9f99bb7a480f1';
93
- },
94
- getNextKey: async function(_prefix, _key) {
95
- return undefined;
98
+ getNextKey: async function(prefix, key) {
99
+ if ((0, _index2.isPrefixedChildKey)(key)) {
100
+ _index2.defaultLogger.warn({
101
+ prefix,
102
+ key
103
+ }, 'genesis child storage not supported');
104
+ return undefined;
105
+ }
106
+ return Object.keys(storage).find((k)=>{
107
+ if (!k.startsWith(prefix)) return false;
108
+ if (key.length > prefix.length) {
109
+ return k > key;
110
+ }
111
+ return true;
112
+ });
96
113
  }
97
114
  };
98
115
  }
@@ -177,10 +194,25 @@ class GenesisProvider {
177
194
  return this.blockHash;
178
195
  case 'state_getKeysPaged':
179
196
  case 'state_getKeysPagedAt':
180
- return [];
197
+ {
198
+ if (params.length < 2) throw Error('invalid params');
199
+ const [prefix, size, start] = params;
200
+ let startKey = start || prefix;
201
+ const keys = [];
202
+ while(keys.length < size){
203
+ const nextKey = await this._jsCallback.getNextKey(prefix, startKey);
204
+ if (!nextKey) break;
205
+ keys.push(nextKey);
206
+ startKey = nextKey;
207
+ }
208
+ return keys;
209
+ }
181
210
  case 'state_getStorage':
182
211
  case 'state_getStorageAt':
183
- return _class_private_field_get(this, _genesis).genesis.raw.top[params[0]];
212
+ {
213
+ if (params.length < 1) throw Error('invalid params');
214
+ return _class_private_field_get(this, _genesis).genesis.raw.top[params[0]];
215
+ }
184
216
  default:
185
217
  throw Error(`${method} not implemented`);
186
218
  }
@@ -0,0 +1,15 @@
1
+ declare const handlers: {
2
+ dev_newBlock: (context: import("../shared.js").Context, [params]: [import("./new-block.js").NewBlockParams]) => Promise<`0x${string}`>;
3
+ dev_setBlockBuildMode: (context: import("../shared.js").Context, [mode]: [import("../../index.js").BuildBlockMode]) => Promise<void>;
4
+ dev_setHead: (context: import("../shared.js").Context, [params]: [number | `0x${string}`]) => Promise<`0x${string}`>;
5
+ dev_setRuntimeLogLevel: (context: import("../shared.js").Context, [runtimeLogLevel]: [number]) => Promise<void>;
6
+ dev_setStorage: (context: import("../shared.js").Context, params: [import("../../index.js").StorageValues, (`0x${string}` | undefined)?]) => Promise<`0x${string}`>;
7
+ dev_timeTravel: (context: import("../shared.js").Context, [date]: [string | number]) => Promise<number>;
8
+ };
9
+ export default handlers;
10
+ export * from './new-block.js';
11
+ export * from './set-block-build-mode.js';
12
+ export * from './set-head.js';
13
+ export * from './set-runtime-log-level.js';
14
+ export * from './set-storage.js';
15
+ export * from './time-travel.js';
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return _default;
9
+ }
10
+ });
11
+ const _newblock = _export_star(require("./new-block.js"), exports);
12
+ const _setblockbuildmode = _export_star(require("./set-block-build-mode.js"), exports);
13
+ const _sethead = _export_star(require("./set-head.js"), exports);
14
+ const _setruntimeloglevel = _export_star(require("./set-runtime-log-level.js"), exports);
15
+ const _setstorage = _export_star(require("./set-storage.js"), exports);
16
+ const _timetravel = _export_star(require("./time-travel.js"), exports);
17
+ function _export_star(from, to) {
18
+ Object.keys(from).forEach(function(k) {
19
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
20
+ Object.defineProperty(to, k, {
21
+ enumerable: true,
22
+ get: function() {
23
+ return from[k];
24
+ }
25
+ });
26
+ }
27
+ });
28
+ return from;
29
+ }
30
+ const handlers = {
31
+ dev_newBlock: _newblock.dev_newBlock,
32
+ dev_setBlockBuildMode: _setblockbuildmode.dev_setBlockBuildMode,
33
+ dev_setHead: _sethead.dev_setHead,
34
+ dev_setRuntimeLogLevel: _setruntimeloglevel.dev_setRuntimeLogLevel,
35
+ dev_setStorage: _setstorage.dev_setStorage,
36
+ dev_timeTravel: _timetravel.dev_timeTravel
37
+ };
38
+ const _default = handlers;
@@ -0,0 +1,128 @@
1
+ import { Context } from '../shared.js';
2
+ import { z } from 'zod';
3
+ declare const schema: z.ZodObject<{
4
+ count: z.ZodOptional<z.ZodNumber>;
5
+ to: z.ZodOptional<z.ZodNumber>;
6
+ dmp: z.ZodOptional<z.ZodArray<z.ZodObject<{
7
+ sentAt: z.ZodNumber;
8
+ msg: z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>;
9
+ }, "strip", z.ZodTypeAny, {
10
+ msg: `0x${string}`;
11
+ sentAt: number;
12
+ }, {
13
+ msg: `0x${string}`;
14
+ sentAt: number;
15
+ }>, "many">>;
16
+ ump: z.ZodOptional<z.ZodRecord<z.ZodNumber, z.ZodArray<z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, "many">>>;
17
+ hrmp: z.ZodOptional<z.ZodRecord<z.ZodUnion<[z.ZodNumber, z.ZodString]>, z.ZodArray<z.ZodObject<{
18
+ sentAt: z.ZodNumber;
19
+ data: z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>;
20
+ }, "strip", z.ZodTypeAny, {
21
+ data: `0x${string}`;
22
+ sentAt: number;
23
+ }, {
24
+ data: `0x${string}`;
25
+ sentAt: number;
26
+ }>, "many">>>;
27
+ transactions: z.ZodOptional<z.ZodArray<z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, "many">>;
28
+ unsafeBlockHeight: z.ZodOptional<z.ZodNumber>;
29
+ }, "strip", z.ZodTypeAny, {
30
+ count?: number | undefined;
31
+ to?: number | undefined;
32
+ dmp?: {
33
+ msg: `0x${string}`;
34
+ sentAt: number;
35
+ }[] | undefined;
36
+ ump?: Record<number, `0x${string}`[]> | undefined;
37
+ hrmp?: Record<string | number, {
38
+ data: `0x${string}`;
39
+ sentAt: number;
40
+ }[]> | undefined;
41
+ transactions?: `0x${string}`[] | undefined;
42
+ unsafeBlockHeight?: number | undefined;
43
+ }, {
44
+ count?: number | undefined;
45
+ to?: number | undefined;
46
+ dmp?: {
47
+ msg: `0x${string}`;
48
+ sentAt: number;
49
+ }[] | undefined;
50
+ ump?: Record<number, `0x${string}`[]> | undefined;
51
+ hrmp?: Record<string | number, {
52
+ data: `0x${string}`;
53
+ sentAt: number;
54
+ }[]> | undefined;
55
+ transactions?: `0x${string}`[] | undefined;
56
+ unsafeBlockHeight?: number | undefined;
57
+ }>;
58
+ type Params = z.infer<typeof schema>;
59
+ export interface NewBlockParams {
60
+ /**
61
+ * The number of blocks to build
62
+ */
63
+ count: Params['count'];
64
+ /**
65
+ * The block number to build to
66
+ */
67
+ to: Params['to'];
68
+ /**
69
+ * The downward messages to include in the block
70
+ */
71
+ dmp: Params['dmp'];
72
+ /**
73
+ * The upward messages to include in the block
74
+ */
75
+ ump: Params['ump'];
76
+ /**
77
+ * The horizontal messages to include in the block
78
+ */
79
+ hrmp: Params['hrmp'];
80
+ /**
81
+ * The transactions to include in the block
82
+ */
83
+ transactions: Params['transactions'];
84
+ /**
85
+ * Build block using a specific block height (unsafe)
86
+ */
87
+ unsafeBlockHeight: Params['unsafeBlockHeight'];
88
+ }
89
+ /**
90
+ * Build new blocks.
91
+ *
92
+ * This function is a dev rpc handler. Use `dev_newBlock` as the method name when calling it.
93
+ *
94
+ * @param context - The context object of the rpc handler
95
+ * @param params - The parameters of the rpc handler
96
+ *
97
+ * @example Build 2 blocks
98
+ * ```ts
99
+ * import { WsProvider } from '@polkadot/rpc-provider'
100
+ * const ws = new WsProvider(`ws://localhost:8000`)
101
+ * await ws.send('dev_newBlock', [{ count: 2 }])
102
+ * ```
103
+ * @example Build a block with upward messages
104
+ * ```ts
105
+ * import { WsProvider } from '@polkadot/rpc-provider'
106
+ * const ws = new WsProvider(`ws://localhost:8000`)
107
+ * await ws.send('dev_newBlock', [
108
+ * {
109
+ * ump: {
110
+ * // https://acala.subscan.io/xcm_message/polkadot-ff66f28818d0b74573e62db8317e354b253fbc80
111
+ * 2000: [
112
+ * '0x021000040000000007903fc4db080a130000000007903fc4db08000d010004000101009c4b11a0974cba4a395c94832fba812868a6cb0ba09e8519b3521093ea359905',
113
+ * ],
114
+ * }
115
+ * }
116
+ * ])
117
+ * ```
118
+ *
119
+ * @example Build two blocks with unsafeBlockHeight
120
+ * ```ts
121
+ * import { WsProvider } from '@polkadot/rpc-provider'
122
+ * const ws = new WsProvider(`ws://localhost:8000`)
123
+ * // this will create two blocks with block height 100000001 and 100000002
124
+ * await ws.send('dev_newBlock', [{ count: 2, unsafeBlockHeight: 100000001 }])
125
+ * ```
126
+ */
127
+ export declare const dev_newBlock: (context: Context, [params]: [NewBlockParams]) => Promise<`0x${string}`>;
128
+ export {};
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "dev_newBlock", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return dev_newBlock;
9
+ }
10
+ });
11
+ const _shared = require("../shared.js");
12
+ const _zod = require("zod");
13
+ const _logger = require("../../logger.js");
14
+ const schema = _zod.z.object({
15
+ count: _zod.z.number().optional(),
16
+ to: _zod.z.number().optional(),
17
+ dmp: _zod.z.array(_zod.z.object({
18
+ sentAt: _zod.z.number(),
19
+ msg: _shared.zHex
20
+ })).min(1).optional(),
21
+ ump: _zod.z.record(_zod.z.number(), _zod.z.array(_shared.zHex).min(1)).optional(),
22
+ hrmp: _zod.z.record(_zod.z.union([
23
+ _zod.z.number(),
24
+ _zod.z.string()
25
+ ]), _zod.z.array(_zod.z.object({
26
+ sentAt: _zod.z.number(),
27
+ data: _shared.zHex
28
+ })).min(1)).optional(),
29
+ transactions: _zod.z.array(_shared.zHex).min(1).optional(),
30
+ unsafeBlockHeight: _zod.z.number().optional()
31
+ });
32
+ const dev_newBlock = async (context, [params])=>{
33
+ const { count, to, hrmp, ump, dmp, transactions, unsafeBlockHeight } = schema.parse(params || {});
34
+ const now = context.chain.head.number;
35
+ const diff = to ? to - now : count;
36
+ const finalCount = diff !== undefined ? Math.max(diff, 1) : 1;
37
+ let finalHash;
38
+ if (unsafeBlockHeight !== undefined && unsafeBlockHeight <= now) {
39
+ throw new _shared.ResponseError(1, 'unsafeBlockHeight must be greater than current block height');
40
+ }
41
+ for(let i = 0; i < finalCount; i++){
42
+ const block = await context.chain.newBlock({
43
+ transactions,
44
+ horizontalMessages: hrmp,
45
+ upwardMessages: ump,
46
+ downwardMessages: dmp,
47
+ unsafeBlockHeight: i === 0 ? unsafeBlockHeight : undefined
48
+ }).catch((error)=>{
49
+ throw new _shared.ResponseError(1, error.toString());
50
+ });
51
+ _logger.defaultLogger.debug({
52
+ hash: block.hash
53
+ }, 'dev_newBlock');
54
+ finalHash = block.hash;
55
+ }
56
+ return finalHash;
57
+ };
@@ -0,0 +1,21 @@
1
+ import { BuildBlockMode } from '../../blockchain/txpool.js';
2
+ import { Context } from '../shared.js';
3
+ /**
4
+ * Set block build mode.
5
+ *
6
+ * 1 - Batch, 2 - Instant, 3 - Manual
7
+ *
8
+ * This function is a dev rpc handler. Use `dev_setBlockBuildMode` as the method name when calling it.
9
+ *
10
+ * @param context - The context object of the rpc handler
11
+ * @param params - The parameters of the rpc handler
12
+ *
13
+ * @example Set build block mode to instant
14
+ * ```ts
15
+ * import { WsProvider } from '@polkadot/rpc-provider'
16
+ * import { BuildBlockMode } from '@acala-network/chopsticks-core'
17
+ * const ws = new WsProvider(`ws://localhost:8000`)
18
+ * await ws.send('dev_setBlockBuildMode', [BuildBlockMode.Instant])
19
+ * ```
20
+ */
21
+ export declare const dev_setBlockBuildMode: (context: Context, [mode]: [BuildBlockMode]) => Promise<void>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "dev_setBlockBuildMode", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return dev_setBlockBuildMode;
9
+ }
10
+ });
11
+ const _txpool = require("../../blockchain/txpool.js");
12
+ const _shared = require("../shared.js");
13
+ const _logger = require("../../logger.js");
14
+ const dev_setBlockBuildMode = async (context, [mode])=>{
15
+ _logger.defaultLogger.debug({
16
+ mode: _txpool.BuildBlockMode[mode]
17
+ }, 'dev_setBlockBuildMode');
18
+ if (_txpool.BuildBlockMode[mode] === undefined) {
19
+ throw new _shared.ResponseError(1, `Invalid mode ${mode}`);
20
+ }
21
+ context.chain.txPool.mode = mode;
22
+ };
@@ -0,0 +1,21 @@
1
+ import { Context } from '../shared.js';
2
+ import { z } from 'zod';
3
+ declare const schema: z.ZodUnion<[z.ZodIntersection<z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>>, z.ZodNumber]>;
4
+ type Params = z.infer<typeof schema>;
5
+ /**
6
+ * Set head.
7
+ *
8
+ * This function is a dev rpc handler. Use `dev_setHead` as the method name when calling it.
9
+ *
10
+ * @param context - The context object of the rpc handler
11
+ * @param hashOrNumber - The block hash or number to set as head
12
+ *
13
+ * @example Set head to block 1000000
14
+ * ```ts
15
+ * import { WsProvider } from '@polkadot/rpc-provider'
16
+ * const ws = new WsProvider(`ws://localhost:8000`)
17
+ * await ws.send('dev_setHead', [1000000])
18
+ * ```
19
+ */
20
+ export declare const dev_setHead: (context: Context, [params]: [Params]) => Promise<`0x${string}`>;
21
+ export {};
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "dev_setHead", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return dev_setHead;
9
+ }
10
+ });
11
+ const _shared = require("../shared.js");
12
+ const _zod = require("zod");
13
+ const schema = _shared.zHash.or(_zod.z.number());
14
+ const dev_setHead = async (context, [params])=>{
15
+ const hashOrNumber = schema.parse(params);
16
+ let block;
17
+ if (typeof hashOrNumber === 'number') {
18
+ const blockNumber = hashOrNumber > 0 ? hashOrNumber : context.chain.head.number + hashOrNumber;
19
+ block = await context.chain.getBlockAt(blockNumber);
20
+ } else {
21
+ block = await context.chain.getBlock(hashOrNumber);
22
+ }
23
+ if (!block) {
24
+ throw new _shared.ResponseError(1, `Block not found ${hashOrNumber}`);
25
+ }
26
+ await context.chain.setHead(block);
27
+ return block.hash;
28
+ };
@@ -0,0 +1,17 @@
1
+ import { Context } from '../shared.js';
2
+ /**
3
+ * Set runtime log level.
4
+ *
5
+ * This function is a dev rpc handler. Use `dev_setRuntimeLogLevel` as the method name when calling it.
6
+ *
7
+ * @param context - The context object of the rpc handler
8
+ * @param runtimeLogLevel - The runtime log level to set
9
+ *
10
+ * @example Set runtime log level to 1
11
+ * ```ts
12
+ * import { WsProvider } from '@polkadot/rpc-provider'
13
+ * const ws = new WsProvider(`ws://localhost:8000`)
14
+ * await ws.send('dev_setRuntimeLogLevel', [1])
15
+ * ```
16
+ */
17
+ export declare const dev_setRuntimeLogLevel: (context: Context, [runtimeLogLevel]: [number]) => Promise<void>;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "dev_setRuntimeLogLevel", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return dev_setRuntimeLogLevel;
9
+ }
10
+ });
11
+ const _shared = require("../shared.js");
12
+ const _logger = require("../../logger.js");
13
+ const dev_setRuntimeLogLevel = async (context, [runtimeLogLevel])=>{
14
+ _logger.defaultLogger.debug({
15
+ runtimeLogLevel
16
+ }, 'dev_setRuntimeLogLevel');
17
+ if (typeof runtimeLogLevel !== 'number') {
18
+ throw new _shared.ResponseError(1, `Invalid runtimeLogLevel ${runtimeLogLevel}`);
19
+ }
20
+ context.chain.runtimeLogLevel = runtimeLogLevel;
21
+ };
@@ -0,0 +1,29 @@
1
+ import { Context } from '../shared.js';
2
+ import { HexString } from '@polkadot/util/types';
3
+ import { StorageValues } from '../../utils/set-storage.js';
4
+ /**
5
+ * Set storage values.
6
+ *
7
+ * This function is a dev rpc handler. Use `dev_setStorage` as the method name when calling it.
8
+ *
9
+ * @param context - The context object of the rpc handler
10
+ * @param params - The parameters of the rpc handler
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { WsProvider } from '@polkadot/rpc-provider'
15
+ * import { Keyring } from '@polkadot/keyring'
16
+ *
17
+ * const ws = new WsProvider(`ws://localhost:8000`)
18
+ * const keyring = new Keyring({ type: 'ed25519' })
19
+ * const bob = keyring.addFromUri('//Bob')
20
+ *
21
+ * const storage = {
22
+ * System: {
23
+ * Account: [[[bob.address], { data: { free: 100000 }, nonce: 1 }]],
24
+ * },
25
+ * }
26
+ * await ws.send('dev_setStorage', [storage])
27
+ * ```
28
+ */
29
+ export declare const dev_setStorage: (context: Context, params: [StorageValues, HexString?]) => Promise<`0x${string}`>;