@acala-network/chopsticks-core 1.0.3 → 1.0.4

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.
package/dist/cjs/api.d.ts CHANGED
@@ -32,7 +32,7 @@ export declare class Api {
32
32
  getFinalizedHead(): Promise<string>;
33
33
  getBlock(hash?: string): Promise<SignedBlock | null>;
34
34
  getStorage(key: string, hash?: string): Promise<`0x${string}` | null>;
35
- getKeysPaged(prefix: string, pageSize: number, startKey: string, hash?: string): Promise<string[]>;
35
+ getKeysPaged(prefix: string, pageSize: number, startKey: string, hash?: string): Promise<`0x${string}`[]>;
36
36
  getStorageBatch(prefix: HexString, keys: HexString[], hash?: HexString): Promise<[`0x${string}`, `0x${string}` | null][]>;
37
37
  subscribeRemoteNewHeads(cb: ProviderInterfaceCallback): Promise<string | number>;
38
38
  subscribeRemoteFinalizedHeads(cb: ProviderInterfaceCallback): Promise<string | number>;
@@ -1,3 +1,4 @@
1
+ import type { HexString } from '@polkadot/util/types';
1
2
  import type { Api } from '../api.js';
2
3
  import type { Database } from '../database.js';
3
4
  export declare enum StorageValueKind {
@@ -21,7 +22,7 @@ export interface StorageLayerProvider {
21
22
  }
22
23
  export declare class RemoteStorageLayer implements StorageLayerProvider {
23
24
  #private;
24
- constructor(api: Api, at: string, db: Database | undefined);
25
+ constructor(api: Api, at: HexString, db: Database | undefined);
25
26
  get(key: string, _cache: boolean): Promise<StorageValue>;
26
27
  findNextKey(prefix: string, startKey: string, _knownBest?: string): Promise<string | undefined>;
27
28
  getKeysPaged(prefix: string, pageSize: number, startKey: string): Promise<string[]>;
@@ -156,12 +156,23 @@ class RemoteStorageLayer {
156
156
  break;
157
157
  }
158
158
  if (_class_private_field_get(this, _db)) {
159
- // batch fetch storage values and save to db, they may be used later
160
- _class_private_field_get(this, _api).getStorageBatch(prefix, batch, _class_private_field_get(this, _at)).then((storage)=>{
161
- for (const [key, value] of storage){
162
- _class_private_field_get(this, _db)?.saveStorage(_class_private_field_get(this, _at), key, value);
159
+ // filter out keys that are not in the db]
160
+ const newBatch = [];
161
+ for (const key of batch){
162
+ const res = await _class_private_field_get(this, _db).queryStorage(_class_private_field_get(this, _at), key);
163
+ if (res) {
164
+ continue;
163
165
  }
164
- });
166
+ newBatch.push(key);
167
+ }
168
+ if (newBatch.length > 0) {
169
+ // batch fetch storage values and save to db, they may be used later
170
+ _class_private_field_get(this, _api).getStorageBatch(prefix, newBatch, _class_private_field_get(this, _at)).then((storage)=>{
171
+ for (const [key, value] of storage){
172
+ _class_private_field_get(this, _db)?.saveStorage(_class_private_field_get(this, _at), key, value);
173
+ }
174
+ });
175
+ }
165
176
  }
166
177
  }
167
178
  return keysPaged;
@@ -18,6 +18,7 @@ export type SetupOptions = {
18
18
  offchainWorker?: boolean;
19
19
  maxMemoryBlockCount?: number;
20
20
  processQueuedMessages?: boolean;
21
+ rpcTimeout?: number;
21
22
  hooks?: {
22
23
  apiFetching?: () => void;
23
24
  };
@@ -37,6 +38,7 @@ export declare const processOptions: (options: SetupOptions) => Promise<{
37
38
  offchainWorker?: boolean;
38
39
  maxMemoryBlockCount?: number;
39
40
  processQueuedMessages?: boolean;
41
+ rpcTimeout?: number;
40
42
  hooks?: {
41
43
  apiFetching?: () => void;
42
44
  };
package/dist/cjs/setup.js CHANGED
@@ -30,7 +30,7 @@ const processOptions = async (options)=>{
30
30
  } else if (typeof options.endpoint === 'string' && /^(https|http):\/\//.test(options.endpoint || '')) {
31
31
  provider = new _rpcprovider.HttpProvider(options.endpoint);
32
32
  } else {
33
- provider = new _rpcprovider.WsProvider(options.endpoint, 3_000);
33
+ provider = new _rpcprovider.WsProvider(options.endpoint, 3_000, undefined, options.rpcTimeout);
34
34
  }
35
35
  const api = new _api.Api(provider);
36
36
  // setup api hooks
@@ -20,7 +20,7 @@ export type Deferred<T> = {
20
20
  export declare function defer<T>(): Deferred<T>;
21
21
  export declare const CHILD_PREFIX_LENGTH: number;
22
22
  export declare const PREFIX_LENGTH = 66;
23
- export declare const prefixedChildKey: (prefix: HexString, key: HexString) => string;
23
+ export declare const prefixedChildKey: (prefix: HexString, key: HexString) => HexString;
24
24
  export declare const isPrefixedChildKey: (key: HexString) => boolean;
25
25
  export declare const splitChildKey: (key: HexString) => [`0x${string}`, `0x${string}`] | never[];
26
26
  export declare const stripChildPrefix: (key: HexString) => `0x${string}`;
package/dist/esm/api.d.ts CHANGED
@@ -32,7 +32,7 @@ export declare class Api {
32
32
  getFinalizedHead(): Promise<string>;
33
33
  getBlock(hash?: string): Promise<SignedBlock | null>;
34
34
  getStorage(key: string, hash?: string): Promise<`0x${string}` | null>;
35
- getKeysPaged(prefix: string, pageSize: number, startKey: string, hash?: string): Promise<string[]>;
35
+ getKeysPaged(prefix: string, pageSize: number, startKey: string, hash?: string): Promise<`0x${string}`[]>;
36
36
  getStorageBatch(prefix: HexString, keys: HexString[], hash?: HexString): Promise<[`0x${string}`, `0x${string}` | null][]>;
37
37
  subscribeRemoteNewHeads(cb: ProviderInterfaceCallback): Promise<string | number>;
38
38
  subscribeRemoteFinalizedHeads(cb: ProviderInterfaceCallback): Promise<string | number>;
@@ -1,3 +1,4 @@
1
+ import type { HexString } from '@polkadot/util/types';
1
2
  import type { Api } from '../api.js';
2
3
  import type { Database } from '../database.js';
3
4
  export declare enum StorageValueKind {
@@ -21,7 +22,7 @@ export interface StorageLayerProvider {
21
22
  }
22
23
  export declare class RemoteStorageLayer implements StorageLayerProvider {
23
24
  #private;
24
- constructor(api: Api, at: string, db: Database | undefined);
25
+ constructor(api: Api, at: HexString, db: Database | undefined);
25
26
  get(key: string, _cache: boolean): Promise<StorageValue>;
26
27
  findNextKey(prefix: string, startKey: string, _knownBest?: string): Promise<string | undefined>;
27
28
  getKeysPaged(prefix: string, pageSize: number, startKey: string): Promise<string[]>;
@@ -89,12 +89,23 @@ export class RemoteStorageLayer {
89
89
  break;
90
90
  }
91
91
  if (this.#db) {
92
- // batch fetch storage values and save to db, they may be used later
93
- this.#api.getStorageBatch(prefix, batch, this.#at).then((storage)=>{
94
- for (const [key, value] of storage){
95
- this.#db?.saveStorage(this.#at, key, value);
92
+ // filter out keys that are not in the db]
93
+ const newBatch = [];
94
+ for (const key of batch){
95
+ const res = await this.#db.queryStorage(this.#at, key);
96
+ if (res) {
97
+ continue;
96
98
  }
97
- });
99
+ newBatch.push(key);
100
+ }
101
+ if (newBatch.length > 0) {
102
+ // batch fetch storage values and save to db, they may be used later
103
+ this.#api.getStorageBatch(prefix, newBatch, this.#at).then((storage)=>{
104
+ for (const [key, value] of storage){
105
+ this.#db?.saveStorage(this.#at, key, value);
106
+ }
107
+ });
108
+ }
98
109
  }
99
110
  }
100
111
  return keysPaged;
@@ -18,6 +18,7 @@ export type SetupOptions = {
18
18
  offchainWorker?: boolean;
19
19
  maxMemoryBlockCount?: number;
20
20
  processQueuedMessages?: boolean;
21
+ rpcTimeout?: number;
21
22
  hooks?: {
22
23
  apiFetching?: () => void;
23
24
  };
@@ -37,6 +38,7 @@ export declare const processOptions: (options: SetupOptions) => Promise<{
37
38
  offchainWorker?: boolean;
38
39
  maxMemoryBlockCount?: number;
39
40
  processQueuedMessages?: boolean;
41
+ rpcTimeout?: number;
40
42
  hooks?: {
41
43
  apiFetching?: () => void;
42
44
  };
package/dist/esm/setup.js CHANGED
@@ -12,7 +12,7 @@ export const processOptions = async (options)=>{
12
12
  } else if (typeof options.endpoint === 'string' && /^(https|http):\/\//.test(options.endpoint || '')) {
13
13
  provider = new HttpProvider(options.endpoint);
14
14
  } else {
15
- provider = new WsProvider(options.endpoint, 3_000);
15
+ provider = new WsProvider(options.endpoint, 3_000, undefined, options.rpcTimeout);
16
16
  }
17
17
  const api = new Api(provider);
18
18
  // setup api hooks
@@ -20,7 +20,7 @@ export type Deferred<T> = {
20
20
  export declare function defer<T>(): Deferred<T>;
21
21
  export declare const CHILD_PREFIX_LENGTH: number;
22
22
  export declare const PREFIX_LENGTH = 66;
23
- export declare const prefixedChildKey: (prefix: HexString, key: HexString) => string;
23
+ export declare const prefixedChildKey: (prefix: HexString, key: HexString) => HexString;
24
24
  export declare const isPrefixedChildKey: (key: HexString) => boolean;
25
25
  export declare const splitChildKey: (key: HexString) => [`0x${string}`, `0x${string}`] | never[];
26
26
  export declare const stripChildPrefix: (key: HexString) => `0x${string}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acala-network/chopsticks-core",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
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.0.3",
17
+ "@acala-network/chopsticks-executor": "1.0.4",
18
18
  "@polkadot/rpc-provider": "^15.7.1",
19
19
  "@polkadot/types": "^15.7.1",
20
20
  "@polkadot/types-codec": "^15.7.1",