@acala-network/chopsticks-core 0.8.0-6 → 0.8.0
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/blockchain/index.d.ts +2 -1
- package/lib/blockchain/index.js +17 -4
- package/lib/db/entities.d.ts +1 -2
- package/package.json +3 -4
|
@@ -32,13 +32,14 @@ export declare class Blockchain {
|
|
|
32
32
|
readonly db: DataSource | undefined;
|
|
33
33
|
readonly mockSignatureHost: boolean;
|
|
34
34
|
readonly allowUnresolvedImports: boolean;
|
|
35
|
-
readonly runtimeLogLevel: number;
|
|
36
35
|
readonly registeredTypes: RegisteredTypes;
|
|
37
36
|
readonly headState: HeadState;
|
|
38
37
|
readonly offchainWorker: OffchainWorker | undefined;
|
|
39
38
|
constructor({ api, buildBlockMode, inherentProvider, db, header, mockSignatureHost, allowUnresolvedImports, runtimeLogLevel, registeredTypes, offchainWorker, maxMemoryBlockCount, }: Options);
|
|
40
39
|
get head(): Block;
|
|
41
40
|
get txPool(): TxPool;
|
|
41
|
+
get runtimeLogLevel(): number;
|
|
42
|
+
set runtimeLogLevel(level: number);
|
|
42
43
|
saveBlockToDB(block: Block): Promise<void>;
|
|
43
44
|
/**
|
|
44
45
|
* Try to load block from db and register it
|
package/lib/blockchain/index.js
CHANGED
|
@@ -19,7 +19,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
19
19
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
20
20
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
21
|
};
|
|
22
|
-
var _Blockchain_instances, _Blockchain_txpool, _Blockchain_inherentProvider, _Blockchain_head, _Blockchain_blocksByNumber, _Blockchain_blocksByHash, _Blockchain_loadingBlocks, _Blockchain_maxMemoryBlockCount, _Blockchain_registerBlock;
|
|
22
|
+
var _Blockchain_instances, _Blockchain_runtimeLogLevel, _Blockchain_txpool, _Blockchain_inherentProvider, _Blockchain_head, _Blockchain_blocksByNumber, _Blockchain_blocksByHash, _Blockchain_loadingBlocks, _Blockchain_maxMemoryBlockCount, _Blockchain_registerBlock;
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.Blockchain = void 0;
|
|
25
25
|
const util_crypto_1 = require("@polkadot/util-crypto");
|
|
@@ -37,6 +37,7 @@ class Blockchain {
|
|
|
37
37
|
constructor({ api, buildBlockMode, inherentProvider, db, header, mockSignatureHost = false, allowUnresolvedImports = false, runtimeLogLevel = 0, registeredTypes = {}, offchainWorker = false, maxMemoryBlockCount = 2000, }) {
|
|
38
38
|
_Blockchain_instances.add(this);
|
|
39
39
|
this.uid = Math.random().toString(36).substring(2);
|
|
40
|
+
_Blockchain_runtimeLogLevel.set(this, void 0);
|
|
40
41
|
_Blockchain_txpool.set(this, void 0);
|
|
41
42
|
_Blockchain_inherentProvider.set(this, void 0);
|
|
42
43
|
_Blockchain_head.set(this, void 0);
|
|
@@ -48,7 +49,7 @@ class Blockchain {
|
|
|
48
49
|
this.db = db;
|
|
49
50
|
this.mockSignatureHost = mockSignatureHost;
|
|
50
51
|
this.allowUnresolvedImports = allowUnresolvedImports;
|
|
51
|
-
this
|
|
52
|
+
__classPrivateFieldSet(this, _Blockchain_runtimeLogLevel, runtimeLogLevel, "f");
|
|
52
53
|
this.registeredTypes = registeredTypes;
|
|
53
54
|
__classPrivateFieldSet(this, _Blockchain_head, new block_1.Block(this, header.number, header.hash), "f");
|
|
54
55
|
__classPrivateFieldGet(this, _Blockchain_instances, "m", _Blockchain_registerBlock).call(this, __classPrivateFieldGet(this, _Blockchain_head, "f"));
|
|
@@ -66,6 +67,13 @@ class Blockchain {
|
|
|
66
67
|
get txPool() {
|
|
67
68
|
return __classPrivateFieldGet(this, _Blockchain_txpool, "f");
|
|
68
69
|
}
|
|
70
|
+
get runtimeLogLevel() {
|
|
71
|
+
return __classPrivateFieldGet(this, _Blockchain_runtimeLogLevel, "f");
|
|
72
|
+
}
|
|
73
|
+
set runtimeLogLevel(level) {
|
|
74
|
+
__classPrivateFieldSet(this, _Blockchain_runtimeLogLevel, level, "f");
|
|
75
|
+
logger.debug(`Runtime log level set to ${logger.level}`);
|
|
76
|
+
}
|
|
69
77
|
saveBlockToDB(block) {
|
|
70
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
79
|
if (this.db) {
|
|
@@ -101,7 +109,12 @@ class Blockchain {
|
|
|
101
109
|
const { hash, number, header, extrinsics, parentHash } = blockData;
|
|
102
110
|
const parentBlock = parentHash ? __classPrivateFieldGet(this, _Blockchain_blocksByHash, "f")[parentHash] : undefined;
|
|
103
111
|
const storageDiff = (_a = blockData.storageDiff) !== null && _a !== void 0 ? _a : undefined;
|
|
104
|
-
const
|
|
112
|
+
const registry = yield this.head.registry;
|
|
113
|
+
const block = new block_1.Block(this, number, hash, parentBlock, {
|
|
114
|
+
header: registry.createType('Header', header),
|
|
115
|
+
extrinsics,
|
|
116
|
+
storageDiff,
|
|
117
|
+
});
|
|
105
118
|
__classPrivateFieldGet(this, _Blockchain_instances, "m", _Blockchain_registerBlock).call(this, block);
|
|
106
119
|
return block;
|
|
107
120
|
}
|
|
@@ -358,7 +371,7 @@ class Blockchain {
|
|
|
358
371
|
}
|
|
359
372
|
}
|
|
360
373
|
exports.Blockchain = Blockchain;
|
|
361
|
-
_Blockchain_txpool = new WeakMap(), _Blockchain_inherentProvider = new WeakMap(), _Blockchain_head = new WeakMap(), _Blockchain_blocksByNumber = new WeakMap(), _Blockchain_blocksByHash = new WeakMap(), _Blockchain_loadingBlocks = new WeakMap(), _Blockchain_maxMemoryBlockCount = new WeakMap(), _Blockchain_instances = new WeakSet(), _Blockchain_registerBlock = function _Blockchain_registerBlock(block) {
|
|
374
|
+
_Blockchain_runtimeLogLevel = new WeakMap(), _Blockchain_txpool = new WeakMap(), _Blockchain_inherentProvider = new WeakMap(), _Blockchain_head = new WeakMap(), _Blockchain_blocksByNumber = new WeakMap(), _Blockchain_blocksByHash = new WeakMap(), _Blockchain_loadingBlocks = new WeakMap(), _Blockchain_maxMemoryBlockCount = new WeakMap(), _Blockchain_instances = new WeakSet(), _Blockchain_registerBlock = function _Blockchain_registerBlock(block) {
|
|
362
375
|
// if exceed max memory block count, delete the oldest block
|
|
363
376
|
if (__classPrivateFieldGet(this, _Blockchain_blocksByNumber, "f").size === __classPrivateFieldGet(this, _Blockchain_maxMemoryBlockCount, "f")) {
|
|
364
377
|
const firstKey = __classPrivateFieldGet(this, _Blockchain_blocksByNumber, "f").keys().next().value;
|
package/lib/db/entities.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { EntitySchema } from 'typeorm';
|
|
2
|
-
import { Header } from '@polkadot/types/interfaces';
|
|
3
2
|
import { HexString } from '@polkadot/util/types';
|
|
4
3
|
export declare const KeyValuePair: EntitySchema<{
|
|
5
4
|
blockHash: string;
|
|
@@ -9,7 +8,7 @@ export declare const KeyValuePair: EntitySchema<{
|
|
|
9
8
|
export declare const BlockEntity: EntitySchema<{
|
|
10
9
|
hash: HexString;
|
|
11
10
|
number: number;
|
|
12
|
-
header:
|
|
11
|
+
header: object;
|
|
13
12
|
parentHash: HexString | null;
|
|
14
13
|
extrinsics: HexString[];
|
|
15
14
|
storageDiff: Record<HexString, HexString | null> | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acala-network/chopsticks-core",
|
|
3
|
-
"version": "0.8.0
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"author": "Bryan Chen <xlchen1291@gmail.com>",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"scripts": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"build": "yarn pack-wasm; tsc -p ./tsconfig.json"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@acala-network/chopsticks-executor": "0.8.0
|
|
12
|
+
"@acala-network/chopsticks-executor": "0.8.0",
|
|
13
13
|
"@polkadot/api": "^10.9.1",
|
|
14
14
|
"@polkadot/util-crypto": "^12.3.2",
|
|
15
15
|
"axios": "^1.5.0",
|
|
@@ -44,6 +44,5 @@
|
|
|
44
44
|
"default": "./lib/*.js"
|
|
45
45
|
},
|
|
46
46
|
"./package.json": "./package.json"
|
|
47
|
-
}
|
|
48
|
-
"stableVersion": "0.7.3"
|
|
47
|
+
}
|
|
49
48
|
}
|