@acala-network/chopsticks 0.2.3 → 0.3.1
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/README.md +12 -1
- package/dist/api.d.ts +3 -2
- package/dist/api.js +15 -20
- package/dist/blockchain/block-builder.d.ts +5 -0
- package/dist/blockchain/block-builder.js +168 -0
- package/dist/blockchain/block.d.ts +6 -4
- package/dist/blockchain/block.js +22 -23
- package/dist/blockchain/head-state.d.ts +4 -2
- package/dist/blockchain/head-state.js +13 -7
- package/dist/blockchain/index.d.ts +13 -8
- package/dist/blockchain/index.js +44 -26
- package/dist/blockchain/inherent/index.d.ts +19 -0
- package/dist/blockchain/inherent/index.js +36 -0
- package/dist/blockchain/inherent/para-enter.d.ts +7 -0
- package/dist/blockchain/inherent/para-enter.js +33 -0
- package/dist/blockchain/inherent/parachain/babe-randomness.d.ts +7 -0
- package/dist/blockchain/inherent/parachain/babe-randomness.js +15 -0
- package/dist/blockchain/inherent/parachain/nimbus-author-inherent.d.ts +7 -0
- package/dist/blockchain/inherent/parachain/nimbus-author-inherent.js +15 -0
- package/dist/blockchain/inherent/parachain/validation-data.d.ts +25 -0
- package/dist/blockchain/{inherents.js → inherent/parachain/validation-data.js} +77 -46
- package/dist/blockchain/txpool.d.ts +17 -2
- package/dist/blockchain/txpool.js +11 -107
- package/dist/dry-run.d.ts +2 -0
- package/dist/dry-run.js +30 -0
- package/dist/executor.d.ts +17 -3
- package/dist/executor.js +43 -3
- package/dist/executor.test.js +16 -9
- package/dist/genesis-provider.d.ts +5 -0
- package/dist/genesis-provider.js +15 -3
- package/dist/index.d.ts +1 -18
- package/dist/index.js +79 -148
- package/dist/rpc/dev.js +39 -2
- package/dist/rpc/shared.d.ts +0 -4
- package/dist/rpc/substrate/author.d.ts +1 -1
- package/dist/rpc/substrate/author.js +7 -2
- package/dist/rpc/substrate/chain.js +2 -2
- package/dist/rpc/substrate/state.js +1 -1
- package/dist/rpc/substrate/system.js +3 -3
- package/dist/run-block.d.ts +2 -0
- package/dist/run-block.js +47 -0
- package/dist/schema/index.js +1 -1
- package/dist/server.d.ts +3 -3
- package/dist/server.js +26 -11
- package/dist/setup-with-server.d.ts +8 -0
- package/dist/setup-with-server.js +23 -0
- package/dist/setup.d.ts +10 -0
- package/dist/setup.js +67 -0
- package/dist/utils/decoder.d.ts +17 -0
- package/dist/utils/decoder.js +101 -0
- package/dist/utils/generate-html-diff.d.ts +4 -0
- package/dist/utils/generate-html-diff.js +20 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +9 -1
- package/dist/utils/open-html.d.ts +1 -0
- package/dist/utils/open-html.js +9 -0
- package/dist/utils/proof.d.ts +10 -2
- package/dist/utils/proof.js +12 -8
- package/dist/utils/set-storage.d.ts +2 -1
- package/dist/utils/time-travel.d.ts +5 -0
- package/dist/utils/time-travel.js +64 -0
- package/dist/xcm/index.d.ts +3 -0
- package/dist/xcm/index.js +67 -0
- package/package.json +10 -7
- package/dist/bindings.d.ts +0 -2
- package/dist/bindings.js +0 -31
- package/dist/blockchain/inherents.d.ts +0 -24
package/dist/executor.test.js
CHANGED
|
@@ -9,20 +9,23 @@ const node_fs_1 = require("node:fs");
|
|
|
9
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
10
10
|
const proof_1 = require("./utils/proof");
|
|
11
11
|
const executor_1 = require("./executor");
|
|
12
|
+
const getCode = () => {
|
|
13
|
+
const code = String((0, node_fs_1.readFileSync)(node_path_1.default.join(__dirname, '../e2e/blobs/acala-runtime-2101.txt'))).trim();
|
|
14
|
+
(0, vitest_1.expect)(code.length).toBeGreaterThan(2);
|
|
15
|
+
return code;
|
|
16
|
+
};
|
|
12
17
|
(0, vitest_1.describe)('wasm', () => {
|
|
13
18
|
(0, vitest_1.it)('get runtime version from wasm runtime', async () => {
|
|
14
|
-
const code = String((0, node_fs_1.readFileSync)(node_path_1.default.join(__dirname, 'runtime.example'))).trim();
|
|
15
|
-
(0, vitest_1.expect)(code.length).toBeGreaterThan(2);
|
|
16
19
|
const expectedRuntimeVersion = {
|
|
17
20
|
specName: 'acala',
|
|
18
21
|
implName: 'acala',
|
|
19
22
|
authoringVersion: 1,
|
|
20
|
-
specVersion:
|
|
23
|
+
specVersion: 2101,
|
|
21
24
|
implVersion: 0,
|
|
22
25
|
apis: [
|
|
23
|
-
['0xdf6acb689907609b',
|
|
26
|
+
['0xdf6acb689907609b', 4],
|
|
24
27
|
['0x37e397fc7c91f5e4', 1],
|
|
25
|
-
['0x40fe3ad401f8959a',
|
|
28
|
+
['0x40fe3ad401f8959a', 6],
|
|
26
29
|
['0xd2bc9897eed08f15', 3],
|
|
27
30
|
['0xf78b278be53f454c', 2],
|
|
28
31
|
['0xdd718d5cc53262d4', 1],
|
|
@@ -30,14 +33,14 @@ const executor_1 = require("./executor");
|
|
|
30
33
|
['0xbc9d89904f5b923f', 1],
|
|
31
34
|
['0x37c8bb1350a9a2a8', 1],
|
|
32
35
|
['0x6ef953004ba30e59', 1],
|
|
33
|
-
['
|
|
34
|
-
['0xe3df3f2aa8a5cc57',
|
|
35
|
-
['0xea93e3f16f3d6962',
|
|
36
|
+
['0x955e168e0cfb3409', 1],
|
|
37
|
+
['0xe3df3f2aa8a5cc57', 2],
|
|
38
|
+
['0xea93e3f16f3d6962', 2],
|
|
36
39
|
],
|
|
37
40
|
transactionVersion: 1,
|
|
38
41
|
stateVersion: 0,
|
|
39
42
|
};
|
|
40
|
-
(0, vitest_1.expect)(await (0, executor_1.getRuntimeVersion)(
|
|
43
|
+
(0, vitest_1.expect)(await (0, executor_1.getRuntimeVersion)(getCode())).toMatchObject(expectedRuntimeVersion);
|
|
41
44
|
});
|
|
42
45
|
(0, vitest_1.it)('calculate state root', async () => {
|
|
43
46
|
const a = await (0, executor_1.calculateStateRoot)([['0x5301bf5ff0298f5c7b93a446709f8e885f772afdd0d8ba3d4d559a06f0742f12', '0x01']]);
|
|
@@ -128,4 +131,8 @@ const executor_1 = require("./executor");
|
|
|
128
131
|
(0, vitest_1.expect)(decoded).toMatchSnapshot();
|
|
129
132
|
(0, vitest_1.expect)(decoded[upgradeKey]).toBe('0x01');
|
|
130
133
|
});
|
|
134
|
+
(0, vitest_1.it)('get aura slot duration', async () => {
|
|
135
|
+
const slotDuration = await (0, executor_1.getAuraSlotDuration)(getCode(), new types_1.TypeRegistry());
|
|
136
|
+
(0, vitest_1.expect)(slotDuration).eq(12000);
|
|
137
|
+
});
|
|
131
138
|
});
|
|
@@ -36,6 +36,11 @@ export declare class GenesisProvider implements ProviderInterface {
|
|
|
36
36
|
extrinsics: never[];
|
|
37
37
|
};
|
|
38
38
|
}>;
|
|
39
|
+
get _jsCallback(): {
|
|
40
|
+
getStorage: (key: HexString) => Promise<string>;
|
|
41
|
+
getNextKey: (_key: HexString) => Promise<string>;
|
|
42
|
+
getPrefixKeys: (_key: HexString) => Promise<never[]>;
|
|
43
|
+
};
|
|
39
44
|
send: (method: string, params: unknown[], _isCacheable?: boolean) => Promise<any>;
|
|
40
45
|
subscribe: (_type: string, _method: string, _params: unknown[], _cb: ProviderInterfaceCallback) => Promise<number | string>;
|
|
41
46
|
unsubscribe: (_type: string, _method: string, _id: number | string) => Promise<boolean>;
|
package/dist/genesis-provider.js
CHANGED
|
@@ -30,7 +30,6 @@ class GenesisProvider {
|
|
|
30
30
|
});
|
|
31
31
|
this.#eventemitter.once('error', reject);
|
|
32
32
|
});
|
|
33
|
-
this.connect();
|
|
34
33
|
}
|
|
35
34
|
static fromUrl = async (url) => {
|
|
36
35
|
let isUrl = false;
|
|
@@ -103,6 +102,20 @@ class GenesisProvider {
|
|
|
103
102
|
},
|
|
104
103
|
};
|
|
105
104
|
};
|
|
105
|
+
get _jsCallback() {
|
|
106
|
+
const storage = this.#genesis.genesis.raw.top;
|
|
107
|
+
return {
|
|
108
|
+
getStorage: async function (key) {
|
|
109
|
+
return storage[key];
|
|
110
|
+
},
|
|
111
|
+
getNextKey: async function (_key) {
|
|
112
|
+
return '0x';
|
|
113
|
+
},
|
|
114
|
+
getPrefixKeys: async function (_key) {
|
|
115
|
+
return [];
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
|
106
119
|
send = async (method, params, _isCacheable) => {
|
|
107
120
|
await this.isReady;
|
|
108
121
|
switch (method) {
|
|
@@ -115,13 +128,12 @@ class GenesisProvider {
|
|
|
115
128
|
case 'state_getMetadata': {
|
|
116
129
|
const code = this.#genesis.genesis.raw.top[(0, util_1.stringToHex)(':code')];
|
|
117
130
|
return (0, executor_1.runTask)({
|
|
118
|
-
blockHash: this.blockHash,
|
|
119
131
|
wasm: code,
|
|
120
132
|
calls: [['Metadata_metadata', '0x']],
|
|
121
133
|
storage: [],
|
|
122
134
|
mockSignatureHost: false,
|
|
123
135
|
allowUnresolvedImports: true,
|
|
124
|
-
});
|
|
136
|
+
}, this._jsCallback);
|
|
125
137
|
}
|
|
126
138
|
case 'chain_getHeader':
|
|
127
139
|
return this.getHeader();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { ProviderInterface } from '@polkadot/rpc-provider/types';
|
|
3
|
-
import { Api } from './api';
|
|
4
|
-
import { Blockchain } from './blockchain';
|
|
5
|
-
import { Config } from './schema';
|
|
6
|
-
export declare const setup: (argv: Config) => Promise<{
|
|
7
|
-
chain: Blockchain;
|
|
8
|
-
api: Api;
|
|
9
|
-
ws: ProviderInterface;
|
|
10
|
-
}>;
|
|
11
|
-
export declare const setupWithServer: (argv: Config) => Promise<{
|
|
12
|
-
close: () => Promise<void>;
|
|
13
|
-
chain: Blockchain;
|
|
14
|
-
api: Api;
|
|
15
|
-
ws: ProviderInterface;
|
|
16
|
-
}>;
|
|
17
|
-
export declare const runBlock: (argv: Config) => Promise<void>;
|
|
18
|
-
export declare const decodeKey: (argv: any) => Promise<void>;
|
|
1
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -3,146 +3,26 @@ 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.decodeKey = exports.runBlock = exports.setupWithServer = exports.setup = void 0;
|
|
7
|
-
require("@polkadot/types-codec");
|
|
8
|
-
const api_1 = require("@polkadot/api");
|
|
9
|
-
const util_1 = require("@polkadot/util");
|
|
10
6
|
const helpers_1 = require("yargs/helpers");
|
|
11
7
|
const node_fs_1 = require("node:fs");
|
|
12
8
|
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
13
9
|
const yargs_1 = __importDefault(require("yargs"));
|
|
14
|
-
const api_2 = require("./api");
|
|
15
|
-
const blockchain_1 = require("./blockchain");
|
|
16
10
|
const txpool_1 = require("./blockchain/txpool");
|
|
17
11
|
const schema_1 = require("./schema");
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
if (argv.genesis) {
|
|
29
|
-
if (typeof argv.genesis === 'string') {
|
|
30
|
-
provider = await genesis_provider_1.GenesisProvider.fromUrl(argv.genesis);
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
provider = new genesis_provider_1.GenesisProvider(argv.genesis);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
provider = new api_1.WsProvider(argv.endpoint);
|
|
38
|
-
}
|
|
39
|
-
const api = new api_2.Api(provider);
|
|
40
|
-
await api.isReady;
|
|
41
|
-
let blockHash;
|
|
42
|
-
if (argv.block == null) {
|
|
43
|
-
blockHash = await api.getBlockHash();
|
|
44
|
-
}
|
|
45
|
-
else if (Number.isInteger(argv.block)) {
|
|
46
|
-
blockHash = await api.getBlockHash(Number(argv.block));
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
blockHash = argv.block;
|
|
50
|
-
}
|
|
51
|
-
logger_1.defaultLogger.info({ ...argv, blockHash }, 'Args');
|
|
52
|
-
let db;
|
|
53
|
-
if (argv.db) {
|
|
54
|
-
db = await (0, db_1.openDb)(argv.db);
|
|
55
|
-
}
|
|
56
|
-
const header = await api.getHeader(blockHash);
|
|
57
|
-
const blockNumber = +header.number;
|
|
58
|
-
const timestamp = argv.timestamp ?? Date.now();
|
|
59
|
-
const setTimestamp = new inherents_1.SetTimestamp((newBlockNumber) => {
|
|
60
|
-
return timestamp + (newBlockNumber - blockNumber) * 12000; // TODO: make this more flexible
|
|
61
|
-
});
|
|
62
|
-
const inherents = new inherents_1.InherentProviders(setTimestamp, [new inherents_1.SetValidationData()]);
|
|
63
|
-
const chain = new blockchain_1.Blockchain({
|
|
64
|
-
api,
|
|
65
|
-
buildBlockMode: argv['build-block-mode'],
|
|
66
|
-
inherentProvider: inherents,
|
|
67
|
-
db,
|
|
68
|
-
header: {
|
|
69
|
-
hash: blockHash,
|
|
70
|
-
number: Number(header.number),
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
const context = { chain, api, ws: provider };
|
|
74
|
-
await (0, import_storage_1.importStorage)(chain, argv['import-storage']);
|
|
75
|
-
await (0, import_storage_1.overrideWasm)(chain, argv['wasm-override']);
|
|
76
|
-
return context;
|
|
77
|
-
};
|
|
78
|
-
exports.setup = setup;
|
|
79
|
-
const setupWithServer = async (argv) => {
|
|
80
|
-
const context = await (0, exports.setup)(argv);
|
|
81
|
-
const port = argv.port || Number(process.env.PORT) || 8000;
|
|
82
|
-
const { close } = (0, server_1.createServer)(port, (0, rpc_1.handler)(context));
|
|
83
|
-
if (argv.genesis) {
|
|
84
|
-
// mine 1st block when starting from genesis to set some mock validation data
|
|
85
|
-
await context.chain.newBlock();
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
...context,
|
|
89
|
-
close,
|
|
90
|
-
};
|
|
12
|
+
const xcm_1 = require("./xcm");
|
|
13
|
+
const decoder_1 = require("./utils/decoder");
|
|
14
|
+
const dry_run_1 = require("./dry-run");
|
|
15
|
+
const run_block_1 = require("./run-block");
|
|
16
|
+
const setup_1 = require("./setup");
|
|
17
|
+
const setup_with_server_1 = require("./setup-with-server");
|
|
18
|
+
const processConfig = (path) => {
|
|
19
|
+
const configFile = (0, node_fs_1.readFileSync)(path, 'utf8');
|
|
20
|
+
const config = js_yaml_1.default.load(configFile);
|
|
21
|
+
return schema_1.configSchema.parse(config);
|
|
91
22
|
};
|
|
92
|
-
|
|
93
|
-
const runBlock = async (argv) => {
|
|
94
|
-
const context = await (0, exports.setupWithServer)(argv);
|
|
95
|
-
const header = await context.chain.head.header;
|
|
96
|
-
const parent = header.parentHash.toHex();
|
|
97
|
-
const wasm = await context.chain.head.wasm;
|
|
98
|
-
const block = context.chain.head;
|
|
99
|
-
const calls = [['Core_initialize_block', header.toHex()]];
|
|
100
|
-
for (const extrinsic of await block.extrinsics) {
|
|
101
|
-
calls.push(['BlockBuilder_apply_extrinsic', extrinsic]);
|
|
102
|
-
}
|
|
103
|
-
calls.push(['BlockBuilder_finalize_block', '0x']);
|
|
104
|
-
const result = await (0, executor_1.runTask)({
|
|
105
|
-
blockHash: parent,
|
|
106
|
-
wasm,
|
|
107
|
-
calls,
|
|
108
|
-
storage: [],
|
|
109
|
-
mockSignatureHost: false,
|
|
110
|
-
allowUnresolvedImports: false,
|
|
111
|
-
});
|
|
112
|
-
if (argv['output-path']) {
|
|
113
|
-
(0, node_fs_1.writeFileSync)(argv['output-path'], JSON.stringify(result, null, 2));
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
console.dir(result, { depth: null, colors: false });
|
|
117
|
-
}
|
|
118
|
-
await context.close();
|
|
119
|
-
setTimeout(() => process.exit(0), 50);
|
|
120
|
-
};
|
|
121
|
-
exports.runBlock = runBlock;
|
|
122
|
-
const decodeKey = async (argv) => {
|
|
123
|
-
const context = await (0, exports.setup)(argv);
|
|
124
|
-
const key = argv.key;
|
|
125
|
-
const meta = await context.chain.head.meta;
|
|
126
|
-
outer: for (const module of Object.values(meta.query)) {
|
|
127
|
-
for (const storage of Object.values(module)) {
|
|
128
|
-
const keyPrefix = (0, util_1.u8aToHex)(storage.keyPrefix());
|
|
129
|
-
if (key.startsWith(keyPrefix)) {
|
|
130
|
-
const decodedKey = meta.registry.createType('StorageKey', key);
|
|
131
|
-
decodedKey.setMeta(storage.meta);
|
|
132
|
-
console.log(`${storage.section}.${storage.method}`, decodedKey.args.map((x) => x.toHuman()).join(', '));
|
|
133
|
-
break outer;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
setTimeout(() => process.exit(0), 50);
|
|
138
|
-
};
|
|
139
|
-
exports.decodeKey = decodeKey;
|
|
140
|
-
const processConfig = (argv) => {
|
|
23
|
+
const processArgv = (argv) => {
|
|
141
24
|
if (argv.config) {
|
|
142
|
-
|
|
143
|
-
const config = js_yaml_1.default.load(configFile);
|
|
144
|
-
const parsed = schema_1.configSchema.parse(config);
|
|
145
|
-
return { ...parsed, ...argv };
|
|
25
|
+
return { ...processConfig(argv.config), ...argv };
|
|
146
26
|
}
|
|
147
27
|
return argv;
|
|
148
28
|
};
|
|
@@ -153,7 +33,6 @@ const defaultOptions = {
|
|
|
153
33
|
},
|
|
154
34
|
block: {
|
|
155
35
|
desc: 'Block hash or block number. Default to latest block',
|
|
156
|
-
string: true,
|
|
157
36
|
},
|
|
158
37
|
'wasm-override': {
|
|
159
38
|
desc: 'Path to wasm override',
|
|
@@ -180,11 +59,34 @@ const defaultOptions = {
|
|
|
180
59
|
desc: 'File path to print output',
|
|
181
60
|
string: true,
|
|
182
61
|
},
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
62
|
+
html: {
|
|
63
|
+
desc: 'Generate html with storage diff',
|
|
64
|
+
},
|
|
65
|
+
open: {
|
|
66
|
+
desc: 'Open generated html',
|
|
67
|
+
},
|
|
68
|
+
}), async (argv) => {
|
|
69
|
+
await (0, run_block_1.runBlock)(processArgv(argv));
|
|
70
|
+
})
|
|
71
|
+
.command('dry-run', 'Dry run an extrinsic', (yargs) => yargs.options({
|
|
72
|
+
...defaultOptions,
|
|
73
|
+
extrinsic: {
|
|
74
|
+
desc: 'Extrinsic to dry run',
|
|
75
|
+
string: true,
|
|
76
|
+
required: true,
|
|
77
|
+
},
|
|
78
|
+
'output-path': {
|
|
79
|
+
desc: 'File path to print output',
|
|
80
|
+
string: true,
|
|
81
|
+
},
|
|
82
|
+
html: {
|
|
83
|
+
desc: 'Generate html with storage diff',
|
|
84
|
+
},
|
|
85
|
+
open: {
|
|
86
|
+
desc: 'Open generated html',
|
|
87
|
+
},
|
|
88
|
+
}), async (argv) => {
|
|
89
|
+
await (0, dry_run_1.dryRun)(processArgv(argv));
|
|
188
90
|
})
|
|
189
91
|
.command('dev', 'Dev mode', (yargs) => yargs.options({
|
|
190
92
|
...defaultOptions,
|
|
@@ -204,11 +106,8 @@ const defaultOptions = {
|
|
|
204
106
|
desc: 'Mock signature host so any signature starts with 0xdeadbeef and filled by 0xcd is considered valid',
|
|
205
107
|
boolean: true,
|
|
206
108
|
},
|
|
207
|
-
}), (argv) => {
|
|
208
|
-
(0,
|
|
209
|
-
console.error(err);
|
|
210
|
-
process.exit(1);
|
|
211
|
-
});
|
|
109
|
+
}), async (argv) => {
|
|
110
|
+
await (0, setup_with_server_1.setupWithServer)(processArgv(argv));
|
|
212
111
|
})
|
|
213
112
|
.command('decode-key <key>', 'Deocde a key', (yargs) => yargs
|
|
214
113
|
.positional('key', {
|
|
@@ -217,11 +116,43 @@ const defaultOptions = {
|
|
|
217
116
|
})
|
|
218
117
|
.options({
|
|
219
118
|
...defaultOptions,
|
|
220
|
-
}), (argv) => {
|
|
221
|
-
(0,
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
119
|
+
}), async (argv) => {
|
|
120
|
+
const context = await (0, setup_1.setup)(processArgv(argv));
|
|
121
|
+
const { storage, decodedKey } = await (0, decoder_1.decodeKey)(context.chain.head, argv.key);
|
|
122
|
+
if (storage && decodedKey) {
|
|
123
|
+
console.log(`${storage.section}.${storage.method}`, decodedKey.args.map((x) => JSON.stringify(x.toHuman())).join(', '));
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
console.log('Unknown');
|
|
127
|
+
}
|
|
128
|
+
process.exit(0);
|
|
129
|
+
})
|
|
130
|
+
.command('xcm', 'XCM setup with relaychain and parachains', (yargs) => yargs.options({
|
|
131
|
+
relaychain: {
|
|
132
|
+
desc: 'Relaychain config file path',
|
|
133
|
+
string: true,
|
|
134
|
+
},
|
|
135
|
+
parachain: {
|
|
136
|
+
desc: 'Parachain config file path',
|
|
137
|
+
type: 'array',
|
|
138
|
+
string: true,
|
|
139
|
+
required: true,
|
|
140
|
+
},
|
|
141
|
+
}), async (argv) => {
|
|
142
|
+
const parachains = [];
|
|
143
|
+
for (const config of argv.parachain) {
|
|
144
|
+
const { chain } = await (0, setup_with_server_1.setupWithServer)(processConfig(config));
|
|
145
|
+
parachains.push(chain);
|
|
146
|
+
}
|
|
147
|
+
if (parachains.length > 1) {
|
|
148
|
+
await (0, xcm_1.connectParachains)(parachains);
|
|
149
|
+
}
|
|
150
|
+
if (argv.relaychain) {
|
|
151
|
+
const { chain: relaychain } = await (0, setup_with_server_1.setupWithServer)(processConfig(argv.relaychain));
|
|
152
|
+
for (const parachain of parachains) {
|
|
153
|
+
await (0, xcm_1.connectDownward)(relaychain, parachain);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
225
156
|
})
|
|
226
157
|
.strict()
|
|
227
158
|
.help()
|
package/dist/rpc/dev.js
CHANGED
|
@@ -2,17 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const shared_1 = require("./shared");
|
|
4
4
|
const set_storage_1 = require("../utils/set-storage");
|
|
5
|
+
const decoder_1 = require("../utils/decoder");
|
|
5
6
|
const logger_1 = require("../logger");
|
|
7
|
+
const generate_html_diff_1 = require("../utils/generate-html-diff");
|
|
8
|
+
const time_travel_1 = require("../utils/time-travel");
|
|
6
9
|
const logger = logger_1.defaultLogger.child({ name: 'rpc-dev' });
|
|
7
10
|
const handlers = {
|
|
8
11
|
dev_newBlock: async (context, [param]) => {
|
|
9
|
-
const { count, to } = param || {};
|
|
12
|
+
const { count, to, hrmp } = param || {};
|
|
10
13
|
const now = context.chain.head.number;
|
|
11
14
|
const diff = to ? to - now : count;
|
|
12
15
|
const finalCount = diff > 0 ? diff : 1;
|
|
13
16
|
let finalHash;
|
|
14
17
|
for (let i = 0; i < finalCount; i++) {
|
|
15
|
-
const block = await context.chain.newBlock()
|
|
18
|
+
const block = await context.chain.newBlock({ inherent: { horizontalMessages: hrmp } }).catch((error) => {
|
|
19
|
+
throw new shared_1.ResponseError(1, error.toString());
|
|
20
|
+
});
|
|
16
21
|
logger.debug({ hash: block.hash }, 'dev_newBlock');
|
|
17
22
|
finalHash = block.hash;
|
|
18
23
|
}
|
|
@@ -29,5 +34,37 @@ const handlers = {
|
|
|
29
34
|
}, 'dev_setStorages');
|
|
30
35
|
return hash;
|
|
31
36
|
},
|
|
37
|
+
dev_timeTravel: async (context, [date]) => {
|
|
38
|
+
const timestamp = typeof date === 'string' ? Date.parse(date) : date;
|
|
39
|
+
if (Number.isNaN(timestamp))
|
|
40
|
+
throw new shared_1.ResponseError(1, 'Invalid date');
|
|
41
|
+
await (0, time_travel_1.timeTravel)(context.chain, timestamp);
|
|
42
|
+
return timestamp;
|
|
43
|
+
},
|
|
44
|
+
dev_dryRun: async (context, [{ html, extrinsic, hrmp, raw }]) => {
|
|
45
|
+
const dryRun = async () => {
|
|
46
|
+
if (extrinsic) {
|
|
47
|
+
const { outcome, storageDiff } = await context.chain.dryRunExtrinsic(extrinsic);
|
|
48
|
+
if (outcome.isErr) {
|
|
49
|
+
throw new Error(outcome.asErr.toString());
|
|
50
|
+
}
|
|
51
|
+
return storageDiff;
|
|
52
|
+
}
|
|
53
|
+
return context.chain.dryRunHrmp(hrmp);
|
|
54
|
+
};
|
|
55
|
+
const storageDiff = await dryRun();
|
|
56
|
+
if (html) {
|
|
57
|
+
return (0, generate_html_diff_1.generateHtmlDiff)(context.chain.head, storageDiff);
|
|
58
|
+
}
|
|
59
|
+
if (raw) {
|
|
60
|
+
return storageDiff;
|
|
61
|
+
}
|
|
62
|
+
const [oldData, newData, delta] = await (0, decoder_1.decodeStorageDiff)(context.chain.head, storageDiff);
|
|
63
|
+
return {
|
|
64
|
+
old: oldData,
|
|
65
|
+
new: newData,
|
|
66
|
+
delta,
|
|
67
|
+
};
|
|
68
|
+
},
|
|
32
69
|
};
|
|
33
70
|
exports.default = handlers;
|
package/dist/rpc/shared.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { ProviderInterface } from '@polkadot/rpc-provider/types';
|
|
2
|
-
import { Api } from '../api';
|
|
3
1
|
import { Blockchain } from '../blockchain';
|
|
4
2
|
export declare const logger: import("pino").default.Logger<{
|
|
5
3
|
level: string;
|
|
@@ -17,8 +15,6 @@ export declare class ResponseError extends Error {
|
|
|
17
15
|
}
|
|
18
16
|
export interface Context {
|
|
19
17
|
chain: Blockchain;
|
|
20
|
-
api: Api;
|
|
21
|
-
ws: ProviderInterface;
|
|
22
18
|
}
|
|
23
19
|
export interface SubscriptionManager {
|
|
24
20
|
subscribe: (method: string, subid: string, onCancel?: () => void) => (data: any) => void;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const shared_1 = require("../../rpc/shared");
|
|
3
4
|
const logger_1 = require("../../logger");
|
|
4
5
|
const logger = logger_1.defaultLogger.child({ name: 'rpc-author' });
|
|
5
6
|
const handlers = {
|
|
6
7
|
author_submitExtrinsic: async (context, [extrinsic]) => {
|
|
7
|
-
return context.chain.submitExtrinsic(extrinsic)
|
|
8
|
+
return context.chain.submitExtrinsic(extrinsic).catch((error) => {
|
|
9
|
+
throw new shared_1.ResponseError(1, error.toString());
|
|
10
|
+
});
|
|
8
11
|
},
|
|
9
12
|
author_submitAndWatchExtrinsic: async (context, [extrinsic], { subscribe, unsubscribe }) => {
|
|
10
13
|
let update = (_block) => { };
|
|
@@ -38,6 +41,8 @@ const handlers = {
|
|
|
38
41
|
author_unwatchExtrinsic: async (_context, [subid], { unsubscribe }) => {
|
|
39
42
|
unsubscribe(subid);
|
|
40
43
|
},
|
|
41
|
-
author_pendingExtrinsics: async (
|
|
44
|
+
author_pendingExtrinsics: async (context) => {
|
|
45
|
+
return context.chain.pendingExtrinsics;
|
|
46
|
+
},
|
|
42
47
|
};
|
|
43
48
|
exports.default = handlers;
|
|
@@ -5,7 +5,7 @@ const handlers = {
|
|
|
5
5
|
chain_getBlockHash: async (context, [blockNumber]) => {
|
|
6
6
|
const block = await context.chain.getBlockAt(blockNumber);
|
|
7
7
|
if (!block) {
|
|
8
|
-
throw new shared_1.ResponseError(1,
|
|
8
|
+
throw new shared_1.ResponseError(1, `Block #${blockNumber} not found`);
|
|
9
9
|
}
|
|
10
10
|
return block.hash;
|
|
11
11
|
},
|
|
@@ -15,7 +15,7 @@ const handlers = {
|
|
|
15
15
|
chain_getBlock: async (context, [hash]) => {
|
|
16
16
|
const block = await context.chain.getBlock(hash);
|
|
17
17
|
if (!block) {
|
|
18
|
-
throw new shared_1.ResponseError(1,
|
|
18
|
+
throw new shared_1.ResponseError(1, `Block ${hash} not found`);
|
|
19
19
|
}
|
|
20
20
|
return {
|
|
21
21
|
block: {
|
|
@@ -41,7 +41,7 @@ const handlers = {
|
|
|
41
41
|
},
|
|
42
42
|
state_subscribeRuntimeVersion: async (context, _params, { subscribe }) => {
|
|
43
43
|
let update = (_block) => { };
|
|
44
|
-
const id = context.chain.headState.subscrubeRuntimeVersion((block) => update(block));
|
|
44
|
+
const id = await context.chain.headState.subscrubeRuntimeVersion((block) => update(block));
|
|
45
45
|
const callback = subscribe('state_runtimeVersion', id);
|
|
46
46
|
update = async (block) => callback(await block.runtimeVersion);
|
|
47
47
|
context.chain.head.runtimeVersion.then(callback);
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const handlers = {
|
|
4
4
|
system_chain: async (context) => {
|
|
5
|
-
return context.api.getSystemChain();
|
|
5
|
+
return context.chain.api.getSystemChain();
|
|
6
6
|
},
|
|
7
7
|
system_properties: async (context) => {
|
|
8
|
-
return context.api.getSystemProperties();
|
|
8
|
+
return context.chain.api.getSystemProperties();
|
|
9
9
|
},
|
|
10
10
|
system_name: async (context) => {
|
|
11
|
-
return context.api.getSystemName();
|
|
11
|
+
return context.chain.api.getSystemName();
|
|
12
12
|
},
|
|
13
13
|
system_version: async (_context) => {
|
|
14
14
|
return 'chopsticks-1.1.0';
|
|
@@ -0,0 +1,47 @@
|
|
|
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 generate_html_diff_1 = require("./utils/generate-html-diff");
|
|
6
|
+
const open_html_1 = require("./utils/open-html");
|
|
7
|
+
const executor_1 = require("./executor");
|
|
8
|
+
const setup_1 = require("./setup");
|
|
9
|
+
const runBlock = async (argv) => {
|
|
10
|
+
const context = await (0, setup_1.setup)(argv);
|
|
11
|
+
const header = await context.chain.head.header;
|
|
12
|
+
const wasm = await context.chain.head.wasm;
|
|
13
|
+
const block = context.chain.head;
|
|
14
|
+
const parent = await block.parentBlock;
|
|
15
|
+
if (!parent)
|
|
16
|
+
throw Error('cant find parent block');
|
|
17
|
+
const calls = [['Core_initialize_block', header.toHex()]];
|
|
18
|
+
for (const extrinsic of await block.extrinsics) {
|
|
19
|
+
calls.push(['BlockBuilder_apply_extrinsic', extrinsic]);
|
|
20
|
+
}
|
|
21
|
+
calls.push(['BlockBuilder_finalize_block', '0x']);
|
|
22
|
+
const result = await (0, executor_1.runTask)({
|
|
23
|
+
wasm,
|
|
24
|
+
calls,
|
|
25
|
+
storage: [],
|
|
26
|
+
mockSignatureHost: false,
|
|
27
|
+
allowUnresolvedImports: false,
|
|
28
|
+
}, (0, executor_1.taskHandler)(parent));
|
|
29
|
+
if (result.Error) {
|
|
30
|
+
throw new Error(result.Error);
|
|
31
|
+
}
|
|
32
|
+
if (argv['html']) {
|
|
33
|
+
const filePath = await (0, generate_html_diff_1.generateHtmlDiffPreviewFile)(block, result.Call.storageDiff, block.hash);
|
|
34
|
+
console.log(`Generated preview ${filePath}`);
|
|
35
|
+
if (argv['open']) {
|
|
36
|
+
(0, open_html_1.openHtml)(filePath);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else if (argv['output-path']) {
|
|
40
|
+
(0, node_fs_1.writeFileSync)(argv['output-path'], JSON.stringify(result, null, 2));
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
console.dir(result, { depth: null, colors: false });
|
|
44
|
+
}
|
|
45
|
+
process.exit(0);
|
|
46
|
+
};
|
|
47
|
+
exports.runBlock = runBlock;
|
package/dist/schema/index.js
CHANGED
|
@@ -17,7 +17,7 @@ exports.configSchema = zod_1.z
|
|
|
17
17
|
.object({
|
|
18
18
|
port: zod_1.z.number().optional(),
|
|
19
19
|
endpoint: zod_1.z.string().optional(),
|
|
20
|
-
block: zod_1.z.union([zod_1.z.string(), zod_1.z.number()]).optional(),
|
|
20
|
+
block: zod_1.z.union([zod_1.z.string().length(66).startsWith('0x'), zod_1.z.number()]).optional(),
|
|
21
21
|
'build-block-mode': zod_1.z.nativeEnum(txpool_1.BuildBlockMode).optional(),
|
|
22
22
|
'import-storage': zod_1.z.any().optional(),
|
|
23
23
|
'mock-signature-host': zod_1.z.boolean().optional(),
|
package/dist/server.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export type Handler = (data: {
|
|
|
3
3
|
method: string;
|
|
4
4
|
params: string[];
|
|
5
5
|
}, subscriptionManager: SubscriptionManager) => Promise<any>;
|
|
6
|
-
export declare const createServer: (
|
|
7
|
-
port:
|
|
6
|
+
export declare const createServer: (handler: Handler, port?: number) => Promise<{
|
|
7
|
+
port: number;
|
|
8
8
|
close: () => Promise<void>;
|
|
9
|
-
}
|
|
9
|
+
}>;
|