-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.ts
More file actions
executable file
·354 lines (324 loc) · 13.1 KB
/
cli.ts
File metadata and controls
executable file
·354 lines (324 loc) · 13.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
#!/usr/bin/env bun
import { Command } from "commander";
import { commandBuild } from "./commands/build.ts";
import { commandBuildWithExtensions } from "./commands/build-with-extensions.ts";
import { commandDecode } from "./commands/decode.ts";
import { commandDecodeCall } from "./commands/decode-call.ts";
import { commandCompare } from "./commands/compare.ts";
import { commandQueryFees } from "./commands/query-fees.ts";
import { commandQueryExtrinsicFees } from "./commands/query-extrinsic-fees.ts";
import { commandCompactScale } from "./commands/compact-scale.ts";
import { commandGetStorage } from "./commands/get-storage.ts";
import { commandGetBlock } from "./commands/get-block.ts";
import { commandListPallets } from "./commands/list-pallets.ts";
import { commandListCalls } from "./commands/list-calls.ts";
import { commandListTypes } from "./commands/list-types.ts";
import { commandDescribeType } from "./commands/describe-type.ts";
import { commandListConstants } from "./commands/list-constants.ts";
import { commandDescribeConstant } from "./commands/describe-constant.ts";
import { commandChainDiff } from "./commands/chain-diff.ts";
import { commandAddChain } from "./commands/add-chain.ts";
import { commandGetValidators } from "./commands/get-validators.ts";
import { commandGetDisputes } from "./commands/get-disputes.ts";
import { commandAnalyzeDisputeVotes } from "./commands/analyze-dispute-votes.ts";
import { commandGetSessionInfo } from "./commands/get-session-info.ts";
import { commandCheckParaValidation } from "./commands/check-para-validation.ts";
import { commandListSignedExtensions } from "./commands/list-signed-extensions.ts";
import { getDefaultChain, getChainNames } from "./lib/chain-config.ts";
const VERSION = "1.0.0";
const program = new Command();
let defaultChain = "default";
let chainNames = "available chains";
try {
defaultChain = getDefaultChain();
chainNames = getChainNames().join(", ");
} catch (e) {
// chains.json doesn't exist yet
}
program
.name("extrinsic")
.description("Polkadot/Substrate extrinsics debugging toolkit")
.version(VERSION);
program
.command("build")
.description("Build a signed extrinsic from components")
.requiredOption(
"--address <hex>",
"Sender address (hex string, with or without 0x)",
)
.requiredOption("--call <hex>", "Call data (hex string, with or without 0x)")
.option("--nonce <number>", "Account nonce", "0")
.option("--tip <number>", "Tip amount", "0")
.option("--era <type>", 'Era type: "immortal" or "mortal"', "mortal")
.option("--decode", "Also decode the built extrinsic", false)
.action(async (options) => {
await commandBuild({
address: options.address,
call: options.call,
nonce: options.nonce,
tip: options.tip,
era: options.era,
decode: options.decode,
});
});
program
.command("build-with-extensions")
.description("Build an extrinsic with custom signed extensions")
.requiredOption(
"--address <hex>",
"Sender address (hex string, with or without 0x)",
)
.requiredOption("--call <hex>", "Call data (hex string, with or without 0x)")
.requiredOption("--extensions <hex>", "Pre-encoded signed extensions (hex string)")
.option("--signature <hex>", "Signature (hex string, 65 bytes: 1 type + 64 sig). Default: dummy signature")
.option("--chain <name>", `Chain name (${chainNames})`, defaultChain)
.option("--decode", "Also decode the built extrinsic", false)
.action(async (options) => {
await commandBuildWithExtensions({
address: options.address,
call: options.call,
extensions: options.extensions,
signature: options.signature,
chain: options.chain,
decode: options.decode,
});
});
program
.command("decode")
.description("Decode and display extrinsic structure")
.argument("<extrinsic>", "Extrinsic hex string")
.option("--name <string>", "Optional name/label for the extrinsic")
.option("--chain <name>", `Chain name (${chainNames})`, defaultChain)
.action(async (extrinsic, options) => {
await commandDecode({ _0: extrinsic, name: options.name, chain: options.chain });
});
program
.command("decode-call")
.description("Decode a call (without extrinsic wrapper)")
.argument("<call>", "Call hex string")
.option("--name <string>", "Optional name/label for the call")
.option("--chain <name>", `Chain name (${chainNames})`, defaultChain)
.action(async (call, options) => {
await commandDecodeCall({ _0: call, name: options.name, chain: options.chain });
});
program
.command("compare")
.description("Compare two extrinsics byte-by-byte")
.argument("<extrinsic1>", "First extrinsic hex string")
.argument("<extrinsic2>", "Second extrinsic hex string")
.option("--name1 <string>", "Name for first extrinsic")
.option("--name2 <string>", "Name for second extrinsic")
.action(async (extrinsic1, extrinsic2, options) => {
await commandCompare({
_0: extrinsic1,
_1: extrinsic2,
name1: options.name1,
name2: options.name2,
});
});
program
.command("query-fees")
.description("Query fees for an extrinsic on a chain")
.requiredOption("--address <hex>", "Sender address")
.requiredOption("--call <hex>", "Call data")
.option("--nonce <number>", "Account nonce", "0")
.option("--tip <number>", "Tip amount", "0")
.option("--era <type>", 'Era type: "immortal" or "mortal"', "immortal")
.option("--chain <name>", `Chain name (${chainNames})`, defaultChain)
.action(async (options) => {
await commandQueryFees({
address: options.address,
call: options.call,
nonce: options.nonce,
tip: options.tip,
era: options.era,
chain: options.chain,
});
});
program
.command("query-extrinsic-fees")
.description("Query fees for an existing extrinsic hex on a chain")
.argument("<extrinsic>", "Extrinsic hex string")
.option("--chain <name>", `Chain name (${chainNames})`, defaultChain)
.action(async (extrinsic, options) => {
await commandQueryExtrinsicFees({ _0: extrinsic, chain: options.chain });
});
program
.command("compact-scale")
.description("Encode/decode SCALE compact values")
.option("--encode <number>", "Encode a number to compact hex")
.option("--decode <hex>", "Decode compact hex to number")
.action(async (options) => {
await commandCompactScale({ encode: options.encode, decode: options.decode });
});
program
.command("get-storage")
.description("Query storage value using state_getStorage RPC")
.argument("<key>", "Storage key (hex)")
.argument("[block]", "Block hash (optional)")
.option("--chain <name>", `Chain name (${chainNames})`, defaultChain)
.action(async (key, block, options) => {
await commandGetStorage({ key, block, chain: options.chain });
});
program
.command("get-block")
.description("Get block data using chain_getBlock RPC")
.option("--hash <hash>", "Block hash (optional, defaults to latest block)")
.option("--chain <name>", `Chain name (${chainNames})`, defaultChain)
.action(async (options) => {
await commandGetBlock({ hash: options.hash, chain: options.chain });
});
program
.command("list-pallets")
.description("List all available pallets on a chain")
.option("--chain <name>", `Chain name (${chainNames})`, defaultChain)
.action(async (options) => {
await commandListPallets({ chain: options.chain });
});
program
.command("list-signed-extensions")
.description("List signed extensions from chain metadata (order and encoding)")
.option("--chain <name>", `Chain name (${chainNames})`, defaultChain)
.option("--verbose", "Show additionalSigned types", false)
.option("--live", "Fetch fresh metadata from RPC instead of local file", false)
.action(async (options) => {
await commandListSignedExtensions({ chain: options.chain, verbose: options.verbose, live: options.live });
});
program
.command("list-calls")
.description("List all calls, optionally filtered by pallet(s)")
.option("--chain <name>", `Chain name (${chainNames})`, defaultChain)
.option("--pallets <names>", "Comma-separated list of pallet names to filter")
.action(async (options) => {
await commandListCalls({ chain: options.chain, pallets: options.pallets });
});
program
.command("list-types")
.description("List all available types on a chain")
.option("--chain <name>", `Chain name (${chainNames})`, defaultChain)
.option("--grouped", "Group types by namespace", false)
.action(async (options) => {
await commandListTypes({ chain: options.chain, grouped: options.grouped });
});
program
.command("describe-type")
.description("Show detailed structure of a type")
.argument("<type>", "Type name or search pattern")
.option("--chain <name>", `Chain name (${chainNames})`, defaultChain)
.action(async (type, options) => {
await commandDescribeType({ _0: type, chain: options.chain });
});
program
.command("list-constants")
.description("List all constants, optionally filtered by pallet")
.option("--chain <name>", `Chain name (${chainNames})`, defaultChain)
.option("--pallet <name>", "Pallet name to filter")
.action(async (options) => {
await commandListConstants({ chain: options.chain, pallet: options.pallet });
});
program
.command("describe-constant")
.description("Show detailed information about a constant")
.argument("<pallet>", "Pallet name")
.argument("<constant>", "Constant name")
.option("--chain <name>", `Chain name (${chainNames})`, defaultChain)
.action(async (pallet, constant, options) => {
await commandDescribeConstant({ _0: pallet, _1: constant, chain: options.chain });
});
program
.command("chain-diff")
.description("Compare pallet calls and types between two chains")
.requiredOption("--pallets <names>", "Comma-separated pallet names")
.option("--old-chain <name>", `Old chain to compare from (${chainNames})`)
.option("--new-chain <name>", `New chain to compare to (${chainNames})`)
.action(async (options) => {
await commandChainDiff({
pallets: options.pallets,
oldChain: options.oldChain,
newChain: options.newChain,
});
});
program
.command("add-chain")
.description("Add a new chain to the configuration")
.requiredOption("--name <name>", "Chain identifier (e.g., 'polkadot')")
.requiredOption("--ws-url <url>", "WebSocket RPC URL")
.option("--display-name <name>", "Human-readable chain name")
.option("--papi-key <key>", "PAPI descriptor key (defaults to chain name)")
.option("--set-default", "Set this chain as the default", false)
.action(async (options) => {
await commandAddChain({
name: options.name,
displayName: options.displayName,
wsUrl: options.wsUrl,
papiKey: options.papiKey,
setDefault: options.setDefault,
});
});
// ============ DISPUTE INVESTIGATION COMMANDS ============
program
.command("get-validators")
.description("Get current session validators with their indices")
.option("--chain <name>", `Chain name (${chainNames})`, defaultChain)
.option("--indices <list>", "Comma-separated validator indices to filter (e.g., 8,11,19,21)")
.option("--session <number>", "Session index (default: current)")
.action(async (options) => {
await commandGetValidators({
chain: options.chain,
indices: options.indices,
session: options.session,
});
});
program
.command("get-disputes")
.description("Get disputes from a block or storage")
.option("--chain <name>", `Chain name (${chainNames})`, defaultChain)
.option("--block <hash>", "Block hash (default: latest)")
.option("--session <number>", "Filter by session index")
.option("--candidate <hash>", "Filter by candidate hash")
.action(async (options) => {
await commandGetDisputes({
chain: options.chain,
block: options.block,
session: options.session,
candidate: options.candidate,
});
});
program
.command("analyze-dispute-votes")
.description("Analyze dispute vote patterns from JSON data")
.option("--file <path>", "Path to JSON file with dispute data")
.option("--json <data>", "Inline JSON dispute data")
.option("--validators <csv>", "CSV file with validator list (from Subscan export)")
.action(async (options) => {
await commandAnalyzeDisputeVotes({
file: options.file,
json: options.json,
validators: options.validators,
});
});
program
.command("get-session-info")
.description("Get current session info including dispute parameters")
.option("--chain <name>", `Chain name (${chainNames})`, defaultChain)
.option("--session <number>", "Session index (default: current)")
.action(async (options) => {
await commandGetSessionInfo({
chain: options.chain,
session: options.session,
});
});
program
.command("check-para-validation")
.description("Check validation status for a parachain")
.requiredOption("--para-id <number>", "Parachain ID (e.g., 1000)")
.option("--chain <name>", `Chain name (${chainNames})`, defaultChain)
.option("--block <hash>", "Block hash (default: latest)")
.action(async (options) => {
await commandCheckParaValidation({
chain: options.chain,
paraId: options.paraId,
block: options.block,
});
});
program.parse();