@acala-network/chopsticks-core 0.8.4 → 0.8.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/lib/api.d.ts +1 -10
- package/lib/api.js +1 -10
- package/lib/blockchain/head-state.d.ts +1 -1
- package/lib/blockchain/head-state.js +2 -2
- package/lib/blockchain/index.d.ts +4 -4
- package/lib/blockchain/index.js +16 -19
- package/lib/blockchain/storage-layer.d.ts +2 -2
- package/lib/blockchain/storage-layer.js +3 -5
- package/lib/chopsticks-provider.d.ts +32 -0
- package/lib/chopsticks-provider.js +168 -248
- package/lib/database.d.ts +26 -0
- package/lib/database.js +2 -0
- package/lib/genesis-provider.d.ts +0 -1
- package/lib/genesis-provider.js +4 -47
- package/lib/index.d.ts +3 -0
- package/lib/index.js +3 -1
- package/lib/rpc/substrate/author.js +6 -3
- package/lib/rpc/substrate/chain.js +2 -2
- package/lib/rpc/substrate/index.d.ts +5 -5
- package/lib/rpc/substrate/state.d.ts +5 -5
- package/lib/rpc/substrate/state.js +11 -7
- package/lib/setup.d.ts +4 -3
- package/lib/setup.js +2 -13
- package/lib/wasm-executor/index.d.ts +1 -1
- package/lib/wasm-executor/index.js +2 -3
- package/lib/wasm-executor/node-wasm-executor.mjs +1 -1
- package/package.json +7 -11
- package/lib/chopsticks-worker.d.ts +0 -1
- package/lib/chopsticks-worker.js +0 -101
- package/lib/db/browser.d.ts +0 -2
- package/lib/db/browser.js +0 -64
- package/lib/db/entities.d.ts +0 -15
- package/lib/db/entities.js +0 -53
- package/lib/db/index.d.ts +0 -1
- package/lib/db/index.js +0 -44
- package/lib/db/node.d.ts +0 -2
- package/lib/db/node.js +0 -49
- package/lib/db/sql-wasm.d.ts +0 -1
- package/lib/db/sql-wasm.js +0 -9
|
@@ -24,20 +24,20 @@ declare const handlers: {
|
|
|
24
24
|
}>;
|
|
25
25
|
system_dryRun: import("..").Handler<[`0x${string}`, `0x${string}`], string>;
|
|
26
26
|
system_accountNextIndex: import("..").Handler<[`0x${string}`], number>;
|
|
27
|
-
state_getRuntimeVersion: import("..").Handler<[`0x${string}`], import("../..").RuntimeVersion |
|
|
28
|
-
state_getMetadata: import("..").Handler<[`0x${string}`], `0x${string}` |
|
|
29
|
-
state_getStorage: import("..").Handler<[`0x${string}`, `0x${string}`], string |
|
|
27
|
+
state_getRuntimeVersion: import("..").Handler<[`0x${string}`], import("../..").RuntimeVersion | null>;
|
|
28
|
+
state_getMetadata: import("..").Handler<[`0x${string}`], `0x${string}` | null>;
|
|
29
|
+
state_getStorage: import("..").Handler<[`0x${string}`, `0x${string}`], string | null>;
|
|
30
30
|
state_getKeysPaged: import("..").Handler<[string, number, string, `0x${string}`], string[] | undefined>;
|
|
31
31
|
state_queryStorageAt: import("..").Handler<[string[], `0x${string}`], [] | [{
|
|
32
32
|
block: `0x${string}`;
|
|
33
|
-
changes:
|
|
33
|
+
changes: [string, string | null][];
|
|
34
34
|
}]>;
|
|
35
35
|
state_call: import("..").Handler<[`0x${string}`, `0x${string}`, `0x${string}`], `0x${string}`>;
|
|
36
36
|
state_subscribeRuntimeVersion: import("..").Handler<[], string>;
|
|
37
37
|
state_unsubscribeRuntimeVersion: import("..").Handler<[`0x${string}`], void>;
|
|
38
38
|
state_subscribeStorage: import("..").Handler<[string[]], string>;
|
|
39
39
|
state_unsubscribeStorage: import("..").Handler<[string], void>;
|
|
40
|
-
childstate_getStorage: import("..").Handler<[`0x${string}`, `0x${string}`, `0x${string}`], string |
|
|
40
|
+
childstate_getStorage: import("..").Handler<[`0x${string}`, `0x${string}`, `0x${string}`], string | null>;
|
|
41
41
|
childstate_getKeysPaged: import("..").Handler<[`0x${string}`, `0x${string}`, number, `0x${string}`, `0x${string}`], `0x${string}`[] | undefined>;
|
|
42
42
|
payment_queryFeeDetails: import("..").Handler<[`0x${string}`, `0x${string}`], `0x${string}`>;
|
|
43
43
|
payment_queryInfo: import("..").Handler<[`0x${string}`, `0x${string}`], `0x${string}`>;
|
|
@@ -7,21 +7,21 @@ import { RuntimeVersion } from '../../wasm-executor';
|
|
|
7
7
|
*
|
|
8
8
|
* @return runtime version
|
|
9
9
|
*/
|
|
10
|
-
export declare const state_getRuntimeVersion: Handler<[HexString], RuntimeVersion |
|
|
10
|
+
export declare const state_getRuntimeVersion: Handler<[HexString], RuntimeVersion | null>;
|
|
11
11
|
/**
|
|
12
12
|
* @param context
|
|
13
13
|
* @param params - [`blockhash`]
|
|
14
14
|
*
|
|
15
15
|
* @return metadata
|
|
16
16
|
*/
|
|
17
|
-
export declare const state_getMetadata: Handler<[HexString], HexString |
|
|
17
|
+
export declare const state_getMetadata: Handler<[HexString], HexString | null>;
|
|
18
18
|
/**
|
|
19
19
|
* @param context
|
|
20
20
|
* @param params - [`key`, `blockhash`]
|
|
21
21
|
*
|
|
22
22
|
* @return storage value
|
|
23
23
|
*/
|
|
24
|
-
export declare const state_getStorage: Handler<[HexString, HexString], string |
|
|
24
|
+
export declare const state_getStorage: Handler<[HexString, HexString], string | null>;
|
|
25
25
|
/**
|
|
26
26
|
* @param context
|
|
27
27
|
* @param params - [`prefix`, `pageSize`, `startKey`, `blockhash`]
|
|
@@ -41,7 +41,7 @@ export declare const state_queryStorageAt: Handler<[
|
|
|
41
41
|
], [] | [
|
|
42
42
|
{
|
|
43
43
|
block: HexString;
|
|
44
|
-
changes:
|
|
44
|
+
changes: [string, string | null][];
|
|
45
45
|
}
|
|
46
46
|
]>;
|
|
47
47
|
/**
|
|
@@ -81,7 +81,7 @@ export declare const state_unsubscribeStorage: Handler<[string], void>;
|
|
|
81
81
|
*
|
|
82
82
|
* @return storage valuse
|
|
83
83
|
*/
|
|
84
|
-
export declare const childstate_getStorage: Handler<[HexString, HexString, HexString], string |
|
|
84
|
+
export declare const childstate_getStorage: Handler<[HexString, HexString, HexString], string | null>;
|
|
85
85
|
/**
|
|
86
86
|
* @param context
|
|
87
87
|
* @param params - [`child`, `prefix`, `pageSize`, `startKey`, `blockhash`]
|
|
@@ -22,7 +22,7 @@ const logger = logger_1.defaultLogger.child({ name: 'rpc-state' });
|
|
|
22
22
|
*/
|
|
23
23
|
const state_getRuntimeVersion = (context, [hash]) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
24
|
const block = yield context.chain.getBlock(hash);
|
|
25
|
-
return block === null || block === void 0 ? void 0 : block.runtimeVersion;
|
|
25
|
+
return (block === null || block === void 0 ? void 0 : block.runtimeVersion) || null;
|
|
26
26
|
});
|
|
27
27
|
exports.state_getRuntimeVersion = state_getRuntimeVersion;
|
|
28
28
|
/**
|
|
@@ -33,7 +33,7 @@ exports.state_getRuntimeVersion = state_getRuntimeVersion;
|
|
|
33
33
|
*/
|
|
34
34
|
const state_getMetadata = (context, [hash]) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
35
|
const block = yield context.chain.getBlock(hash);
|
|
36
|
-
return block === null || block === void 0 ? void 0 : block.metadata;
|
|
36
|
+
return (block === null || block === void 0 ? void 0 : block.metadata) || null;
|
|
37
37
|
});
|
|
38
38
|
exports.state_getMetadata = state_getMetadata;
|
|
39
39
|
/**
|
|
@@ -44,7 +44,8 @@ exports.state_getMetadata = state_getMetadata;
|
|
|
44
44
|
*/
|
|
45
45
|
const state_getStorage = (context, [key, hash]) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
46
|
const block = yield context.chain.getBlock(hash);
|
|
47
|
-
|
|
47
|
+
const value = (yield (block === null || block === void 0 ? void 0 : block.get(key))) || null;
|
|
48
|
+
return value || null;
|
|
48
49
|
});
|
|
49
50
|
exports.state_getStorage = state_getStorage;
|
|
50
51
|
/**
|
|
@@ -69,7 +70,7 @@ const state_queryStorageAt = (context, [keys, hash]) => __awaiter(void 0, void 0
|
|
|
69
70
|
if (!block) {
|
|
70
71
|
return [];
|
|
71
72
|
}
|
|
72
|
-
const values = yield Promise.all(keys.map((key) => __awaiter(void 0, void 0, void 0, function* () { return [key, yield block.get(key)]; })));
|
|
73
|
+
const values = yield Promise.all(keys.map((key) => __awaiter(void 0, void 0, void 0, function* () { return [key, yield block.get(key).then((val) => val || null)]; })));
|
|
73
74
|
return [
|
|
74
75
|
{
|
|
75
76
|
block: block.hash,
|
|
@@ -101,7 +102,9 @@ const state_subscribeRuntimeVersion = (context, _params, { subscribe }) => __awa
|
|
|
101
102
|
const id = yield context.chain.headState.subscrubeRuntimeVersion((block) => update(block));
|
|
102
103
|
const callback = subscribe('state_runtimeVersion', id);
|
|
103
104
|
update = (block) => __awaiter(void 0, void 0, void 0, function* () { return callback(yield block.runtimeVersion); });
|
|
104
|
-
|
|
105
|
+
setTimeout(() => {
|
|
106
|
+
context.chain.head.runtimeVersion.then(callback);
|
|
107
|
+
}, 50);
|
|
105
108
|
return id;
|
|
106
109
|
});
|
|
107
110
|
exports.state_subscribeRuntimeVersion = state_subscribeRuntimeVersion;
|
|
@@ -135,7 +138,7 @@ const state_subscribeStorage = (context, [keys], { subscribe }) => __awaiter(voi
|
|
|
135
138
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
136
139
|
const pairs = yield Promise.all(keys.map((key) => __awaiter(void 0, void 0, void 0, function* () {
|
|
137
140
|
const val = yield context.chain.head.get(key);
|
|
138
|
-
return [key, val];
|
|
141
|
+
return [key, val || null];
|
|
139
142
|
})));
|
|
140
143
|
callback({
|
|
141
144
|
block: context.chain.head.hash,
|
|
@@ -165,7 +168,8 @@ const childstate_getStorage = (context, [child, key, hash]) => __awaiter(void 0,
|
|
|
165
168
|
throw new shared_1.ResponseError(-32000, 'Client error: Invalid child storage key');
|
|
166
169
|
}
|
|
167
170
|
const block = yield context.chain.getBlock(hash);
|
|
168
|
-
|
|
171
|
+
const value = yield (block === null || block === void 0 ? void 0 : block.get((0, utils_1.prefixedChildKey)(child, key)));
|
|
172
|
+
return value || null;
|
|
169
173
|
});
|
|
170
174
|
exports.childstate_getStorage = childstate_getStorage;
|
|
171
175
|
/**
|
package/lib/setup.d.ts
CHANGED
|
@@ -2,13 +2,14 @@ import '@polkadot/types-codec';
|
|
|
2
2
|
import { RegisteredTypes } from '@polkadot/types/types';
|
|
3
3
|
import { Blockchain } from './blockchain';
|
|
4
4
|
import { BuildBlockMode } from './blockchain/txpool';
|
|
5
|
-
import {
|
|
5
|
+
import { Database } from './database';
|
|
6
|
+
import { GenesisProvider } from './genesis-provider';
|
|
6
7
|
export type SetupOptions = {
|
|
7
8
|
endpoint?: string;
|
|
8
9
|
block?: string | number | null;
|
|
9
|
-
genesis?:
|
|
10
|
+
genesis?: GenesisProvider;
|
|
10
11
|
buildBlockMode?: BuildBlockMode;
|
|
11
|
-
db?:
|
|
12
|
+
db?: Database;
|
|
12
13
|
mockSignatureHost?: boolean;
|
|
13
14
|
allowUnresolvedImports?: boolean;
|
|
14
15
|
runtimeLogLevel?: number;
|
package/lib/setup.js
CHANGED
|
@@ -14,19 +14,12 @@ require("@polkadot/types-codec");
|
|
|
14
14
|
const api_1 = require("@polkadot/api");
|
|
15
15
|
const api_2 = require("./api");
|
|
16
16
|
const blockchain_1 = require("./blockchain");
|
|
17
|
-
const genesis_provider_1 = require("./genesis-provider");
|
|
18
17
|
const inherent_1 = require("./blockchain/inherent");
|
|
19
18
|
const logger_1 = require("./logger");
|
|
20
|
-
const db_1 = require("./db");
|
|
21
19
|
const setup = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
20
|
let provider;
|
|
23
21
|
if (options.genesis) {
|
|
24
|
-
|
|
25
|
-
provider = yield genesis_provider_1.GenesisProvider.fromUrl(options.genesis);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
provider = new genesis_provider_1.GenesisProvider(options.genesis);
|
|
29
|
-
}
|
|
22
|
+
provider = options.genesis;
|
|
30
23
|
}
|
|
31
24
|
else {
|
|
32
25
|
provider = new api_1.WsProvider(options.endpoint);
|
|
@@ -58,10 +51,6 @@ const setup = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
58
51
|
throw new Error(`Invalid block number or hash: ${options.block}`);
|
|
59
52
|
}
|
|
60
53
|
logger_1.defaultLogger.debug(Object.assign(Object.assign({}, options), { blockHash }), 'Args');
|
|
61
|
-
let db;
|
|
62
|
-
if (options.db) {
|
|
63
|
-
db = yield (0, db_1.openDb)(options.db);
|
|
64
|
-
}
|
|
65
54
|
const header = yield api.getHeader(blockHash);
|
|
66
55
|
if (!header) {
|
|
67
56
|
throw new Error(`Cannot find header for ${blockHash}`);
|
|
@@ -76,7 +65,7 @@ const setup = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
76
65
|
api,
|
|
77
66
|
buildBlockMode: options.buildBlockMode,
|
|
78
67
|
inherentProvider: inherents,
|
|
79
|
-
db,
|
|
68
|
+
db: options.db,
|
|
80
69
|
header: {
|
|
81
70
|
hash: blockHash,
|
|
82
71
|
number: Number(header.number),
|
|
@@ -30,7 +30,7 @@ export interface WasmExecutor {
|
|
|
30
30
|
runtimeLogLevel: number;
|
|
31
31
|
}, callback?: JsCallback) => Promise<any>;
|
|
32
32
|
}
|
|
33
|
-
export declare const getRuntimeVersion: (code: HexString) => Promise<RuntimeVersion
|
|
33
|
+
export declare const getRuntimeVersion: ((code: HexString) => Promise<RuntimeVersion>) & _.MemoizedFunction;
|
|
34
34
|
export declare const calculateStateRoot: (entries: [HexString, HexString][], trie_version: number) => Promise<HexString>;
|
|
35
35
|
export declare const decodeProof: (trieRootHash: HexString, keys: HexString[], nodes: HexString[]) => Promise<Record<`0x${string}`, `0x${string}` | null>>;
|
|
36
36
|
export declare const createProof: (nodes: HexString[], entries: [HexString, HexString | null][]) => Promise<{
|
|
@@ -56,15 +56,14 @@ const getWorker = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
56
56
|
}
|
|
57
57
|
return __executor_worker;
|
|
58
58
|
});
|
|
59
|
-
|
|
59
|
+
exports.getRuntimeVersion = lodash_1.default.memoize((code) => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
60
|
const worker = yield getWorker();
|
|
61
61
|
return worker.remote.getRuntimeVersion(code).then((version) => {
|
|
62
62
|
version.specName = (0, util_1.hexToString)(version.specName);
|
|
63
63
|
version.implName = (0, util_1.hexToString)(version.implName);
|
|
64
64
|
return version;
|
|
65
65
|
});
|
|
66
|
-
});
|
|
67
|
-
exports.getRuntimeVersion = getRuntimeVersion;
|
|
66
|
+
}));
|
|
68
67
|
// trie_version: 0 for old trie, 1 for new trie
|
|
69
68
|
const calculateStateRoot = (entries, trie_version) => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
69
|
const worker = yield getWorker();
|
|
@@ -29,6 +29,6 @@ const runTask = async (task, callback) => {
|
|
|
29
29
|
return pkg.run_task(task, callback, process.env.RUST_LOG)
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
const wasmExecutor = { runTask, getRuntimeVersion, calculateStateRoot, createProof, decodeProof }
|
|
33
33
|
|
|
34
34
|
Comlink.expose(wasmExecutor, nodeEndpoint(parentPort))
|
package/package.json
CHANGED
|
@@ -1,35 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acala-network/chopsticks-core",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.5-1",
|
|
4
4
|
"author": "Acala Developers <hello@acala.network>",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"clean": "rm -rf lib tsconfig.tsbuildinfo",
|
|
8
|
-
"
|
|
9
|
-
"build": "yarn pack-wasm; tsc -p ./tsconfig.json; yarn copyfiles",
|
|
8
|
+
"build": "tsc -p ./tsconfig.json; yarn copyfiles",
|
|
10
9
|
"copyfiles": "cp -r src/wasm-executor/*.mjs lib/wasm-executor/",
|
|
11
10
|
"docs:prep": "typedoc"
|
|
12
11
|
},
|
|
13
12
|
"dependencies": {
|
|
14
|
-
"@acala-network/chopsticks-executor": "0.8.
|
|
13
|
+
"@acala-network/chopsticks-executor": "0.8.5-1",
|
|
15
14
|
"@polkadot/api": "^10.9.1",
|
|
16
15
|
"@polkadot/util-crypto": "^12.3.2",
|
|
17
|
-
"axios": "^1.5.1",
|
|
18
16
|
"comlink": "^4.4.1",
|
|
19
17
|
"eventemitter3": "^5.0.1",
|
|
20
|
-
"localforage": "^1.10.0",
|
|
21
18
|
"lodash": "^4.17.21",
|
|
22
19
|
"pino": "^8.15.0",
|
|
23
20
|
"pino-pretty": "^10.2.0",
|
|
24
|
-
"sql.js": "^1.8.0",
|
|
25
|
-
"sqlite3": "^5.1.6",
|
|
26
|
-
"typeorm": "^0.3.17",
|
|
27
21
|
"zod": "^3.22.3"
|
|
28
22
|
},
|
|
29
23
|
"devDependencies": {
|
|
30
24
|
"@types/lodash": "^4.14.199",
|
|
31
|
-
"@types/sql.js": "^1.4.4",
|
|
32
|
-
"fflate": "^0.8.0",
|
|
33
25
|
"typescript": "^5.1.6"
|
|
34
26
|
},
|
|
35
27
|
"files": [
|
|
@@ -47,5 +39,9 @@
|
|
|
47
39
|
"default": "./lib/*.js"
|
|
48
40
|
},
|
|
49
41
|
"./package.json": "./package.json"
|
|
42
|
+
},
|
|
43
|
+
"browser": {
|
|
44
|
+
"./lib/wasm-executor/node-wasm-executor.mjs": "./lib/wasm-executor/browser-wasm-executor.mjs",
|
|
45
|
+
"./lib/wasm-executor/node-worker.js": "./lib/wasm-executor/browser-worker.js"
|
|
50
46
|
}
|
|
51
47
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/chopsticks-worker.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const rpc_1 = require("./rpc");
|
|
13
|
-
const logger_1 = require("./logger");
|
|
14
|
-
const utils_1 = require("./utils");
|
|
15
|
-
const setup_1 = require("./setup");
|
|
16
|
-
let chain;
|
|
17
|
-
const logger = logger_1.defaultLogger.child({ name: '[Chopsticks worker]' });
|
|
18
|
-
const subscriptions = {};
|
|
19
|
-
const providerHandlers = Object.assign(Object.assign({}, rpc_1.allHandlers), { new_block: (context, _params, _subscriptionManager) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
-
const { chain } = context;
|
|
21
|
-
const block = yield chain.newBlock();
|
|
22
|
-
return block;
|
|
23
|
-
}) });
|
|
24
|
-
const subscriptionManager = {
|
|
25
|
-
subscribe: (method, subid, onCancel = () => { }) => {
|
|
26
|
-
subscriptions[subid] = onCancel;
|
|
27
|
-
return (data) => {
|
|
28
|
-
postMessage({
|
|
29
|
-
type: 'subscribe-callback',
|
|
30
|
-
method,
|
|
31
|
-
subid,
|
|
32
|
-
result: JSON.stringify(data),
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
},
|
|
36
|
-
unsubscribe: (subid) => {
|
|
37
|
-
if (subscriptions[subid]) {
|
|
38
|
-
subscriptions[subid](subid); // call onCancel
|
|
39
|
-
postMessage({
|
|
40
|
-
type: 'unsubscribe-callback',
|
|
41
|
-
subid,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
onmessage = (e) => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
-
var _a;
|
|
48
|
-
switch (e.data.type) {
|
|
49
|
-
case 'connect':
|
|
50
|
-
try {
|
|
51
|
-
logger.debug('onMessage: connect. Initializing...');
|
|
52
|
-
chain = yield (0, setup_1.setup)({
|
|
53
|
-
endpoint: e.data.endpoint,
|
|
54
|
-
mockSignatureHost: true,
|
|
55
|
-
db: e.data.dbPath,
|
|
56
|
-
block: e.data.blockHash,
|
|
57
|
-
});
|
|
58
|
-
logger.debug('onMessage: connect. Chain setup done.');
|
|
59
|
-
yield (0, utils_1.setStorage)(chain, e.data.storageValues);
|
|
60
|
-
logger.debug('onMessage: connect. Set storage done.');
|
|
61
|
-
postMessage({
|
|
62
|
-
type: 'connection',
|
|
63
|
-
connected: true,
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
catch (e) {
|
|
67
|
-
logger.error('onMessage: connect error.', e);
|
|
68
|
-
postMessage({
|
|
69
|
-
type: 'connection',
|
|
70
|
-
connected: false,
|
|
71
|
-
message: e,
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
break;
|
|
75
|
-
case 'disconnect':
|
|
76
|
-
if (chain) {
|
|
77
|
-
yield ((_a = chain === null || chain === void 0 ? void 0 : chain.api) === null || _a === void 0 ? void 0 : _a.disconnect());
|
|
78
|
-
yield (chain === null || chain === void 0 ? void 0 : chain.close());
|
|
79
|
-
}
|
|
80
|
-
break;
|
|
81
|
-
case 'send':
|
|
82
|
-
{
|
|
83
|
-
const { method, params } = e.data;
|
|
84
|
-
const handler = providerHandlers[method];
|
|
85
|
-
if (!handler) {
|
|
86
|
-
logger.error(`Unable to find rpc handler=${method}`);
|
|
87
|
-
return Promise.reject(new Error(`Unable to find handler=${method}`));
|
|
88
|
-
}
|
|
89
|
-
const result = yield handler({ chain: chain }, params, subscriptionManager);
|
|
90
|
-
postMessage({
|
|
91
|
-
type: 'send-result',
|
|
92
|
-
id: e.data.id,
|
|
93
|
-
method: method,
|
|
94
|
-
result: JSON.stringify(result),
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
break;
|
|
98
|
-
default:
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
});
|
package/lib/db/browser.d.ts
DELETED
package/lib/db/browser.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.openDb = void 0;
|
|
39
|
-
const typeorm_1 = require("typeorm");
|
|
40
|
-
const localforage_1 = require("localforage");
|
|
41
|
-
const sql_js_1 = __importDefault(require("sql.js"));
|
|
42
|
-
const entities = __importStar(require("./entities"));
|
|
43
|
-
const sql_wasm_1 = require("./sql-wasm");
|
|
44
|
-
const openDb = (location) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
-
if (!globalThis.localforage) {
|
|
46
|
-
globalThis.localforage = (0, localforage_1.createInstance)({ name: 'chopsticks' });
|
|
47
|
-
}
|
|
48
|
-
const source = new typeorm_1.DataSource({
|
|
49
|
-
type: 'sqljs',
|
|
50
|
-
location,
|
|
51
|
-
entities: Object.values(entities),
|
|
52
|
-
synchronize: true,
|
|
53
|
-
autoSave: true,
|
|
54
|
-
logging: false,
|
|
55
|
-
useLocalForage: true,
|
|
56
|
-
driver: sql_js_1.default,
|
|
57
|
-
sqlJsConfig: {
|
|
58
|
-
wasmBinary: sql_wasm_1.SQL_WASM_BYTES,
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
yield source.initialize();
|
|
62
|
-
return source;
|
|
63
|
-
});
|
|
64
|
-
exports.openDb = openDb;
|
package/lib/db/entities.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { EntitySchema } from 'typeorm';
|
|
2
|
-
import { HexString } from '@polkadot/util/types';
|
|
3
|
-
export declare const KeyValuePair: EntitySchema<{
|
|
4
|
-
blockHash: string;
|
|
5
|
-
key: string;
|
|
6
|
-
value: string | null;
|
|
7
|
-
}>;
|
|
8
|
-
export declare const BlockEntity: EntitySchema<{
|
|
9
|
-
hash: HexString;
|
|
10
|
-
number: number;
|
|
11
|
-
header: object;
|
|
12
|
-
parentHash: HexString | null;
|
|
13
|
-
extrinsics: HexString[];
|
|
14
|
-
storageDiff: Record<HexString, HexString | null> | null;
|
|
15
|
-
}>;
|
package/lib/db/entities.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BlockEntity = exports.KeyValuePair = void 0;
|
|
4
|
-
const typeorm_1 = require("typeorm");
|
|
5
|
-
exports.KeyValuePair = new typeorm_1.EntitySchema({
|
|
6
|
-
name: 'KeyValuePair',
|
|
7
|
-
columns: {
|
|
8
|
-
blockHash: {
|
|
9
|
-
primary: true,
|
|
10
|
-
type: 'varchar',
|
|
11
|
-
nullable: false,
|
|
12
|
-
},
|
|
13
|
-
key: {
|
|
14
|
-
primary: true,
|
|
15
|
-
type: 'varchar',
|
|
16
|
-
nullable: false,
|
|
17
|
-
},
|
|
18
|
-
value: {
|
|
19
|
-
type: 'text',
|
|
20
|
-
nullable: true,
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
exports.BlockEntity = new typeorm_1.EntitySchema({
|
|
25
|
-
name: 'Block',
|
|
26
|
-
columns: {
|
|
27
|
-
hash: {
|
|
28
|
-
primary: true,
|
|
29
|
-
type: 'varchar',
|
|
30
|
-
nullable: false,
|
|
31
|
-
},
|
|
32
|
-
number: {
|
|
33
|
-
type: 'int',
|
|
34
|
-
nullable: false,
|
|
35
|
-
},
|
|
36
|
-
header: {
|
|
37
|
-
type: 'simple-json',
|
|
38
|
-
nullable: false,
|
|
39
|
-
},
|
|
40
|
-
parentHash: {
|
|
41
|
-
type: 'varchar',
|
|
42
|
-
nullable: true,
|
|
43
|
-
},
|
|
44
|
-
extrinsics: {
|
|
45
|
-
type: 'simple-array',
|
|
46
|
-
nullable: false,
|
|
47
|
-
},
|
|
48
|
-
storageDiff: {
|
|
49
|
-
type: 'simple-json',
|
|
50
|
-
nullable: true,
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
});
|
package/lib/db/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const openDb: (dbPath: string) => Promise<import("typeorm").DataSource>;
|
package/lib/db/index.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.openDb = void 0;
|
|
36
|
-
const openDb = (dbPath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
-
if (typeof window === 'undefined') {
|
|
38
|
-
return (yield Promise.resolve().then(() => __importStar(require('./node')))).openDb(dbPath);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
return (yield Promise.resolve().then(() => __importStar(require('./browser')))).openDb(dbPath);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
exports.openDb = openDb;
|
package/lib/db/node.d.ts
DELETED
package/lib/db/node.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.openDb = void 0;
|
|
36
|
-
const typeorm_1 = require("typeorm");
|
|
37
|
-
const entities = __importStar(require("./entities"));
|
|
38
|
-
const openDb = (dbPath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
-
const source = new typeorm_1.DataSource({
|
|
40
|
-
type: 'sqlite',
|
|
41
|
-
database: dbPath,
|
|
42
|
-
entities: Object.values(entities),
|
|
43
|
-
synchronize: true,
|
|
44
|
-
logging: false,
|
|
45
|
-
});
|
|
46
|
-
yield source.initialize();
|
|
47
|
-
return source;
|
|
48
|
-
});
|
|
49
|
-
exports.openDb = openDb;
|
package/lib/db/sql-wasm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const SQL_WASM_BYTES: Uint8Array;
|