@cogcoin/client 1.1.4 → 1.1.6

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.
Files changed (107) hide show
  1. package/README.md +4 -5
  2. package/dist/bitcoind/indexer-daemon.d.ts +3 -7
  3. package/dist/bitcoind/indexer-daemon.js +43 -158
  4. package/dist/bitcoind/managed-runtime/bitcoind-policy.d.ts +16 -0
  5. package/dist/bitcoind/managed-runtime/bitcoind-policy.js +177 -0
  6. package/dist/bitcoind/managed-runtime/indexer-policy.d.ts +34 -0
  7. package/dist/bitcoind/managed-runtime/indexer-policy.js +200 -0
  8. package/dist/bitcoind/managed-runtime/status.d.ts +11 -0
  9. package/dist/bitcoind/managed-runtime/status.js +59 -0
  10. package/dist/bitcoind/managed-runtime/types.d.ts +37 -0
  11. package/dist/bitcoind/managed-runtime/types.js +1 -0
  12. package/dist/bitcoind/progress/tty-renderer.js +3 -2
  13. package/dist/bitcoind/service.d.ts +2 -7
  14. package/dist/bitcoind/service.js +46 -94
  15. package/dist/cli/command-registry.d.ts +39 -0
  16. package/dist/cli/command-registry.js +1132 -0
  17. package/dist/cli/commands/client-admin.js +6 -56
  18. package/dist/cli/commands/mining-admin.js +9 -32
  19. package/dist/cli/commands/mining-read.js +15 -56
  20. package/dist/cli/commands/mining-runtime.js +258 -57
  21. package/dist/cli/commands/service-runtime.js +1 -64
  22. package/dist/cli/commands/status.js +2 -15
  23. package/dist/cli/commands/update.js +6 -21
  24. package/dist/cli/commands/wallet-admin.js +18 -120
  25. package/dist/cli/commands/wallet-mutation.js +4 -7
  26. package/dist/cli/commands/wallet-read.js +31 -138
  27. package/dist/cli/context.js +2 -4
  28. package/dist/cli/mining-format.js +8 -2
  29. package/dist/cli/mutation-command-groups.d.ts +11 -11
  30. package/dist/cli/mutation-command-groups.js +9 -18
  31. package/dist/cli/mutation-json.d.ts +1 -17
  32. package/dist/cli/mutation-json.js +1 -28
  33. package/dist/cli/mutation-success.d.ts +0 -1
  34. package/dist/cli/mutation-success.js +0 -19
  35. package/dist/cli/output.d.ts +1 -10
  36. package/dist/cli/output.js +52 -481
  37. package/dist/cli/parse.d.ts +1 -1
  38. package/dist/cli/parse.js +38 -695
  39. package/dist/cli/runner.js +28 -113
  40. package/dist/cli/types.d.ts +7 -8
  41. package/dist/cli/update-notifier.js +1 -1
  42. package/dist/cli/wallet-format.js +1 -1
  43. package/dist/wallet/lifecycle/access.d.ts +5 -0
  44. package/dist/wallet/lifecycle/access.js +79 -0
  45. package/dist/wallet/lifecycle/context.d.ts +26 -0
  46. package/dist/wallet/lifecycle/context.js +58 -0
  47. package/dist/wallet/lifecycle/managed-core.d.ts +15 -0
  48. package/dist/wallet/lifecycle/managed-core.js +197 -0
  49. package/dist/wallet/lifecycle/repair-bitcoind.d.ts +10 -0
  50. package/dist/wallet/lifecycle/repair-bitcoind.js +142 -0
  51. package/dist/wallet/lifecycle/repair-indexer.d.ts +8 -0
  52. package/dist/wallet/lifecycle/repair-indexer.js +117 -0
  53. package/dist/wallet/lifecycle/repair-mining.d.ts +49 -0
  54. package/dist/wallet/lifecycle/repair-mining.js +304 -0
  55. package/dist/wallet/lifecycle/repair-runtime.d.ts +36 -0
  56. package/dist/wallet/lifecycle/repair-runtime.js +206 -0
  57. package/dist/wallet/lifecycle/repair.d.ts +9 -0
  58. package/dist/wallet/lifecycle/repair.js +127 -0
  59. package/dist/wallet/lifecycle/setup-prompts.d.ts +7 -0
  60. package/dist/wallet/lifecycle/setup-prompts.js +88 -0
  61. package/dist/wallet/lifecycle/setup-state.d.ts +26 -0
  62. package/dist/wallet/lifecycle/setup-state.js +159 -0
  63. package/dist/wallet/lifecycle/setup.d.ts +15 -0
  64. package/dist/wallet/lifecycle/setup.js +124 -0
  65. package/dist/wallet/lifecycle/types.d.ts +156 -0
  66. package/dist/wallet/lifecycle/types.js +1 -0
  67. package/dist/wallet/lifecycle.d.ts +4 -165
  68. package/dist/wallet/lifecycle.js +3 -1656
  69. package/dist/wallet/mining/candidate.d.ts +60 -0
  70. package/dist/wallet/mining/candidate.js +290 -0
  71. package/dist/wallet/mining/competitiveness.d.ts +22 -0
  72. package/dist/wallet/mining/competitiveness.js +640 -0
  73. package/dist/wallet/mining/control.js +7 -251
  74. package/dist/wallet/mining/cycle.d.ts +39 -0
  75. package/dist/wallet/mining/cycle.js +542 -0
  76. package/dist/wallet/mining/engine-state.d.ts +66 -0
  77. package/dist/wallet/mining/engine-state.js +211 -0
  78. package/dist/wallet/mining/engine-types.d.ts +173 -0
  79. package/dist/wallet/mining/engine-types.js +1 -0
  80. package/dist/wallet/mining/engine-utils.d.ts +7 -0
  81. package/dist/wallet/mining/engine-utils.js +75 -0
  82. package/dist/wallet/mining/events.d.ts +2 -0
  83. package/dist/wallet/mining/events.js +19 -0
  84. package/dist/wallet/mining/lifecycle.d.ts +71 -0
  85. package/dist/wallet/mining/lifecycle.js +355 -0
  86. package/dist/wallet/mining/projection.d.ts +61 -0
  87. package/dist/wallet/mining/projection.js +319 -0
  88. package/dist/wallet/mining/publish.d.ts +79 -0
  89. package/dist/wallet/mining/publish.js +614 -0
  90. package/dist/wallet/mining/runner.d.ts +12 -418
  91. package/dist/wallet/mining/runner.js +274 -3433
  92. package/dist/wallet/mining/supervisor.d.ts +134 -0
  93. package/dist/wallet/mining/supervisor.js +558 -0
  94. package/dist/wallet/mining/visualizer-sync.d.ts +42 -0
  95. package/dist/wallet/mining/visualizer-sync.js +166 -0
  96. package/dist/wallet/mining/visualizer.d.ts +1 -0
  97. package/dist/wallet/mining/visualizer.js +33 -18
  98. package/dist/wallet/read/context.js +13 -188
  99. package/dist/wallet/reset.d.ts +1 -1
  100. package/dist/wallet/reset.js +35 -11
  101. package/dist/wallet/runtime.d.ts +0 -6
  102. package/dist/wallet/runtime.js +2 -38
  103. package/dist/wallet/tx/common.d.ts +18 -0
  104. package/dist/wallet/tx/common.js +40 -26
  105. package/package.json +1 -1
  106. package/dist/wallet/state/seed-index.d.ts +0 -43
  107. package/dist/wallet/state/seed-index.js +0 -151
package/dist/cli/parse.js CHANGED
@@ -1,276 +1,16 @@
1
- import { isWalletMutationCommand } from "./mutation-command-groups.js";
2
- import { isJsonOutputSupportedCommand, isPreviewJsonOutputSupportedCommand, } from "./output.js";
3
- export const HELP_TEXT = `Usage: cogcoin <command> [options]
4
-
5
- Commands:
6
- status Show wallet-aware local service and chain status
7
- status --output json Emit the stable v1 machine-readable status envelope
8
- update Show the current and latest client versions and install updates
9
- update --output json Emit the stable v1 machine-readable update result envelope
10
- client unlock Unlock password-protected local wallet secrets for a limited time
11
- client lock Flush the cached client password unlock session
12
- client change-password Rotate the client password that protects local wallet secrets
13
- bitcoin start Start the managed Bitcoin daemon
14
- bitcoin stop Stop the managed Bitcoin daemon and paired indexer
15
- bitcoin status Show managed Bitcoin daemon status without starting it
16
- bitcoin transfer <sats> --to <address>
17
- Send plain BTC from the wallet address
18
- indexer start Start the managed Cogcoin indexer (and bitcoind if needed)
19
- indexer stop Stop the managed Cogcoin indexer only
20
- indexer status Show managed Cogcoin indexer status without starting it
21
- init Initialize a new local wallet root
22
- init --output json Emit the stable v1 machine-readable init result envelope
23
- restore Restore an imported named seed from a 24-word mnemonic; run sync afterward
24
- reset Factory-reset local Cogcoin state with interactive retention prompts
25
- repair Recover bounded wallet/indexer/runtime state
26
- wallet address Alias for address
27
- wallet ids Alias for ids
28
- mine Run the miner in the foreground
29
- mine start Start the miner as a background worker
30
- mine stop Stop the active background miner
31
- mine setup Configure the built-in mining provider
32
- mine setup --output json
33
- Emit the stable v1 machine-readable mine setup result envelope
34
- mine prompt Show per-domain mining prompt state
35
- mine prompt --output json
36
- Emit the stable v1 machine-readable mine prompt list envelope
37
- mine prompt <domain> Configure a per-domain mining prompt override
38
- mine prompt <domain> --output json
39
- Emit the stable v1 machine-readable mine prompt result envelope
40
- mine prompt list Alias for mine prompt
41
- mine status Show mining control-plane health and readiness
42
- mine log Show recent mining control-plane events
43
- anchor <domain> Anchor an owned unanchored domain with the wallet address
44
- register <domain>
45
- Register a root domain or subdomain
46
- transfer <domain> --to <btc-target>
47
- Transfer an unanchored domain to another BTC address or script
48
- sell <domain> <price> List an unanchored domain for sale in COG
49
- unsell <domain> Clear an active domain listing
50
- buy <domain>
51
- Buy an unanchored listed domain in COG
52
- send <amount> --to <btc-target>
53
- Send COG from the wallet address to another BTC target
54
- claim <lock-id> --preimage <32-byte-hex>
55
- Claim an active COG lock before timeout
56
- reclaim <lock-id> Reclaim an expired COG lock as the original locker
57
- cog lock <amount> --to-domain <domain> (--for <blocks-or-duration> | --until-height <height>) --condition <sha256hex>
58
- Lock COG to an anchored recipient domain
59
- wallet status Show detailed wallet-local status and service health
60
- wallet init Initialize a new local wallet root
61
- wallet restore Restore an imported named seed from a 24-word mnemonic; run sync afterward
62
- wallet delete Delete one imported named seed without affecting main
63
- wallet show-mnemonic Reveal the initialized wallet recovery phrase after typed confirmation
64
- address Show the BTC wallet address for this wallet
65
- ids Show the local wallet address
66
- balance Show local wallet COG balances
67
- locks Show locally related active COG locks
68
- domain list Alias for domains
69
- domain show <domain> Alias for show <domain>
70
- domains [--anchored] [--listed] [--mineable]
71
- Show locally related domains
72
- show <domain> Show one domain and its local-wallet relationship
73
- fields <domain> List current fields on a domain
74
- field <domain> <field> Show one current field value
75
- field create <domain> <field>
76
- Create a new empty anchored field
77
- field set <domain> <field>
78
- Update an existing anchored field value
79
- field clear <domain> <field>
80
- Clear an existing anchored field value
81
- rep give <source-domain> <target-domain> <amount>
82
- Burn COG as anchored-domain reputation support
83
- rep revoke <source-domain> <target-domain> <amount>
84
- Revoke visible support without refunding burned COG
85
-
86
- Options:
87
- --db <path> Override the SQLite database path
88
- --data-dir <path> Override the managed bitcoin datadir
89
- --for <duration> Relative timeout for cog lock, like 15m, 2h, or 1d
90
- --message <text> Founding message text for anchor
91
- --to <btc-target> Transfer or send target as an address or spk:<hex>
92
- --to-domain <domain>
93
- Recipient domain for cog lock
94
- --condition <sha256hex>
95
- 32-byte lock condition hash
96
- --until-height <height>
97
- Absolute timeout height for cog lock
98
- --preimage <32-byte-hex>
99
- Claim preimage for an active lock
100
- --review <text> Optional public review text for reputation operations
101
- --satvb <n> Override the mutation fee rate in sat/vB
102
- --text <utf8> UTF-8 payload text for endpoint or field writes
103
- --json <json> UTF-8 payload JSON text for endpoint or field writes
104
- --bytes <spec> Payload bytes as hex:<hex> or @<path>
105
- --permanent Create the field as permanent
106
- --format <spec> Advanced field format as raw:<u8>
107
- --value <spec> Advanced field value as hex:<hex>, @<path>, or utf8:<text>
108
- --claimable Show only currently claimable locks
109
- --reclaimable Show only currently reclaimable locks
110
- --anchored Show only anchored domains
111
- --listed Show only currently listed domains
112
- --mineable Show only locally mineable root domains
113
- --limit <n> Limit list rows (1..1000)
114
- --all Show all rows for list commands
115
- --follow Follow mining log output
116
- --output <mode> Output mode: text, json, or preview-json
117
- --progress <mode> Progress output mode: auto, tty, or none
118
- --seed <name> Select an imported wallet seed for wallet-aware commands
119
- --force Reserved for future use
120
- --force-race Allow a visible root registration race
121
- --yes Approve eligible plain yes/no mutation confirmations non-interactively
122
- --help Show help
123
- --version Show package version
124
-
125
- Quickstart:
126
- 1. Run \`cogcoin init\` to create the wallet.
127
- 2. Run \`cogcoin sync\` to bootstrap assumeutxo and the managed Bitcoin/indexer state.
128
- 3. Run \`cogcoin address\`, then fund the wallet with about 0.0015 BTC so you can buy a 6+ character domain to start mining and still keep BTC available for mining transaction fees.
129
-
130
- Examples:
131
- cogcoin status --output json
132
- cogcoin bitcoin status
133
- cogcoin indexer status
134
- cogcoin init --output json
135
- cogcoin restore --seed trading
136
- cogcoin wallet address
137
- cogcoin domain list --mineable
138
- cogcoin register alpha-child
139
- cogcoin anchor alpha
140
- cogcoin register alpha --satvb 12.5
141
- cogcoin buy alpha
142
- cogcoin field set alpha bio --text "hello"
143
- cogcoin rep give alpha beta 10 --review "great operator"
144
- cogcoin mine setup --output json
145
- cogcoin mine prompt
146
- cogcoin mine prompt alpha
147
- cogcoin register alpha-child --output preview-json
148
- cogcoin mine status
149
- `;
150
- function supportsYesFlag(command) {
151
- switch (command) {
152
- case "update":
153
- case "sync":
154
- case "follow":
155
- case "bitcoin-transfer":
156
- case "repair":
157
- case "wallet-delete":
158
- case "register":
159
- case "domain-register":
160
- case "transfer":
161
- case "domain-transfer":
162
- case "sell":
163
- case "domain-sell":
164
- case "unsell":
165
- case "domain-unsell":
166
- case "buy":
167
- case "domain-buy":
168
- case "send":
169
- case "cog-send":
170
- case "claim":
171
- case "cog-claim":
172
- case "reclaim":
173
- case "cog-reclaim":
174
- case "cog-lock":
175
- case "field-create":
176
- case "field-set":
177
- case "field-clear":
178
- case "domain-endpoint-set":
179
- case "domain-endpoint-clear":
180
- case "domain-delegate-set":
181
- case "domain-delegate-clear":
182
- case "domain-miner-set":
183
- case "domain-miner-clear":
184
- case "domain-canonical":
185
- case "rep-give":
186
- case "rep-revoke":
187
- return true;
188
- default:
189
- return false;
190
- }
191
- }
192
- function supportsSeedFlag(command) {
193
- switch (command) {
194
- case "status":
195
- case "bitcoin-transfer":
196
- case "anchor":
197
- case "domain-anchor":
198
- case "register":
199
- case "domain-register":
200
- case "transfer":
201
- case "domain-transfer":
202
- case "sell":
203
- case "domain-sell":
204
- case "unsell":
205
- case "domain-unsell":
206
- case "buy":
207
- case "domain-buy":
208
- case "domain-endpoint-set":
209
- case "domain-endpoint-clear":
210
- case "domain-delegate-set":
211
- case "domain-delegate-clear":
212
- case "domain-miner-set":
213
- case "domain-miner-clear":
214
- case "domain-canonical":
215
- case "field-list":
216
- case "field-show":
217
- case "field-create":
218
- case "field-set":
219
- case "field-clear":
220
- case "send":
221
- case "claim":
222
- case "reclaim":
223
- case "cog-send":
224
- case "cog-claim":
225
- case "cog-reclaim":
226
- case "cog-lock":
227
- case "rep-give":
228
- case "rep-revoke":
229
- case "cog-balance":
230
- case "cog-locks":
231
- case "mine":
232
- case "mine-start":
233
- case "mine-stop":
234
- case "mine-setup":
235
- case "mine-prompt":
236
- case "mine-prompt-list":
237
- case "mine-status":
238
- case "mine-log":
239
- case "wallet-delete":
240
- case "wallet-restore":
241
- case "restore":
242
- case "wallet-show-mnemonic":
243
- case "wallet-status":
244
- case "wallet-address":
245
- case "wallet-ids":
246
- case "address":
247
- case "ids":
248
- case "balance":
249
- case "locks":
250
- case "domain-list":
251
- case "domains":
252
- case "domain-show":
253
- case "show":
254
- case "fields":
255
- case "field":
256
- return true;
257
- default:
258
- return false;
259
- }
260
- }
261
- function requiresSeedFlag(command) {
262
- return command === "restore" || command === "wallet-restore" || command === "wallet-delete";
263
- }
1
+ import { commandSupportsSatvb, commandSupportsYesFlag, getCommandHandlerFamily, renderHelpText, resolveCommandMatch, resolveUnknownCommandError, } from "./command-registry.js";
2
+ export const HELP_TEXT = renderHelpText();
264
3
  export function parseCliArgs(argv) {
265
4
  let command = null;
5
+ let commandFamily = null;
6
+ let invokedCommandTokens = null;
7
+ let invokedCommandPath = null;
266
8
  const args = [];
267
9
  let help = false;
268
10
  let version = false;
269
- let outputMode = "text";
270
11
  let dbPath = null;
271
12
  let dataDir = null;
272
13
  let progressOutput = "auto";
273
- let seedName = null;
274
14
  let unlockFor = null;
275
15
  let assumeYes = false;
276
16
  let force = false;
@@ -307,15 +47,6 @@ export function parseCliArgs(argv) {
307
47
  version = true;
308
48
  continue;
309
49
  }
310
- if (token === "--output") {
311
- index += 1;
312
- const value = argv[index] ?? null;
313
- if (value !== "text" && value !== "json" && value !== "preview-json") {
314
- throw new Error("cli_invalid_output_mode");
315
- }
316
- outputMode = value;
317
- continue;
318
- }
319
50
  if (token === "--db") {
320
51
  index += 1;
321
52
  dbPath = argv[index] ?? null;
@@ -325,15 +56,7 @@ export function parseCliArgs(argv) {
325
56
  continue;
326
57
  }
327
58
  if (token === "--seed") {
328
- index += 1;
329
- seedName = argv[index] ?? null;
330
- if (seedName === null) {
331
- throw new Error("cli_missing_seed_name");
332
- }
333
- if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(seedName)) {
334
- throw new Error("cli_invalid_seed_name");
335
- }
336
- continue;
59
+ throw new Error("cli_seed_removed");
337
60
  }
338
61
  if (token === "--data-dir") {
339
62
  index += 1;
@@ -531,358 +254,16 @@ export function parseCliArgs(argv) {
531
254
  throw new Error(`cli_unknown_flag_${token.slice(2)}`);
532
255
  }
533
256
  if (command === null) {
534
- if (token === "wallet") {
535
- const subcommand = argv[index + 1] ?? null;
536
- if (subcommand === "status") {
537
- command = "wallet-status";
538
- index += 1;
539
- continue;
540
- }
541
- if (subcommand === "address") {
542
- command = "wallet-address";
543
- index += 1;
544
- continue;
545
- }
546
- if (subcommand === "ids") {
547
- command = "wallet-ids";
548
- index += 1;
549
- continue;
550
- }
551
- if (subcommand === "init") {
552
- command = "wallet-init";
553
- index += 1;
554
- continue;
555
- }
556
- if (subcommand === "restore") {
557
- command = "wallet-restore";
558
- index += 1;
559
- continue;
560
- }
561
- if (subcommand === "delete") {
562
- command = "wallet-delete";
563
- index += 1;
564
- continue;
565
- }
566
- if (subcommand === "show-mnemonic") {
567
- command = "wallet-show-mnemonic";
568
- index += 1;
569
- continue;
570
- }
571
- if (subcommand === "export") {
572
- throw new Error("cli_wallet_export_removed");
573
- }
574
- if (subcommand === "import") {
575
- throw new Error("cli_wallet_import_removed");
576
- }
577
- throw new Error(`cli_unknown_command_wallet${subcommand === null ? "" : `_${subcommand}`}`);
578
- }
579
- if (token === "bitcoin") {
580
- const subcommand = argv[index + 1] ?? null;
581
- if (subcommand === "start") {
582
- command = "bitcoin-start";
583
- index += 1;
584
- continue;
585
- }
586
- if (subcommand === "stop") {
587
- command = "bitcoin-stop";
588
- index += 1;
589
- continue;
590
- }
591
- if (subcommand === "status") {
592
- command = "bitcoin-status";
593
- index += 1;
594
- continue;
595
- }
596
- if (subcommand === "transfer") {
597
- command = "bitcoin-transfer";
598
- index += 1;
599
- continue;
600
- }
601
- throw new Error(`cli_unknown_command_bitcoin${subcommand === null ? "" : `_${subcommand}`}`);
602
- }
603
- if (token === "client") {
604
- const subcommand = argv[index + 1] ?? null;
605
- if (subcommand === "unlock") {
606
- command = "client-unlock";
607
- index += 1;
608
- continue;
609
- }
610
- if (subcommand === "lock") {
611
- command = "client-lock";
612
- index += 1;
613
- continue;
614
- }
615
- if (subcommand === "change-password") {
616
- command = "client-change-password";
617
- index += 1;
618
- continue;
619
- }
620
- throw new Error(`cli_unknown_command_client${subcommand === null ? "" : `_${subcommand}`}`);
621
- }
622
- if (token === "indexer") {
623
- const subcommand = argv[index + 1] ?? null;
624
- if (subcommand === "start") {
625
- command = "indexer-start";
626
- index += 1;
627
- continue;
628
- }
629
- if (subcommand === "stop") {
630
- command = "indexer-stop";
631
- index += 1;
632
- continue;
633
- }
634
- if (subcommand === "status") {
635
- command = "indexer-status";
636
- index += 1;
637
- continue;
638
- }
639
- throw new Error(`cli_unknown_command_indexer${subcommand === null ? "" : `_${subcommand}`}`);
257
+ const match = resolveCommandMatch(argv, index);
258
+ if (match === null) {
259
+ throw new Error(resolveUnknownCommandError(argv, index));
640
260
  }
641
- if (token === "mine") {
642
- const subcommand = argv[index + 1] ?? null;
643
- if (subcommand === null || subcommand.startsWith("--")) {
644
- command = "mine";
645
- continue;
646
- }
647
- if (subcommand === "start") {
648
- command = "mine-start";
649
- index += 1;
650
- continue;
651
- }
652
- if (subcommand === "stop") {
653
- command = "mine-stop";
654
- index += 1;
655
- continue;
656
- }
657
- if (subcommand === "setup") {
658
- command = "mine-setup";
659
- index += 1;
660
- continue;
661
- }
662
- if (subcommand === "prompt") {
663
- const action = argv[index + 2] ?? null;
664
- command = action === null || action.startsWith("--") || action === "list"
665
- ? "mine-prompt-list"
666
- : "mine-prompt";
667
- index += action === "list" ? 2 : 1;
668
- continue;
669
- }
670
- if (subcommand === "status") {
671
- command = "mine-status";
672
- index += 1;
673
- continue;
674
- }
675
- if (subcommand === "log") {
676
- command = "mine-log";
677
- index += 1;
678
- continue;
679
- }
680
- throw new Error(`cli_unknown_command_mine${subcommand === null ? "" : `_${subcommand}`}`);
681
- }
682
- if (token === "domain") {
683
- const subcommand = argv[index + 1] ?? null;
684
- if (subcommand === "register") {
685
- command = "domain-register";
686
- index += 1;
687
- continue;
688
- }
689
- if (subcommand === "list") {
690
- command = "domain-list";
691
- index += 1;
692
- continue;
693
- }
694
- if (subcommand === "show") {
695
- command = "domain-show";
696
- index += 1;
697
- continue;
698
- }
699
- if (subcommand === "anchor") {
700
- const action = argv[index + 2] ?? null;
701
- if (action === "clear") {
702
- throw new Error("cli_anchor_clear_removed");
703
- }
704
- command = "domain-anchor";
705
- index += 1;
706
- continue;
707
- }
708
- if (subcommand === "transfer") {
709
- command = "domain-transfer";
710
- index += 1;
711
- continue;
712
- }
713
- if (subcommand === "sell") {
714
- command = "domain-sell";
715
- index += 1;
716
- continue;
717
- }
718
- if (subcommand === "unsell") {
719
- command = "domain-unsell";
720
- index += 1;
721
- continue;
722
- }
723
- if (subcommand === "buy") {
724
- command = "domain-buy";
725
- index += 1;
726
- continue;
727
- }
728
- if (subcommand === "endpoint") {
729
- const action = argv[index + 2] ?? null;
730
- if (action === "set") {
731
- command = "domain-endpoint-set";
732
- index += 2;
733
- continue;
734
- }
735
- if (action === "clear") {
736
- command = "domain-endpoint-clear";
737
- index += 2;
738
- continue;
739
- }
740
- throw new Error(`cli_unknown_command_domain_endpoint${action === null ? "" : `_${action}`}`);
741
- }
742
- if (subcommand === "delegate") {
743
- const action = argv[index + 2] ?? null;
744
- if (action === "set") {
745
- command = "domain-delegate-set";
746
- index += 2;
747
- continue;
748
- }
749
- if (action === "clear") {
750
- command = "domain-delegate-clear";
751
- index += 2;
752
- continue;
753
- }
754
- throw new Error(`cli_unknown_command_domain_delegate${action === null ? "" : `_${action}`}`);
755
- }
756
- if (subcommand === "miner") {
757
- const action = argv[index + 2] ?? null;
758
- if (action === "set") {
759
- command = "domain-miner-set";
760
- index += 2;
761
- continue;
762
- }
763
- if (action === "clear") {
764
- command = "domain-miner-clear";
765
- index += 2;
766
- continue;
767
- }
768
- throw new Error(`cli_unknown_command_domain_miner${action === null ? "" : `_${action}`}`);
769
- }
770
- if (subcommand === "canonical") {
771
- command = "domain-canonical";
772
- index += 1;
773
- continue;
774
- }
775
- throw new Error(`cli_unknown_command_domain${subcommand === null ? "" : `_${subcommand}`}`);
776
- }
777
- if (token === "cog") {
778
- const subcommand = argv[index + 1] ?? null;
779
- if (subcommand === "send") {
780
- command = "cog-send";
781
- index += 1;
782
- continue;
783
- }
784
- if (subcommand === "claim") {
785
- command = "cog-claim";
786
- index += 1;
787
- continue;
788
- }
789
- if (subcommand === "reclaim") {
790
- command = "cog-reclaim";
791
- index += 1;
792
- continue;
793
- }
794
- if (subcommand === "lock") {
795
- command = "cog-lock";
796
- index += 1;
797
- continue;
798
- }
799
- if (subcommand === "balance") {
800
- command = "cog-balance";
801
- index += 1;
802
- continue;
803
- }
804
- if (subcommand === "locks") {
805
- command = "cog-locks";
806
- index += 1;
807
- continue;
808
- }
809
- throw new Error(`cli_unknown_command_cog${subcommand === null ? "" : `_${subcommand}`}`);
810
- }
811
- if (token === "rep") {
812
- const subcommand = argv[index + 1] ?? null;
813
- if (subcommand === "give") {
814
- command = "rep-give";
815
- index += 1;
816
- continue;
817
- }
818
- if (subcommand === "revoke") {
819
- command = "rep-revoke";
820
- index += 1;
821
- continue;
822
- }
823
- throw new Error(`cli_unknown_command_rep${subcommand === null ? "" : `_${subcommand}`}`);
824
- }
825
- if (token === "field") {
826
- const subcommand = argv[index + 1] ?? null;
827
- if (subcommand === "list") {
828
- command = "field-list";
829
- index += 1;
830
- continue;
831
- }
832
- if (subcommand === "show") {
833
- command = "field-show";
834
- index += 1;
835
- continue;
836
- }
837
- if (subcommand === "create") {
838
- command = "field-create";
839
- index += 1;
840
- continue;
841
- }
842
- if (subcommand === "set") {
843
- command = "field-set";
844
- index += 1;
845
- continue;
846
- }
847
- if (subcommand === "clear") {
848
- command = "field-clear";
849
- index += 1;
850
- continue;
851
- }
852
- command = "field";
853
- continue;
854
- }
855
- if (token === "init"
856
- || token === "restore"
857
- || token === "reset"
858
- || token === "repair"
859
- || token === "update"
860
- || token === "sync"
861
- || token === "status"
862
- || token === "follow"
863
- || token === "anchor"
864
- || token === "register"
865
- || token === "transfer"
866
- || token === "sell"
867
- || token === "unsell"
868
- || token === "buy"
869
- || token === "send"
870
- || token === "claim"
871
- || token === "reclaim"
872
- || token === "address"
873
- || token === "ids"
874
- || token === "balance"
875
- || token === "locks"
876
- || token === "domains"
877
- || token === "show"
878
- || token === "fields") {
879
- if (token === "anchor" && argv[index + 1] === "clear") {
880
- throw new Error("cli_anchor_clear_removed");
881
- }
882
- command = token;
883
- continue;
884
- }
885
- throw new Error(`cli_unknown_command_${token}`);
261
+ command = match.command;
262
+ commandFamily = getCommandHandlerFamily(match.command);
263
+ invokedCommandTokens = [...match.invokedTokens];
264
+ invokedCommandPath = match.invokedTokens.join(" ");
265
+ index += match.consumedTokens - 1;
266
+ continue;
886
267
  }
887
268
  args.push(token);
888
269
  }
@@ -895,11 +276,7 @@ export function parseCliArgs(argv) {
895
276
  || command === "indexer-stop"
896
277
  || command === "indexer-status"
897
278
  || command === "init"
898
- || command === "restore"
899
279
  || command === "reset"
900
- || command === "wallet-init"
901
- || command === "wallet-delete"
902
- || command === "wallet-restore"
903
280
  || command === "wallet-status"
904
281
  || command === "repair"
905
282
  || command === "sync"
@@ -911,25 +288,18 @@ export function parseCliArgs(argv) {
911
288
  || command === "mine-prompt-list"
912
289
  || command === "mine-status"
913
290
  || command === "mine-log"
914
- || command === "wallet-address"
915
- || command === "wallet-ids"
916
291
  || command === "address"
917
292
  || command === "ids"
918
293
  || command === "balance"
919
- || command === "cog-balance"
920
294
  || command === "locks"
921
- || command === "cog-locks"
922
- || command === "domain-list"
923
295
  || command === "domains")
924
296
  && args.length !== 0) {
925
297
  throw new Error(`cli_unexpected_argument_${args[0]}`);
926
298
  }
927
- if ((command === "register" || command === "domain-register") && args.length !== 1) {
299
+ if (command === "register" && args.length !== 1) {
928
300
  throw new Error("cli_missing_domain_argument");
929
301
  }
930
- if ((command === "anchor"
931
- || command === "domain-anchor")
932
- && args.length !== 1) {
302
+ if (command === "anchor" && args.length !== 1) {
933
303
  throw new Error("cli_missing_domain_argument");
934
304
  }
935
305
  if (command === "mine-prompt" && args.length !== 1) {
@@ -949,53 +319,44 @@ export function parseCliArgs(argv) {
949
319
  if (command === "domain-miner-set" && args.length !== 2) {
950
320
  throw new Error("cli_missing_miner_arguments");
951
321
  }
952
- if ((command === "transfer" || command === "domain-transfer") && args.length !== 1) {
322
+ if (command === "transfer" && args.length !== 1) {
953
323
  throw new Error("cli_missing_domain_argument");
954
324
  }
955
- if ((command === "sell" || command === "domain-sell") && args.length !== 2) {
325
+ if (command === "sell" && args.length !== 2) {
956
326
  throw new Error("cli_missing_sell_arguments");
957
327
  }
958
- if ((command === "unsell" || command === "domain-unsell" || command === "buy" || command === "domain-buy") && args.length !== 1) {
328
+ if ((command === "unsell" || command === "buy") && args.length !== 1) {
959
329
  throw new Error("cli_missing_domain_argument");
960
330
  }
961
- if ((command === "send" || command === "cog-send" || command === "cog-lock" || command === "bitcoin-transfer") && args.length !== 1) {
331
+ if ((command === "send" || command === "cog-lock" || command === "bitcoin-transfer") && args.length !== 1) {
962
332
  throw new Error("cli_missing_amount_argument");
963
333
  }
964
- if ((command === "claim" || command === "cog-claim" || command === "reclaim" || command === "cog-reclaim") && args.length !== 1) {
334
+ if ((command === "claim" || command === "reclaim") && args.length !== 1) {
965
335
  throw new Error("cli_missing_lock_argument");
966
336
  }
967
337
  if ((command === "rep-give" || command === "rep-revoke") && args.length !== 3) {
968
338
  throw new Error("cli_missing_reputation_arguments");
969
339
  }
970
- if ((command === "show" || command === "domain-show" || command === "fields") && args.length !== 1) {
340
+ if ((command === "show" || command === "fields") && args.length !== 1) {
971
341
  throw new Error(command === "show" ? "cli_missing_domain_argument" : "cli_missing_domain_argument");
972
342
  }
973
- if (command === "field-list" && args.length !== 1) {
974
- throw new Error("cli_missing_domain_argument");
975
- }
976
- if ((command === "field" || command === "field-show" || command === "field-create" || command === "field-set" || command === "field-clear") && args.length !== 2) {
343
+ if ((command === "field" || command === "field-create" || command === "field-set" || command === "field-clear") && args.length !== 2) {
977
344
  throw new Error("cli_missing_field_arguments");
978
345
  }
979
346
  if (unlockFor !== null
980
347
  && command !== "cog-lock") {
981
348
  throw new Error("cli_unlock_duration_not_supported_for_command");
982
349
  }
983
- if (assumeYes && !supportsYesFlag(command)) {
350
+ if (assumeYes && !commandSupportsYesFlag(command)) {
984
351
  throw new Error("cli_yes_not_supported_for_command");
985
352
  }
986
- if (seedName !== null && !supportsSeedFlag(command)) {
987
- throw new Error("cli_seed_not_supported_for_command");
988
- }
989
- if (requiresSeedFlag(command) && seedName === null) {
990
- throw new Error("cli_missing_seed_name");
991
- }
992
- if (forceRace && command !== "register" && command !== "domain-register") {
353
+ if (forceRace && command !== "register") {
993
354
  throw new Error("cli_force_race_not_supported_for_command");
994
355
  }
995
356
  if (force) {
996
357
  throw new Error("cli_force_not_supported_for_command");
997
358
  }
998
- if (anchorMessage !== null && command !== "anchor" && command !== "domain-anchor") {
359
+ if (anchorMessage !== null && command !== "anchor") {
999
360
  throw new Error("cli_message_not_supported_for_command");
1000
361
  }
1001
362
  const namedPayloadFlagCount = Number(endpointText !== null) + Number(endpointJson !== null) + Number(endpointBytes !== null);
@@ -1033,20 +394,16 @@ export function parseCliArgs(argv) {
1033
394
  if (command === "field-set" && namedPayloadFlagCount === 0 && !hasRawPayloadFlags) {
1034
395
  throw new Error("cli_field_set_requires_value");
1035
396
  }
1036
- if ((command === "field-clear" || command === "field" || command === "field-show" || command === "field-list")
397
+ if ((command === "field-clear" || command === "field" || command === "fields")
1037
398
  && (namedPayloadFlagCount > 0 || hasRawPayloadFlags || fieldPermanent)) {
1038
399
  throw new Error("cli_field_flags_not_supported_for_command");
1039
400
  }
1040
- if (transferTarget !== null && command !== "transfer" && command !== "domain-transfer") {
1041
- if (command !== "send" && command !== "cog-send" && command !== "bitcoin-transfer") {
401
+ if (transferTarget !== null && command !== "transfer") {
402
+ if (command !== "send" && command !== "bitcoin-transfer") {
1042
403
  throw new Error("cli_to_not_supported_for_command");
1043
404
  }
1044
405
  }
1045
- if ((command === "transfer"
1046
- || command === "domain-transfer"
1047
- || command === "send"
1048
- || command === "cog-send"
1049
- || command === "bitcoin-transfer")
406
+ if ((command === "transfer" || command === "send" || command === "bitcoin-transfer")
1050
407
  && transferTarget === null) {
1051
408
  throw new Error("cli_missing_transfer_target");
1052
409
  }
@@ -1059,37 +416,31 @@ export function parseCliArgs(argv) {
1059
416
  if (untilHeight !== null && command !== "cog-lock") {
1060
417
  throw new Error("cli_until_height_not_supported_for_command");
1061
418
  }
1062
- if (preimageHex !== null && command !== "claim" && command !== "cog-claim") {
419
+ if (preimageHex !== null && command !== "claim") {
1063
420
  throw new Error("cli_preimage_not_supported_for_command");
1064
421
  }
1065
422
  if (reviewText !== null && command !== "rep-give" && command !== "rep-revoke") {
1066
423
  throw new Error("cli_review_not_supported_for_command");
1067
424
  }
1068
- if (satvb !== null && !isWalletMutationCommand(command)) {
425
+ if (satvb !== null && !commandSupportsSatvb(command)) {
1069
426
  throw new Error("cli_satvb_not_supported_for_command");
1070
427
  }
1071
428
  if ((locksClaimableOnly || locksReclaimableOnly)
1072
- && command !== "locks"
1073
- && command !== "cog-locks") {
429
+ && command !== "locks") {
1074
430
  throw new Error("cli_lock_filters_not_supported_for_command");
1075
431
  }
1076
432
  if (locksClaimableOnly && locksReclaimableOnly) {
1077
433
  throw new Error("cli_conflicting_lock_filters");
1078
434
  }
1079
435
  if ((domainsAnchoredOnly || domainsListedOnly || domainsMineableOnly)
1080
- && command !== "domain-list"
1081
436
  && command !== "domains") {
1082
437
  throw new Error("cli_domain_filters_not_supported_for_command");
1083
438
  }
1084
439
  if ((listLimit !== null || listAll)
1085
440
  && command !== "locks"
1086
- && command !== "cog-locks"
1087
- && command !== "wallet-ids"
1088
441
  && command !== "ids"
1089
- && command !== "domain-list"
1090
442
  && command !== "domains"
1091
443
  && command !== "fields"
1092
- && command !== "field-list"
1093
444
  && command !== "mine-log") {
1094
445
  throw new Error("cli_lock_filters_not_supported_for_command");
1095
446
  }
@@ -1099,18 +450,9 @@ export function parseCliArgs(argv) {
1099
450
  if (follow && command !== "mine-log") {
1100
451
  throw new Error("cli_follow_not_supported_for_command");
1101
452
  }
1102
- if (command === "mine-log" && follow && outputMode !== "text") {
1103
- throw new Error("cli_follow_json_not_supported");
1104
- }
1105
453
  if (command === "mine-log" && follow && (listAll || listLimit !== null)) {
1106
454
  throw new Error("cli_follow_limit_not_supported");
1107
455
  }
1108
- if (outputMode === "json" && !isJsonOutputSupportedCommand(command)) {
1109
- throw new Error("cli_output_not_supported_for_command");
1110
- }
1111
- if (outputMode === "preview-json" && !isPreviewJsonOutputSupportedCommand(command)) {
1112
- throw new Error("cli_output_not_supported_for_command");
1113
- }
1114
456
  if (command === "cog-lock") {
1115
457
  if (lockRecipientDomain === null) {
1116
458
  throw new Error("cli_missing_lock_domain");
@@ -1122,19 +464,20 @@ export function parseCliArgs(argv) {
1122
464
  throw new Error("cli_lock_timeout_requires_exactly_one_mode");
1123
465
  }
1124
466
  }
1125
- if ((command === "claim" || command === "cog-claim") && preimageHex === null) {
467
+ if (command === "claim" && preimageHex === null) {
1126
468
  throw new Error("cli_missing_claim_preimage");
1127
469
  }
1128
470
  return {
1129
471
  command,
472
+ commandFamily,
473
+ invokedCommandTokens,
474
+ invokedCommandPath,
1130
475
  args,
1131
476
  help,
1132
477
  version,
1133
- outputMode,
1134
478
  dbPath,
1135
479
  dataDir,
1136
480
  progressOutput,
1137
- seedName,
1138
481
  unlockFor,
1139
482
  assumeYes,
1140
483
  force,