@acala-network/chopsticks 0.8.0-3 → 0.8.0-5
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/plugins/decode-key/index.js +2 -2
- package/lib/plugins/dry-run/rpc.js +3 -3
- package/lib/setup-with-server.d.ts +1 -1
- package/lib/setup-with-server.js +4 -1
- package/lib/utils/decoder.d.ts +5 -16
- package/lib/utils/decoder.js +4 -89
- package/lib/utils/generate-html-diff.js +2 -2
- package/package.json +5 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cli = void 0;
|
|
4
|
-
const
|
|
4
|
+
const chopsticks_core_1 = require("@acala-network/chopsticks-core");
|
|
5
5
|
const cli_options_1 = require("../../cli-options");
|
|
6
6
|
const context_1 = require("../../context");
|
|
7
7
|
const cli = (y) => {
|
|
@@ -14,7 +14,7 @@ const cli = (y) => {
|
|
|
14
14
|
...cli_options_1.defaultOptions,
|
|
15
15
|
}), async (argv) => {
|
|
16
16
|
const context = await (0, context_1.setupContext)(argv);
|
|
17
|
-
const { storage, decodedKey } = (0,
|
|
17
|
+
const { storage, decodedKey } = (0, chopsticks_core_1.decodeKey)(await context.chain.head.meta, context.chain.head, argv.key);
|
|
18
18
|
if (storage && decodedKey) {
|
|
19
19
|
console.log(`${storage.section}.${storage.method}`, decodedKey.args.map((x) => JSON.stringify(x.toHuman())).join(', '));
|
|
20
20
|
}
|
|
@@ -68,10 +68,10 @@ const rpc = async (context, [params]) => {
|
|
|
68
68
|
if (raw) {
|
|
69
69
|
return storageDiff;
|
|
70
70
|
}
|
|
71
|
-
const
|
|
71
|
+
const { oldState, newState, delta } = await (0, decoder_1.decodeStorageDiff)(context.chain.head, storageDiff);
|
|
72
72
|
return {
|
|
73
|
-
old:
|
|
74
|
-
new:
|
|
73
|
+
old: oldState,
|
|
74
|
+
new: newState,
|
|
75
75
|
delta,
|
|
76
76
|
};
|
|
77
77
|
};
|
package/lib/setup-with-server.js
CHANGED
|
@@ -16,8 +16,11 @@ const setupWithServer = async (argv) => {
|
|
|
16
16
|
shared_1.logger.info(`${await context.chain.api.getSystemChain()} RPC listening on port ${listenPort}`);
|
|
17
17
|
return {
|
|
18
18
|
...context,
|
|
19
|
-
close,
|
|
20
19
|
listenPort,
|
|
20
|
+
async close() {
|
|
21
|
+
await context.chain.close();
|
|
22
|
+
await close();
|
|
23
|
+
},
|
|
21
24
|
};
|
|
22
25
|
};
|
|
23
26
|
exports.setupWithServer = setupWithServer;
|
package/lib/utils/decoder.d.ts
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
import '@polkadot/types-codec';
|
|
2
1
|
import { Block } from '@acala-network/chopsticks-core';
|
|
3
|
-
import { DecoratedMeta } from '@polkadot/types/metadata/decorate/types';
|
|
4
2
|
import { HexString } from '@polkadot/util/types';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
export declare const decodeStorageDiff: (block: Block, diff: [HexString, HexString | null][]) => Promise<({} | undefined)[]>;
|
|
3
|
+
export declare const decodeStorageDiff: (block: Block, diff: [HexString, HexString | null][]) => Promise<{
|
|
4
|
+
oldState: {};
|
|
5
|
+
newState: {};
|
|
6
|
+
delta: import("jsondiffpatch").Delta | undefined;
|
|
7
|
+
}>;
|
package/lib/utils/decoder.js
CHANGED
|
@@ -3,105 +3,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.decodeStorageDiff =
|
|
7
|
-
require("@
|
|
8
|
-
const util_crypto_1 = require("@polkadot/util-crypto");
|
|
6
|
+
exports.decodeStorageDiff = void 0;
|
|
7
|
+
const chopsticks_core_1 = require("@acala-network/chopsticks-core");
|
|
9
8
|
const jsondiffpatch_1 = require("jsondiffpatch");
|
|
10
|
-
const util_1 = require("@polkadot/util");
|
|
11
9
|
const lodash_1 = __importDefault(require("lodash"));
|
|
12
10
|
const diffPatcher = (0, jsondiffpatch_1.create)({
|
|
13
11
|
array: { detectMove: false },
|
|
14
12
|
textDiff: { minLength: Number.MAX_VALUE }, // skip text diff
|
|
15
13
|
});
|
|
16
|
-
const _CACHE = {};
|
|
17
|
-
const getCache = (uid) => {
|
|
18
|
-
if (!_CACHE[uid]) {
|
|
19
|
-
_CACHE[uid] = {};
|
|
20
|
-
}
|
|
21
|
-
return _CACHE[uid];
|
|
22
|
-
};
|
|
23
|
-
const getStorageEntry = (meta, block, key) => {
|
|
24
|
-
const cache = getCache(block.chain.uid);
|
|
25
|
-
for (const [prefix, storageEntry] of Object.entries(cache)) {
|
|
26
|
-
if (key.startsWith(prefix))
|
|
27
|
-
return storageEntry;
|
|
28
|
-
}
|
|
29
|
-
for (const module of Object.values(meta.query)) {
|
|
30
|
-
for (const storage of Object.values(module)) {
|
|
31
|
-
const keyPrefix = (0, util_1.u8aToHex)(storage.keyPrefix());
|
|
32
|
-
if (key.startsWith(keyPrefix)) {
|
|
33
|
-
cache[keyPrefix] = storage;
|
|
34
|
-
return storage;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return undefined;
|
|
39
|
-
};
|
|
40
|
-
const decodeKey = (meta, block, key) => {
|
|
41
|
-
const storage = getStorageEntry(meta, block, key);
|
|
42
|
-
const decodedKey = meta.registry.createType('StorageKey', key);
|
|
43
|
-
if (storage) {
|
|
44
|
-
decodedKey.setMeta(storage.meta);
|
|
45
|
-
return { storage, decodedKey };
|
|
46
|
-
}
|
|
47
|
-
return {};
|
|
48
|
-
};
|
|
49
|
-
exports.decodeKey = decodeKey;
|
|
50
|
-
const decodeKeyValue = (meta, block, key, value) => {
|
|
51
|
-
const { storage, decodedKey } = (0, exports.decodeKey)(meta, block, key);
|
|
52
|
-
if (!storage || !decodedKey) {
|
|
53
|
-
return { [key]: value };
|
|
54
|
-
}
|
|
55
|
-
const decodeValue = () => {
|
|
56
|
-
if (!value)
|
|
57
|
-
return null;
|
|
58
|
-
if (storage.section === 'substrate' && storage.method === 'code') {
|
|
59
|
-
return `:code blake2_256 ${(0, util_crypto_1.blake2AsHex)(value, 256)} (${(0, util_1.hexToU8a)(value).length} bytes)`;
|
|
60
|
-
}
|
|
61
|
-
return meta.registry.createType(decodedKey.outputType, (0, util_1.hexToU8a)(value)).toHuman();
|
|
62
|
-
};
|
|
63
|
-
switch (decodedKey.args.length) {
|
|
64
|
-
case 2: {
|
|
65
|
-
return {
|
|
66
|
-
[storage.section]: {
|
|
67
|
-
[storage.method]: {
|
|
68
|
-
[decodedKey.args[0].toString()]: {
|
|
69
|
-
[decodedKey.args[1].toString()]: decodeValue(),
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
case 1: {
|
|
76
|
-
return {
|
|
77
|
-
[storage.section]: {
|
|
78
|
-
[storage.method]: {
|
|
79
|
-
[decodedKey.args[0].toString()]: decodeValue(),
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
default:
|
|
85
|
-
return {
|
|
86
|
-
[storage.section]: {
|
|
87
|
-
[storage.method]: decodeValue(),
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
exports.decodeKeyValue = decodeKeyValue;
|
|
93
14
|
const decodeStorageDiff = async (block, diff) => {
|
|
94
|
-
const oldState =
|
|
95
|
-
const newState = {};
|
|
96
|
-
const meta = await block.meta;
|
|
97
|
-
for (const [key, value] of diff) {
|
|
98
|
-
lodash_1.default.merge(oldState, (0, exports.decodeKeyValue)(meta, block, key, (await block.get(key))));
|
|
99
|
-
lodash_1.default.merge(newState, (0, exports.decodeKeyValue)(meta, block, key, value));
|
|
100
|
-
}
|
|
15
|
+
const [oldState, newState] = await (0, chopsticks_core_1.decodeBlockStorageDiff)(block, diff);
|
|
101
16
|
const oldStateWithoutEvents = lodash_1.default.cloneDeep(oldState);
|
|
102
17
|
if (oldStateWithoutEvents['system']?.['events']) {
|
|
103
18
|
oldStateWithoutEvents['system']['events'] = [];
|
|
104
19
|
}
|
|
105
|
-
return
|
|
20
|
+
return { oldState, newState, delta: diffPatcher.diff(oldStateWithoutEvents, newState) };
|
|
106
21
|
};
|
|
107
22
|
exports.decodeStorageDiff = decodeStorageDiff;
|
|
@@ -9,9 +9,9 @@ const node_fs_1 = require("node:fs");
|
|
|
9
9
|
const lodash_1 = require("lodash");
|
|
10
10
|
const node_path_1 = __importDefault(require("node:path"));
|
|
11
11
|
const generateHtmlDiff = async (block, diff) => {
|
|
12
|
-
const
|
|
12
|
+
const { oldState, delta } = await (0, decoder_1.decodeStorageDiff)(block, diff);
|
|
13
13
|
const htmlTemplate = (0, node_fs_1.readFileSync)(node_path_1.default.join(__dirname, '../../template/diff.html'), 'utf-8');
|
|
14
|
-
return (0, lodash_1.template)(htmlTemplate)({ left: JSON.stringify(
|
|
14
|
+
return (0, lodash_1.template)(htmlTemplate)({ left: JSON.stringify(oldState), delta: JSON.stringify(delta) });
|
|
15
15
|
};
|
|
16
16
|
exports.generateHtmlDiff = generateHtmlDiff;
|
|
17
17
|
const generateHtmlDiffPreviewFile = async (block, diff, filename) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acala-network/chopsticks",
|
|
3
|
-
"version": "0.8.0-
|
|
3
|
+
"version": "0.8.0-5",
|
|
4
4
|
"author": "Bryan Chen <xlchen1291@gmail.com>",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"bin": "./chopsticks.js",
|
|
@@ -16,24 +16,24 @@
|
|
|
16
16
|
"dev:moonbeam": "cd ../..; ts-node-dev --transpile-only --inspect -r tsconfig-paths/register --notify=false packages/chopsticks/src/cli.ts -- --config=configs/moonbeam.yml"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@acala-network/chopsticks-core": "0.8.0-
|
|
19
|
+
"@acala-network/chopsticks-core": "0.8.0-5",
|
|
20
20
|
"@pnpm/npm-conf": "^2.2.2",
|
|
21
21
|
"@polkadot/api": "^10.9.1",
|
|
22
22
|
"axios": "^1.4.0",
|
|
23
23
|
"dotenv": "^16.3.1",
|
|
24
24
|
"global-agent": "^3.0.0",
|
|
25
25
|
"js-yaml": "^4.1.0",
|
|
26
|
-
"jsondiffpatch": "^0.
|
|
26
|
+
"jsondiffpatch": "^0.5.0",
|
|
27
27
|
"lodash": "^4.17.21",
|
|
28
28
|
"ws": "^8.13.0",
|
|
29
29
|
"yargs": "^17.7.2",
|
|
30
|
-
"zod": "^3.
|
|
30
|
+
"zod": "^3.22.2"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/global-agent": "^2.1.1",
|
|
34
34
|
"@types/js-yaml": "^4.0.5",
|
|
35
35
|
"@types/lodash": "^4.14.197",
|
|
36
|
-
"@types/node": "^20.
|
|
36
|
+
"@types/node": "^20.5.1",
|
|
37
37
|
"@types/ws": "^8.5.5",
|
|
38
38
|
"@types/yargs": "^17.0.24",
|
|
39
39
|
"ts-node": "^10.9.1",
|