@acala-network/chopsticks-core 1.0.3 → 1.0.5-1
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 +1 -1
- package/dist/cjs/blockchain/storage-layer.d.ts +2 -1
- package/dist/cjs/blockchain/storage-layer.js +16 -5
- package/dist/cjs/setup.d.ts +2 -0
- package/dist/cjs/setup.js +1 -1
- package/dist/cjs/utils/index.d.ts +1 -1
- package/dist/cjs/wasm-executor/index.js +6 -3
- package/dist/esm/api.d.ts +1 -1
- package/dist/esm/blockchain/storage-layer.d.ts +2 -1
- package/dist/esm/blockchain/storage-layer.js +16 -5
- package/dist/esm/setup.d.ts +2 -0
- package/dist/esm/setup.js +1 -1
- package/dist/esm/utils/index.d.ts +1 -1
- package/dist/esm/wasm-executor/index.js +6 -3
- package/package.json +2 -2
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
|
|
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:
|
|
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
|
-
//
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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;
|
package/dist/cjs/setup.d.ts
CHANGED
|
@@ -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) =>
|
|
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}`;
|
|
@@ -135,20 +135,23 @@ const createProof = async (nodes, updates)=>{
|
|
|
135
135
|
nodes: newNodes
|
|
136
136
|
};
|
|
137
137
|
};
|
|
138
|
+
let nextTaskId = 0;
|
|
138
139
|
const runTask = async (task, callback = emptyTaskHandler)=>{
|
|
140
|
+
const taskId = nextTaskId++;
|
|
139
141
|
const task2 = {
|
|
140
142
|
...task,
|
|
143
|
+
id: taskId,
|
|
141
144
|
storageProofSize: task.storageProofSize ?? 0
|
|
142
145
|
};
|
|
143
146
|
const worker = await getWorker();
|
|
144
|
-
logger.trace((0, _logger.truncate)(task2),
|
|
147
|
+
logger.trace((0, _logger.truncate)(task2), `runTask #${taskId}`);
|
|
145
148
|
const response = await worker.remote.runTask(task2, _comlink.proxy(callback));
|
|
146
149
|
if ('Call' in response) {
|
|
147
|
-
logger.trace((0, _logger.truncate)(response.Call),
|
|
150
|
+
logger.trace((0, _logger.truncate)(response.Call), `taskResponse #${taskId}`);
|
|
148
151
|
} else {
|
|
149
152
|
logger.trace({
|
|
150
153
|
response
|
|
151
|
-
},
|
|
154
|
+
}, `taskResponse ${taskId}`);
|
|
152
155
|
}
|
|
153
156
|
return response;
|
|
154
157
|
};
|
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
|
|
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:
|
|
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
|
-
//
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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;
|
package/dist/esm/setup.d.ts
CHANGED
|
@@ -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) =>
|
|
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}`;
|
|
@@ -48,20 +48,23 @@ export const createProof = async (nodes, updates)=>{
|
|
|
48
48
|
nodes: newNodes
|
|
49
49
|
};
|
|
50
50
|
};
|
|
51
|
+
let nextTaskId = 0;
|
|
51
52
|
export const runTask = async (task, callback = emptyTaskHandler)=>{
|
|
53
|
+
const taskId = nextTaskId++;
|
|
52
54
|
const task2 = {
|
|
53
55
|
...task,
|
|
56
|
+
id: taskId,
|
|
54
57
|
storageProofSize: task.storageProofSize ?? 0
|
|
55
58
|
};
|
|
56
59
|
const worker = await getWorker();
|
|
57
|
-
logger.trace(truncate(task2),
|
|
60
|
+
logger.trace(truncate(task2), `runTask #${taskId}`);
|
|
58
61
|
const response = await worker.remote.runTask(task2, Comlink.proxy(callback));
|
|
59
62
|
if ('Call' in response) {
|
|
60
|
-
logger.trace(truncate(response.Call),
|
|
63
|
+
logger.trace(truncate(response.Call), `taskResponse #${taskId}`);
|
|
61
64
|
} else {
|
|
62
65
|
logger.trace({
|
|
63
66
|
response
|
|
64
|
-
},
|
|
67
|
+
}, `taskResponse ${taskId}`);
|
|
65
68
|
}
|
|
66
69
|
return response;
|
|
67
70
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acala-network/chopsticks-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5-1",
|
|
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.
|
|
17
|
+
"@acala-network/chopsticks-executor": "1.0.5-1",
|
|
18
18
|
"@polkadot/rpc-provider": "^15.7.1",
|
|
19
19
|
"@polkadot/types": "^15.7.1",
|
|
20
20
|
"@polkadot/types-codec": "^15.7.1",
|