@acala-network/chopsticks 0.5.3 → 0.5.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/api.js +1 -5
- package/lib/blockchain/block-builder.js +36 -43
- package/lib/blockchain/block.js +24 -28
- package/lib/blockchain/head-state.js +9 -14
- package/lib/blockchain/index.js +24 -28
- package/lib/blockchain/inherent/index.js +11 -20
- package/lib/blockchain/inherent/para-enter.js +3 -7
- package/lib/blockchain/inherent/parachain/babe-randomness.js +3 -7
- package/lib/blockchain/inherent/parachain/nimbus-author-inherent.js +3 -7
- package/lib/blockchain/inherent/parachain/validation-data.js +26 -33
- package/lib/blockchain/storage-layer.js +8 -16
- package/lib/blockchain/txpool.js +13 -20
- package/lib/cli.js +30 -35
- package/lib/db/entities.js +6 -9
- package/lib/db/index.js +5 -32
- package/lib/dry-run-preimage.js +23 -27
- package/lib/dry-run.js +12 -16
- package/lib/executor.js +24 -36
- package/lib/genesis-provider.js +17 -24
- package/lib/index.js +7 -31
- package/lib/logger.js +3 -10
- package/lib/rpc/dev/dry-run.js +21 -28
- package/lib/rpc/dev/index.js +14 -16
- package/lib/rpc/index.js +9 -16
- package/lib/rpc/shared.js +3 -7
- package/lib/rpc/substrate/author.js +8 -10
- package/lib/rpc/substrate/chain.js +5 -7
- package/lib/rpc/substrate/index.js +11 -16
- package/lib/rpc/substrate/payment.js +7 -9
- package/lib/rpc/substrate/state.js +5 -7
- package/lib/rpc/substrate/system.js +6 -11
- package/lib/run-block.js +12 -16
- package/lib/schema/index.js +22 -25
- package/lib/server.js +8 -35
- package/lib/setup-with-server.js +8 -12
- package/lib/setup.js +26 -30
- package/lib/utils/decoder.js +16 -25
- package/lib/utils/generate-html-diff.js +12 -20
- package/lib/utils/import-storage.js +11 -19
- package/lib/utils/index.js +10 -19
- package/lib/utils/open-html.js +3 -7
- package/lib/utils/proof.js +9 -17
- package/lib/utils/set-storage.js +10 -14
- package/lib/utils/time-travel.js +21 -28
- package/lib/xcm/downward.js +11 -15
- package/lib/xcm/horizontal.js +7 -11
- package/lib/xcm/index.js +14 -19
- package/lib/xcm/upward.js +6 -10
- package/package.json +2 -2
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const util_1 = require("@polkadot/util");
|
|
7
|
-
const node_fs_1 = require("node:fs");
|
|
8
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
1
|
+
import { hexToU8a } from '@polkadot/util';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
9
4
|
const handlers = {
|
|
10
5
|
system_localPeerId: async () => '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY',
|
|
11
6
|
system_nodeRoles: async () => ['Full'],
|
|
@@ -20,7 +15,7 @@ const handlers = {
|
|
|
20
15
|
return context.chain.api.getSystemName();
|
|
21
16
|
},
|
|
22
17
|
system_version: async (_context) => {
|
|
23
|
-
const { version } = JSON.parse(
|
|
18
|
+
const { version } = JSON.parse(readFileSync(path.join(__dirname, '../../../package.json'), 'utf-8'));
|
|
24
19
|
return `chopsticks-v${version}`;
|
|
25
20
|
},
|
|
26
21
|
system_chainType: async (_context) => {
|
|
@@ -42,8 +37,8 @@ const handlers = {
|
|
|
42
37
|
const registry = await head.registry;
|
|
43
38
|
const account = registry.createType('AccountId', address);
|
|
44
39
|
const result = await head.call('AccountNonceApi_account_nonce', [account.toHex()]);
|
|
45
|
-
const nonce = registry.createType('Index',
|
|
40
|
+
const nonce = registry.createType('Index', hexToU8a(result.result)).toNumber();
|
|
46
41
|
return nonce + context.chain.txPool.pendingExtrinsicsBy(address).length;
|
|
47
42
|
},
|
|
48
43
|
};
|
|
49
|
-
|
|
44
|
+
export default handlers;
|
package/lib/run-block.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const setup_1 = require("./setup");
|
|
9
|
-
const runBlock = async (argv) => {
|
|
10
|
-
const context = await (0, setup_1.setup)(argv);
|
|
1
|
+
import { writeFileSync } from 'node:fs';
|
|
2
|
+
import { generateHtmlDiffPreviewFile } from './utils/generate-html-diff';
|
|
3
|
+
import { openHtml } from './utils/open-html';
|
|
4
|
+
import { runTask, taskHandler } from './executor';
|
|
5
|
+
import { setup } from './setup';
|
|
6
|
+
export const runBlock = async (argv) => {
|
|
7
|
+
const context = await setup(argv);
|
|
11
8
|
const header = await context.chain.head.header;
|
|
12
9
|
const wasm = await context.chain.head.wasm;
|
|
13
10
|
const block = context.chain.head;
|
|
@@ -19,29 +16,28 @@ const runBlock = async (argv) => {
|
|
|
19
16
|
calls.push(['BlockBuilder_apply_extrinsic', [extrinsic]]);
|
|
20
17
|
}
|
|
21
18
|
calls.push(['BlockBuilder_finalize_block', []]);
|
|
22
|
-
const result = await
|
|
19
|
+
const result = await runTask({
|
|
23
20
|
wasm,
|
|
24
21
|
calls,
|
|
25
22
|
storage: [],
|
|
26
23
|
mockSignatureHost: false,
|
|
27
24
|
allowUnresolvedImports: false,
|
|
28
|
-
},
|
|
25
|
+
}, taskHandler(parent));
|
|
29
26
|
if (result.Error) {
|
|
30
27
|
throw new Error(result.Error);
|
|
31
28
|
}
|
|
32
29
|
if (argv['html']) {
|
|
33
|
-
const filePath = await
|
|
30
|
+
const filePath = await generateHtmlDiffPreviewFile(parent, result.Call.storageDiff, block.hash);
|
|
34
31
|
console.log(`Generated preview ${filePath}`);
|
|
35
32
|
if (argv['open']) {
|
|
36
|
-
|
|
33
|
+
openHtml(filePath);
|
|
37
34
|
}
|
|
38
35
|
}
|
|
39
36
|
else if (argv['output-path']) {
|
|
40
|
-
|
|
37
|
+
writeFileSync(argv['output-path'], JSON.stringify(result, null, 2));
|
|
41
38
|
}
|
|
42
39
|
else {
|
|
43
40
|
console.dir(result, { depth: null, colors: false });
|
|
44
41
|
}
|
|
45
42
|
process.exit(0);
|
|
46
43
|
};
|
|
47
|
-
exports.runBlock = runBlock;
|
package/lib/schema/index.js
CHANGED
|
@@ -1,30 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
ss58Format: zod_1.z.number().optional(),
|
|
11
|
-
tokenDecimals: zod_1.z.union([zod_1.z.number(), zod_1.z.array(zod_1.z.number())]).optional(),
|
|
12
|
-
tokenSymbol: zod_1.z.union([zod_1.z.string(), zod_1.z.array(zod_1.z.string())]).optional(),
|
|
1
|
+
import { BuildBlockMode } from '../blockchain/txpool';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export const genesisSchema = z.object({
|
|
4
|
+
id: z.string(),
|
|
5
|
+
name: z.string(),
|
|
6
|
+
properties: z.object({
|
|
7
|
+
ss58Format: z.number().optional(),
|
|
8
|
+
tokenDecimals: z.union([z.number(), z.array(z.number())]).optional(),
|
|
9
|
+
tokenSymbol: z.union([z.string(), z.array(z.string())]).optional(),
|
|
13
10
|
}),
|
|
14
|
-
genesis:
|
|
11
|
+
genesis: z.object({ raw: z.object({ top: z.record(z.string()) }) }),
|
|
15
12
|
});
|
|
16
|
-
|
|
13
|
+
export const configSchema = z
|
|
17
14
|
.object({
|
|
18
|
-
port:
|
|
19
|
-
endpoint:
|
|
20
|
-
block:
|
|
21
|
-
'build-block-mode':
|
|
22
|
-
'import-storage':
|
|
23
|
-
'mock-signature-host':
|
|
24
|
-
db:
|
|
25
|
-
'wasm-override':
|
|
26
|
-
genesis:
|
|
27
|
-
timestamp:
|
|
28
|
-
'registered-types':
|
|
15
|
+
port: z.number().optional(),
|
|
16
|
+
endpoint: z.string().optional(),
|
|
17
|
+
block: z.union([z.string().length(66).startsWith('0x'), z.number()]).optional(),
|
|
18
|
+
'build-block-mode': z.nativeEnum(BuildBlockMode).optional(),
|
|
19
|
+
'import-storage': z.any().optional(),
|
|
20
|
+
'mock-signature-host': z.boolean().optional(),
|
|
21
|
+
db: z.string().optional(),
|
|
22
|
+
'wasm-override': z.string().optional(),
|
|
23
|
+
genesis: z.union([z.string(), genesisSchema]).optional(),
|
|
24
|
+
timestamp: z.number().optional(),
|
|
25
|
+
'registered-types': z.any().optional(),
|
|
29
26
|
})
|
|
30
27
|
.strict();
|
package/lib/server.js
CHANGED
|
@@ -1,32 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.createServer = void 0;
|
|
27
|
-
const ws_1 = __importStar(require("ws"));
|
|
28
|
-
const logger_1 = require("./logger");
|
|
29
|
-
const logger = logger_1.defaultLogger.child({ name: 'ws' });
|
|
1
|
+
import WebSocket, { WebSocketServer } from 'ws';
|
|
2
|
+
import { defaultLogger, truncate } from './logger';
|
|
3
|
+
const logger = defaultLogger.child({ name: 'ws' });
|
|
30
4
|
const parseRequest = (request) => {
|
|
31
5
|
try {
|
|
32
6
|
return JSON.parse(request);
|
|
@@ -36,7 +10,7 @@ const parseRequest = (request) => {
|
|
|
36
10
|
}
|
|
37
11
|
};
|
|
38
12
|
const createWS = async (port) => {
|
|
39
|
-
const wss = new
|
|
13
|
+
const wss = new WebSocketServer({ port, maxPayload: 1024 * 1024 * 100 });
|
|
40
14
|
const promise = new Promise((resolve) => {
|
|
41
15
|
wss.on('listening', () => {
|
|
42
16
|
resolve([wss, wss.address().port]);
|
|
@@ -47,7 +21,7 @@ const createWS = async (port) => {
|
|
|
47
21
|
});
|
|
48
22
|
return promise;
|
|
49
23
|
};
|
|
50
|
-
const createServer = async (handler, port) => {
|
|
24
|
+
export const createServer = async (handler, port) => {
|
|
51
25
|
let wss;
|
|
52
26
|
let listenPort;
|
|
53
27
|
for (let i = 0; i < 5; i++) {
|
|
@@ -66,7 +40,7 @@ const createServer = async (handler, port) => {
|
|
|
66
40
|
wss.on('connection', (ws) => {
|
|
67
41
|
logger.debug('New connection');
|
|
68
42
|
const send = (data) => {
|
|
69
|
-
if (ws.readyState ===
|
|
43
|
+
if (ws.readyState === WebSocket.OPEN) {
|
|
70
44
|
ws.send(JSON.stringify(data));
|
|
71
45
|
}
|
|
72
46
|
};
|
|
@@ -76,7 +50,7 @@ const createServer = async (handler, port) => {
|
|
|
76
50
|
subscriptions[subid] = onCancel;
|
|
77
51
|
return (data) => {
|
|
78
52
|
if (subscriptions[subid]) {
|
|
79
|
-
logger.trace({ method, subid, data:
|
|
53
|
+
logger.trace({ method, subid, data: truncate(data) }, 'Subscription notification');
|
|
80
54
|
send({
|
|
81
55
|
jsonrpc: '2.0',
|
|
82
56
|
method,
|
|
@@ -132,7 +106,7 @@ const createServer = async (handler, port) => {
|
|
|
132
106
|
logger.trace({
|
|
133
107
|
id: req.id,
|
|
134
108
|
method: req.method,
|
|
135
|
-
result:
|
|
109
|
+
result: truncate(resp),
|
|
136
110
|
}, 'Sending response for request');
|
|
137
111
|
send({
|
|
138
112
|
id: req.id,
|
|
@@ -165,4 +139,3 @@ const createServer = async (handler, port) => {
|
|
|
165
139
|
}),
|
|
166
140
|
};
|
|
167
141
|
};
|
|
168
|
-
exports.createServer = createServer;
|
package/lib/setup-with-server.js
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const setup_1 = require("./setup");
|
|
8
|
-
const setupWithServer = async (argv) => {
|
|
9
|
-
const context = await (0, setup_1.setup)(argv);
|
|
1
|
+
import { createServer } from './server';
|
|
2
|
+
import { handler } from './rpc';
|
|
3
|
+
import { logger } from './rpc/shared';
|
|
4
|
+
import { setup } from './setup';
|
|
5
|
+
export const setupWithServer = async (argv) => {
|
|
6
|
+
const context = await setup(argv);
|
|
10
7
|
const port = argv.port ?? 8000;
|
|
11
8
|
if (argv.genesis) {
|
|
12
9
|
// mine 1st block when starting from genesis to set some mock validation data
|
|
13
10
|
await context.chain.newBlock();
|
|
14
11
|
}
|
|
15
|
-
const { close, port: listenPort } = await
|
|
16
|
-
|
|
12
|
+
const { close, port: listenPort } = await createServer(handler(context), port);
|
|
13
|
+
logger.info(`${await context.chain.api.getSystemChain()} RPC listening on port ${listenPort}`);
|
|
17
14
|
return {
|
|
18
15
|
...context,
|
|
19
16
|
close,
|
|
20
17
|
listenPort,
|
|
21
18
|
};
|
|
22
19
|
};
|
|
23
|
-
exports.setupWithServer = setupWithServer;
|
package/lib/setup.js
CHANGED
|
@@ -1,30 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const db_1 = require("./db");
|
|
13
|
-
const time_travel_1 = require("./utils/time-travel");
|
|
14
|
-
const setup = async (argv) => {
|
|
1
|
+
import '@polkadot/types-codec';
|
|
2
|
+
import { WsProvider } from '@polkadot/api';
|
|
3
|
+
import { Api } from './api';
|
|
4
|
+
import { Blockchain } from './blockchain';
|
|
5
|
+
import { GenesisProvider } from './genesis-provider';
|
|
6
|
+
import { InherentProviders, ParaInherentEnter, SetBabeRandomness, SetNimbusAuthorInherent, SetTimestamp, SetValidationData, } from './blockchain/inherent';
|
|
7
|
+
import { defaultLogger } from './logger';
|
|
8
|
+
import { importStorage, overrideWasm } from './utils/import-storage';
|
|
9
|
+
import { openDb } from './db';
|
|
10
|
+
import { timeTravel } from './utils/time-travel';
|
|
11
|
+
export const setup = async (argv) => {
|
|
15
12
|
let provider;
|
|
16
13
|
if (argv.genesis) {
|
|
17
14
|
if (typeof argv.genesis === 'string') {
|
|
18
|
-
provider = await
|
|
15
|
+
provider = await GenesisProvider.fromUrl(argv.genesis);
|
|
19
16
|
}
|
|
20
17
|
else {
|
|
21
|
-
provider = new
|
|
18
|
+
provider = new GenesisProvider(argv.genesis);
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
21
|
else {
|
|
25
|
-
provider = new
|
|
22
|
+
provider = new WsProvider(argv.endpoint);
|
|
26
23
|
}
|
|
27
|
-
const api = new
|
|
24
|
+
const api = new Api(provider);
|
|
28
25
|
await api.isReady;
|
|
29
26
|
let blockHash;
|
|
30
27
|
if (argv.block == null) {
|
|
@@ -39,19 +36,19 @@ const setup = async (argv) => {
|
|
|
39
36
|
else {
|
|
40
37
|
throw new Error(`Invalid block number or hash: ${argv.block}`);
|
|
41
38
|
}
|
|
42
|
-
|
|
39
|
+
defaultLogger.debug({ ...argv, blockHash }, 'Args');
|
|
43
40
|
let db;
|
|
44
41
|
if (argv.db) {
|
|
45
|
-
db = await
|
|
42
|
+
db = await openDb(argv.db);
|
|
46
43
|
}
|
|
47
44
|
const header = await api.getHeader(blockHash);
|
|
48
|
-
const inherents = new
|
|
49
|
-
new
|
|
50
|
-
new
|
|
51
|
-
new
|
|
52
|
-
new
|
|
45
|
+
const inherents = new InherentProviders(new SetTimestamp(), [
|
|
46
|
+
new SetValidationData(),
|
|
47
|
+
new ParaInherentEnter(),
|
|
48
|
+
new SetNimbusAuthorInherent(),
|
|
49
|
+
new SetBabeRandomness(),
|
|
53
50
|
]);
|
|
54
|
-
const chain = new
|
|
51
|
+
const chain = new Blockchain({
|
|
55
52
|
api,
|
|
56
53
|
buildBlockMode: argv['build-block-mode'],
|
|
57
54
|
inherentProvider: inherents,
|
|
@@ -65,11 +62,10 @@ const setup = async (argv) => {
|
|
|
65
62
|
registeredTypes: argv['registered-types'],
|
|
66
63
|
});
|
|
67
64
|
if (argv.timestamp)
|
|
68
|
-
await
|
|
65
|
+
await timeTravel(chain, argv.timestamp);
|
|
69
66
|
// override wasm before importing storage, in case new pallets have been
|
|
70
67
|
// added that have storage imports
|
|
71
|
-
await
|
|
72
|
-
await
|
|
68
|
+
await overrideWasm(chain, argv['wasm-override']);
|
|
69
|
+
await importStorage(chain, argv['import-storage']);
|
|
73
70
|
return { chain, api, ws: provider };
|
|
74
71
|
};
|
|
75
|
-
exports.setup = setup;
|
package/lib/utils/decoder.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
require("@polkadot/types-codec");
|
|
8
|
-
const util_crypto_1 = require("@polkadot/util-crypto");
|
|
9
|
-
const jsondiffpatch_1 = require("jsondiffpatch");
|
|
10
|
-
const util_1 = require("@polkadot/util");
|
|
11
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
12
|
-
const diffPatcher = (0, jsondiffpatch_1.create)({
|
|
1
|
+
import '@polkadot/types-codec';
|
|
2
|
+
import { blake2AsHex } from '@polkadot/util-crypto';
|
|
3
|
+
import { create } from 'jsondiffpatch';
|
|
4
|
+
import { hexToU8a, u8aToHex } from '@polkadot/util';
|
|
5
|
+
import _ from 'lodash';
|
|
6
|
+
const diffPatcher = create({
|
|
13
7
|
array: { detectMove: false },
|
|
14
8
|
textDiff: { minLength: Number.MAX_VALUE }, // skip text diff
|
|
15
9
|
});
|
|
@@ -28,7 +22,7 @@ const getStorageEntry = (meta, block, key) => {
|
|
|
28
22
|
}
|
|
29
23
|
for (const module of Object.values(meta.query)) {
|
|
30
24
|
for (const storage of Object.values(module)) {
|
|
31
|
-
const keyPrefix =
|
|
25
|
+
const keyPrefix = u8aToHex(storage.keyPrefix());
|
|
32
26
|
if (key.startsWith(keyPrefix)) {
|
|
33
27
|
cache[keyPrefix] = storage;
|
|
34
28
|
return storage;
|
|
@@ -37,7 +31,7 @@ const getStorageEntry = (meta, block, key) => {
|
|
|
37
31
|
}
|
|
38
32
|
return undefined;
|
|
39
33
|
};
|
|
40
|
-
const decodeKey = (meta, block, key) => {
|
|
34
|
+
export const decodeKey = (meta, block, key) => {
|
|
41
35
|
const storage = getStorageEntry(meta, block, key);
|
|
42
36
|
const decodedKey = meta.registry.createType('StorageKey', key);
|
|
43
37
|
if (storage) {
|
|
@@ -46,9 +40,8 @@ const decodeKey = (meta, block, key) => {
|
|
|
46
40
|
}
|
|
47
41
|
return {};
|
|
48
42
|
};
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
const { storage, decodedKey } = (0, exports.decodeKey)(meta, block, key);
|
|
43
|
+
export const decodeKeyValue = (meta, block, key, value) => {
|
|
44
|
+
const { storage, decodedKey } = decodeKey(meta, block, key);
|
|
52
45
|
if (!storage || !decodedKey) {
|
|
53
46
|
return { [key]: value };
|
|
54
47
|
}
|
|
@@ -56,9 +49,9 @@ const decodeKeyValue = (meta, block, key, value) => {
|
|
|
56
49
|
if (!value)
|
|
57
50
|
return null;
|
|
58
51
|
if (storage.section === 'substrate' && storage.method === 'code') {
|
|
59
|
-
return `:code blake2_256 ${
|
|
52
|
+
return `:code blake2_256 ${blake2AsHex(value, 256)} (${hexToU8a(value).length} bytes)`;
|
|
60
53
|
}
|
|
61
|
-
return meta.registry.createType(decodedKey.outputType,
|
|
54
|
+
return meta.registry.createType(decodedKey.outputType, hexToU8a(value)).toHuman();
|
|
62
55
|
};
|
|
63
56
|
switch (decodedKey.args.length) {
|
|
64
57
|
case 2: {
|
|
@@ -89,19 +82,17 @@ const decodeKeyValue = (meta, block, key, value) => {
|
|
|
89
82
|
};
|
|
90
83
|
}
|
|
91
84
|
};
|
|
92
|
-
|
|
93
|
-
const decodeStorageDiff = async (block, diff) => {
|
|
85
|
+
export const decodeStorageDiff = async (block, diff) => {
|
|
94
86
|
const oldState = {};
|
|
95
87
|
const newState = {};
|
|
96
88
|
const meta = await block.meta;
|
|
97
89
|
for (const [key, value] of diff) {
|
|
98
|
-
|
|
99
|
-
|
|
90
|
+
_.merge(oldState, decodeKeyValue(meta, block, key, (await block.get(key))));
|
|
91
|
+
_.merge(newState, decodeKeyValue(meta, block, key, value));
|
|
100
92
|
}
|
|
101
|
-
const oldStateWithoutEvents =
|
|
93
|
+
const oldStateWithoutEvents = _.cloneDeep(oldState);
|
|
102
94
|
if (oldStateWithoutEvents['system']?.['events']) {
|
|
103
95
|
oldStateWithoutEvents['system']['events'] = [];
|
|
104
96
|
}
|
|
105
97
|
return [oldState, newState, diffPatcher.diff(oldStateWithoutEvents, newState)];
|
|
106
98
|
};
|
|
107
|
-
exports.decodeStorageDiff = decodeStorageDiff;
|
|
@@ -1,24 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { decodeStorageDiff } from './decoder';
|
|
2
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { template } from 'lodash';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
export const generateHtmlDiff = async (block, diff) => {
|
|
6
|
+
const [left, _right, delta] = await decodeStorageDiff(block, diff);
|
|
7
|
+
const htmlTemplate = readFileSync(path.join(__dirname, '../../template/diff.html'), 'utf-8');
|
|
8
|
+
return template(htmlTemplate)({ left: JSON.stringify(left), delta: JSON.stringify(delta) });
|
|
4
9
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const node_fs_1 = require("node:fs");
|
|
9
|
-
const lodash_1 = require("lodash");
|
|
10
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
-
const generateHtmlDiff = async (block, diff) => {
|
|
12
|
-
const [left, _right, delta] = await (0, decoder_1.decodeStorageDiff)(block, diff);
|
|
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(left), delta: JSON.stringify(delta) });
|
|
15
|
-
};
|
|
16
|
-
exports.generateHtmlDiff = generateHtmlDiff;
|
|
17
|
-
const generateHtmlDiffPreviewFile = async (block, diff, filename) => {
|
|
18
|
-
const html = await (0, exports.generateHtmlDiff)(block, diff);
|
|
19
|
-
(0, node_fs_1.mkdirSync)('./preview', { recursive: true });
|
|
10
|
+
export const generateHtmlDiffPreviewFile = async (block, diff, filename) => {
|
|
11
|
+
const html = await generateHtmlDiff(block, diff);
|
|
12
|
+
mkdirSync('./preview', { recursive: true });
|
|
20
13
|
const filePath = `./preview/${filename}.html`;
|
|
21
|
-
|
|
14
|
+
writeFileSync(filePath, html);
|
|
22
15
|
return filePath;
|
|
23
16
|
};
|
|
24
|
-
exports.generateHtmlDiffPreviewFile = generateHtmlDiffPreviewFile;
|
|
@@ -1,35 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
exports.overrideWasm = exports.importStorage = void 0;
|
|
7
|
-
const node_fs_1 = require("node:fs");
|
|
8
|
-
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
9
|
-
const set_storage_1 = require("./set-storage");
|
|
10
|
-
const logger_1 = require("../logger");
|
|
11
|
-
const importStorage = async (chain, storage) => {
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import yaml from 'js-yaml';
|
|
3
|
+
import { setStorage } from './set-storage';
|
|
4
|
+
import { defaultLogger } from '../logger';
|
|
5
|
+
export const importStorage = async (chain, storage) => {
|
|
12
6
|
if (storage == null) {
|
|
13
7
|
return;
|
|
14
8
|
}
|
|
15
9
|
let storageValue;
|
|
16
10
|
if (typeof storage === 'string') {
|
|
17
|
-
if (!
|
|
11
|
+
if (!existsSync(storage))
|
|
18
12
|
throw Error(`File ${storage} does not exist`);
|
|
19
|
-
storageValue =
|
|
13
|
+
storageValue = yaml.load(String(readFileSync(storage)));
|
|
20
14
|
}
|
|
21
15
|
else {
|
|
22
16
|
storageValue = storage;
|
|
23
17
|
}
|
|
24
|
-
const blockHash = await
|
|
25
|
-
|
|
18
|
+
const blockHash = await setStorage(chain, storageValue);
|
|
19
|
+
defaultLogger.trace({ blockHash, storage }, 'ImportStorage');
|
|
26
20
|
};
|
|
27
|
-
|
|
28
|
-
const overrideWasm = async (chain, wasmPath) => {
|
|
21
|
+
export const overrideWasm = async (chain, wasmPath) => {
|
|
29
22
|
if (wasmPath == null) {
|
|
30
23
|
return;
|
|
31
24
|
}
|
|
32
|
-
const wasm =
|
|
25
|
+
const wasm = readFileSync(wasmPath);
|
|
33
26
|
let wasmHex;
|
|
34
27
|
if (wasm.at(0) === 0x30 && wasm.at(1) === 0x78) {
|
|
35
28
|
// starts with 0x
|
|
@@ -40,4 +33,3 @@ const overrideWasm = async (chain, wasmPath) => {
|
|
|
40
33
|
}
|
|
41
34
|
chain.head.setWasm(wasmHex);
|
|
42
35
|
};
|
|
43
|
-
exports.overrideWasm = overrideWasm;
|
package/lib/utils/index.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.defer = exports.isUrl = exports.getParaId = exports.compactHex = exports.fetchKeysToArray = exports.fetchKeys = void 0;
|
|
4
|
-
const util_1 = require("@polkadot/util");
|
|
5
|
-
async function fetchKeys(getKeys, processKey) {
|
|
1
|
+
import { compactStripLength, hexToU8a, u8aToHex } from '@polkadot/util';
|
|
2
|
+
export async function fetchKeys(getKeys, processKey) {
|
|
6
3
|
const processKeys = async (keys) => {
|
|
7
4
|
for (const key of keys) {
|
|
8
5
|
await processKey(key);
|
|
@@ -19,26 +16,22 @@ async function fetchKeys(getKeys, processKey) {
|
|
|
19
16
|
nextKey = await processKeys(keys);
|
|
20
17
|
}
|
|
21
18
|
}
|
|
22
|
-
|
|
23
|
-
async function fetchKeysToArray(getKeys) {
|
|
19
|
+
export async function fetchKeysToArray(getKeys) {
|
|
24
20
|
const res = [];
|
|
25
21
|
await fetchKeys(getKeys, (key) => res.push(key));
|
|
26
22
|
return res;
|
|
27
23
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return (0, util_1.u8aToHex)((0, util_1.compactStripLength)(value)[1]);
|
|
24
|
+
export const compactHex = (value) => {
|
|
25
|
+
return u8aToHex(compactStripLength(value)[1]);
|
|
31
26
|
};
|
|
32
|
-
|
|
33
|
-
const getParaId = async (chain) => {
|
|
27
|
+
export const getParaId = async (chain) => {
|
|
34
28
|
const meta = await chain.head.meta;
|
|
35
|
-
const raw = await chain.head.get(
|
|
29
|
+
const raw = await chain.head.get(compactHex(meta.query.parachainInfo.parachainId()));
|
|
36
30
|
if (!raw)
|
|
37
31
|
throw new Error('Cannot find parachain id');
|
|
38
|
-
return meta.registry.createType('u32',
|
|
32
|
+
return meta.registry.createType('u32', hexToU8a(raw));
|
|
39
33
|
};
|
|
40
|
-
|
|
41
|
-
const isUrl = (url) => {
|
|
34
|
+
export const isUrl = (url) => {
|
|
42
35
|
try {
|
|
43
36
|
new URL(url);
|
|
44
37
|
return true;
|
|
@@ -47,8 +40,7 @@ const isUrl = (url) => {
|
|
|
47
40
|
return false;
|
|
48
41
|
}
|
|
49
42
|
};
|
|
50
|
-
|
|
51
|
-
function defer() {
|
|
43
|
+
export function defer() {
|
|
52
44
|
const deferred = {};
|
|
53
45
|
deferred.promise = new Promise((resolve, reject) => {
|
|
54
46
|
deferred.resolve = resolve;
|
|
@@ -56,4 +48,3 @@ function defer() {
|
|
|
56
48
|
});
|
|
57
49
|
return deferred;
|
|
58
50
|
}
|
|
59
|
-
exports.defer = defer;
|
package/lib/utils/open-html.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.openHtml = void 0;
|
|
4
|
-
const node_child_process_1 = require("node:child_process");
|
|
5
|
-
const openHtml = (filePath) => {
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
2
|
+
export const openHtml = (filePath) => {
|
|
6
3
|
const start = process.platform == 'darwin' ? 'open' : process.platform == 'win32' ? 'start' : 'xdg-open';
|
|
7
|
-
|
|
4
|
+
execSync(start + ' ' + filePath);
|
|
8
5
|
};
|
|
9
|
-
exports.openHtml = openHtml;
|