@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
package/lib/api.d.ts
CHANGED
|
@@ -29,16 +29,7 @@ type SignedBlock = {
|
|
|
29
29
|
* @example Instantiate an API
|
|
30
30
|
*
|
|
31
31
|
* ```ts
|
|
32
|
-
*
|
|
33
|
-
* if (options.genesis) {
|
|
34
|
-
* if (typeof options.genesis === 'string') {
|
|
35
|
-
* provider = await GenesisProvider.fromUrl(options.genesis)
|
|
36
|
-
* } else {
|
|
37
|
-
* provider = new GenesisProvider(options.genesis)
|
|
38
|
-
* }
|
|
39
|
-
* } else {
|
|
40
|
-
* provider = new WsProvider(options.endpoint)
|
|
41
|
-
* }
|
|
32
|
+
* const provider = new WsProvider(options.endpoint)
|
|
42
33
|
* const api = new Api(provider)
|
|
43
34
|
* await api.isReady
|
|
44
35
|
* ```
|
package/lib/api.js
CHANGED
|
@@ -30,16 +30,7 @@ const utils_1 = require("./utils");
|
|
|
30
30
|
* @example Instantiate an API
|
|
31
31
|
*
|
|
32
32
|
* ```ts
|
|
33
|
-
*
|
|
34
|
-
* if (options.genesis) {
|
|
35
|
-
* if (typeof options.genesis === 'string') {
|
|
36
|
-
* provider = await GenesisProvider.fromUrl(options.genesis)
|
|
37
|
-
* } else {
|
|
38
|
-
* provider = new GenesisProvider(options.genesis)
|
|
39
|
-
* }
|
|
40
|
-
* } else {
|
|
41
|
-
* provider = new WsProvider(options.endpoint)
|
|
42
|
-
* }
|
|
33
|
+
* const provider = new WsProvider(options.endpoint)
|
|
43
34
|
* const api = new Api(provider)
|
|
44
35
|
* await api.isReady
|
|
45
36
|
* ```
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Block } from './block';
|
|
2
|
-
type Callback = (block: Block, pairs: [string, string][]) => void | Promise<void>;
|
|
2
|
+
type Callback = (block: Block, pairs: [string, string | null][]) => void | Promise<void>;
|
|
3
3
|
export declare const randomId: () => string;
|
|
4
4
|
export declare class HeadState {
|
|
5
5
|
#private;
|
|
@@ -48,7 +48,7 @@ class HeadState {
|
|
|
48
48
|
const id = (0, exports.randomId)();
|
|
49
49
|
__classPrivateFieldGet(this, _HeadState_storageListeners, "f")[id] = [keys, cb];
|
|
50
50
|
for (const key of keys) {
|
|
51
|
-
__classPrivateFieldGet(this, _HeadState_oldValues, "f")[key] = yield __classPrivateFieldGet(this, _HeadState_head, "f").get(key);
|
|
51
|
+
__classPrivateFieldGet(this, _HeadState_oldValues, "f")[key] = yield __classPrivateFieldGet(this, _HeadState_head, "f").get(key).then((val) => val || null);
|
|
52
52
|
}
|
|
53
53
|
return id;
|
|
54
54
|
});
|
|
@@ -61,7 +61,7 @@ class HeadState {
|
|
|
61
61
|
const id = (0, exports.randomId)();
|
|
62
62
|
const codeKey = (0, util_1.stringToHex)(':code');
|
|
63
63
|
__classPrivateFieldGet(this, _HeadState_storageListeners, "f")[id] = [[codeKey], cb];
|
|
64
|
-
__classPrivateFieldGet(this, _HeadState_oldValues, "f")[codeKey] = yield __classPrivateFieldGet(this, _HeadState_head, "f").get(codeKey);
|
|
64
|
+
__classPrivateFieldGet(this, _HeadState_oldValues, "f")[codeKey] = yield __classPrivateFieldGet(this, _HeadState_head, "f").get(codeKey).then((val) => val || null);
|
|
65
65
|
return id;
|
|
66
66
|
});
|
|
67
67
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ApplyExtrinsicResult } from '@polkadot/types/interfaces';
|
|
2
|
-
import { DataSource } from 'typeorm';
|
|
3
2
|
import { HexString } from '@polkadot/util/types';
|
|
4
3
|
import { RegisteredTypes } from '@polkadot/types/types';
|
|
5
4
|
import type { TransactionValidity } from '@polkadot/types/interfaces/txqueue';
|
|
6
5
|
import { Api } from '../api';
|
|
7
6
|
import { Block } from './block';
|
|
8
7
|
import { BuildBlockMode, BuildBlockParams, DownwardMessage, HorizontalMessage, TxPool } from './txpool';
|
|
8
|
+
import { Database } from '../database';
|
|
9
9
|
import { HeadState } from './head-state';
|
|
10
10
|
import { InherentProvider } from './inherent';
|
|
11
11
|
import { OffchainWorker } from '../offchain';
|
|
@@ -17,7 +17,7 @@ export interface Options {
|
|
|
17
17
|
/** Inherent provider, for creating inherents. */
|
|
18
18
|
inherentProvider: InherentProvider;
|
|
19
19
|
/** Datasource for caching storage and blocks data. */
|
|
20
|
-
db?:
|
|
20
|
+
db?: Database;
|
|
21
21
|
/** Used to create the initial head. */
|
|
22
22
|
header: {
|
|
23
23
|
number: number;
|
|
@@ -65,7 +65,7 @@ export declare class Blockchain {
|
|
|
65
65
|
/** API instance, for getting on-chain data. */
|
|
66
66
|
readonly api: Api;
|
|
67
67
|
/** Datasource for caching storage and blocks data. */
|
|
68
|
-
readonly db:
|
|
68
|
+
readonly db: Database | undefined;
|
|
69
69
|
/** Enable mock signature. Any signature starts with 0xdeadbeef and filled by 0xcd is considered valid */
|
|
70
70
|
readonly mockSignatureHost: boolean;
|
|
71
71
|
/** Allow wasm unresolved imports. */
|
|
@@ -88,7 +88,7 @@ export declare class Blockchain {
|
|
|
88
88
|
* Try to load block from db and register it.
|
|
89
89
|
* If pass in number, get block by number, else get block by hash.
|
|
90
90
|
*/
|
|
91
|
-
loadBlockFromDB(
|
|
91
|
+
loadBlockFromDB(hashOrNumber: number | HexString): Promise<Block | undefined>;
|
|
92
92
|
/**
|
|
93
93
|
* Get block by number.
|
|
94
94
|
*/
|
package/lib/blockchain/index.js
CHANGED
|
@@ -25,7 +25,6 @@ exports.Blockchain = void 0;
|
|
|
25
25
|
const util_crypto_1 = require("@polkadot/util-crypto");
|
|
26
26
|
const util_1 = require("@polkadot/util");
|
|
27
27
|
const block_1 = require("./block");
|
|
28
|
-
const entities_1 = require("../db/entities");
|
|
29
28
|
const txpool_1 = require("./txpool");
|
|
30
29
|
const head_state_1 = require("./head-state");
|
|
31
30
|
const offchain_1 = require("../offchain");
|
|
@@ -104,22 +103,19 @@ class Blockchain {
|
|
|
104
103
|
logger.debug(`Runtime log level set to ${logger.level}`);
|
|
105
104
|
}
|
|
106
105
|
saveBlockToDB(block) {
|
|
106
|
+
var _a;
|
|
107
107
|
return __awaiter(this, void 0, void 0, function* () {
|
|
108
108
|
if (this.db) {
|
|
109
109
|
const { hash, number, header, extrinsics } = block;
|
|
110
110
|
// delete old ones with the same block number if any, keep the latest one
|
|
111
|
-
yield this.db.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
yield
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
parentHash: (_a = (yield block.parentBlock)) === null || _a === void 0 ? void 0 : _a.hash,
|
|
120
|
-
storageDiff: yield block.storageDiff(),
|
|
121
|
-
}, ['hash']);
|
|
122
|
-
}));
|
|
111
|
+
yield this.db.saveBlock({
|
|
112
|
+
hash,
|
|
113
|
+
number,
|
|
114
|
+
header: (yield header).toHex(),
|
|
115
|
+
extrinsics: yield extrinsics,
|
|
116
|
+
parentHash: ((_a = (yield block.parentBlock)) === null || _a === void 0 ? void 0 : _a.hash) || null,
|
|
117
|
+
storageDiff: yield block.storageDiff(),
|
|
118
|
+
});
|
|
123
119
|
}
|
|
124
120
|
});
|
|
125
121
|
}
|
|
@@ -127,13 +123,13 @@ class Blockchain {
|
|
|
127
123
|
* Try to load block from db and register it.
|
|
128
124
|
* If pass in number, get block by number, else get block by hash.
|
|
129
125
|
*/
|
|
130
|
-
loadBlockFromDB(
|
|
126
|
+
loadBlockFromDB(hashOrNumber) {
|
|
131
127
|
var _a;
|
|
132
128
|
return __awaiter(this, void 0, void 0, function* () {
|
|
133
129
|
if (this.db) {
|
|
134
|
-
const blockData =
|
|
135
|
-
.
|
|
136
|
-
|
|
130
|
+
const blockData = typeof hashOrNumber === 'number'
|
|
131
|
+
? yield this.db.queryBlockByNumber(hashOrNumber)
|
|
132
|
+
: yield this.db.queryBlock(hashOrNumber);
|
|
137
133
|
if (blockData) {
|
|
138
134
|
const { hash, number, header, extrinsics } = blockData;
|
|
139
135
|
const parentHash = blockData.parentHash || undefined;
|
|
@@ -242,7 +238,7 @@ class Blockchain {
|
|
|
242
238
|
delete __classPrivateFieldGet(this, _Blockchain_blocksByHash, "f")[block.hash];
|
|
243
239
|
// delete from db
|
|
244
240
|
if (this.db) {
|
|
245
|
-
yield this.db.
|
|
241
|
+
yield this.db.deleteBlock(block.hash);
|
|
246
242
|
}
|
|
247
243
|
});
|
|
248
244
|
}
|
|
@@ -452,7 +448,8 @@ class Blockchain {
|
|
|
452
448
|
var _a;
|
|
453
449
|
return __awaiter(this, void 0, void 0, function* () {
|
|
454
450
|
yield (0, wasm_executor_1.releaseWorker)();
|
|
455
|
-
yield
|
|
451
|
+
yield this.api.disconnect();
|
|
452
|
+
yield ((_a = this.db) === null || _a === void 0 ? void 0 : _a.close());
|
|
456
453
|
});
|
|
457
454
|
}
|
|
458
455
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DataSource } from 'typeorm';
|
|
2
1
|
import { Api } from '../api';
|
|
2
|
+
import { Database } from '../database';
|
|
3
3
|
export declare const enum StorageValueKind {
|
|
4
4
|
Deleted = "Deleted",
|
|
5
5
|
DeletedPrefix = "DeletedPrefix"
|
|
@@ -25,7 +25,7 @@ export interface StorageLayerProvider {
|
|
|
25
25
|
}
|
|
26
26
|
export declare class RemoteStorageLayer implements StorageLayerProvider {
|
|
27
27
|
#private;
|
|
28
|
-
constructor(api: Api, at: string, db:
|
|
28
|
+
constructor(api: Api, at: string, db: Database | undefined);
|
|
29
29
|
get(key: string, _cache: boolean): Promise<StorageValue>;
|
|
30
30
|
foldInto(_into: StorageLayer): Promise<StorageLayerProvider>;
|
|
31
31
|
fold(): Promise<void>;
|
|
@@ -49,7 +49,6 @@ var _RemoteStorageLayer_api, _RemoteStorageLayer_at, _RemoteStorageLayer_db, _Re
|
|
|
49
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
50
|
exports.StorageLayer = exports.RemoteStorageLayer = exports.StorageValueKind = void 0;
|
|
51
51
|
const lodash_1 = __importDefault(require("lodash"));
|
|
52
|
-
const entities_1 = require("../db/entities");
|
|
53
52
|
const logger_1 = require("../logger");
|
|
54
53
|
const key_cache_1 = __importStar(require("../utils/key-cache"));
|
|
55
54
|
const logger = logger_1.defaultLogger.child({ name: 'layer' });
|
|
@@ -72,16 +71,15 @@ class RemoteStorageLayer {
|
|
|
72
71
|
get(key, _cache) {
|
|
73
72
|
var _a, _b;
|
|
74
73
|
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
-
const keyValuePair = (_a = __classPrivateFieldGet(this, _RemoteStorageLayer_db, "f")) === null || _a === void 0 ? void 0 : _a.getRepository(entities_1.KeyValuePair);
|
|
76
74
|
if (__classPrivateFieldGet(this, _RemoteStorageLayer_db, "f")) {
|
|
77
|
-
const res = yield (
|
|
75
|
+
const res = yield __classPrivateFieldGet(this, _RemoteStorageLayer_db, "f").queryStorage(__classPrivateFieldGet(this, _RemoteStorageLayer_at, "f"), key);
|
|
78
76
|
if (res) {
|
|
79
|
-
return (
|
|
77
|
+
return (_a = res.value) !== null && _a !== void 0 ? _a : undefined;
|
|
80
78
|
}
|
|
81
79
|
}
|
|
82
80
|
logger.trace({ at: __classPrivateFieldGet(this, _RemoteStorageLayer_at, "f"), key }, 'RemoteStorageLayer get');
|
|
83
81
|
const data = yield __classPrivateFieldGet(this, _RemoteStorageLayer_api, "f").getStorage(key, __classPrivateFieldGet(this, _RemoteStorageLayer_at, "f"));
|
|
84
|
-
|
|
82
|
+
(_b = __classPrivateFieldGet(this, _RemoteStorageLayer_db, "f")) === null || _b === void 0 ? void 0 : _b.saveStorage(__classPrivateFieldGet(this, _RemoteStorageLayer_at, "f"), key, data);
|
|
85
83
|
return data !== null && data !== void 0 ? data : undefined;
|
|
86
84
|
});
|
|
87
85
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ProviderInterface, ProviderInterfaceCallback, ProviderInterfaceEmitCb, ProviderInterfaceEmitted } from '@polkadot/rpc-provider/types';
|
|
2
|
+
import { Blockchain } from './blockchain';
|
|
3
|
+
import { Database } from './database';
|
|
4
|
+
interface SubscriptionHandler {
|
|
5
|
+
callback: ProviderInterfaceCallback;
|
|
6
|
+
type: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Provider for local chopsticks chain
|
|
10
|
+
*/
|
|
11
|
+
export declare class ChopsticksProvider implements ProviderInterface {
|
|
12
|
+
#private;
|
|
13
|
+
readonly chain: Blockchain;
|
|
14
|
+
constructor(chain: Blockchain);
|
|
15
|
+
static fromEndpoint: (endpoint: string, block?: number | string | null, db?: Database) => Promise<ChopsticksProvider>;
|
|
16
|
+
get hasSubscriptions(): boolean;
|
|
17
|
+
get isClonable(): boolean;
|
|
18
|
+
get isConnected(): boolean;
|
|
19
|
+
get isReady(): Promise<void>;
|
|
20
|
+
clone: () => ChopsticksProvider;
|
|
21
|
+
connect: () => Promise<void>;
|
|
22
|
+
disconnect: () => Promise<void>;
|
|
23
|
+
on: (type: ProviderInterfaceEmitted, sub: ProviderInterfaceEmitCb) => (() => void);
|
|
24
|
+
subscriptionManager: {
|
|
25
|
+
subscribe: (method: string, subid: string, onCancel?: () => void) => (data: any) => void;
|
|
26
|
+
unsubscribe: (subid: string) => void;
|
|
27
|
+
};
|
|
28
|
+
send: <T>(method: string, params: unknown[], _isCacheable?: boolean, subscription?: SubscriptionHandler) => Promise<T>;
|
|
29
|
+
subscribe(type: string, method: string, params: unknown[], callback: ProviderInterfaceCallback): Promise<number | string>;
|
|
30
|
+
unsubscribe(_type: string, method: string, id: number | string): Promise<boolean>;
|
|
31
|
+
}
|
|
32
|
+
export {};
|