@acala-network/chopsticks-core 0.8.0-3 → 0.8.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/lib/blockchain/index.d.ts +1 -0
- package/lib/blockchain/index.js +6 -0
- package/lib/utils/decoder.d.ts +24 -0
- package/lib/utils/decoder.js +113 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +1 -0
- package/package.json +2 -2
|
@@ -70,4 +70,5 @@ export declare class Blockchain {
|
|
|
70
70
|
dryRunDmp(dmp: DownwardMessage[], at?: HexString): Promise<[HexString, HexString | null][]>;
|
|
71
71
|
dryRunUmp(ump: Record<number, HexString[]>, at?: HexString): Promise<[HexString, HexString | null][]>;
|
|
72
72
|
getInherents(): Promise<HexString[]>;
|
|
73
|
+
close(): Promise<void>;
|
|
73
74
|
}
|
package/lib/blockchain/index.js
CHANGED
|
@@ -342,6 +342,12 @@ class Blockchain {
|
|
|
342
342
|
return inherents;
|
|
343
343
|
});
|
|
344
344
|
}
|
|
345
|
+
close() {
|
|
346
|
+
var _a;
|
|
347
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
348
|
+
yield ((_a = this.db) === null || _a === void 0 ? void 0 : _a.destroy());
|
|
349
|
+
});
|
|
350
|
+
}
|
|
345
351
|
}
|
|
346
352
|
exports.Blockchain = Blockchain;
|
|
347
353
|
_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) {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import '@polkadot/types-codec';
|
|
2
|
+
import { Block } from '../blockchain/block';
|
|
3
|
+
import { DecoratedMeta } from '@polkadot/types/metadata/decorate/types';
|
|
4
|
+
import { HexString } from '@polkadot/util/types';
|
|
5
|
+
import { StorageEntry } from '@polkadot/types/primitive/types';
|
|
6
|
+
import { StorageKey } from '@polkadot/types';
|
|
7
|
+
export declare const decodeKey: (meta: DecoratedMeta, block: Block, key: HexString) => {
|
|
8
|
+
storage?: StorageEntry | undefined;
|
|
9
|
+
decodedKey?: StorageKey<import("@polkadot/types-codec/types").AnyTuple> | undefined;
|
|
10
|
+
};
|
|
11
|
+
export declare const decodeKeyValue: (meta: DecoratedMeta, block: Block, key: HexString, value?: HexString | null) => {
|
|
12
|
+
[x: string]: `0x${string}` | null | undefined;
|
|
13
|
+
} | {
|
|
14
|
+
[x: string]: {
|
|
15
|
+
[x: string]: import("@polkadot/types-codec/types").AnyJson;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Decode block storage diff
|
|
20
|
+
* @param block Block to compare storage diff
|
|
21
|
+
* @param diff Storage diff
|
|
22
|
+
* @returns decoded old state and new state
|
|
23
|
+
*/
|
|
24
|
+
export declare const decodeBlockStorageDiff: (block: Block, diff: [HexString, HexString | null][]) => Promise<{}[]>;
|
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.decodeBlockStorageDiff = exports.decodeKeyValue = exports.decodeKey = void 0;
|
|
16
|
+
require("@polkadot/types-codec");
|
|
17
|
+
const util_crypto_1 = require("@polkadot/util-crypto");
|
|
18
|
+
const util_1 = require("@polkadot/util");
|
|
19
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
20
|
+
const _CACHE = {};
|
|
21
|
+
const getCache = (uid) => {
|
|
22
|
+
if (!_CACHE[uid]) {
|
|
23
|
+
_CACHE[uid] = new Map();
|
|
24
|
+
}
|
|
25
|
+
return _CACHE[uid];
|
|
26
|
+
};
|
|
27
|
+
const getStorageEntry = (meta, block, key) => {
|
|
28
|
+
const cache = getCache(block.chain.uid);
|
|
29
|
+
for (const [prefix, storageEntry] of cache.entries()) {
|
|
30
|
+
if (key.startsWith(prefix))
|
|
31
|
+
return storageEntry;
|
|
32
|
+
}
|
|
33
|
+
for (const module of Object.values(meta.query)) {
|
|
34
|
+
for (const storage of Object.values(module)) {
|
|
35
|
+
const keyPrefix = (0, util_1.u8aToHex)(storage.keyPrefix());
|
|
36
|
+
if (key.startsWith(keyPrefix)) {
|
|
37
|
+
cache.set(keyPrefix, storage);
|
|
38
|
+
return storage;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
};
|
|
44
|
+
const decodeKey = (meta, block, key) => {
|
|
45
|
+
const storage = getStorageEntry(meta, block, key);
|
|
46
|
+
const decodedKey = meta.registry.createType('StorageKey', key);
|
|
47
|
+
if (storage) {
|
|
48
|
+
decodedKey.setMeta(storage.meta);
|
|
49
|
+
return { storage, decodedKey };
|
|
50
|
+
}
|
|
51
|
+
return {};
|
|
52
|
+
};
|
|
53
|
+
exports.decodeKey = decodeKey;
|
|
54
|
+
const decodeKeyValue = (meta, block, key, value) => {
|
|
55
|
+
const { storage, decodedKey } = (0, exports.decodeKey)(meta, block, key);
|
|
56
|
+
if (!storage || !decodedKey) {
|
|
57
|
+
return { [key]: value };
|
|
58
|
+
}
|
|
59
|
+
const decodeValue = () => {
|
|
60
|
+
if (!value)
|
|
61
|
+
return null;
|
|
62
|
+
if (storage.section === 'substrate' && storage.method === 'code') {
|
|
63
|
+
return `:code blake2_256 ${(0, util_crypto_1.blake2AsHex)(value, 256)} (${(0, util_1.hexToU8a)(value).length} bytes)`;
|
|
64
|
+
}
|
|
65
|
+
return meta.registry.createType(decodedKey.outputType, (0, util_1.hexToU8a)(value)).toHuman();
|
|
66
|
+
};
|
|
67
|
+
switch (decodedKey.args.length) {
|
|
68
|
+
case 2: {
|
|
69
|
+
return {
|
|
70
|
+
[storage.section]: {
|
|
71
|
+
[storage.method]: {
|
|
72
|
+
[decodedKey.args[0].toString()]: {
|
|
73
|
+
[decodedKey.args[1].toString()]: decodeValue(),
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
case 1: {
|
|
80
|
+
return {
|
|
81
|
+
[storage.section]: {
|
|
82
|
+
[storage.method]: {
|
|
83
|
+
[decodedKey.args[0].toString()]: decodeValue(),
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
default:
|
|
89
|
+
return {
|
|
90
|
+
[storage.section]: {
|
|
91
|
+
[storage.method]: decodeValue(),
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
exports.decodeKeyValue = decodeKeyValue;
|
|
97
|
+
/**
|
|
98
|
+
* Decode block storage diff
|
|
99
|
+
* @param block Block to compare storage diff
|
|
100
|
+
* @param diff Storage diff
|
|
101
|
+
* @returns decoded old state and new state
|
|
102
|
+
*/
|
|
103
|
+
const decodeBlockStorageDiff = (block, diff) => __awaiter(void 0, void 0, void 0, function* () {
|
|
104
|
+
const oldState = {};
|
|
105
|
+
const newState = {};
|
|
106
|
+
const meta = yield block.meta;
|
|
107
|
+
for (const [key, value] of diff) {
|
|
108
|
+
lodash_1.default.merge(oldState, (0, exports.decodeKeyValue)(meta, block, key, (yield block.get(key))));
|
|
109
|
+
lodash_1.default.merge(newState, (0, exports.decodeKeyValue)(meta, block, key, value));
|
|
110
|
+
}
|
|
111
|
+
return [oldState, newState];
|
|
112
|
+
});
|
|
113
|
+
exports.decodeBlockStorageDiff = decodeBlockStorageDiff;
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { StorageKey } from '@polkadot/types';
|
|
|
3
3
|
import { Blockchain } from '../blockchain';
|
|
4
4
|
export * from './set-storage';
|
|
5
5
|
export * from './time-travel';
|
|
6
|
+
export * from './decoder';
|
|
6
7
|
export type GetKeys = (startKey?: string) => Promise<StorageKey<any>[]>;
|
|
7
8
|
export type ProcessKey = (key: StorageKey<any>) => any;
|
|
8
9
|
export declare function fetchKeys(getKeys: GetKeys, processKey: ProcessKey): Promise<void>;
|
package/lib/utils/index.js
CHANGED
|
@@ -27,6 +27,7 @@ exports.defer = exports.isUrl = exports.getParaId = exports.compactHex = exports
|
|
|
27
27
|
const util_1 = require("@polkadot/util");
|
|
28
28
|
__exportStar(require("./set-storage"), exports);
|
|
29
29
|
__exportStar(require("./time-travel"), exports);
|
|
30
|
+
__exportStar(require("./decoder"), exports);
|
|
30
31
|
function fetchKeys(getKeys, processKey) {
|
|
31
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
33
|
const processKeys = (keys) => __awaiter(this, void 0, void 0, function* () {
|
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
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-4",
|
|
13
13
|
"@polkadot/api": "^10.9.1",
|
|
14
14
|
"axios": "^1.4.0",
|
|
15
15
|
"eventemitter3": "^5.0.1",
|