@acala-network/chopsticks 0.7.2 → 0.8.0-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/cli-options.d.ts +40 -0
- package/lib/cli-options.js +43 -0
- package/lib/cli.d.ts +1 -2
- package/lib/cli.js +20 -183
- package/lib/context.d.ts +5 -0
- package/lib/context.js +37 -0
- package/lib/index.d.ts +2 -7
- package/lib/index.js +4 -15
- package/lib/logger.d.ts +1 -7
- package/lib/logger.js +3 -38
- package/lib/plugins/decode-key/index.d.ts +2 -0
- package/lib/plugins/decode-key/index.js +27 -0
- package/lib/plugins/dry-run/cli.d.ts +2 -0
- package/lib/plugins/dry-run/cli.js +46 -0
- package/lib/plugins/dry-run/dry-run-extrinsic.d.ts +2 -0
- package/lib/{dry-run.js → plugins/dry-run/dry-run-extrinsic.js} +8 -8
- package/lib/{dry-run-preimage.d.ts → plugins/dry-run/dry-run-preimage.d.ts} +1 -1
- package/lib/{dry-run-preimage.js → plugins/dry-run/dry-run-preimage.js} +10 -12
- package/lib/plugins/dry-run/index.d.ts +2 -0
- package/lib/plugins/dry-run/index.js +18 -0
- package/lib/plugins/dry-run/rpc.d.ts +3 -0
- package/lib/{rpc/dev/dry-run.js → plugins/dry-run/rpc.js} +10 -7
- package/lib/plugins/index.d.ts +4 -0
- package/lib/plugins/index.js +52 -0
- package/lib/plugins/new-block/index.d.ts +2 -0
- package/lib/plugins/new-block/index.js +28 -0
- package/lib/plugins/run-block/index.d.ts +2 -0
- package/lib/plugins/run-block/index.js +67 -0
- package/lib/plugins/set-block-build-mode/index.d.ts +2 -0
- package/lib/plugins/set-block-build-mode/index.js +14 -0
- package/lib/plugins/set-head/index.d.ts +2 -0
- package/lib/plugins/set-head/index.js +20 -0
- package/lib/plugins/set-storage/index.d.ts +2 -0
- package/lib/plugins/set-storage/index.js +18 -0
- package/lib/plugins/time-travel/index.d.ts +2 -0
- package/lib/plugins/time-travel/index.js +13 -0
- package/lib/plugins/try-runtime/index.d.ts +2 -0
- package/lib/plugins/try-runtime/index.js +58 -0
- package/lib/rpc/index.d.ts +1 -1
- package/lib/rpc/index.js +11 -4
- package/lib/rpc/shared.d.ts +1 -1
- package/lib/rpc/shared.js +1 -1
- package/lib/rpc/substrate/author.js +3 -3
- package/lib/schema/index.d.ts +9 -66
- package/lib/schema/index.js +41 -14
- package/lib/server.js +2 -1
- package/lib/setup-with-server.d.ts +1 -3
- package/lib/setup-with-server.js +2 -2
- package/lib/utils/decoder.d.ts +1 -1
- package/lib/utils/generate-html-diff.d.ts +1 -1
- package/lib/utils/override.d.ts +4 -0
- package/lib/utils/{import-storage.js → override.js} +6 -6
- package/package.json +13 -16
- package/lib/api.d.ts +0 -43
- package/lib/api.js +0 -79
- package/lib/blockchain/block-builder.d.ts +0 -10
- package/lib/blockchain/block-builder.js +0 -297
- package/lib/blockchain/block.d.ts +0 -45
- package/lib/blockchain/block.js +0 -194
- package/lib/blockchain/head-state.d.ts +0 -15
- package/lib/blockchain/head-state.js +0 -71
- package/lib/blockchain/index.d.ts +0 -64
- package/lib/blockchain/index.js +0 -243
- package/lib/blockchain/inherent/index.d.ts +0 -19
- package/lib/blockchain/inherent/index.js +0 -36
- package/lib/blockchain/inherent/para-enter.d.ts +0 -7
- package/lib/blockchain/inherent/para-enter.js +0 -33
- package/lib/blockchain/inherent/parachain/babe-randomness.d.ts +0 -7
- package/lib/blockchain/inherent/parachain/babe-randomness.js +0 -15
- package/lib/blockchain/inherent/parachain/nimbus-author-inherent.d.ts +0 -7
- package/lib/blockchain/inherent/parachain/nimbus-author-inherent.js +0 -15
- package/lib/blockchain/inherent/parachain/validation-data.d.ts +0 -19
- package/lib/blockchain/inherent/parachain/validation-data.js +0 -172
- package/lib/blockchain/storage-layer.d.ts +0 -32
- package/lib/blockchain/storage-layer.js +0 -200
- package/lib/blockchain/txpool.d.ts +0 -45
- package/lib/blockchain/txpool.js +0 -184
- package/lib/db/entities.d.ts +0 -5
- package/lib/db/entities.js +0 -33
- package/lib/db/index.d.ts +0 -3
- package/lib/db/index.js +0 -41
- package/lib/dry-run.d.ts +0 -2
- package/lib/executor.d.ts +0 -40
- package/lib/executor.js +0 -131
- package/lib/genesis-provider.d.ts +0 -44
- package/lib/genesis-provider.js +0 -155
- package/lib/offchain.d.ts +0 -10
- package/lib/offchain.js +0 -37
- package/lib/rpc/dev/dry-run.d.ts +0 -2
- package/lib/rpc/dev/index.d.ts +0 -3
- package/lib/rpc/dev/index.js +0 -75
- package/lib/run-block.d.ts +0 -2
- package/lib/run-block.js +0 -51
- package/lib/setup.d.ts +0 -11
- package/lib/setup.js +0 -86
- package/lib/try-runtime.d.ts +0 -2
- package/lib/try-runtime.js +0 -36
- package/lib/utils/import-storage.d.ts +0 -5
- package/lib/utils/index.d.ts +0 -16
- package/lib/utils/index.js +0 -59
- package/lib/utils/key-cache.d.ts +0 -10
- package/lib/utils/key-cache.js +0 -66
- package/lib/utils/proof.d.ts +0 -15
- package/lib/utils/proof.js +0 -41
- package/lib/utils/set-storage.d.ts +0 -7
- package/lib/utils/set-storage.js +0 -59
- package/lib/utils/time-travel.d.ts +0 -5
- package/lib/utils/time-travel.js +0 -65
- package/lib/xcm/downward.d.ts +0 -2
- package/lib/xcm/downward.js +0 -29
- package/lib/xcm/horizontal.d.ts +0 -2
- package/lib/xcm/horizontal.js +0 -29
- package/lib/xcm/index.d.ts +0 -9
- package/lib/xcm/index.js +0 -25
- package/lib/xcm/upward.d.ts +0 -2
- package/lib/xcm/upward.js +0 -21
package/lib/offchain.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OffchainWorker = void 0;
|
|
4
|
-
const util_crypto_1 = require("@polkadot/util-crypto");
|
|
5
|
-
const shared_1 = require("./rpc/shared");
|
|
6
|
-
const rxjs_1 = require("rxjs");
|
|
7
|
-
class OffchainWorker {
|
|
8
|
-
pendingExtrinsics = [];
|
|
9
|
-
offchainStorage = new Map();
|
|
10
|
-
get(key) {
|
|
11
|
-
return this.offchainStorage.get(key);
|
|
12
|
-
}
|
|
13
|
-
set(key, value) {
|
|
14
|
-
this.offchainStorage.set(key, value);
|
|
15
|
-
}
|
|
16
|
-
async run(block) {
|
|
17
|
-
shared_1.logger.info({ number: block.number, hash: block.hash }, `Run Offchain Worker for block #${block.number.toLocaleString()}`);
|
|
18
|
-
const header = await block.header;
|
|
19
|
-
await block.call('OffchainWorkerApi_offchain_worker', [header.toHex()]);
|
|
20
|
-
shared_1.logger.info(`Offchain Worker complete for block #${block.number.toLocaleString()}`);
|
|
21
|
-
const txs = this.pendingExtrinsics.splice(0);
|
|
22
|
-
if (txs.length > 0) {
|
|
23
|
-
rxjs_1.queueScheduler.schedule(async (transactions) => {
|
|
24
|
-
await block.chain.txPool.buildBlock({ transactions });
|
|
25
|
-
}, 100, txs);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
async pushExtrinsic(block, extrinsic) {
|
|
29
|
-
const validity = await block.chain.validateExtrinsic(extrinsic, '0x01');
|
|
30
|
-
if (validity.isOk) {
|
|
31
|
-
this.pendingExtrinsics.push(extrinsic);
|
|
32
|
-
return (0, util_crypto_1.blake2AsHex)(extrinsic, 256);
|
|
33
|
-
}
|
|
34
|
-
throw validity.asErr;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.OffchainWorker = OffchainWorker;
|
package/lib/rpc/dev/dry-run.d.ts
DELETED
package/lib/rpc/dev/index.d.ts
DELETED
package/lib/rpc/dev/index.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const txpool_1 = require("../../blockchain/txpool");
|
|
4
|
-
const shared_1 = require("../shared");
|
|
5
|
-
const set_storage_1 = require("../../utils/set-storage");
|
|
6
|
-
const logger_1 = require("../../logger");
|
|
7
|
-
const dry_run_1 = require("./dry-run");
|
|
8
|
-
const time_travel_1 = require("../../utils/time-travel");
|
|
9
|
-
const logger = logger_1.defaultLogger.child({ name: 'rpc-dev' });
|
|
10
|
-
const handlers = {
|
|
11
|
-
dev_newBlock: async (context, [param]) => {
|
|
12
|
-
const { count, to, hrmp, ump, dmp, transactions } = param || {};
|
|
13
|
-
const now = context.chain.head.number;
|
|
14
|
-
const diff = to ? to - now : count;
|
|
15
|
-
const finalCount = diff > 0 ? diff : 1;
|
|
16
|
-
let finalHash;
|
|
17
|
-
for (let i = 0; i < finalCount; i++) {
|
|
18
|
-
const block = await context.chain
|
|
19
|
-
.newBlock({
|
|
20
|
-
transactions,
|
|
21
|
-
horizontalMessages: hrmp,
|
|
22
|
-
upwardMessages: ump,
|
|
23
|
-
downwardMessages: dmp,
|
|
24
|
-
})
|
|
25
|
-
.catch((error) => {
|
|
26
|
-
throw new shared_1.ResponseError(1, error.toString());
|
|
27
|
-
});
|
|
28
|
-
logger.debug({ hash: block.hash }, 'dev_newBlock');
|
|
29
|
-
finalHash = block.hash;
|
|
30
|
-
}
|
|
31
|
-
return finalHash;
|
|
32
|
-
},
|
|
33
|
-
dev_setStorage: async (context, params) => {
|
|
34
|
-
const [values, blockHash] = params;
|
|
35
|
-
const hash = await (0, set_storage_1.setStorage)(context.chain, values, blockHash).catch((error) => {
|
|
36
|
-
throw new shared_1.ResponseError(1, error.toString());
|
|
37
|
-
});
|
|
38
|
-
logger.debug({
|
|
39
|
-
hash,
|
|
40
|
-
values,
|
|
41
|
-
}, 'dev_setStorage');
|
|
42
|
-
return hash;
|
|
43
|
-
},
|
|
44
|
-
dev_timeTravel: async (context, [date]) => {
|
|
45
|
-
const timestamp = typeof date === 'string' ? Date.parse(date) : date;
|
|
46
|
-
if (Number.isNaN(timestamp))
|
|
47
|
-
throw new shared_1.ResponseError(1, 'Invalid date');
|
|
48
|
-
await (0, time_travel_1.timeTravel)(context.chain, timestamp);
|
|
49
|
-
return timestamp;
|
|
50
|
-
},
|
|
51
|
-
dev_setHead: async (context, [hashOrNumber]) => {
|
|
52
|
-
let block;
|
|
53
|
-
if (typeof hashOrNumber === 'number') {
|
|
54
|
-
const blockNumber = hashOrNumber > 0 ? hashOrNumber : context.chain.head.number + hashOrNumber;
|
|
55
|
-
block = await context.chain.getBlockAt(blockNumber);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
block = await context.chain.getBlock(hashOrNumber);
|
|
59
|
-
}
|
|
60
|
-
if (!block) {
|
|
61
|
-
throw new shared_1.ResponseError(1, `Block not found ${hashOrNumber}`);
|
|
62
|
-
}
|
|
63
|
-
await context.chain.setHead(block);
|
|
64
|
-
return block.hash;
|
|
65
|
-
},
|
|
66
|
-
dev_dryRun: dry_run_1.dev_dryRun,
|
|
67
|
-
dev_setBlockBuildMode: async (context, [mode]) => {
|
|
68
|
-
logger.debug({ mode }, 'dev_setBlockBuildMode');
|
|
69
|
-
if (txpool_1.BuildBlockMode[mode] === undefined) {
|
|
70
|
-
throw new shared_1.ResponseError(1, `Invalid mode ${mode}`);
|
|
71
|
-
}
|
|
72
|
-
context.chain.txPool.mode = mode;
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
exports.default = handlers;
|
package/lib/run-block.d.ts
DELETED
package/lib/run-block.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runBlock = void 0;
|
|
4
|
-
const node_fs_1 = require("node:fs");
|
|
5
|
-
const logger_1 = require("./logger");
|
|
6
|
-
const generate_html_diff_1 = require("./utils/generate-html-diff");
|
|
7
|
-
const open_html_1 = require("./utils/open-html");
|
|
8
|
-
const executor_1 = require("./executor");
|
|
9
|
-
const setup_1 = require("./setup");
|
|
10
|
-
const runBlock = async (argv) => {
|
|
11
|
-
const context = await (0, setup_1.setup)(argv, true);
|
|
12
|
-
const header = await context.chain.head.header;
|
|
13
|
-
const block = context.chain.head;
|
|
14
|
-
const parent = await block.parentBlock;
|
|
15
|
-
if (!parent)
|
|
16
|
-
throw Error('cant find parent block');
|
|
17
|
-
const wasm = await parent.wasm;
|
|
18
|
-
const calls = [['Core_initialize_block', [header.toHex()]]];
|
|
19
|
-
for (const extrinsic of await block.extrinsics) {
|
|
20
|
-
calls.push(['BlockBuilder_apply_extrinsic', [extrinsic]]);
|
|
21
|
-
}
|
|
22
|
-
calls.push(['BlockBuilder_finalize_block', []]);
|
|
23
|
-
const result = await (0, executor_1.runTask)({
|
|
24
|
-
wasm,
|
|
25
|
-
calls,
|
|
26
|
-
mockSignatureHost: false,
|
|
27
|
-
allowUnresolvedImports: false,
|
|
28
|
-
runtimeLogLevel: argv['runtime-log-level'] || 0,
|
|
29
|
-
}, (0, executor_1.taskHandler)(parent));
|
|
30
|
-
if (result.Error) {
|
|
31
|
-
throw new Error(result.Error);
|
|
32
|
-
}
|
|
33
|
-
for (const logs of result.Call.runtimeLogs) {
|
|
34
|
-
logger_1.defaultLogger.info(`RuntimeLogs:\n${logs}`);
|
|
35
|
-
}
|
|
36
|
-
if (argv['html']) {
|
|
37
|
-
const filePath = await (0, generate_html_diff_1.generateHtmlDiffPreviewFile)(parent, result.Call.storageDiff, block.hash);
|
|
38
|
-
console.log(`Generated preview ${filePath}`);
|
|
39
|
-
if (argv['open']) {
|
|
40
|
-
(0, open_html_1.openHtml)(filePath);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
else if (argv['output-path']) {
|
|
44
|
-
(0, node_fs_1.writeFileSync)(argv['output-path'], JSON.stringify(result, null, 2));
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
console.dir(result, { depth: null, colors: false });
|
|
48
|
-
}
|
|
49
|
-
process.exit(0);
|
|
50
|
-
};
|
|
51
|
-
exports.runBlock = runBlock;
|
package/lib/setup.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import './utils/tunnel';
|
|
2
|
-
import '@polkadot/types-codec';
|
|
3
|
-
import { ProviderInterface } from '@polkadot/rpc-provider/types';
|
|
4
|
-
import { Api } from './api';
|
|
5
|
-
import { Blockchain } from './blockchain';
|
|
6
|
-
import { Config } from './schema';
|
|
7
|
-
export declare const setup: (argv: Config, runBlock?: boolean) => Promise<{
|
|
8
|
-
chain: Blockchain;
|
|
9
|
-
api: Api;
|
|
10
|
-
ws: ProviderInterface;
|
|
11
|
-
}>;
|
package/lib/setup.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setup = void 0;
|
|
4
|
-
require("./utils/tunnel");
|
|
5
|
-
require("@polkadot/types-codec");
|
|
6
|
-
const api_1 = require("@polkadot/api");
|
|
7
|
-
const api_2 = require("./api");
|
|
8
|
-
const blockchain_1 = require("./blockchain");
|
|
9
|
-
const genesis_provider_1 = require("./genesis-provider");
|
|
10
|
-
const inherent_1 = require("./blockchain/inherent");
|
|
11
|
-
const logger_1 = require("./logger");
|
|
12
|
-
const import_storage_1 = require("./utils/import-storage");
|
|
13
|
-
const db_1 = require("./db");
|
|
14
|
-
const time_travel_1 = require("./utils/time-travel");
|
|
15
|
-
const setup = async (argv, runBlock = false) => {
|
|
16
|
-
let provider;
|
|
17
|
-
if (argv.genesis) {
|
|
18
|
-
if (typeof argv.genesis === 'string') {
|
|
19
|
-
provider = await genesis_provider_1.GenesisProvider.fromUrl(argv.genesis);
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
provider = new genesis_provider_1.GenesisProvider(argv.genesis);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
provider = new api_1.WsProvider(argv.endpoint);
|
|
27
|
-
}
|
|
28
|
-
const api = new api_2.Api(provider);
|
|
29
|
-
await api.isReady;
|
|
30
|
-
let blockHash;
|
|
31
|
-
if (argv.block == null) {
|
|
32
|
-
blockHash = await api.getBlockHash();
|
|
33
|
-
}
|
|
34
|
-
else if (typeof argv.block === 'string' && argv.block.startsWith('0x')) {
|
|
35
|
-
blockHash = argv.block;
|
|
36
|
-
}
|
|
37
|
-
else if (Number.isInteger(+argv.block)) {
|
|
38
|
-
blockHash = await api.getBlockHash(Number(argv.block));
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
throw new Error(`Invalid block number or hash: ${argv.block}`);
|
|
42
|
-
}
|
|
43
|
-
logger_1.defaultLogger.debug({ ...argv, blockHash }, 'Args');
|
|
44
|
-
let db;
|
|
45
|
-
if (argv.db) {
|
|
46
|
-
db = await (0, db_1.openDb)(argv.db);
|
|
47
|
-
}
|
|
48
|
-
const header = await api.getHeader(blockHash);
|
|
49
|
-
const inherents = new inherent_1.InherentProviders(new inherent_1.SetTimestamp(), [
|
|
50
|
-
new inherent_1.SetValidationData(),
|
|
51
|
-
new inherent_1.ParaInherentEnter(),
|
|
52
|
-
new inherent_1.SetNimbusAuthorInherent(),
|
|
53
|
-
new inherent_1.SetBabeRandomness(),
|
|
54
|
-
]);
|
|
55
|
-
const chain = new blockchain_1.Blockchain({
|
|
56
|
-
api,
|
|
57
|
-
buildBlockMode: argv['build-block-mode'],
|
|
58
|
-
inherentProvider: inherents,
|
|
59
|
-
db,
|
|
60
|
-
header: {
|
|
61
|
-
hash: blockHash,
|
|
62
|
-
number: Number(header.number),
|
|
63
|
-
},
|
|
64
|
-
mockSignatureHost: argv['mock-signature-host'],
|
|
65
|
-
allowUnresolvedImports: argv['allow-unresolved-imports'],
|
|
66
|
-
runtimeLogLevel: argv['runtime-log-level'],
|
|
67
|
-
registeredTypes: argv['registered-types'],
|
|
68
|
-
offchainWorker: argv['offchain-worker'],
|
|
69
|
-
});
|
|
70
|
-
if (argv.timestamp)
|
|
71
|
-
await (0, time_travel_1.timeTravel)(chain, argv.timestamp);
|
|
72
|
-
let at;
|
|
73
|
-
if (runBlock) {
|
|
74
|
-
// in case of run block we need to apply wasm-override and import-storage to parent block
|
|
75
|
-
const block = await chain.head.parentBlock;
|
|
76
|
-
if (!block)
|
|
77
|
-
throw new Error('Cannot find parent block');
|
|
78
|
-
at = block.hash;
|
|
79
|
-
}
|
|
80
|
-
// override wasm before importing storage, in case new pallets have been
|
|
81
|
-
// added that have storage imports
|
|
82
|
-
await (0, import_storage_1.overrideWasm)(chain, argv['wasm-override'], at);
|
|
83
|
-
await (0, import_storage_1.importStorage)(chain, argv['import-storage'], at);
|
|
84
|
-
return { chain, api, ws: provider };
|
|
85
|
-
};
|
|
86
|
-
exports.setup = setup;
|
package/lib/try-runtime.d.ts
DELETED
package/lib/try-runtime.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tryRuntime = void 0;
|
|
4
|
-
const node_fs_1 = require("node:fs");
|
|
5
|
-
const generate_html_diff_1 = require("./utils/generate-html-diff");
|
|
6
|
-
const open_html_1 = require("./utils/open-html");
|
|
7
|
-
const setup_1 = require("./setup");
|
|
8
|
-
const tryRuntime = async (argv) => {
|
|
9
|
-
const context = await (0, setup_1.setup)(argv);
|
|
10
|
-
const block = context.chain.head;
|
|
11
|
-
const registry = await block.registry;
|
|
12
|
-
registry.register({
|
|
13
|
-
UpgradeCheckSelect: {
|
|
14
|
-
_enum: {
|
|
15
|
-
None: null,
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
});
|
|
19
|
-
const select_none = registry.createType('UpgradeCheckSelect', 'None');
|
|
20
|
-
const result = await block.call('TryRuntime_on_runtime_upgrade', [select_none.toHex()]);
|
|
21
|
-
if (argv['html']) {
|
|
22
|
-
const filePath = await (0, generate_html_diff_1.generateHtmlDiffPreviewFile)(block, result.storageDiff, block.hash);
|
|
23
|
-
console.log(`Generated preview ${filePath}`);
|
|
24
|
-
if (argv['open']) {
|
|
25
|
-
(0, open_html_1.openHtml)(filePath);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
else if (argv['output-path']) {
|
|
29
|
-
(0, node_fs_1.writeFileSync)(argv['output-path'], JSON.stringify(result, null, 2));
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
console.dir(result, { depth: null, colors: false });
|
|
33
|
-
}
|
|
34
|
-
process.exit(0);
|
|
35
|
-
};
|
|
36
|
-
exports.tryRuntime = tryRuntime;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { HexString } from '@polkadot/util/types';
|
|
2
|
-
import { Blockchain } from '../blockchain';
|
|
3
|
-
import { StorageValues } from './set-storage';
|
|
4
|
-
export declare const importStorage: (chain: Blockchain, storage?: string | StorageValues, at?: HexString) => Promise<void>;
|
|
5
|
-
export declare const overrideWasm: (chain: Blockchain, wasmPath?: string, at?: HexString) => Promise<void>;
|
package/lib/utils/index.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { HexString } from '@polkadot/util/types';
|
|
2
|
-
import { StorageKey } from '@polkadot/types';
|
|
3
|
-
import { Blockchain } from '../blockchain';
|
|
4
|
-
export type GetKeys = (startKey?: string) => Promise<StorageKey<any>[]>;
|
|
5
|
-
export type ProcessKey = (key: StorageKey<any>) => any;
|
|
6
|
-
export declare function fetchKeys(getKeys: GetKeys, processKey: ProcessKey): Promise<void>;
|
|
7
|
-
export declare function fetchKeysToArray(getKeys: GetKeys): Promise<StorageKey<any>[]>;
|
|
8
|
-
export declare const compactHex: (value: Uint8Array) => HexString;
|
|
9
|
-
export declare const getParaId: (chain: Blockchain) => Promise<import("@polkadot/types").U32>;
|
|
10
|
-
export declare const isUrl: (url: string) => boolean;
|
|
11
|
-
export type Deferred<T> = {
|
|
12
|
-
resolve: (value: T | PromiseLike<T>) => void;
|
|
13
|
-
reject: (reason?: any) => void;
|
|
14
|
-
promise: Promise<T>;
|
|
15
|
-
};
|
|
16
|
-
export declare function defer<T>(): Deferred<T>;
|
package/lib/utils/index.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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) {
|
|
6
|
-
const processKeys = async (keys) => {
|
|
7
|
-
for (const key of keys) {
|
|
8
|
-
await processKey(key);
|
|
9
|
-
}
|
|
10
|
-
if (keys.length > 0) {
|
|
11
|
-
return keys[keys.length - 1];
|
|
12
|
-
}
|
|
13
|
-
return undefined;
|
|
14
|
-
};
|
|
15
|
-
const keys = await getKeys();
|
|
16
|
-
let nextKey = await processKeys(keys);
|
|
17
|
-
while (nextKey) {
|
|
18
|
-
const keys = await getKeys(nextKey.toHex());
|
|
19
|
-
nextKey = await processKeys(keys);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.fetchKeys = fetchKeys;
|
|
23
|
-
async function fetchKeysToArray(getKeys) {
|
|
24
|
-
const res = [];
|
|
25
|
-
await fetchKeys(getKeys, (key) => res.push(key));
|
|
26
|
-
return res;
|
|
27
|
-
}
|
|
28
|
-
exports.fetchKeysToArray = fetchKeysToArray;
|
|
29
|
-
const compactHex = (value) => {
|
|
30
|
-
return (0, util_1.u8aToHex)((0, util_1.compactStripLength)(value)[1]);
|
|
31
|
-
};
|
|
32
|
-
exports.compactHex = compactHex;
|
|
33
|
-
const getParaId = async (chain) => {
|
|
34
|
-
const meta = await chain.head.meta;
|
|
35
|
-
const raw = await chain.head.get((0, exports.compactHex)(meta.query.parachainInfo.parachainId()));
|
|
36
|
-
if (!raw)
|
|
37
|
-
throw new Error('Cannot find parachain id');
|
|
38
|
-
return meta.registry.createType('u32', (0, util_1.hexToU8a)(raw));
|
|
39
|
-
};
|
|
40
|
-
exports.getParaId = getParaId;
|
|
41
|
-
const isUrl = (url) => {
|
|
42
|
-
try {
|
|
43
|
-
new URL(url);
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
catch (e) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
exports.isUrl = isUrl;
|
|
51
|
-
function defer() {
|
|
52
|
-
const deferred = {};
|
|
53
|
-
deferred.promise = new Promise((resolve, reject) => {
|
|
54
|
-
deferred.resolve = resolve;
|
|
55
|
-
deferred.reject = reject;
|
|
56
|
-
});
|
|
57
|
-
return deferred;
|
|
58
|
-
}
|
|
59
|
-
exports.defer = defer;
|
package/lib/utils/key-cache.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { HexString } from '@polkadot/util/types';
|
|
2
|
-
export declare const PREFIX_LENGTH = 66;
|
|
3
|
-
export default class KeyCache {
|
|
4
|
-
readonly ranges: Array<{
|
|
5
|
-
prefix: string;
|
|
6
|
-
keys: string[];
|
|
7
|
-
}>;
|
|
8
|
-
feed(keys: HexString[]): void;
|
|
9
|
-
next(startKey: HexString): Promise<HexString | undefined>;
|
|
10
|
-
}
|
package/lib/utils/key-cache.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.PREFIX_LENGTH = void 0;
|
|
7
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
-
// 0x + 32 module + 32 method
|
|
9
|
-
exports.PREFIX_LENGTH = 66;
|
|
10
|
-
class KeyCache {
|
|
11
|
-
ranges = [];
|
|
12
|
-
feed(keys) {
|
|
13
|
-
const _keys = keys.filter((key) => key.length >= exports.PREFIX_LENGTH);
|
|
14
|
-
if (_keys.length === 0)
|
|
15
|
-
return;
|
|
16
|
-
const startKey = _keys[0].slice(exports.PREFIX_LENGTH);
|
|
17
|
-
const endKey = _keys[_keys.length - 1].slice(exports.PREFIX_LENGTH);
|
|
18
|
-
const grouped = lodash_1.default.groupBy(_keys, (key) => key.slice(0, exports.PREFIX_LENGTH));
|
|
19
|
-
for (const [prefix, keys] of Object.entries(grouped)) {
|
|
20
|
-
const ranges = this.ranges.filter((range) => range.prefix === prefix);
|
|
21
|
-
if (ranges.length === 0) {
|
|
22
|
-
// no existing range with prefix
|
|
23
|
-
this.ranges.push({ prefix, keys: keys.map((i) => i.slice(exports.PREFIX_LENGTH)) });
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
let merged = false;
|
|
27
|
-
for (const range of ranges) {
|
|
28
|
-
const startPosition = lodash_1.default.sortedIndex(range.keys, startKey);
|
|
29
|
-
if (startPosition >= 0 && range.keys[startPosition] === startKey) {
|
|
30
|
-
// found existing range with prefix
|
|
31
|
-
range.keys.splice(startPosition, keys.length, ...keys.map((i) => i.slice(exports.PREFIX_LENGTH)));
|
|
32
|
-
merged = true;
|
|
33
|
-
break;
|
|
34
|
-
}
|
|
35
|
-
const endPosition = lodash_1.default.sortedIndex(range.keys, endKey);
|
|
36
|
-
if (endPosition >= 0 && range.keys[endPosition] === endKey) {
|
|
37
|
-
// found existing range with prefix
|
|
38
|
-
range.keys.splice(0, endPosition + 1, ...keys.map((i) => i.slice(exports.PREFIX_LENGTH)));
|
|
39
|
-
merged = true;
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
// insert new prefix with range
|
|
44
|
-
if (!merged) {
|
|
45
|
-
this.ranges.push({ prefix, keys: keys.map((i) => i.slice(exports.PREFIX_LENGTH)) });
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
// TODO: merge ranges if they overlap
|
|
49
|
-
}
|
|
50
|
-
async next(startKey) {
|
|
51
|
-
if (startKey.length < exports.PREFIX_LENGTH)
|
|
52
|
-
return;
|
|
53
|
-
const prefix = startKey.slice(0, exports.PREFIX_LENGTH);
|
|
54
|
-
const key = startKey.slice(exports.PREFIX_LENGTH);
|
|
55
|
-
for (const range of this.ranges.filter((range) => range.prefix === prefix)) {
|
|
56
|
-
const index = lodash_1.default.sortedIndex(range.keys, key);
|
|
57
|
-
if (range.keys[index] !== key)
|
|
58
|
-
continue;
|
|
59
|
-
const nextKey = range.keys[index + 1];
|
|
60
|
-
if (nextKey) {
|
|
61
|
-
return [prefix, nextKey].join('');
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
exports.default = KeyCache;
|
package/lib/utils/proof.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { HrmpChannelId } from '@polkadot/types/interfaces';
|
|
2
|
-
import { u32 } from '@polkadot/types';
|
|
3
|
-
export declare const WELL_KNOWN_KEYS: {
|
|
4
|
-
EPOCH_INDEX: `0x${string}`;
|
|
5
|
-
CURRENT_BLOCK_RANDOMNESS: `0x${string}`;
|
|
6
|
-
ONE_EPOCH_AGO_RANDOMNESS: `0x${string}`;
|
|
7
|
-
TWO_EPOCHS_AGO_RANDOMNESS: `0x${string}`;
|
|
8
|
-
CURRENT_SLOT: `0x${string}`;
|
|
9
|
-
ACTIVE_CONFIG: `0x${string}`;
|
|
10
|
-
};
|
|
11
|
-
export declare const dmqMqcHead: (paraId: u32) => `0x${string}`;
|
|
12
|
-
export declare const upgradeGoAheadSignal: (paraId: u32) => `0x${string}`;
|
|
13
|
-
export declare const hrmpIngressChannelIndex: (paraId: u32) => `0x${string}`;
|
|
14
|
-
export declare const hrmpEgressChannelIndex: (paraId: u32) => `0x${string}`;
|
|
15
|
-
export declare const hrmpChannels: (channelId: HrmpChannelId) => `0x${string}`;
|
package/lib/utils/proof.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hrmpChannels = exports.hrmpEgressChannelIndex = exports.hrmpIngressChannelIndex = exports.upgradeGoAheadSignal = exports.dmqMqcHead = exports.WELL_KNOWN_KEYS = void 0;
|
|
4
|
-
const util_1 = require("@polkadot/util");
|
|
5
|
-
const util_crypto_1 = require("@polkadot/util-crypto");
|
|
6
|
-
exports.WELL_KNOWN_KEYS = {
|
|
7
|
-
EPOCH_INDEX: '0x1cb6f36e027abb2091cfb5110ab5087f38316cbf8fa0da822a20ac1c55bf1be3',
|
|
8
|
-
CURRENT_BLOCK_RANDOMNESS: '0x1cb6f36e027abb2091cfb5110ab5087fd077dfdb8adb10f78f10a5df8742c545',
|
|
9
|
-
ONE_EPOCH_AGO_RANDOMNESS: '0x1cb6f36e027abb2091cfb5110ab5087f7ce678799d3eff024253b90e84927cc6',
|
|
10
|
-
TWO_EPOCHS_AGO_RANDOMNESS: '0x1cb6f36e027abb2091cfb5110ab5087f7a414cb008e0e61e46722aa60abdd672',
|
|
11
|
-
CURRENT_SLOT: '0x1cb6f36e027abb2091cfb5110ab5087f06155b3cd9a8c9e5e9a23fd5dc13a5ed',
|
|
12
|
-
ACTIVE_CONFIG: '0x06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385',
|
|
13
|
-
};
|
|
14
|
-
const hash = (prefix, suffix) => {
|
|
15
|
-
return (0, util_1.u8aToHex)((0, util_1.u8aConcat)((0, util_1.hexToU8a)(prefix), (0, util_crypto_1.xxhashAsU8a)(suffix, 64), suffix));
|
|
16
|
-
};
|
|
17
|
-
const dmqMqcHead = (paraId) => {
|
|
18
|
-
const prefix = '0x63f78c98723ddc9073523ef3beefda0c4d7fefc408aac59dbfe80a72ac8e3ce5';
|
|
19
|
-
return hash(prefix, paraId.toU8a());
|
|
20
|
-
};
|
|
21
|
-
exports.dmqMqcHead = dmqMqcHead;
|
|
22
|
-
const upgradeGoAheadSignal = (paraId) => {
|
|
23
|
-
const prefix = '0xcd710b30bd2eab0352ddcc26417aa1949e94c040f5e73d9b7addd6cb603d15d3';
|
|
24
|
-
return hash(prefix, paraId.toU8a());
|
|
25
|
-
};
|
|
26
|
-
exports.upgradeGoAheadSignal = upgradeGoAheadSignal;
|
|
27
|
-
const hrmpIngressChannelIndex = (paraId) => {
|
|
28
|
-
const prefix = '0x6a0da05ca59913bc38a8630590f2627c1d3719f5b0b12c7105c073c507445948';
|
|
29
|
-
return hash(prefix, paraId.toU8a());
|
|
30
|
-
};
|
|
31
|
-
exports.hrmpIngressChannelIndex = hrmpIngressChannelIndex;
|
|
32
|
-
const hrmpEgressChannelIndex = (paraId) => {
|
|
33
|
-
const prefix = '0x6a0da05ca59913bc38a8630590f2627cf12b746dcf32e843354583c9702cc020';
|
|
34
|
-
return hash(prefix, paraId.toU8a());
|
|
35
|
-
};
|
|
36
|
-
exports.hrmpEgressChannelIndex = hrmpEgressChannelIndex;
|
|
37
|
-
const hrmpChannels = (channelId) => {
|
|
38
|
-
const prefix = '0x6a0da05ca59913bc38a8630590f2627cb6604cff828a6e3f579ca6c59ace013d';
|
|
39
|
-
return hash(prefix, channelId.toU8a());
|
|
40
|
-
};
|
|
41
|
-
exports.hrmpChannels = hrmpChannels;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { HexString } from '@polkadot/util/types';
|
|
2
|
-
import { Blockchain } from '../blockchain';
|
|
3
|
-
type RawStorageValues = [string, string | null][];
|
|
4
|
-
type StorageConfig = Record<string, Record<string, any>>;
|
|
5
|
-
export type StorageValues = RawStorageValues | StorageConfig;
|
|
6
|
-
export declare const setStorage: (chain: Blockchain, storage: StorageValues, blockHash?: HexString) => Promise<HexString>;
|
|
7
|
-
export {};
|
package/lib/utils/set-storage.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setStorage = void 0;
|
|
4
|
-
const types_1 = require("@polkadot/types");
|
|
5
|
-
const string_1 = require("@polkadot/util/string");
|
|
6
|
-
const util_1 = require("@polkadot/util");
|
|
7
|
-
function objectToStorageItems(meta, storage) {
|
|
8
|
-
const storageItems = [];
|
|
9
|
-
for (const sectionName in storage) {
|
|
10
|
-
const section = storage[sectionName];
|
|
11
|
-
const pallet = meta.query[(0, string_1.stringCamelCase)(sectionName)];
|
|
12
|
-
if (!pallet)
|
|
13
|
-
throw Error(`Cannot find pallet ${sectionName}`);
|
|
14
|
-
for (const storageName in section) {
|
|
15
|
-
const storage = section[storageName];
|
|
16
|
-
if (storageName === '$removePrefix') {
|
|
17
|
-
for (const mapName of storage) {
|
|
18
|
-
const storageEntry = pallet[(0, string_1.stringCamelCase)(mapName)];
|
|
19
|
-
if (!storageEntry)
|
|
20
|
-
throw Error(`Cannot find storage ${mapName} in pallet ${sectionName}`);
|
|
21
|
-
const prefix = storageEntry.keyPrefix();
|
|
22
|
-
storageItems.push([(0, util_1.u8aToHex)(prefix), "DeletedPrefix" /* StorageValueKind.DeletedPrefix */]);
|
|
23
|
-
}
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
const storageEntry = pallet[(0, string_1.stringCamelCase)(storageName)];
|
|
27
|
-
if (!storageEntry)
|
|
28
|
-
throw Error(`Cannot find storage ${storageName} in pallet ${sectionName}`);
|
|
29
|
-
if (storageEntry.meta.type.isPlain) {
|
|
30
|
-
const key = new types_1.StorageKey(meta.registry, [storageEntry]);
|
|
31
|
-
const type = storageEntry.meta.modifier.isOptional ? `Option<${key.outputType}>` : key.outputType;
|
|
32
|
-
storageItems.push([key.toHex(), storage ? meta.registry.createType(type, storage).toHex() : null]);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
for (const [keys, value] of storage) {
|
|
36
|
-
const key = new types_1.StorageKey(meta.registry, [storageEntry, keys]);
|
|
37
|
-
const type = storageEntry.meta.modifier.isOptional ? `Option<${key.outputType}>` : key.outputType;
|
|
38
|
-
storageItems.push([key.toHex(), value ? meta.registry.createType(type, value).toHex() : null]);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return storageItems;
|
|
44
|
-
}
|
|
45
|
-
const setStorage = async (chain, storage, blockHash) => {
|
|
46
|
-
const block = await chain.getBlock(blockHash);
|
|
47
|
-
if (!block)
|
|
48
|
-
throw Error(`Cannot find block ${blockHash || 'latest'}`);
|
|
49
|
-
let storageItems;
|
|
50
|
-
if (Array.isArray(storage)) {
|
|
51
|
-
storageItems = storage;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
storageItems = objectToStorageItems(await block.meta, storage);
|
|
55
|
-
}
|
|
56
|
-
block.pushStorageLayer().setAll(storageItems);
|
|
57
|
-
return block.hash;
|
|
58
|
-
};
|
|
59
|
-
exports.setStorage = setStorage;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Blockchain } from '../blockchain';
|
|
2
|
-
export declare const getCurrentSlot: (chain: Blockchain) => Promise<number>;
|
|
3
|
-
export declare const getCurrentTimestamp: (chain: Blockchain) => Promise<number>;
|
|
4
|
-
export declare const getSlotDuration: (chain: Blockchain) => Promise<number>;
|
|
5
|
-
export declare const timeTravel: (chain: Blockchain, timestamp: number) => Promise<void>;
|