@acala-network/chopsticks-core 1.0.2-2 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/dist/cjs/api.d.ts +4 -4
  2. package/dist/cjs/api.js +20 -23
  3. package/dist/cjs/blockchain/block-builder.d.ts +5 -5
  4. package/dist/cjs/blockchain/block-builder.js +17 -18
  5. package/dist/cjs/blockchain/block.d.ts +6 -6
  6. package/dist/cjs/blockchain/block.js +1 -1
  7. package/dist/cjs/blockchain/head-state.d.ts +1 -1
  8. package/dist/cjs/blockchain/index.d.ts +9 -9
  9. package/dist/cjs/blockchain/index.js +5 -5
  10. package/dist/cjs/blockchain/inherent/index.d.ts +5 -5
  11. package/dist/cjs/blockchain/inherent/index.js +1 -1
  12. package/dist/cjs/blockchain/inherent/para-enter.d.ts +4 -4
  13. package/dist/cjs/blockchain/inherent/parachain/babe-randomness.d.ts +4 -4
  14. package/dist/cjs/blockchain/inherent/parachain/nimbus-author-inherent.d.ts +4 -4
  15. package/dist/cjs/blockchain/inherent/parachain/validation-data.d.ts +4 -4
  16. package/dist/cjs/blockchain/inherent/parachain/validation-data.js +3 -3
  17. package/dist/cjs/blockchain/inherent/timestamp.d.ts +3 -3
  18. package/dist/cjs/blockchain/storage-layer.d.ts +3 -3
  19. package/dist/cjs/blockchain/storage-layer.js +5 -4
  20. package/dist/cjs/blockchain/txpool.d.ts +3 -3
  21. package/dist/cjs/blockchain/txpool.js +2 -2
  22. package/dist/cjs/chopsticks-provider.d.ts +3 -3
  23. package/dist/cjs/chopsticks-provider.js +8 -9
  24. package/dist/cjs/database.d.ts +1 -1
  25. package/dist/cjs/genesis-provider.d.ts +4 -4
  26. package/dist/cjs/genesis-provider.js +12 -12
  27. package/dist/cjs/index.d.ts +1 -1
  28. package/dist/cjs/logger.js +2 -3
  29. package/dist/cjs/offchain.d.ts +2 -2
  30. package/dist/cjs/offchain.js +1 -1
  31. package/dist/cjs/rpc/dev/new-block.d.ts +5 -5
  32. package/dist/cjs/rpc/dev/new-block.js +1 -1
  33. package/dist/cjs/rpc/dev/set-block-build-mode.d.ts +1 -1
  34. package/dist/cjs/rpc/dev/set-block-build-mode.js +1 -1
  35. package/dist/cjs/rpc/dev/set-head.d.ts +1 -1
  36. package/dist/cjs/rpc/dev/set-head.js +1 -1
  37. package/dist/cjs/rpc/dev/set-runtime-log-level.d.ts +1 -1
  38. package/dist/cjs/rpc/dev/set-runtime-log-level.js +1 -1
  39. package/dist/cjs/rpc/dev/set-storage.d.ts +3 -3
  40. package/dist/cjs/rpc/dev/set-storage.js +1 -1
  41. package/dist/cjs/rpc/dev/time-travel.d.ts +1 -1
  42. package/dist/cjs/rpc/dev/time-travel.js +1 -1
  43. package/dist/cjs/rpc/index.d.ts +1 -1
  44. package/dist/cjs/rpc/rpc-spec/chainHead_v1.d.ts +11 -2
  45. package/dist/cjs/rpc/rpc-spec/chainHead_v1.js +33 -2
  46. package/dist/cjs/rpc/rpc-spec/chainSpec_v1.d.ts +3 -3
  47. package/dist/cjs/rpc/rpc-spec/transaction_v1.d.ts +2 -2
  48. package/dist/cjs/rpc/shared.d.ts +1 -1
  49. package/dist/cjs/rpc/substrate/archive.d.ts +2 -2
  50. package/dist/cjs/rpc/substrate/author.d.ts +2 -2
  51. package/dist/cjs/rpc/substrate/author.js +1 -1
  52. package/dist/cjs/rpc/substrate/chain.d.ts +2 -2
  53. package/dist/cjs/rpc/substrate/payment.d.ts +2 -2
  54. package/dist/cjs/rpc/substrate/state.d.ts +3 -3
  55. package/dist/cjs/rpc/substrate/state.js +1 -1
  56. package/dist/cjs/rpc/substrate/system.d.ts +3 -3
  57. package/dist/cjs/setup.d.ts +4 -4
  58. package/dist/cjs/setup.js +1 -1
  59. package/dist/cjs/utils/decoder.d.ts +5 -5
  60. package/dist/cjs/utils/decoder.js +2 -2
  61. package/dist/cjs/utils/index.d.ts +4 -4
  62. package/dist/cjs/utils/index.js +1 -1
  63. package/dist/cjs/utils/key-cache.d.ts +1 -1
  64. package/dist/cjs/utils/proof.d.ts +3 -3
  65. package/dist/cjs/utils/set-storage.d.ts +2 -2
  66. package/dist/cjs/utils/set-storage.js +1 -1
  67. package/dist/cjs/utils/time-travel.d.ts +1 -1
  68. package/dist/cjs/utils/well-known-keys.d.ts +2 -2
  69. package/dist/cjs/utils/well-known-keys.js +2 -2
  70. package/dist/cjs/wasm-executor/browser-wasm-executor.js +1 -1
  71. package/dist/cjs/wasm-executor/index.d.ts +3 -3
  72. package/dist/cjs/wasm-executor/index.js +14 -20
  73. package/dist/cjs/wasm-executor/node-wasm-executor.js +1 -1
  74. package/dist/cjs/wasm-executor/node-worker.js +1 -1
  75. package/dist/cjs/xcm/downward.d.ts +1 -1
  76. package/dist/cjs/xcm/horizontal.d.ts +1 -1
  77. package/dist/cjs/xcm/index.d.ts +1 -1
  78. package/dist/cjs/xcm/index.js +2 -2
  79. package/dist/cjs/xcm/upward.d.ts +1 -1
  80. package/dist/esm/api.d.ts +4 -4
  81. package/dist/esm/api.js +20 -23
  82. package/dist/esm/blockchain/block-builder.d.ts +5 -5
  83. package/dist/esm/blockchain/block-builder.js +17 -18
  84. package/dist/esm/blockchain/block.d.ts +6 -6
  85. package/dist/esm/blockchain/block.js +1 -1
  86. package/dist/esm/blockchain/head-state.d.ts +1 -1
  87. package/dist/esm/blockchain/index.d.ts +9 -9
  88. package/dist/esm/blockchain/index.js +5 -5
  89. package/dist/esm/blockchain/inherent/index.d.ts +5 -5
  90. package/dist/esm/blockchain/inherent/index.js +1 -1
  91. package/dist/esm/blockchain/inherent/para-enter.d.ts +4 -4
  92. package/dist/esm/blockchain/inherent/parachain/babe-randomness.d.ts +4 -4
  93. package/dist/esm/blockchain/inherent/parachain/nimbus-author-inherent.d.ts +4 -4
  94. package/dist/esm/blockchain/inherent/parachain/validation-data.d.ts +4 -4
  95. package/dist/esm/blockchain/inherent/parachain/validation-data.js +3 -3
  96. package/dist/esm/blockchain/inherent/timestamp.d.ts +3 -3
  97. package/dist/esm/blockchain/storage-layer.d.ts +3 -3
  98. package/dist/esm/blockchain/storage-layer.js +5 -4
  99. package/dist/esm/blockchain/txpool.d.ts +3 -3
  100. package/dist/esm/blockchain/txpool.js +2 -2
  101. package/dist/esm/chopsticks-provider.d.ts +3 -3
  102. package/dist/esm/chopsticks-provider.js +8 -9
  103. package/dist/esm/database.d.ts +1 -1
  104. package/dist/esm/genesis-provider.d.ts +4 -4
  105. package/dist/esm/genesis-provider.js +3 -3
  106. package/dist/esm/index.d.ts +1 -1
  107. package/dist/esm/logger.js +2 -3
  108. package/dist/esm/offchain.d.ts +2 -2
  109. package/dist/esm/offchain.js +1 -1
  110. package/dist/esm/rpc/dev/new-block.d.ts +5 -5
  111. package/dist/esm/rpc/dev/new-block.js +1 -1
  112. package/dist/esm/rpc/dev/set-block-build-mode.d.ts +1 -1
  113. package/dist/esm/rpc/dev/set-block-build-mode.js +1 -1
  114. package/dist/esm/rpc/dev/set-head.d.ts +1 -1
  115. package/dist/esm/rpc/dev/set-head.js +1 -1
  116. package/dist/esm/rpc/dev/set-runtime-log-level.d.ts +1 -1
  117. package/dist/esm/rpc/dev/set-runtime-log-level.js +1 -1
  118. package/dist/esm/rpc/dev/set-storage.d.ts +3 -3
  119. package/dist/esm/rpc/dev/set-storage.js +1 -1
  120. package/dist/esm/rpc/dev/time-travel.d.ts +1 -1
  121. package/dist/esm/rpc/dev/time-travel.js +1 -1
  122. package/dist/esm/rpc/index.d.ts +1 -1
  123. package/dist/esm/rpc/rpc-spec/chainHead_v1.d.ts +11 -2
  124. package/dist/esm/rpc/rpc-spec/chainHead_v1.js +42 -2
  125. package/dist/esm/rpc/rpc-spec/chainSpec_v1.d.ts +3 -3
  126. package/dist/esm/rpc/rpc-spec/transaction_v1.d.ts +2 -2
  127. package/dist/esm/rpc/shared.d.ts +1 -1
  128. package/dist/esm/rpc/substrate/archive.d.ts +2 -2
  129. package/dist/esm/rpc/substrate/author.d.ts +2 -2
  130. package/dist/esm/rpc/substrate/author.js +1 -1
  131. package/dist/esm/rpc/substrate/chain.d.ts +2 -2
  132. package/dist/esm/rpc/substrate/payment.d.ts +2 -2
  133. package/dist/esm/rpc/substrate/state.d.ts +3 -3
  134. package/dist/esm/rpc/substrate/state.js +1 -1
  135. package/dist/esm/rpc/substrate/system.d.ts +3 -3
  136. package/dist/esm/setup.d.ts +4 -4
  137. package/dist/esm/setup.js +1 -1
  138. package/dist/esm/utils/decoder.d.ts +5 -5
  139. package/dist/esm/utils/decoder.js +2 -2
  140. package/dist/esm/utils/index.d.ts +4 -4
  141. package/dist/esm/utils/index.js +1 -1
  142. package/dist/esm/utils/key-cache.d.ts +1 -1
  143. package/dist/esm/utils/proof.d.ts +3 -3
  144. package/dist/esm/utils/set-storage.d.ts +2 -2
  145. package/dist/esm/utils/set-storage.js +1 -1
  146. package/dist/esm/utils/time-travel.d.ts +1 -1
  147. package/dist/esm/utils/well-known-keys.d.ts +2 -2
  148. package/dist/esm/utils/well-known-keys.js +2 -2
  149. package/dist/esm/wasm-executor/browser-wasm-executor.js +1 -1
  150. package/dist/esm/wasm-executor/index.d.ts +3 -3
  151. package/dist/esm/wasm-executor/index.js +14 -20
  152. package/dist/esm/wasm-executor/node-wasm-executor.js +1 -1
  153. package/dist/esm/wasm-executor/node-worker.js +1 -1
  154. package/dist/esm/xcm/downward.d.ts +1 -1
  155. package/dist/esm/xcm/horizontal.d.ts +1 -1
  156. package/dist/esm/xcm/index.d.ts +1 -1
  157. package/dist/esm/xcm/index.js +2 -2
  158. package/dist/esm/xcm/upward.d.ts +1 -1
  159. package/package.json +2 -2
@@ -1,5 +1,5 @@
1
- import { Context } from '../shared.js';
2
1
  import { z } from 'zod';
2
+ import { type Context } from '../shared.js';
3
3
  declare const schema: z.ZodObject<{
4
4
  count: z.ZodOptional<z.ZodNumber>;
5
5
  to: z.ZodOptional<z.ZodNumber>;
@@ -31,6 +31,8 @@ declare const schema: z.ZodObject<{
31
31
  }, "strip", z.ZodTypeAny, {
32
32
  transactions?: `0x${string}`[] | undefined;
33
33
  unsafeBlockHeight?: number | undefined;
34
+ relayChainStateOverrides?: [`0x${string}`, `0x${string}` | null][] | undefined;
35
+ relayParentNumber?: number | undefined;
34
36
  ump?: Record<number, `0x${string}`[]> | undefined;
35
37
  dmp?: {
36
38
  msg: `0x${string}`;
@@ -40,13 +42,13 @@ declare const schema: z.ZodObject<{
40
42
  data: `0x${string}`;
41
43
  sentAt: number;
42
44
  }[]> | undefined;
43
- relayChainStateOverrides?: [`0x${string}`, `0x${string}` | null][] | undefined;
44
- relayParentNumber?: number | undefined;
45
45
  count?: number | undefined;
46
46
  to?: number | undefined;
47
47
  }, {
48
48
  transactions?: `0x${string}`[] | undefined;
49
49
  unsafeBlockHeight?: number | undefined;
50
+ relayChainStateOverrides?: [`0x${string}`, `0x${string}` | null][] | undefined;
51
+ relayParentNumber?: number | undefined;
50
52
  ump?: Record<number, `0x${string}`[]> | undefined;
51
53
  dmp?: {
52
54
  msg: `0x${string}`;
@@ -56,8 +58,6 @@ declare const schema: z.ZodObject<{
56
58
  data: `0x${string}`;
57
59
  sentAt: number;
58
60
  }[]> | undefined;
59
- relayChainStateOverrides?: [`0x${string}`, `0x${string}` | null][] | undefined;
60
- relayParentNumber?: number | undefined;
61
61
  count?: number | undefined;
62
62
  to?: number | undefined;
63
63
  }>;
@@ -1,5 +1,5 @@
1
- import { ResponseError, zHex } from '../shared.js';
2
1
  import { z } from 'zod';
2
+ import { ResponseError, zHex } from '../shared.js';
3
3
  import { defaultLogger } from '../../logger.js';
4
4
  const schema = z.object({
5
5
  count: z.number().optional(),
@@ -1,5 +1,5 @@
1
1
  import { BuildBlockMode } from '../../blockchain/txpool.js';
2
- import { Context } from '../shared.js';
2
+ import { type Context } from '../shared.js';
3
3
  /**
4
4
  * Set block build mode.
5
5
  *
@@ -1,6 +1,6 @@
1
1
  import { BuildBlockMode } from '../../blockchain/txpool.js';
2
- import { ResponseError } from '../shared.js';
3
2
  import { defaultLogger } from '../../logger.js';
3
+ import { ResponseError } from '../shared.js';
4
4
  /**
5
5
  * Set block build mode.
6
6
  *
@@ -1,5 +1,5 @@
1
- import { Context } from '../shared.js';
2
1
  import { z } from 'zod';
2
+ import { type Context } from '../shared.js';
3
3
  declare const schema: z.ZodUnion<[z.ZodIntersection<z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>>, z.ZodNumber]>;
4
4
  type Params = z.infer<typeof schema>;
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { ResponseError, zHash } from '../shared.js';
2
1
  import { z } from 'zod';
2
+ import { ResponseError, zHash } from '../shared.js';
3
3
  const schema = zHash.or(z.number());
4
4
  /**
5
5
  * Set head.
@@ -1,4 +1,4 @@
1
- import { Context } from '../shared.js';
1
+ import { type Context } from '../shared.js';
2
2
  /**
3
3
  * Set runtime log level.
4
4
  *
@@ -1,5 +1,5 @@
1
- import { ResponseError } from '../shared.js';
2
1
  import { defaultLogger } from '../../logger.js';
2
+ import { ResponseError } from '../shared.js';
3
3
  /**
4
4
  * Set runtime log level.
5
5
  *
@@ -1,6 +1,6 @@
1
- import { Context } from '../shared.js';
2
- import { HexString } from '@polkadot/util/types';
3
- import { StorageValues } from '../../utils/set-storage.js';
1
+ import type { HexString } from '@polkadot/util/types';
2
+ import { type Context } from '../shared.js';
3
+ import { type StorageValues } from '../../utils/set-storage.js';
4
4
  /**
5
5
  * Set storage values.
6
6
  *
@@ -1,6 +1,6 @@
1
1
  import { ResponseError } from '../shared.js';
2
- import { setStorage } from '../../utils/set-storage.js';
3
2
  import { defaultLogger } from '../../logger.js';
3
+ import { setStorage } from '../../utils/set-storage.js';
4
4
  /**
5
5
  * Set storage values.
6
6
  *
@@ -1,4 +1,4 @@
1
- import { Context } from '../shared.js';
1
+ import { type Context } from '../shared.js';
2
2
  /**
3
3
  * Travel to a specific time.
4
4
  *
@@ -1,5 +1,5 @@
1
- import { ResponseError } from '../shared.js';
2
1
  import { timeTravel } from '../../utils/time-travel.js';
2
+ import { ResponseError } from '../shared.js';
3
3
  /**
4
4
  * Travel to a specific time.
5
5
  *
@@ -1,5 +1,5 @@
1
- import { Handlers } from './shared.js';
2
1
  import dev from './dev/index.js';
2
+ import type { Handlers } from './shared.js';
3
3
  import substrate from './substrate/index.js';
4
4
  export declare const allHandlers: Handlers;
5
5
  export { substrate, dev };
@@ -1,5 +1,5 @@
1
- import { Handler } from '../shared.js';
2
- import { HexString } from '@polkadot/util/types';
1
+ import type { HexString } from '@polkadot/util/types';
2
+ import { type Handler } from '../shared.js';
3
3
  /**
4
4
  * Start a chainHead follow subscription
5
5
  *
@@ -54,6 +54,15 @@ export interface StorageItemRequest {
54
54
  * @param params - [`followSubscription`, `hash`, `items`, `childTrie`]
55
55
  *
56
56
  * @return OperationStarted event with operationId to receive the result on the follow subscription
57
+ *
58
+ * The query type `closestDescendantMerkleValue` is not up to spec.
59
+ * According to the spec, the result should be the Merkle value of the key or
60
+ * the closest descendant of the key.
61
+ * As chopsticks doesn't have direct access to the Merkle tree, it will return
62
+ * a string that will change every time that one of the descendant changes, but
63
+ * it won't be the actual Merkle value.
64
+ * This should be enough for applications that don't rely on the actual Merkle
65
+ * value, but just use it to detect for storage changes.
57
66
  */
58
67
  export declare const chainHead_v1_storage: Handler<[
59
68
  string,
@@ -1,5 +1,5 @@
1
- import { ResponseError } from '../shared.js';
2
1
  import { defaultLogger } from '../../logger.js';
2
+ import { ResponseError } from '../shared.js';
3
3
  const logger = defaultLogger.child({
4
4
  name: 'rpc-chainHead_v1'
5
5
  });
@@ -47,6 +47,16 @@ async function afterResponse(fn) {
47
47
  ],
48
48
  prunedBlockHashes: []
49
49
  });
50
+ const storageDiffs = following.get(id)?.storageDiffs;
51
+ if (storageDiffs?.size) {
52
+ // Fetch the storage diffs and update the `closestDescendantMerkleValue` for those that changed
53
+ const diffKeys = Object.keys(await block.storageDiff());
54
+ for (const [prefix, value] of storageDiffs.entries()){
55
+ if (diffKeys.some((key)=>key.startsWith(prefix))) {
56
+ storageDiffs.set(prefix, value + 1);
57
+ }
58
+ }
59
+ }
50
60
  };
51
61
  const id = context.chain.headState.subscribeHead(update);
52
62
  const cleanup = ()=>{
@@ -56,7 +66,8 @@ async function afterResponse(fn) {
56
66
  const callback = subscribe('chainHead_v1_followEvent', id, cleanup);
57
67
  following.set(id, {
58
68
  callback,
59
- pendingDescendantValues: new Map()
69
+ pendingDescendantValues: new Map(),
70
+ storageDiffs: new Map()
60
71
  });
61
72
  afterResponse(async ()=>{
62
73
  callback({
@@ -165,6 +176,15 @@ async function getDescendantValues(block, params) {
165
176
  * @param params - [`followSubscription`, `hash`, `items`, `childTrie`]
166
177
  *
167
178
  * @return OperationStarted event with operationId to receive the result on the follow subscription
179
+ *
180
+ * The query type `closestDescendantMerkleValue` is not up to spec.
181
+ * According to the spec, the result should be the Merkle value of the key or
182
+ * the closest descendant of the key.
183
+ * As chopsticks doesn't have direct access to the Merkle tree, it will return
184
+ * a string that will change every time that one of the descendant changes, but
185
+ * it won't be the actual Merkle value.
186
+ * This should be enough for applications that don't rely on the actual Merkle
187
+ * value, but just use it to detect for storage changes.
168
188
  */ export const chainHead_v1_storage = async (context, [followSubscription, hash, items, _childTrie])=>{
169
189
  const operationId = randomId();
170
190
  afterResponse(async ()=>{
@@ -209,6 +229,26 @@ async function getDescendantValues(block, params) {
209
229
  });
210
230
  return next;
211
231
  }
232
+ case 'closestDescendantMerkleValue':
233
+ {
234
+ const followingSubscription = following.get(followSubscription);
235
+ if (!followingSubscription) return null;
236
+ if (!followingSubscription.storageDiffs.has(sir.key)) {
237
+ // Set up a diff watch for this key
238
+ followingSubscription.storageDiffs.set(sir.key, 0);
239
+ }
240
+ followingSubscription.callback({
241
+ event: 'operationStorageItems',
242
+ operationId,
243
+ items: [
244
+ {
245
+ key: sir.key,
246
+ closestDescendantMerkleValue: String(followingSubscription.storageDiffs.get(sir.key))
247
+ }
248
+ ]
249
+ });
250
+ return null;
251
+ }
212
252
  default:
213
253
  // TODO
214
254
  console.warn(`Storage type not implemented ${sir.type}`);
@@ -1,6 +1,6 @@
1
- import { ChainProperties } from '../../index.js';
2
- import { Handler } from '../shared.js';
3
- import { HexString } from '@polkadot/util/types';
1
+ import type { HexString } from '@polkadot/util/types';
2
+ import type { ChainProperties } from '../../index.js';
3
+ import { type Handler } from '../shared.js';
4
4
  export declare const chainSpec_v1_chainName: Handler<[], string>;
5
5
  export declare const chainSpec_v1_genesisHash: Handler<[], HexString>;
6
6
  export declare const chainSpec_v1_properties: Handler<[], ChainProperties>;
@@ -1,5 +1,5 @@
1
- import { Handler } from '../shared.js';
2
- import { HexString } from '@polkadot/util/types';
1
+ import type { HexString } from '@polkadot/util/types';
2
+ import type { Handler } from '../shared.js';
3
3
  /**
4
4
  * Submit the extrinsic to the transaction pool
5
5
  *
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { Blockchain } from '../blockchain/index.js';
2
+ import type { Blockchain } from '../blockchain/index.js';
3
3
  export declare const logger: import("pino").default.Logger<never, boolean>;
4
4
  export declare const zHex: z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>;
5
5
  export declare const zHash: z.ZodIntersection<z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>>;
@@ -1,5 +1,5 @@
1
- import { HexString } from '@polkadot/util/types';
2
- import { Handler } from '../shared.js';
1
+ import type { HexString } from '@polkadot/util/types';
2
+ import { type Handler } from '../shared.js';
3
3
  /**
4
4
  * @param context
5
5
  * @param params - [`blockhash`]
@@ -1,5 +1,5 @@
1
- import { HexString } from '@polkadot/util/types';
2
- import { Handler } from '../shared.js';
1
+ import type { HexString } from '@polkadot/util/types';
2
+ import { type Handler } from '../shared.js';
3
3
  /**
4
4
  * @param context
5
5
  * @param params - [`extrinsic`]
@@ -1,6 +1,6 @@
1
1
  import { APPLY_EXTRINSIC_ERROR } from '../../blockchain/txpool.js';
2
- import { ResponseError } from '../shared.js';
3
2
  import { defaultLogger } from '../../logger.js';
3
+ import { ResponseError } from '../shared.js';
4
4
  const logger = defaultLogger.child({
5
5
  name: 'rpc-author'
6
6
  });
@@ -1,6 +1,6 @@
1
- import { HexString } from '@polkadot/util/types';
2
- import { Handler } from '../shared.js';
1
+ import type { HexString } from '@polkadot/util/types';
3
2
  import type { Header } from '../../index.js';
3
+ import { type Handler } from '../shared.js';
4
4
  /**
5
5
  * @param context
6
6
  * @param params - [`blockNumber` | `blockNumber[]` | null]
@@ -1,5 +1,5 @@
1
- import { HexString } from '@polkadot/util/types';
2
- import { Handler } from '../shared.js';
1
+ import type { HexString } from '@polkadot/util/types';
2
+ import { type Handler } from '../shared.js';
3
3
  /**
4
4
  * @param context
5
5
  * @param params - [`extrinsic`, `blockhash`]
@@ -1,6 +1,6 @@
1
- import { HexString } from '@polkadot/util/types';
2
- import { Handler } from '../shared.js';
3
- import { RuntimeVersion } from '../../wasm-executor/index.js';
1
+ import type { HexString } from '@polkadot/util/types';
2
+ import type { RuntimeVersion } from '../../wasm-executor/index.js';
3
+ import { type Handler } from '../shared.js';
4
4
  /**
5
5
  * @param context
6
6
  * @param params - [`blockhash`]
@@ -1,7 +1,7 @@
1
1
  import { stringToHex } from '@polkadot/util';
2
- import { ResponseError } from '../shared.js';
3
2
  import { defaultLogger } from '../../logger.js';
4
3
  import { isPrefixedChildKey, prefixedChildKey, stripChildPrefix } from '../../utils/index.js';
4
+ import { ResponseError } from '../shared.js';
5
5
  const logger = defaultLogger.child({
6
6
  name: 'rpc-state'
7
7
  });
@@ -1,6 +1,6 @@
1
- import { HexString } from '@polkadot/util/types';
2
- import { ChainProperties } from '../../index.js';
3
- import { Handler } from '../shared.js';
1
+ import type { HexString } from '@polkadot/util/types';
2
+ import type { ChainProperties } from '../../index.js';
3
+ import type { Handler } from '../shared.js';
4
4
  export declare const system_localPeerId: () => Promise<string>;
5
5
  export declare const system_nodeRoles: () => Promise<string[]>;
6
6
  export declare const system_localListenAddresses: () => Promise<never[]>;
@@ -1,10 +1,10 @@
1
1
  import '@polkadot/types-codec';
2
- import { RegisteredTypes } from '@polkadot/types/types';
2
+ import type { RegisteredTypes } from '@polkadot/types/types';
3
3
  import { Api } from './api.js';
4
4
  import { Blockchain } from './blockchain/index.js';
5
- import { BuildBlockMode } from './blockchain/txpool.js';
6
- import { Database } from './database.js';
7
- import { GenesisProvider } from './genesis-provider.js';
5
+ import type { BuildBlockMode } from './blockchain/txpool.js';
6
+ import type { Database } from './database.js';
7
+ import type { GenesisProvider } from './genesis-provider.js';
8
8
  export type SetupOptions = {
9
9
  endpoint?: string | string[];
10
10
  block?: string | number | null;
package/dist/esm/setup.js CHANGED
@@ -2,8 +2,8 @@ import '@polkadot/types-codec';
2
2
  import { HttpProvider, WsProvider } from '@polkadot/rpc-provider';
3
3
  import { Api } from './api.js';
4
4
  import { Blockchain } from './blockchain/index.js';
5
- import { defaultLogger } from './logger.js';
6
5
  import { inherentProviders } from './blockchain/inherent/index.js';
6
+ import { defaultLogger } from './logger.js';
7
7
  export const processOptions = async (options)=>{
8
8
  defaultLogger.debug(options, 'Setup options');
9
9
  let provider;
@@ -1,9 +1,9 @@
1
1
  import '@polkadot/types-codec';
2
- import { Block } from '../blockchain/block.js';
3
- import { DecoratedMeta } from '@polkadot/types/metadata/decorate/types';
4
- import { HexString } from '@polkadot/util/types';
5
- import { StorageEntry } from '@polkadot/types/primitive/types';
6
- import { StorageKey } from '@polkadot/types';
2
+ import type { StorageKey } from '@polkadot/types';
3
+ import type { DecoratedMeta } from '@polkadot/types/metadata/decorate/types';
4
+ import type { StorageEntry } from '@polkadot/types/primitive/types';
5
+ import type { HexString } from '@polkadot/util/types';
6
+ import type { Block } from '../blockchain/block.js';
7
7
  export declare const decodeKey: (meta: DecoratedMeta, key: HexString) => {
8
8
  storage?: StorageEntry;
9
9
  decodedKey?: StorageKey;
@@ -1,9 +1,9 @@
1
1
  import '@polkadot/types-codec';
2
- import { LRUCache } from 'lru-cache';
3
2
  import { hexToU8a, u8aToHex } from '@polkadot/util';
4
3
  import _ from 'lodash';
5
- import { decodeWellKnownKey } from './well-known-keys.js';
4
+ import { LRUCache } from 'lru-cache';
6
5
  import { defaultLogger } from '../logger.js';
6
+ import { decodeWellKnownKey } from './well-known-keys.js';
7
7
  const logger = defaultLogger.child({
8
8
  name: 'decoder'
9
9
  });
@@ -1,7 +1,7 @@
1
- import { HexString } from '@polkadot/util/types';
2
- import { StorageKey } from '@polkadot/types';
3
- import { Block } from '../blockchain/block.js';
4
- import { Blockchain } from '../blockchain/index.js';
1
+ import type { StorageKey } from '@polkadot/types';
2
+ import type { HexString } from '@polkadot/util/types';
3
+ import type { Block } from '../blockchain/block.js';
4
+ import type { Blockchain } from '../blockchain/index.js';
5
5
  export * from './set-storage.js';
6
6
  export * from './time-travel.js';
7
7
  export * from './decoder.js';
@@ -1,6 +1,6 @@
1
1
  import { compactStripLength, u8aToHex } from '@polkadot/util';
2
- import { getAuraSlotDuration } from '../wasm-executor/index.js';
3
2
  import { hexAddPrefix, hexStripPrefix } from '@polkadot/util/hex';
3
+ import { getAuraSlotDuration } from '../wasm-executor/index.js';
4
4
  export * from './set-storage.js';
5
5
  export * from './time-travel.js';
6
6
  export * from './decoder.js';
@@ -1,4 +1,4 @@
1
- import { HexString } from '@polkadot/util/types';
1
+ import type { HexString } from '@polkadot/util/types';
2
2
  export default class KeyCache {
3
3
  readonly prefixLength: number;
4
4
  constructor(prefixLength: number);
@@ -1,6 +1,6 @@
1
- import { HexString } from '@polkadot/util/types';
2
- import { HrmpChannelId } from '@polkadot/types/interfaces';
3
- import { u32 } from '@polkadot/types';
1
+ import type { u32 } from '@polkadot/types';
2
+ import type { HrmpChannelId } from '@polkadot/types/interfaces';
3
+ import type { HexString } from '@polkadot/util/types';
4
4
  export declare const WELL_KNOWN_KEYS: {
5
5
  EPOCH_INDEX: HexString;
6
6
  CURRENT_BLOCK_RANDOMNESS: HexString;
@@ -1,5 +1,5 @@
1
- import { HexString } from '@polkadot/util/types';
2
- import { Blockchain } from '../blockchain/index.js';
1
+ import type { HexString } from '@polkadot/util/types';
2
+ import type { Blockchain } from '../blockchain/index.js';
3
3
  type RawStorageValues = [string, string | null][];
4
4
  type StorageConfig = Record<string, Record<string, any>>;
5
5
  export type StorageValues = RawStorageValues | StorageConfig;
@@ -1,6 +1,6 @@
1
1
  import { StorageKey } from '@polkadot/types';
2
- import { stringCamelCase } from '@polkadot/util/string';
3
2
  import { u8aToHex } from '@polkadot/util';
3
+ import { stringCamelCase } from '@polkadot/util/string';
4
4
  import { StorageValueKind } from '../blockchain/storage-layer.js';
5
5
  function objectToStorageItems(meta, storage) {
6
6
  const storageItems = [];
@@ -1,2 +1,2 @@
1
- import { Blockchain } from '../blockchain/index.js';
1
+ import type { Blockchain } from '../blockchain/index.js';
2
2
  export declare const timeTravel: (chain: Blockchain, timestamp: number) => Promise<void>;
@@ -1,5 +1,5 @@
1
- import { HexString } from '@polkadot/util/types';
2
- import { Registry } from '@polkadot/types-codec/types';
1
+ import type { Registry } from '@polkadot/types-codec/types';
2
+ import type { HexString } from '@polkadot/util/types';
3
3
  export declare const decodeWellKnownKey: (registry: Registry, key: HexString, value?: HexString | null) => {
4
4
  name: string;
5
5
  key: any[];
@@ -1,5 +1,5 @@
1
- import { blake2AsHex } from '@polkadot/util-crypto';
2
1
  import { hexToU8a, stringToHex } from '@polkadot/util';
2
+ import { blake2AsHex } from '@polkadot/util-crypto';
3
3
  const decodeValue = (type)=>(registry, value)=>{
4
4
  return registry.createType(type, hexToU8a(value)).toJSON();
5
5
  };
@@ -52,7 +52,7 @@ const wellKnownKeys = [
52
52
  prefixHex: '0xf5207f03cfdce586301014700e2c2593fad157e461d71fd4c1f936839a5f1f3e',
53
53
  decodeKey: (registry, key)=>{
54
54
  // get last 4 bytes
55
- const last4Bytes = '0x' + key.slice(-8);
55
+ const last4Bytes = `0x${key.slice(-8)}`;
56
56
  return [
57
57
  registry.createType('u32', hexToU8a(last4Bytes)).toJSON()
58
58
  ];
@@ -1,5 +1,5 @@
1
- import * as Comlink from 'comlink';
2
1
  import * as pkg from '@acala-network/chopsticks-executor';
2
+ import * as Comlink from 'comlink';
3
3
  const getRuntimeVersion = async (code)=>{
4
4
  return pkg.get_runtime_version(code);
5
5
  };
@@ -1,9 +1,9 @@
1
+ import type { HexString } from '@polkadot/util/types';
1
2
  import * as Comlink from 'comlink';
2
- import { HexString } from '@polkadot/util/types';
3
3
  import _ from 'lodash';
4
- import { Block } from '../blockchain/block.js';
4
+ import type { Block } from '../blockchain/block.js';
5
5
  import type { JsCallback } from '@acala-network/chopsticks-executor';
6
- export { JsCallback };
6
+ export type { JsCallback };
7
7
  export type RuntimeVersion = {
8
8
  specName: string;
9
9
  implName: string;
@@ -1,9 +1,9 @@
1
- import * as Comlink from 'comlink';
2
1
  import { hexToString, hexToU8a, u8aToBn } from '@polkadot/util';
3
2
  import { randomAsHex } from '@polkadot/util-crypto';
3
+ import * as Comlink from 'comlink';
4
4
  import _ from 'lodash';
5
- import { PREFIX_LENGTH, stripChildPrefix } from '../utils/index.js';
6
5
  import { defaultLogger, truncate } from '../logger.js';
6
+ import { PREFIX_LENGTH, stripChildPrefix } from '../utils/index.js';
7
7
  const logger = defaultLogger.child({
8
8
  name: 'executor'
9
9
  });
@@ -67,10 +67,8 @@ export const runTask = async (task, callback = emptyTaskHandler)=>{
67
67
  };
68
68
  export const taskHandler = (block)=>{
69
69
  return {
70
- getStorage: async function(key) {
71
- return block.get(key);
72
- },
73
- getNextKey: async function(prefix, key) {
70
+ getStorage: async (key)=>block.get(key),
71
+ getNextKey: async (prefix, key)=>{
74
72
  const [nextKey] = await block.getKeysPaged({
75
73
  prefix: prefix.length === 2 /** 0x */ ? key.slice(0, PREFIX_LENGTH) : prefix,
76
74
  pageSize: 1,
@@ -78,17 +76,13 @@ export const taskHandler = (block)=>{
78
76
  });
79
77
  return nextKey && stripChildPrefix(nextKey);
80
78
  },
81
- offchainGetStorage: async function(key) {
79
+ offchainGetStorage: async (key)=>{
82
80
  if (!block.chain.offchainWorker) throw new Error('offchain worker not found');
83
81
  return block.chain.offchainWorker.get(key);
84
82
  },
85
- offchainTimestamp: async function() {
86
- return Date.now();
87
- },
88
- offchainRandomSeed: async function() {
89
- return randomAsHex(32);
90
- },
91
- offchainSubmitTransaction: async function(tx) {
83
+ offchainTimestamp: async ()=>Date.now(),
84
+ offchainRandomSeed: async ()=>randomAsHex(32),
85
+ offchainSubmitTransaction: async (tx)=>{
92
86
  if (!block.chain.offchainWorker) throw new Error('offchain worker not found');
93
87
  try {
94
88
  const hash = await block.chain.offchainWorker.pushExtrinsic(block, tx);
@@ -106,22 +100,22 @@ export const taskHandler = (block)=>{
106
100
  };
107
101
  };
108
102
  export const emptyTaskHandler = {
109
- getStorage: async function(_key) {
103
+ getStorage: async (_key)=>{
110
104
  throw new Error('Method not implemented');
111
105
  },
112
- getNextKey: async function(_prefix, _key) {
106
+ getNextKey: async (_prefix, _key)=>{
113
107
  throw new Error('Method not implemented');
114
108
  },
115
- offchainGetStorage: async function(_key) {
109
+ offchainGetStorage: async (_key)=>{
116
110
  throw new Error('Method not implemented');
117
111
  },
118
- offchainTimestamp: async function() {
112
+ offchainTimestamp: async ()=>{
119
113
  throw new Error('Method not implemented');
120
114
  },
121
- offchainRandomSeed: async function() {
115
+ offchainRandomSeed: async ()=>{
122
116
  throw new Error('Method not implemented');
123
117
  },
124
- offchainSubmitTransaction: async function(_tx) {
118
+ offchainSubmitTransaction: async (_tx)=>{
125
119
  throw new Error('Method not implemented');
126
120
  }
127
121
  };
@@ -1,5 +1,5 @@
1
- import * as Comlink from 'comlink';
2
1
  import * as pkg from '@acala-network/chopsticks-executor';
2
+ import * as Comlink from 'comlink';
3
3
  import { parentPort } from 'node:worker_threads';
4
4
  import nodeEndpoint from 'comlink/dist/umd/node-adapter.js';
5
5
  const getRuntimeVersion = async (code)=>{
@@ -1,6 +1,6 @@
1
+ import threads from 'node:worker_threads';
1
2
  import { wrap } from 'comlink';
2
3
  import nodeEndpoint from 'comlink/dist/umd/node-adapter.js';
3
- import threads from 'node:worker_threads';
4
4
  export const startWorker = async ()=>{
5
5
  const worker = new threads.Worker(new URL('node-wasm-executor.js', import.meta.url), {
6
6
  name: 'chopsticks-wasm-executor'
@@ -1,2 +1,2 @@
1
- import { Blockchain } from '../blockchain/index.js';
1
+ import type { Blockchain } from '../blockchain/index.js';
2
2
  export declare const connectDownward: (relaychain: Blockchain, parachain: Blockchain) => Promise<void>;
@@ -1,2 +1,2 @@
1
- import { Blockchain } from '../blockchain/index.js';
1
+ import type { Blockchain } from '../blockchain/index.js';
2
2
  export declare const connectHorizontal: (parachains: Record<number, Blockchain>, disableAutoHrmp?: boolean) => Promise<void>;
@@ -1,4 +1,4 @@
1
- import { Blockchain } from '../blockchain/index.js';
1
+ import type { Blockchain } from '../blockchain/index.js';
2
2
  export declare const xcmLogger: import("pino").default.Logger<never, boolean>;
3
3
  export declare const connectVertical: (relaychain: Blockchain, parachain: Blockchain) => Promise<void>;
4
4
  export declare const connectParachains: (parachains: Blockchain[], disableAutoHrmp?: boolean) => Promise<void>;