@acala-network/chopsticks-core 1.2.0 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,11 @@
1
1
  import { blake2AsHex } from '@polkadot/util-crypto';
2
2
  import { defaultLogger } from '../../logger.js';
3
3
  import { ResponseError } from '../shared.js';
4
+ import { afterResponse, getDescendantValues } from './storage-common.js';
4
5
  const logger = defaultLogger.child({
5
6
  name: 'rpc-chainHead_v1'
6
7
  });
7
8
  const following = new Map();
8
- async function afterResponse(fn) {
9
- await new Promise((resolve)=>setTimeout(resolve, 0));
10
- fn();
11
- }
12
9
  /**
13
10
  * Start a chainHead follow subscription
14
11
  *
@@ -146,30 +143,6 @@ const randomId = ()=>Math.random().toString(36).substring(2);
146
143
  });
147
144
  return operationStarted(operationId);
148
145
  };
149
- const PAGE_SIZE = 1000;
150
- async function getDescendantValues(block, params) {
151
- const keys = await block.getKeysPaged({
152
- ...params,
153
- pageSize: PAGE_SIZE
154
- });
155
- const items = await Promise.all(keys.map((key)=>block.get(key).then((value)=>({
156
- key,
157
- value
158
- }))));
159
- if (keys.length < PAGE_SIZE) {
160
- return {
161
- items,
162
- next: null
163
- };
164
- }
165
- return {
166
- items,
167
- next: {
168
- ...params,
169
- startKey: keys[PAGE_SIZE - 1]
170
- }
171
- };
172
- }
173
146
  /**
174
147
  * Query the storage for a given block
175
148
  *
@@ -1,3 +1,4 @@
1
+ import * as ArchiveV1RPC from './archive_v1.js';
1
2
  import * as ChainHeadV1RPC from './chainHead_v1.js';
2
3
  import * as ChainSpecV1RPC from './chainSpec_v1.js';
3
4
  import * as TransactionV1RPC from './transaction_v1.js';
@@ -23,5 +24,13 @@ declare const handlers: {
23
24
  chainHead_v1_continue: import("../shared.js").Handler<[string, import("@polkadot/util/types").HexString], null>;
24
25
  chainHead_v1_stopOperation: import("../shared.js").Handler<[string, import("@polkadot/util/types").HexString], null>;
25
26
  chainHead_v1_unpin: import("../shared.js").Handler<[string, import("@polkadot/util/types").HexString | import("@polkadot/util/types").HexString[]], null>;
27
+ archive_v1_body: import("../shared.js").Handler<[import("@polkadot/util/types").HexString], import("@polkadot/util/types").HexString[] | null>;
28
+ archive_v1_call: import("../shared.js").Handler<[import("@polkadot/util/types").HexString, string, import("@polkadot/util/types").HexString], ArchiveV1RPC.CallResult | null>;
29
+ archive_v1_finalizedHeight: import("../shared.js").Handler<undefined, number>;
30
+ archive_v1_genesisHash: import("../shared.js").Handler<undefined, import("@polkadot/util/types").HexString>;
31
+ archive_v1_hashByHeight: import("../shared.js").Handler<[number], import("@polkadot/util/types").HexString[]>;
32
+ archive_v1_header: import("../shared.js").Handler<[import("@polkadot/util/types").HexString], import("@polkadot/util/types").HexString | null>;
33
+ archive_v1_storage: import("../shared.js").Handler<[import("@polkadot/util/types").HexString, ChainHeadV1RPC.StorageItemRequest[], import("@polkadot/util/types").HexString | null], string>;
34
+ archive_v1_stopStorage: import("../shared.js").Handler<[string], null>;
26
35
  };
27
36
  export default handlers;
@@ -1,8 +1,10 @@
1
+ import * as ArchiveV1RPC from './archive_v1.js';
1
2
  import * as ChainHeadV1RPC from './chainHead_v1.js';
2
3
  import * as ChainSpecV1RPC from './chainSpec_v1.js';
3
4
  import * as TransactionV1RPC from './transaction_v1.js';
4
5
  export { ChainHeadV1RPC, TransactionV1RPC, ChainSpecV1RPC };
5
6
  const handlers = {
7
+ ...ArchiveV1RPC,
6
8
  ...ChainHeadV1RPC,
7
9
  ...TransactionV1RPC,
8
10
  ...ChainSpecV1RPC
@@ -0,0 +1,16 @@
1
+ import type { HexString } from '@polkadot/util/types';
2
+ import type { Block } from '../../blockchain/block.js';
3
+ export declare function getDescendantValues(block: Block, params: DescendantValuesParams): Promise<{
4
+ items: Array<{
5
+ key: string;
6
+ value?: HexString;
7
+ }>;
8
+ next: DescendantValuesParams | null;
9
+ }>;
10
+ export declare const PAGE_SIZE = 1000;
11
+ export type DescendantValuesParams = {
12
+ prefix: string;
13
+ startKey: string;
14
+ isDescendantHashes?: boolean;
15
+ };
16
+ export declare function afterResponse(fn: () => void): Promise<void>;
@@ -0,0 +1,28 @@
1
+ export async function getDescendantValues(block, params) {
2
+ const keys = await block.getKeysPaged({
3
+ ...params,
4
+ pageSize: PAGE_SIZE
5
+ });
6
+ const items = (await block.getMany(keys)).map((value, idx)=>({
7
+ key: keys[idx],
8
+ value
9
+ }));
10
+ if (keys.length < PAGE_SIZE) {
11
+ return {
12
+ items,
13
+ next: null
14
+ };
15
+ }
16
+ return {
17
+ items,
18
+ next: {
19
+ ...params,
20
+ startKey: keys[PAGE_SIZE - 1]
21
+ }
22
+ };
23
+ }
24
+ export const PAGE_SIZE = 1000;
25
+ export async function afterResponse(fn) {
26
+ await new Promise((resolve)=>setTimeout(resolve, 0));
27
+ fn();
28
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acala-network/chopsticks-core",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "author": "Acala Developers <hello@acala.network>",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -14,7 +14,7 @@
14
14
  "depcheck": "npx depcheck"
15
15
  },
16
16
  "dependencies": {
17
- "@acala-network/chopsticks-executor": "1.2.0",
17
+ "@acala-network/chopsticks-executor": "1.2.2",
18
18
  "@polkadot/rpc-provider": "^16.4.1",
19
19
  "@polkadot/types": "^16.4.1",
20
20
  "@polkadot/types-codec": "^16.4.1",
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "devDependencies": {
34
34
  "@swc/cli": "0.7.8",
35
- "@swc/core": "^1.12.11",
35
+ "@swc/core": "^1.12.14",
36
36
  "@types/lodash": "^4.17.20",
37
37
  "typescript": "^5.8.3",
38
38
  "vitest": "^3.2.4"