@cogcoin/client 0.5.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/LICENSE +21 -0
- package/README.md +136 -0
- package/dist/app-paths.d.ts +38 -0
- package/dist/app-paths.js +121 -0
- package/dist/art/banner.txt +13 -0
- package/dist/art/scroll.txt +13 -0
- package/dist/art/train-car.txt +6 -0
- package/dist/art/train-smoke.txt +6 -0
- package/dist/art/train.txt +6 -0
- package/dist/bitcoind/bootstrap/chainstate.d.ts +4 -0
- package/dist/bitcoind/bootstrap/chainstate.js +13 -0
- package/dist/bitcoind/bootstrap/constants.d.ts +7 -0
- package/dist/bitcoind/bootstrap/constants.js +12 -0
- package/dist/bitcoind/bootstrap/controller.d.ts +29 -0
- package/dist/bitcoind/bootstrap/controller.js +101 -0
- package/dist/bitcoind/bootstrap/download.d.ts +2 -0
- package/dist/bitcoind/bootstrap/download.js +196 -0
- package/dist/bitcoind/bootstrap/headers.d.ts +13 -0
- package/dist/bitcoind/bootstrap/headers.js +61 -0
- package/dist/bitcoind/bootstrap/paths.d.ts +4 -0
- package/dist/bitcoind/bootstrap/paths.js +15 -0
- package/dist/bitcoind/bootstrap/snapshot-file.d.ts +7 -0
- package/dist/bitcoind/bootstrap/snapshot-file.js +42 -0
- package/dist/bitcoind/bootstrap/state.d.ts +40 -0
- package/dist/bitcoind/bootstrap/state.js +70 -0
- package/dist/bitcoind/bootstrap/types.d.ts +28 -0
- package/dist/bitcoind/bootstrap/types.js +1 -0
- package/dist/bitcoind/bootstrap.d.ts +8 -0
- package/dist/bitcoind/bootstrap.js +7 -0
- package/dist/bitcoind/client/factory.d.ts +3 -0
- package/dist/bitcoind/client/factory.js +57 -0
- package/dist/bitcoind/client/follow-block-times.d.ts +8 -0
- package/dist/bitcoind/client/follow-block-times.js +25 -0
- package/dist/bitcoind/client/follow-loop.d.ts +10 -0
- package/dist/bitcoind/client/follow-loop.js +57 -0
- package/dist/bitcoind/client/internal-types.d.ts +63 -0
- package/dist/bitcoind/client/internal-types.js +18 -0
- package/dist/bitcoind/client/managed-client.d.ts +20 -0
- package/dist/bitcoind/client/managed-client.js +197 -0
- package/dist/bitcoind/client/rate-tracker.d.ts +2 -0
- package/dist/bitcoind/client/rate-tracker.js +24 -0
- package/dist/bitcoind/client/sync-engine.d.ts +3 -0
- package/dist/bitcoind/client/sync-engine.js +143 -0
- package/dist/bitcoind/client.d.ts +1 -0
- package/dist/bitcoind/client.js +1 -0
- package/dist/bitcoind/errors.d.ts +1 -0
- package/dist/bitcoind/errors.js +49 -0
- package/dist/bitcoind/index.d.ts +2 -0
- package/dist/bitcoind/index.js +1 -0
- package/dist/bitcoind/indexer-daemon-main.d.ts +1 -0
- package/dist/bitcoind/indexer-daemon-main.js +472 -0
- package/dist/bitcoind/indexer-daemon.d.ts +107 -0
- package/dist/bitcoind/indexer-daemon.js +391 -0
- package/dist/bitcoind/node.d.ts +8 -0
- package/dist/bitcoind/node.js +219 -0
- package/dist/bitcoind/normalize.d.ts +3 -0
- package/dist/bitcoind/normalize.js +47 -0
- package/dist/bitcoind/progress/assets.d.ts +10 -0
- package/dist/bitcoind/progress/assets.js +90 -0
- package/dist/bitcoind/progress/constants.d.ts +48 -0
- package/dist/bitcoind/progress/constants.js +53 -0
- package/dist/bitcoind/progress/controller.d.ts +28 -0
- package/dist/bitcoind/progress/controller.js +188 -0
- package/dist/bitcoind/progress/follow-scene.d.ts +40 -0
- package/dist/bitcoind/progress/follow-scene.js +367 -0
- package/dist/bitcoind/progress/formatting.d.ts +23 -0
- package/dist/bitcoind/progress/formatting.js +227 -0
- package/dist/bitcoind/progress/quote-scene.d.ts +4 -0
- package/dist/bitcoind/progress/quote-scene.js +137 -0
- package/dist/bitcoind/progress/train-scene.d.ts +9 -0
- package/dist/bitcoind/progress/train-scene.js +92 -0
- package/dist/bitcoind/progress/tty-renderer.d.ts +18 -0
- package/dist/bitcoind/progress/tty-renderer.js +150 -0
- package/dist/bitcoind/progress.d.ts +7 -0
- package/dist/bitcoind/progress.js +7 -0
- package/dist/bitcoind/quotes.d.ts +24 -0
- package/dist/bitcoind/quotes.js +195 -0
- package/dist/bitcoind/rpc.d.ts +71 -0
- package/dist/bitcoind/rpc.js +322 -0
- package/dist/bitcoind/service-paths.d.ts +19 -0
- package/dist/bitcoind/service-paths.js +49 -0
- package/dist/bitcoind/service.d.ts +40 -0
- package/dist/bitcoind/service.js +735 -0
- package/dist/bitcoind/testing.d.ts +9 -0
- package/dist/bitcoind/testing.js +9 -0
- package/dist/bitcoind/types.d.ts +396 -0
- package/dist/bitcoind/types.js +3 -0
- package/dist/bytes.d.ts +9 -0
- package/dist/bytes.js +36 -0
- package/dist/cli/commands/follow.d.ts +2 -0
- package/dist/cli/commands/follow.js +43 -0
- package/dist/cli/commands/mining-admin.d.ts +2 -0
- package/dist/cli/commands/mining-admin.js +92 -0
- package/dist/cli/commands/mining-read.d.ts +2 -0
- package/dist/cli/commands/mining-read.js +173 -0
- package/dist/cli/commands/mining-runtime.d.ts +2 -0
- package/dist/cli/commands/mining-runtime.js +108 -0
- package/dist/cli/commands/status.d.ts +2 -0
- package/dist/cli/commands/status.js +31 -0
- package/dist/cli/commands/sync.d.ts +2 -0
- package/dist/cli/commands/sync.js +52 -0
- package/dist/cli/commands/wallet-admin.d.ts +2 -0
- package/dist/cli/commands/wallet-admin.js +175 -0
- package/dist/cli/commands/wallet-mutation.d.ts +2 -0
- package/dist/cli/commands/wallet-mutation.js +681 -0
- package/dist/cli/commands/wallet-read.d.ts +2 -0
- package/dist/cli/commands/wallet-read.js +265 -0
- package/dist/cli/context.d.ts +3 -0
- package/dist/cli/context.js +75 -0
- package/dist/cli/io.d.ts +3 -0
- package/dist/cli/io.js +12 -0
- package/dist/cli/mining-format.d.ts +5 -0
- package/dist/cli/mining-format.js +156 -0
- package/dist/cli/mining-json.d.ts +49 -0
- package/dist/cli/mining-json.js +89 -0
- package/dist/cli/mutation-command-groups.d.ts +15 -0
- package/dist/cli/mutation-command-groups.js +71 -0
- package/dist/cli/mutation-json.d.ts +430 -0
- package/dist/cli/mutation-json.js +311 -0
- package/dist/cli/mutation-resolved-json.d.ts +124 -0
- package/dist/cli/mutation-resolved-json.js +129 -0
- package/dist/cli/mutation-success.d.ts +20 -0
- package/dist/cli/mutation-success.js +47 -0
- package/dist/cli/mutation-text-format.d.ts +22 -0
- package/dist/cli/mutation-text-format.js +171 -0
- package/dist/cli/mutation-text-write.d.ts +13 -0
- package/dist/cli/mutation-text-write.js +16 -0
- package/dist/cli/output.d.ts +185 -0
- package/dist/cli/output.js +1085 -0
- package/dist/cli/parse.d.ts +3 -0
- package/dist/cli/parse.js +971 -0
- package/dist/cli/preview-json.d.ts +416 -0
- package/dist/cli/preview-json.js +293 -0
- package/dist/cli/prompt.d.ts +3 -0
- package/dist/cli/prompt.js +33 -0
- package/dist/cli/read-json.d.ts +187 -0
- package/dist/cli/read-json.js +675 -0
- package/dist/cli/runner.d.ts +2 -0
- package/dist/cli/runner.js +129 -0
- package/dist/cli/signals.d.ts +3 -0
- package/dist/cli/signals.js +63 -0
- package/dist/cli/status-format.d.ts +2 -0
- package/dist/cli/status-format.js +48 -0
- package/dist/cli/types.d.ts +148 -0
- package/dist/cli/types.js +2 -0
- package/dist/cli/wallet-format.d.ts +29 -0
- package/dist/cli/wallet-format.js +637 -0
- package/dist/cli/workflow-hints.d.ts +13 -0
- package/dist/cli/workflow-hints.js +94 -0
- package/dist/cli-runner.d.ts +3 -0
- package/dist/cli-runner.js +3 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +6 -0
- package/dist/client/default-client.d.ts +11 -0
- package/dist/client/default-client.js +118 -0
- package/dist/client/factory.d.ts +2 -0
- package/dist/client/factory.js +15 -0
- package/dist/client/initialization.d.ts +6 -0
- package/dist/client/initialization.js +30 -0
- package/dist/client/persistence.d.ts +5 -0
- package/dist/client/persistence.js +28 -0
- package/dist/client/store-adapter.d.ts +3 -0
- package/dist/client/store-adapter.js +20 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.js +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/passive-status.d.ts +36 -0
- package/dist/passive-status.js +100 -0
- package/dist/sqlite/better-sqlite3.d.ts +26 -0
- package/dist/sqlite/better-sqlite3.js +4 -0
- package/dist/sqlite/checkpoints.d.ts +11 -0
- package/dist/sqlite/checkpoints.js +27 -0
- package/dist/sqlite/driver.d.ts +17 -0
- package/dist/sqlite/driver.js +98 -0
- package/dist/sqlite/index.d.ts +4 -0
- package/dist/sqlite/index.js +9 -0
- package/dist/sqlite/migrate.d.ts +2 -0
- package/dist/sqlite/migrate.js +37 -0
- package/dist/sqlite/store.d.ts +3 -0
- package/dist/sqlite/store.js +122 -0
- package/dist/sqlite/tip-meta.d.ts +26 -0
- package/dist/sqlite/tip-meta.js +97 -0
- package/dist/sqlite/types.d.ts +10 -0
- package/dist/sqlite/types.js +1 -0
- package/dist/types.d.ts +55 -0
- package/dist/types.js +1 -0
- package/dist/wallet/archive.d.ts +4 -0
- package/dist/wallet/archive.js +39 -0
- package/dist/wallet/cogop/constants.d.ts +32 -0
- package/dist/wallet/cogop/constants.js +32 -0
- package/dist/wallet/cogop/index.d.ts +32 -0
- package/dist/wallet/cogop/index.js +213 -0
- package/dist/wallet/cogop/numeric.d.ts +3 -0
- package/dist/wallet/cogop/numeric.js +24 -0
- package/dist/wallet/cogop/scriptpubkey.d.ts +2 -0
- package/dist/wallet/cogop/scriptpubkey.js +13 -0
- package/dist/wallet/cogop/validate-name.d.ts +2 -0
- package/dist/wallet/cogop/validate-name.js +18 -0
- package/dist/wallet/fs/atomic.d.ts +6 -0
- package/dist/wallet/fs/atomic.js +46 -0
- package/dist/wallet/fs/lock.d.ts +19 -0
- package/dist/wallet/fs/lock.js +61 -0
- package/dist/wallet/fs/status-file.d.ts +1 -0
- package/dist/wallet/fs/status-file.js +4 -0
- package/dist/wallet/lifecycle.d.ts +193 -0
- package/dist/wallet/lifecycle.js +1475 -0
- package/dist/wallet/material.d.ts +45 -0
- package/dist/wallet/material.js +118 -0
- package/dist/wallet/mining/config.d.ts +18 -0
- package/dist/wallet/mining/config.js +44 -0
- package/dist/wallet/mining/constants.d.ts +24 -0
- package/dist/wallet/mining/constants.js +24 -0
- package/dist/wallet/mining/control.d.ts +53 -0
- package/dist/wallet/mining/control.js +758 -0
- package/dist/wallet/mining/coordination.d.ts +40 -0
- package/dist/wallet/mining/coordination.js +121 -0
- package/dist/wallet/mining/hook-protocol.d.ts +47 -0
- package/dist/wallet/mining/hook-protocol.js +161 -0
- package/dist/wallet/mining/hook-runner.d.ts +1 -0
- package/dist/wallet/mining/hook-runner.js +52 -0
- package/dist/wallet/mining/hooks.d.ts +38 -0
- package/dist/wallet/mining/hooks.js +520 -0
- package/dist/wallet/mining/index.d.ts +8 -0
- package/dist/wallet/mining/index.js +6 -0
- package/dist/wallet/mining/runner.d.ts +155 -0
- package/dist/wallet/mining/runner.js +2574 -0
- package/dist/wallet/mining/runtime-artifacts.d.ts +17 -0
- package/dist/wallet/mining/runtime-artifacts.js +166 -0
- package/dist/wallet/mining/sentences.d.ts +23 -0
- package/dist/wallet/mining/sentences.js +281 -0
- package/dist/wallet/mining/state.d.ts +9 -0
- package/dist/wallet/mining/state.js +75 -0
- package/dist/wallet/mining/types.d.ts +141 -0
- package/dist/wallet/mining/types.js +1 -0
- package/dist/wallet/mining/visualizer.d.ts +19 -0
- package/dist/wallet/mining/visualizer.js +134 -0
- package/dist/wallet/mining/worker-main.d.ts +1 -0
- package/dist/wallet/mining/worker-main.js +17 -0
- package/dist/wallet/read/context.d.ts +20 -0
- package/dist/wallet/read/context.js +532 -0
- package/dist/wallet/read/filter.d.ts +9 -0
- package/dist/wallet/read/filter.js +42 -0
- package/dist/wallet/read/index.d.ts +4 -0
- package/dist/wallet/read/index.js +3 -0
- package/dist/wallet/read/project.d.ts +11 -0
- package/dist/wallet/read/project.js +300 -0
- package/dist/wallet/read/types.d.ts +144 -0
- package/dist/wallet/read/types.js +1 -0
- package/dist/wallet/runtime.d.ts +26 -0
- package/dist/wallet/runtime.js +28 -0
- package/dist/wallet/state/crypto.d.ts +31 -0
- package/dist/wallet/state/crypto.js +127 -0
- package/dist/wallet/state/provider.d.ts +37 -0
- package/dist/wallet/state/provider.js +312 -0
- package/dist/wallet/state/session.d.ts +12 -0
- package/dist/wallet/state/session.js +23 -0
- package/dist/wallet/state/storage.d.ts +19 -0
- package/dist/wallet/state/storage.js +55 -0
- package/dist/wallet/tx/anchor.d.ts +40 -0
- package/dist/wallet/tx/anchor.js +1210 -0
- package/dist/wallet/tx/cog.d.ts +92 -0
- package/dist/wallet/tx/cog.js +1055 -0
- package/dist/wallet/tx/common.d.ts +89 -0
- package/dist/wallet/tx/common.js +156 -0
- package/dist/wallet/tx/confirm.d.ts +15 -0
- package/dist/wallet/tx/confirm.js +24 -0
- package/dist/wallet/tx/domain-admin.d.ts +105 -0
- package/dist/wallet/tx/domain-admin.js +869 -0
- package/dist/wallet/tx/domain-market.d.ts +112 -0
- package/dist/wallet/tx/domain-market.js +1365 -0
- package/dist/wallet/tx/field.d.ts +101 -0
- package/dist/wallet/tx/field.js +1853 -0
- package/dist/wallet/tx/identity-selector.d.ts +12 -0
- package/dist/wallet/tx/identity-selector.js +52 -0
- package/dist/wallet/tx/index.d.ts +7 -0
- package/dist/wallet/tx/index.js +7 -0
- package/dist/wallet/tx/journal.d.ts +5 -0
- package/dist/wallet/tx/journal.js +31 -0
- package/dist/wallet/tx/register.d.ts +68 -0
- package/dist/wallet/tx/register.js +952 -0
- package/dist/wallet/tx/reputation.d.ts +72 -0
- package/dist/wallet/tx/reputation.js +693 -0
- package/dist/wallet/tx/targets.d.ts +7 -0
- package/dist/wallet/tx/targets.js +122 -0
- package/dist/wallet/types.d.ts +249 -0
- package/dist/wallet/types.js +1 -0
- package/dist/writing_quotes.json +1654 -0
- package/package.json +78 -0
|
@@ -0,0 +1,1085 @@
|
|
|
1
|
+
export function writeJsonValue(stream, value) {
|
|
2
|
+
stream.write(`${JSON.stringify(value, jsonReplacer)}\n`);
|
|
3
|
+
}
|
|
4
|
+
export function isStructuredOutputMode(mode) {
|
|
5
|
+
return mode === "json" || mode === "preview-json";
|
|
6
|
+
}
|
|
7
|
+
function jsonReplacer(_key, value) {
|
|
8
|
+
return typeof value === "bigint" ? value.toString() : value;
|
|
9
|
+
}
|
|
10
|
+
export function createSuccessEnvelope(schema, command, data, options = {}) {
|
|
11
|
+
return {
|
|
12
|
+
schema,
|
|
13
|
+
ok: true,
|
|
14
|
+
command,
|
|
15
|
+
generatedAtUnixMs: options.generatedAtUnixMs ?? Date.now(),
|
|
16
|
+
warnings: options.warnings ?? [],
|
|
17
|
+
explanations: options.explanations ?? [],
|
|
18
|
+
nextSteps: options.nextSteps ?? [],
|
|
19
|
+
data,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function createErrorEnvelope(schema, command, errorCode, message, options = {}) {
|
|
23
|
+
return {
|
|
24
|
+
schema,
|
|
25
|
+
ok: false,
|
|
26
|
+
command,
|
|
27
|
+
generatedAtUnixMs: options.generatedAtUnixMs ?? Date.now(),
|
|
28
|
+
warnings: options.warnings ?? [],
|
|
29
|
+
explanations: options.explanations ?? [],
|
|
30
|
+
nextSteps: options.nextSteps ?? [],
|
|
31
|
+
error: {
|
|
32
|
+
code: errorCode,
|
|
33
|
+
message,
|
|
34
|
+
details: options.details ?? {},
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export function createPreviewSuccessEnvelope(schema, command, outcome, data, options = {}) {
|
|
39
|
+
return {
|
|
40
|
+
schema,
|
|
41
|
+
ok: true,
|
|
42
|
+
command,
|
|
43
|
+
generatedAtUnixMs: options.generatedAtUnixMs ?? Date.now(),
|
|
44
|
+
outcome,
|
|
45
|
+
warnings: options.warnings ?? [],
|
|
46
|
+
explanations: options.explanations ?? [],
|
|
47
|
+
nextSteps: options.nextSteps ?? [],
|
|
48
|
+
data,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export function createMutationSuccessEnvelope(schema, command, outcome, data, options = {}) {
|
|
52
|
+
return {
|
|
53
|
+
schema,
|
|
54
|
+
ok: true,
|
|
55
|
+
command,
|
|
56
|
+
generatedAtUnixMs: options.generatedAtUnixMs ?? Date.now(),
|
|
57
|
+
outcome,
|
|
58
|
+
warnings: options.warnings ?? [],
|
|
59
|
+
explanations: options.explanations ?? [],
|
|
60
|
+
nextSteps: options.nextSteps ?? [],
|
|
61
|
+
data,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export function createPreviewErrorEnvelope(schema, command, errorCode, message, options = {}) {
|
|
65
|
+
return {
|
|
66
|
+
schema,
|
|
67
|
+
ok: false,
|
|
68
|
+
command,
|
|
69
|
+
generatedAtUnixMs: options.generatedAtUnixMs ?? Date.now(),
|
|
70
|
+
outcome: options.outcome ?? "failed",
|
|
71
|
+
warnings: options.warnings ?? [],
|
|
72
|
+
explanations: options.explanations ?? [],
|
|
73
|
+
nextSteps: options.nextSteps ?? [],
|
|
74
|
+
error: {
|
|
75
|
+
code: errorCode,
|
|
76
|
+
message,
|
|
77
|
+
details: options.details ?? {},
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export function createMutationErrorEnvelope(schema, command, errorCode, message, options = {}) {
|
|
82
|
+
return {
|
|
83
|
+
schema,
|
|
84
|
+
ok: false,
|
|
85
|
+
command,
|
|
86
|
+
generatedAtUnixMs: options.generatedAtUnixMs ?? Date.now(),
|
|
87
|
+
outcome: options.outcome ?? "failed",
|
|
88
|
+
warnings: options.warnings ?? [],
|
|
89
|
+
explanations: options.explanations ?? [],
|
|
90
|
+
nextSteps: options.nextSteps ?? [],
|
|
91
|
+
error: {
|
|
92
|
+
code: errorCode,
|
|
93
|
+
message,
|
|
94
|
+
details: options.details ?? {},
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export function normalizeListPage(items, options) {
|
|
99
|
+
const totalKnown = items.length;
|
|
100
|
+
const appliedLimit = options.all ? null : (options.limit ?? options.defaultLimit);
|
|
101
|
+
const pagedItems = appliedLimit === null ? [...items] : items.slice(0, appliedLimit);
|
|
102
|
+
const truncated = appliedLimit !== null && totalKnown > appliedLimit;
|
|
103
|
+
return {
|
|
104
|
+
items: pagedItems,
|
|
105
|
+
page: {
|
|
106
|
+
limit: appliedLimit,
|
|
107
|
+
returned: pagedItems.length,
|
|
108
|
+
truncated,
|
|
109
|
+
moreAvailable: truncated,
|
|
110
|
+
totalKnown,
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
export function createTruncationNote(page) {
|
|
115
|
+
if (!page.truncated || page.limit === null || page.totalKnown === null) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
return `Showing first ${page.returned} of ${page.totalKnown}. Use --limit <n> or --all for more.`;
|
|
119
|
+
}
|
|
120
|
+
export function classifyCliError(error) {
|
|
121
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
122
|
+
if (message.startsWith("cli_")) {
|
|
123
|
+
return { exitCode: 2, errorCode: message, message };
|
|
124
|
+
}
|
|
125
|
+
if (/^wallet_init_confirmation_failed_word_\d+$/.test(message)) {
|
|
126
|
+
return { exitCode: 2, errorCode: message, message };
|
|
127
|
+
}
|
|
128
|
+
if (message === "mining_hooks_enable_trust_acknowledgement_required") {
|
|
129
|
+
return { exitCode: 2, errorCode: message, message };
|
|
130
|
+
}
|
|
131
|
+
if (message === "mining_setup_invalid_provider"
|
|
132
|
+
|| message === "mining_setup_missing_api_key") {
|
|
133
|
+
return { exitCode: 2, errorCode: message, message };
|
|
134
|
+
}
|
|
135
|
+
if (message.startsWith("mining_hooks_enable_template_created:")) {
|
|
136
|
+
return {
|
|
137
|
+
exitCode: 4,
|
|
138
|
+
errorCode: "mining_hooks_enable_template_created",
|
|
139
|
+
message,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
if (message.startsWith("mining_hooks_enable_validation_failed:")) {
|
|
143
|
+
return {
|
|
144
|
+
exitCode: 5,
|
|
145
|
+
errorCode: "mining_hooks_enable_validation_failed",
|
|
146
|
+
message,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
if (message.endsWith("_typed_ack_required")) {
|
|
150
|
+
return { exitCode: 2, errorCode: message, message };
|
|
151
|
+
}
|
|
152
|
+
if (message === "wallet_typed_confirmation_rejected"
|
|
153
|
+
|| message === "wallet_export_overwrite_declined"
|
|
154
|
+
|| message === "wallet_prompt_value_required"
|
|
155
|
+
|| message === "wallet_archive_passphrase_mismatch") {
|
|
156
|
+
return { exitCode: 2, errorCode: message, message };
|
|
157
|
+
}
|
|
158
|
+
if (message === "not_found") {
|
|
159
|
+
return { exitCode: 3, errorCode: "not_found", message: "Requested object not found." };
|
|
160
|
+
}
|
|
161
|
+
if (message === "wallet_import_archive_not_found") {
|
|
162
|
+
return { exitCode: 3, errorCode: message, message };
|
|
163
|
+
}
|
|
164
|
+
if (isBlockedError(message)) {
|
|
165
|
+
return { exitCode: 4, errorCode: message, message };
|
|
166
|
+
}
|
|
167
|
+
return { exitCode: 5, errorCode: message, message };
|
|
168
|
+
}
|
|
169
|
+
function isBlockedError(message) {
|
|
170
|
+
if (message === "wallet_locked"
|
|
171
|
+
|| message === "wallet_uninitialized"
|
|
172
|
+
|| message === "local-state-corrupt"
|
|
173
|
+
|| message === "wallet_already_initialized"
|
|
174
|
+
|| message === "wallet_export_core_replica_not_ready"
|
|
175
|
+
|| message === "wallet_export_tip_mismatch"
|
|
176
|
+
|| message === "wallet_export_requires_quiescent_local_state"
|
|
177
|
+
|| message === "wallet_repair_indexer_reset_requires_yes"
|
|
178
|
+
|| message === "managed_bitcoind_service_version_mismatch"
|
|
179
|
+
|| message === "managed_bitcoind_wallet_root_mismatch"
|
|
180
|
+
|| message === "managed_bitcoind_runtime_mismatch"
|
|
181
|
+
|| message === "indexer_daemon_service_version_mismatch"
|
|
182
|
+
|| message === "indexer_daemon_wallet_root_mismatch"
|
|
183
|
+
|| message === "indexer_daemon_schema_mismatch"
|
|
184
|
+
|| message === "mine_setup_requires_tty"
|
|
185
|
+
|| message === "mining_hooks_enable_requires_tty"
|
|
186
|
+
|| message === "mining_preemption_timeout"
|
|
187
|
+
|| message === "wallet_secret_provider_linux_secret_tool_missing"
|
|
188
|
+
|| message === "wallet_secret_provider_linux_secret_service_unavailable"
|
|
189
|
+
|| message === "wallet_secret_provider_linux_runtime_error") {
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
return /(?:^|_)(?:locked|uninitialized|repair_required|requires_tty|typed_ack_required|confirmation_rejected|tip_mismatch|core_replica_not_ready|setup|no_eligible_sender|ambiguous_sender|insufficient|stale|paused|validation|catching_up|starting|unavailable|schema_mismatch|service_version_mismatch|wallet_root_mismatch|runtime_mismatch|replica_missing|replica_mismatch|failed)(?:_|$)/.test(message)
|
|
193
|
+
|| /repair-required/.test(message);
|
|
194
|
+
}
|
|
195
|
+
export function formatCliTextError(error) {
|
|
196
|
+
const classified = classifyCliError(error);
|
|
197
|
+
const presentation = createCliErrorPresentation(classified.errorCode, classified.message);
|
|
198
|
+
if (presentation === null) {
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
const lines = [`What happened: ${presentation.what}`];
|
|
202
|
+
if (presentation.why !== null) {
|
|
203
|
+
lines.push(`Why: ${presentation.why}`);
|
|
204
|
+
}
|
|
205
|
+
if (presentation.next !== null) {
|
|
206
|
+
lines.push(`Next: ${presentation.next}`);
|
|
207
|
+
}
|
|
208
|
+
return lines;
|
|
209
|
+
}
|
|
210
|
+
export function createCliErrorPresentation(errorCode, fallbackMessage) {
|
|
211
|
+
if (errorCode === "wallet_locked") {
|
|
212
|
+
return {
|
|
213
|
+
what: "Wallet is locked.",
|
|
214
|
+
why: "This command needs access to the unlocked local wallet state before it can continue.",
|
|
215
|
+
next: "Run `cogcoin unlock --for 15m` and retry.",
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
if (errorCode === "wallet_uninitialized") {
|
|
219
|
+
return {
|
|
220
|
+
what: "Wallet is not initialized.",
|
|
221
|
+
why: "There is no local wallet root yet for this command to use.",
|
|
222
|
+
next: "Run `cogcoin init` first.",
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
if (errorCode === "wallet_already_initialized") {
|
|
226
|
+
return {
|
|
227
|
+
what: "Wallet is already initialized.",
|
|
228
|
+
why: "This machine already has a local wallet root, so initialization cannot safely create a second one in the same runtime location.",
|
|
229
|
+
next: "Run `cogcoin status` to inspect the existing wallet, or export/import it instead of reinitializing.",
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
if (errorCode === "local-state-corrupt" || errorCode.includes("repair_required") || errorCode.includes("repair-required")) {
|
|
233
|
+
return {
|
|
234
|
+
what: "Local recovery is required.",
|
|
235
|
+
why: "The wallet detected unresolved or untrusted local state for this operation.",
|
|
236
|
+
next: "Run `cogcoin repair`, then retry the command.",
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
if (errorCode.endsWith("_typed_ack_required")) {
|
|
240
|
+
return {
|
|
241
|
+
what: "Typed acknowledgement is still required.",
|
|
242
|
+
why: "`--yes` only bypasses plain yes/no confirmation. This path requires the exact typed acknowledgement because it is higher risk or irreversible.",
|
|
243
|
+
next: "Rerun the command in an interactive terminal and type the requested acknowledgement.",
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
if (errorCode === "wallet_typed_confirmation_rejected") {
|
|
247
|
+
return {
|
|
248
|
+
what: "Typed acknowledgement was declined.",
|
|
249
|
+
why: "This secure admin command requires the exact typed acknowledgement before it will continue.",
|
|
250
|
+
next: "Rerun the command in an interactive terminal and type the requested acknowledgement.",
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
if (errorCode === "wallet_export_overwrite_declined") {
|
|
254
|
+
return {
|
|
255
|
+
what: "Archive overwrite was declined.",
|
|
256
|
+
why: "The export path already exists, and the command will not replace that archive unless you explicitly approve it.",
|
|
257
|
+
next: "Rerun the command and type `yes` when prompted if you want to overwrite the archive.",
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
if (/^wallet_init_confirmation_failed_word_\d+$/.test(errorCode)) {
|
|
261
|
+
return {
|
|
262
|
+
what: "Mnemonic confirmation failed.",
|
|
263
|
+
why: "The requested recovery-phrase confirmation word did not match, so wallet initialization was canceled before it could finish.",
|
|
264
|
+
next: "Run `cogcoin init` again and re-enter the requested confirmation words carefully.",
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
if (errorCode === "mining_hooks_enable_trust_acknowledgement_required") {
|
|
268
|
+
return {
|
|
269
|
+
what: "Trust acknowledgement is still required.",
|
|
270
|
+
why: "Enabling a custom mining hook grants unsandboxed local JavaScript full access to the current OS account and readable local data.",
|
|
271
|
+
next: "Rerun `cogcoin hooks enable mining` in an interactive terminal and type the requested trust acknowledgement.",
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
if (errorCode === "mining_hooks_enable_template_created") {
|
|
275
|
+
return {
|
|
276
|
+
what: "Default mining hook template was created.",
|
|
277
|
+
why: "The wallet wrote starter custom-hook files and stopped before enabling custom mode so you can review and edit them first.",
|
|
278
|
+
next: "Edit `generate-sentences.js`, then rerun `cogcoin hooks enable mining`.",
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
if (errorCode === "mining_hooks_enable_validation_failed") {
|
|
282
|
+
return {
|
|
283
|
+
what: "Custom mining hook validation failed.",
|
|
284
|
+
why: "The hook files, package shape, trust checks, or isolated validation run did not pass the required checks.",
|
|
285
|
+
next: "Fix the custom mining hook and rerun `cogcoin hooks enable mining`.",
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
if (errorCode === "mining_setup_invalid_provider") {
|
|
289
|
+
return {
|
|
290
|
+
what: "Mining provider choice is invalid.",
|
|
291
|
+
why: "Built-in mining setup currently supports only `openai` or `anthropic` as the provider selection.",
|
|
292
|
+
next: "Rerun `cogcoin mine setup` and choose either `openai` or `anthropic`.",
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
if (errorCode === "mining_setup_missing_api_key") {
|
|
296
|
+
return {
|
|
297
|
+
what: "Mining provider API key is required.",
|
|
298
|
+
why: "Built-in mining setup cannot save provider configuration without a non-empty API key.",
|
|
299
|
+
next: "Rerun `cogcoin mine setup` and enter the provider API key when prompted.",
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
if (errorCode.endsWith("_confirmation_rejected")) {
|
|
303
|
+
return {
|
|
304
|
+
what: "Confirmation was declined.",
|
|
305
|
+
why: "The command requires explicit approval before it will publish a state-changing action.",
|
|
306
|
+
next: "Rerun the command and confirm it. If this command uses a plain yes/no path, you can also add `--yes`.",
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
if (errorCode === "wallet_prompt_value_required") {
|
|
310
|
+
return {
|
|
311
|
+
what: "Required input was not provided.",
|
|
312
|
+
why: "This secure admin command needs a non-empty terminal response before it can continue safely.",
|
|
313
|
+
next: "Rerun the command in an interactive terminal and enter the requested value.",
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
if (errorCode === "wallet_archive_passphrase_mismatch") {
|
|
317
|
+
return {
|
|
318
|
+
what: "Archive passphrases did not match.",
|
|
319
|
+
why: "The archive passphrase must be entered the same way twice so the wallet does not seal the archive with a typo.",
|
|
320
|
+
next: "Rerun the command and enter the same archive passphrase both times.",
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
if (errorCode === "wallet_secret_provider_linux_secret_tool_missing") {
|
|
324
|
+
return {
|
|
325
|
+
what: "Linux secret-store support (`secret-tool`) is not installed.",
|
|
326
|
+
why: "Cogcoin uses `secret-tool` to talk to Secret Service on Linux, but that helper is not available in this environment.",
|
|
327
|
+
next: "Install `secret-tool`/libsecret for this machine, then rerun the command.",
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
if (errorCode === "wallet_secret_provider_linux_secret_service_unavailable") {
|
|
331
|
+
return {
|
|
332
|
+
what: "Linux Secret Service is unavailable or locked.",
|
|
333
|
+
why: "The local Secret Service session could not be reached for wallet-secret storage, so the wallet cannot read or write its encryption keys.",
|
|
334
|
+
next: "Start or unlock your desktop keyring/Secret Service session, then rerun the command.",
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
if (errorCode === "wallet_secret_provider_linux_runtime_error") {
|
|
338
|
+
return {
|
|
339
|
+
what: "Linux secret-store operation failed.",
|
|
340
|
+
why: "`secret-tool` ran but did not complete a usable wallet-secret operation for this command.",
|
|
341
|
+
next: "Check that Secret Service is running correctly on this machine, then retry.",
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
if (errorCode.endsWith("_requires_tty")) {
|
|
345
|
+
return {
|
|
346
|
+
what: "Interactive terminal input is required.",
|
|
347
|
+
why: "This command needs terminal input before it can continue safely.",
|
|
348
|
+
next: "Rerun the command in an interactive terminal.",
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
if (errorCode === "wallet_import_archive_not_found") {
|
|
352
|
+
return {
|
|
353
|
+
what: "Wallet archive was not found.",
|
|
354
|
+
why: "The specified import archive path does not exist or is not readable from this machine.",
|
|
355
|
+
next: "Check the archive path and retry.",
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
if (errorCode === "wallet_export_requires_quiescent_local_state") {
|
|
359
|
+
return {
|
|
360
|
+
what: "Wallet export is blocked until local state is quiescent.",
|
|
361
|
+
why: "Portable export waits for mining, proactive families, and pending mutations to settle so the archive reflects trustworthy local state.",
|
|
362
|
+
next: "Wait for active local work to finish or repair it, then retry the export.",
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
if (errorCode.includes("tip_mismatch") || errorCode.includes("stale") || errorCode.includes("catching_up") || errorCode.includes("starting")) {
|
|
366
|
+
return {
|
|
367
|
+
what: "Trusted service state is not ready.",
|
|
368
|
+
why: "The wallet, bitcoind, or indexer is not yet aligned closely enough for this command to proceed safely.",
|
|
369
|
+
next: "Check `cogcoin status`, wait for services to settle, and retry. If the state stays degraded, run `cogcoin repair`.",
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
if (errorCode === "indexer_daemon_service_version_mismatch") {
|
|
373
|
+
return {
|
|
374
|
+
what: "The live indexer daemon is running an incompatible service API version.",
|
|
375
|
+
why: "This wallet only trusts indexer daemons that speak `cogcoin/indexer-ipc/v1`, and the reachable daemon reported a different API version.",
|
|
376
|
+
next: "Run `cogcoin repair` so the wallet can stop the incompatible daemon and restart a compatible managed indexer service.",
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
if (errorCode === "indexer_daemon_wallet_root_mismatch") {
|
|
380
|
+
return {
|
|
381
|
+
what: "The live indexer daemon belongs to a different wallet root.",
|
|
382
|
+
why: "Managed indexer daemons are namespaced per wallet root, and the reachable daemon reported a different wallet root than this local wallet.",
|
|
383
|
+
next: "Run `cogcoin repair` so the wallet can stop the conflicting managed daemon and restore the correct local indexer service.",
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
if (errorCode === "indexer_daemon_schema_mismatch") {
|
|
387
|
+
return {
|
|
388
|
+
what: "The live indexer daemon is using an incompatible sqlite schema.",
|
|
389
|
+
why: "This wallet only trusts indexer daemons with the expected sqlite schema contract, and the reachable daemon reported a schema mismatch.",
|
|
390
|
+
next: "Run `cogcoin repair` after stopping the incompatible daemon, then retry.",
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
if (errorCode === "indexer_daemon_protocol_error") {
|
|
394
|
+
return {
|
|
395
|
+
what: "The live indexer daemon socket is not speaking the expected protocol.",
|
|
396
|
+
why: "A process is bound to the managed indexer socket, but it did not respond with a valid cogcoin indexer IPC status exchange.",
|
|
397
|
+
next: "Run `cogcoin repair` to clear stale managed indexer artifacts and restore a compatible daemon.",
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
if (errorCode === "managed_bitcoind_service_version_mismatch" || errorCode.includes("bitcoind_service_version_mismatch")) {
|
|
401
|
+
return {
|
|
402
|
+
what: "The live managed bitcoind service is running an incompatible service version.",
|
|
403
|
+
why: "This wallet only trusts managed bitcoind services that speak `cogcoin/bitcoind-service/v1`, and the reachable service reported a different runtime contract.",
|
|
404
|
+
next: "Run `cogcoin repair` so the wallet can stop the incompatible managed bitcoind service and restart a compatible one.",
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
if (errorCode === "managed_bitcoind_wallet_root_mismatch" || errorCode.includes("bitcoind_wallet_root_mismatch")) {
|
|
408
|
+
return {
|
|
409
|
+
what: "The live managed bitcoind service belongs to a different wallet root.",
|
|
410
|
+
why: "Managed bitcoind services are tied to one wallet root, and the reachable service reported a different wallet root than this local wallet expects.",
|
|
411
|
+
next: "Run `cogcoin repair` so the wallet can stop the conflicting managed bitcoind service and restore the correct one.",
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
if (errorCode === "managed_bitcoind_runtime_mismatch" || errorCode.includes("bitcoind_runtime_mismatch")) {
|
|
415
|
+
return {
|
|
416
|
+
what: "The live managed bitcoind service runtime does not match this wallet.",
|
|
417
|
+
why: "The reachable service is using a different chain, data directory, or runtime root than this wallet expects, so its status cannot be trusted here.",
|
|
418
|
+
next: "Run `cogcoin repair` so the wallet can clear the conflicting runtime and restart a compatible managed bitcoind service.",
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
if (errorCode.includes("bitcoind_replica_missing")) {
|
|
422
|
+
return {
|
|
423
|
+
what: "The managed Core wallet replica is missing.",
|
|
424
|
+
why: "This wallet needs a matching managed Core descriptor-wallet replica before it can safely perform stateful operations.",
|
|
425
|
+
next: "Run `cogcoin repair` to recreate the managed Core wallet replica, then retry.",
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
if (errorCode.includes("bitcoind_replica_mismatch")) {
|
|
429
|
+
return {
|
|
430
|
+
what: "The managed Core wallet replica does not match trusted wallet state.",
|
|
431
|
+
why: "The local wallet state and the managed Core replica disagree, so this command refuses to keep going on untrusted Core metadata.",
|
|
432
|
+
next: "Run `cogcoin repair` to recreate or rebind the managed Core wallet replica, then retry.",
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
if (errorCode === "mining_preemption_timeout") {
|
|
436
|
+
return {
|
|
437
|
+
what: "Wallet repair is blocked by active mining work.",
|
|
438
|
+
why: "Repair waits for mining generation work to acknowledge preemption before it mutates local indexer runtime artifacts.",
|
|
439
|
+
next: "Pause or stop mining, then rerun `cogcoin repair`.",
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
if (errorCode.includes("paused")) {
|
|
443
|
+
return {
|
|
444
|
+
what: "Work is currently paused.",
|
|
445
|
+
why: "Another wallet or mining workflow has priority right now.",
|
|
446
|
+
next: "Wait for the current work to settle, then rerun the command.",
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
if (errorCode.includes("setup") || errorCode.includes("validation") || errorCode.includes("core_replica_not_ready")) {
|
|
450
|
+
return {
|
|
451
|
+
what: "Local setup is incomplete.",
|
|
452
|
+
why: "This command depends on a local component that is not ready yet.",
|
|
453
|
+
next: "Review the local status output, finish the required setup or repair step, and retry.",
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
if (errorCode.includes("insufficient")) {
|
|
457
|
+
return {
|
|
458
|
+
what: "Available funds are insufficient.",
|
|
459
|
+
why: "The selected wallet identity does not currently have enough spendable funds for this operation.",
|
|
460
|
+
next: "Choose a different identity or add more funds, then retry.",
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
if (errorCode === "wallet_register_from_not_supported_for_subdomain") {
|
|
464
|
+
return {
|
|
465
|
+
what: "`--from` is not supported for subdomain registration.",
|
|
466
|
+
why: "Subdomain registration always derives the sender from the anchored parent owner, so this command will not accept an explicit sender override.",
|
|
467
|
+
next: "Retry without `--from`, or register a root domain if you need explicit sender selection.",
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
if (errorCode === "wallet_register_sender_not_root_eligible") {
|
|
471
|
+
return {
|
|
472
|
+
what: "Selected sender is not eligible for root registration.",
|
|
473
|
+
why: "Root registration can use funding identity `0` or a locally controlled anchored owner identity with a current canonical anchor outpoint.",
|
|
474
|
+
next: "Run `cogcoin ids`, then retry with `--from id:0` or an anchored local owner selector.",
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
if (errorCode === "wallet_register_sender_not_found") {
|
|
478
|
+
return {
|
|
479
|
+
what: "Selected sender was not found locally.",
|
|
480
|
+
why: "The provided selector did not resolve to a locally controlled identity in this wallet.",
|
|
481
|
+
next: "Run `cogcoin ids` and retry with one of the listed selectors.",
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
if (errorCode === "wallet_register_sender_read_only") {
|
|
485
|
+
return {
|
|
486
|
+
what: "Selected sender is read-only.",
|
|
487
|
+
why: "This local identity is tracked for visibility only and cannot author new owner transactions.",
|
|
488
|
+
next: "Retry with a locally controlled non-read-only sender.",
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
if (errorCode === "wallet_register_sender_address_unavailable") {
|
|
492
|
+
return {
|
|
493
|
+
what: "Selected sender could not be displayed.",
|
|
494
|
+
why: "The selector resolved to a local identity, but the wallet does not have a usable display address for it.",
|
|
495
|
+
next: "Run `cogcoin ids` and retry with a different local sender selector.",
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
if (errorCode === "wallet_buy_sender_not_found") {
|
|
499
|
+
return {
|
|
500
|
+
what: "Selected buyer was not found locally.",
|
|
501
|
+
why: "The provided `--from` selector did not resolve to a locally controlled identity in this wallet.",
|
|
502
|
+
next: "Run `cogcoin ids` and retry with one of the listed selectors.",
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
if (errorCode === "wallet_buy_sender_read_only") {
|
|
506
|
+
return {
|
|
507
|
+
what: "Selected buyer is read-only.",
|
|
508
|
+
why: "This local identity is tracked for visibility only and cannot author a domain purchase.",
|
|
509
|
+
next: "Retry with a locally controlled non-read-only buyer selector.",
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
if (errorCode === "wallet_buy_sender_address_unavailable") {
|
|
513
|
+
return {
|
|
514
|
+
what: "Selected buyer could not be displayed.",
|
|
515
|
+
why: "The selector resolved to a local identity, but the wallet does not have a usable display address for it.",
|
|
516
|
+
next: "Run `cogcoin ids` and retry with a different local buyer selector.",
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
if (errorCode === "wallet_buy_already_owner") {
|
|
520
|
+
return {
|
|
521
|
+
what: "Selected buyer already owns the domain.",
|
|
522
|
+
why: "A buy mutation must come from a different local identity than the current domain owner.",
|
|
523
|
+
next: "Choose a different buyer with `--from`, or inspect the current owner with `cogcoin show <domain>`.",
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
if (errorCode === "wallet_buy_insufficient_cog_balance") {
|
|
527
|
+
return {
|
|
528
|
+
what: "Selected buyer does not have enough COG.",
|
|
529
|
+
why: "The chosen local identity does not currently have the listed domain price available in spendable COG balance.",
|
|
530
|
+
next: "Choose a different buyer or add more COG to that identity, then retry.",
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
if (errorCode === "wallet_transfer_owner_not_locally_controlled" || errorCode === "wallet_sell_owner_not_locally_controlled") {
|
|
534
|
+
return {
|
|
535
|
+
what: "Domain owner is not locally controlled.",
|
|
536
|
+
why: "This command must be authored by the current unanchored domain owner, and that owner identity is not available in this wallet with a usable address.",
|
|
537
|
+
next: "Inspect the current owner with `cogcoin show <domain>`, then retry from the wallet that controls that owner identity.",
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
if (errorCode === "wallet_transfer_owner_read_only" || errorCode === "wallet_sell_owner_read_only") {
|
|
541
|
+
return {
|
|
542
|
+
what: "Domain owner is read-only.",
|
|
543
|
+
why: "The current domain owner is tracked locally for visibility, but this wallet cannot author owner mutations from a read-only identity.",
|
|
544
|
+
next: "Use the wallet that controls the owner identity, or import the spendable owner into this wallet before retrying.",
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
if (errorCode === "wallet_field_create_owner_not_locally_controlled"
|
|
548
|
+
|| errorCode === "wallet_field_set_owner_not_locally_controlled"
|
|
549
|
+
|| errorCode === "wallet_field_clear_owner_not_locally_controlled") {
|
|
550
|
+
return {
|
|
551
|
+
what: "Anchored field owner is not locally controlled.",
|
|
552
|
+
why: "Field mutations must be authored by the current anchored owner of the domain, and that owner identity is not available in this wallet with a usable address.",
|
|
553
|
+
next: "Inspect the current owner with `cogcoin show <domain>`, then retry from the wallet that controls that anchored owner identity.",
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
if (errorCode === "wallet_field_create_owner_read_only"
|
|
557
|
+
|| errorCode === "wallet_field_set_owner_read_only"
|
|
558
|
+
|| errorCode === "wallet_field_clear_owner_read_only") {
|
|
559
|
+
return {
|
|
560
|
+
what: "Anchored field owner is read-only.",
|
|
561
|
+
why: "The current anchored owner is tracked locally for visibility, but this wallet cannot author field mutations from a read-only identity.",
|
|
562
|
+
next: "Use the wallet that controls the anchored owner identity, or import the spendable owner into this wallet before retrying.",
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
if (errorCode === "wallet_domain_endpoint_owner_not_locally_controlled"
|
|
566
|
+
|| errorCode === "wallet_domain_delegate_owner_not_locally_controlled"
|
|
567
|
+
|| errorCode === "wallet_domain_miner_owner_not_locally_controlled"
|
|
568
|
+
|| errorCode === "wallet_domain_canonical_owner_not_locally_controlled") {
|
|
569
|
+
return {
|
|
570
|
+
what: "Anchored domain owner is not locally controlled.",
|
|
571
|
+
why: "This anchored domain-admin command must be authored by the current anchored owner, and that owner identity is not available in this wallet with a usable address.",
|
|
572
|
+
next: "Inspect the current owner with `cogcoin show <domain>`, then retry from the wallet that controls that anchored owner identity.",
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
if (errorCode === "wallet_domain_endpoint_owner_read_only"
|
|
576
|
+
|| errorCode === "wallet_domain_delegate_owner_read_only"
|
|
577
|
+
|| errorCode === "wallet_domain_miner_owner_read_only"
|
|
578
|
+
|| errorCode === "wallet_domain_canonical_owner_read_only") {
|
|
579
|
+
return {
|
|
580
|
+
what: "Anchored domain owner is read-only.",
|
|
581
|
+
why: "The current anchored owner is tracked locally for visibility, but this wallet cannot author anchored admin mutations from a read-only identity.",
|
|
582
|
+
next: "Use the wallet that controls the anchored owner identity, or import the spendable owner into this wallet before retrying.",
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
if (errorCode === "wallet_rep_give_source_owner_not_locally_controlled"
|
|
586
|
+
|| errorCode === "wallet_rep_revoke_source_owner_not_locally_controlled") {
|
|
587
|
+
return {
|
|
588
|
+
what: "Anchored reputation source owner is not locally controlled.",
|
|
589
|
+
why: "Reputation mutations must be authored by the current anchored owner of the source domain, and that owner identity is not available in this wallet with a usable address.",
|
|
590
|
+
next: "Inspect the current source-domain owner with `cogcoin show <domain>`, then retry from the wallet that controls that anchored owner identity.",
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
if (errorCode === "wallet_rep_give_source_owner_read_only"
|
|
594
|
+
|| errorCode === "wallet_rep_revoke_source_owner_read_only") {
|
|
595
|
+
return {
|
|
596
|
+
what: "Anchored reputation source owner is read-only.",
|
|
597
|
+
why: "The current anchored source-domain owner is tracked locally for visibility, but this wallet cannot author reputation mutations from a read-only identity.",
|
|
598
|
+
next: "Use the wallet that controls the anchored source-domain owner identity, or import the spendable owner into this wallet before retrying.",
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
if (errorCode === "wallet_send_sender_address_unavailable" || errorCode === "wallet_lock_sender_address_unavailable") {
|
|
602
|
+
return {
|
|
603
|
+
what: "Selected sender could not be displayed.",
|
|
604
|
+
why: "The wallet resolved a local sender identity, but it does not have a usable display address for that identity.",
|
|
605
|
+
next: "Run `cogcoin ids` and retry with a different local sender selector.",
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
if (errorCode === "wallet_claim_sender_not_local") {
|
|
609
|
+
return {
|
|
610
|
+
what: "The claim sender is not locally controlled.",
|
|
611
|
+
why: "Before timeout, the wallet may only claim as the current recipient-domain owner, and that owner is not available in this wallet.",
|
|
612
|
+
next: "Check the current recipient-domain owner with `cogcoin show <domain>` or use the wallet that controls that owner identity.",
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
if (errorCode === "wallet_reclaim_sender_not_local") {
|
|
616
|
+
return {
|
|
617
|
+
what: "The reclaim sender is not locally controlled.",
|
|
618
|
+
why: "After timeout, the wallet may only reclaim as the original locker, and that locker identity is not available in this wallet.",
|
|
619
|
+
next: "Use the wallet that controls the original locker identity, or inspect the lock details with `cogcoin locks`.",
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
if (errorCode.includes("ambiguous_sender") || errorCode.includes("no_eligible_sender")) {
|
|
623
|
+
return {
|
|
624
|
+
what: "Sender selection could not be resolved.",
|
|
625
|
+
why: "The wallet could not determine one eligible local sender for this command.",
|
|
626
|
+
next: "Inspect `cogcoin ids` and rerun the command with an explicit `--from` selector when supported.",
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
if (classifiedAsBlockedMessage(errorCode)) {
|
|
630
|
+
return {
|
|
631
|
+
what: fallbackMessage,
|
|
632
|
+
why: "The command was blocked by the current local wallet or service state.",
|
|
633
|
+
next: "Review `cogcoin status` and retry after the blocking condition is cleared.",
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
return null;
|
|
637
|
+
}
|
|
638
|
+
function classifiedAsBlockedMessage(errorCode) {
|
|
639
|
+
return isBlockedError(errorCode);
|
|
640
|
+
}
|
|
641
|
+
export function describeCanonicalCommand(parsed) {
|
|
642
|
+
const args = parsed.args;
|
|
643
|
+
switch (parsed.command) {
|
|
644
|
+
case "init":
|
|
645
|
+
case "wallet-init":
|
|
646
|
+
return "cogcoin init";
|
|
647
|
+
case "unlock":
|
|
648
|
+
case "wallet-unlock":
|
|
649
|
+
return "cogcoin unlock";
|
|
650
|
+
case "repair":
|
|
651
|
+
return "cogcoin repair";
|
|
652
|
+
case "wallet-lock":
|
|
653
|
+
return "cogcoin wallet lock";
|
|
654
|
+
case "anchor":
|
|
655
|
+
case "domain-anchor":
|
|
656
|
+
return `cogcoin anchor ${args[0] ?? "<domain>"}`;
|
|
657
|
+
case "register":
|
|
658
|
+
case "domain-register":
|
|
659
|
+
return `cogcoin register ${args[0] ?? "<domain>"}`;
|
|
660
|
+
case "transfer":
|
|
661
|
+
case "domain-transfer":
|
|
662
|
+
return `cogcoin transfer ${args[0] ?? "<domain>"}`;
|
|
663
|
+
case "sell":
|
|
664
|
+
case "domain-sell":
|
|
665
|
+
return `cogcoin sell ${args[0] ?? "<domain>"} ${args[1] ?? "<price>"}`;
|
|
666
|
+
case "unsell":
|
|
667
|
+
case "domain-unsell":
|
|
668
|
+
return `cogcoin unsell ${args[0] ?? "<domain>"}`;
|
|
669
|
+
case "buy":
|
|
670
|
+
case "domain-buy":
|
|
671
|
+
return `cogcoin buy ${args[0] ?? "<domain>"}`;
|
|
672
|
+
case "send":
|
|
673
|
+
case "cog-send":
|
|
674
|
+
return `cogcoin send ${args[0] ?? "<amount>"}`;
|
|
675
|
+
case "claim":
|
|
676
|
+
case "cog-claim":
|
|
677
|
+
return `cogcoin claim ${args[0] ?? "<lock-id>"}`;
|
|
678
|
+
case "reclaim":
|
|
679
|
+
case "cog-reclaim":
|
|
680
|
+
return `cogcoin reclaim ${args[0] ?? "<lock-id>"}`;
|
|
681
|
+
case "cog-lock":
|
|
682
|
+
return `cogcoin cog lock ${args[0] ?? "<amount>"}`;
|
|
683
|
+
case "domain-endpoint-set":
|
|
684
|
+
return `cogcoin domain endpoint set ${args[0] ?? "<domain>"}`;
|
|
685
|
+
case "domain-endpoint-clear":
|
|
686
|
+
return `cogcoin domain endpoint clear ${args[0] ?? "<domain>"}`;
|
|
687
|
+
case "domain-delegate-set":
|
|
688
|
+
return `cogcoin domain delegate set ${args[0] ?? "<domain>"} ${args[1] ?? "<btc-target>"}`;
|
|
689
|
+
case "domain-delegate-clear":
|
|
690
|
+
return `cogcoin domain delegate clear ${args[0] ?? "<domain>"}`;
|
|
691
|
+
case "domain-miner-set":
|
|
692
|
+
return `cogcoin domain miner set ${args[0] ?? "<domain>"} ${args[1] ?? "<btc-target>"}`;
|
|
693
|
+
case "domain-miner-clear":
|
|
694
|
+
return `cogcoin domain miner clear ${args[0] ?? "<domain>"}`;
|
|
695
|
+
case "domain-canonical":
|
|
696
|
+
return `cogcoin domain canonical ${args[0] ?? "<domain>"}`;
|
|
697
|
+
case "field-create":
|
|
698
|
+
return `cogcoin field create ${args[0] ?? "<domain>"} ${args[1] ?? "<field>"}`;
|
|
699
|
+
case "field-set":
|
|
700
|
+
return `cogcoin field set ${args[0] ?? "<domain>"} ${args[1] ?? "<field>"}`;
|
|
701
|
+
case "field-clear":
|
|
702
|
+
return `cogcoin field clear ${args[0] ?? "<domain>"} ${args[1] ?? "<field>"}`;
|
|
703
|
+
case "rep-give":
|
|
704
|
+
return `cogcoin rep give ${args[0] ?? "<source-domain>"} ${args[1] ?? "<target-domain>"} ${args[2] ?? "<amount>"}`;
|
|
705
|
+
case "rep-revoke":
|
|
706
|
+
return `cogcoin rep revoke ${args[0] ?? "<source-domain>"} ${args[1] ?? "<target-domain>"} ${args[2] ?? "<amount>"}`;
|
|
707
|
+
case "wallet-address":
|
|
708
|
+
case "address":
|
|
709
|
+
return "cogcoin address";
|
|
710
|
+
case "wallet-ids":
|
|
711
|
+
case "ids":
|
|
712
|
+
return "cogcoin ids";
|
|
713
|
+
case "wallet-status":
|
|
714
|
+
return "cogcoin wallet status";
|
|
715
|
+
case "hooks-mining-status":
|
|
716
|
+
return `cogcoin hooks status${parsed.verify ? " --verify" : ""}`;
|
|
717
|
+
case "hooks-mining-enable":
|
|
718
|
+
return "cogcoin hooks enable mining";
|
|
719
|
+
case "hooks-mining-disable":
|
|
720
|
+
return "cogcoin hooks disable mining";
|
|
721
|
+
case "mine-setup":
|
|
722
|
+
return "cogcoin mine setup";
|
|
723
|
+
case "mine-start":
|
|
724
|
+
return "cogcoin mine start";
|
|
725
|
+
case "mine-stop":
|
|
726
|
+
return "cogcoin mine stop";
|
|
727
|
+
case "mine-status":
|
|
728
|
+
return "cogcoin mine status";
|
|
729
|
+
case "mine-log":
|
|
730
|
+
return `cogcoin mine log${parsed.follow ? " --follow" : ""}`;
|
|
731
|
+
case "cog-balance":
|
|
732
|
+
case "balance":
|
|
733
|
+
return "cogcoin balance";
|
|
734
|
+
case "cog-locks":
|
|
735
|
+
case "locks":
|
|
736
|
+
return "cogcoin locks";
|
|
737
|
+
case "field-list":
|
|
738
|
+
case "fields":
|
|
739
|
+
return `cogcoin fields ${args[0] ?? "<domain>"}`;
|
|
740
|
+
case "field-show":
|
|
741
|
+
case "field":
|
|
742
|
+
return `cogcoin field ${args[0] ?? "<domain>"} ${args[1] ?? "<field>"}`;
|
|
743
|
+
case "domain-show":
|
|
744
|
+
case "show":
|
|
745
|
+
return `cogcoin show ${args[0] ?? "<domain>"}`;
|
|
746
|
+
case "status":
|
|
747
|
+
return "cogcoin status";
|
|
748
|
+
case "domain-list":
|
|
749
|
+
case "domains":
|
|
750
|
+
return "cogcoin domains";
|
|
751
|
+
default:
|
|
752
|
+
return parsed.command === null ? "cogcoin" : `cogcoin ${parsed.command.replaceAll("-", " ")}`;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
export function inferOutputMode(argv) {
|
|
756
|
+
const index = argv.lastIndexOf("--output");
|
|
757
|
+
if (index === -1) {
|
|
758
|
+
return "text";
|
|
759
|
+
}
|
|
760
|
+
const value = argv[index + 1];
|
|
761
|
+
if (value === "json" || value === "preview-json") {
|
|
762
|
+
return value;
|
|
763
|
+
}
|
|
764
|
+
return "text";
|
|
765
|
+
}
|
|
766
|
+
export function resolveStableJsonSchema(parsed) {
|
|
767
|
+
switch (parsed.command) {
|
|
768
|
+
case "status":
|
|
769
|
+
return "cogcoin/status/v1";
|
|
770
|
+
case "wallet-address":
|
|
771
|
+
case "address":
|
|
772
|
+
return "cogcoin/address/v1";
|
|
773
|
+
case "wallet-ids":
|
|
774
|
+
case "ids":
|
|
775
|
+
return "cogcoin/ids/v1";
|
|
776
|
+
case "wallet-status":
|
|
777
|
+
return "cogcoin/wallet-status/v1";
|
|
778
|
+
case "hooks-mining-status":
|
|
779
|
+
return "cogcoin/hooks-status/v1";
|
|
780
|
+
case "mine-status":
|
|
781
|
+
return "cogcoin/mine-status/v1";
|
|
782
|
+
case "mine-log":
|
|
783
|
+
return "cogcoin/mine-log/v1";
|
|
784
|
+
case "balance":
|
|
785
|
+
case "cog-balance":
|
|
786
|
+
return "cogcoin/balance/v1";
|
|
787
|
+
case "locks":
|
|
788
|
+
case "cog-locks":
|
|
789
|
+
return "cogcoin/locks/v1";
|
|
790
|
+
case "domain-list":
|
|
791
|
+
case "domains":
|
|
792
|
+
return "cogcoin/domains/v1";
|
|
793
|
+
case "domain-show":
|
|
794
|
+
case "show":
|
|
795
|
+
return "cogcoin/show/v1";
|
|
796
|
+
case "fields":
|
|
797
|
+
case "field-list":
|
|
798
|
+
return "cogcoin/fields/v1";
|
|
799
|
+
case "field":
|
|
800
|
+
case "field-show":
|
|
801
|
+
return "cogcoin/field/v1";
|
|
802
|
+
default:
|
|
803
|
+
return null;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
export function resolveStableMutationJsonSchema(parsed) {
|
|
807
|
+
switch (parsed.command) {
|
|
808
|
+
case "init":
|
|
809
|
+
case "wallet-init":
|
|
810
|
+
return "cogcoin/init/v1";
|
|
811
|
+
case "unlock":
|
|
812
|
+
case "wallet-unlock":
|
|
813
|
+
return "cogcoin/unlock/v1";
|
|
814
|
+
case "wallet-export":
|
|
815
|
+
return "cogcoin/wallet-export/v1";
|
|
816
|
+
case "wallet-import":
|
|
817
|
+
return "cogcoin/wallet-import/v1";
|
|
818
|
+
case "wallet-lock":
|
|
819
|
+
return "cogcoin/wallet-lock/v1";
|
|
820
|
+
case "repair":
|
|
821
|
+
return "cogcoin/repair/v1";
|
|
822
|
+
case "anchor":
|
|
823
|
+
case "domain-anchor":
|
|
824
|
+
return "cogcoin/anchor/v1";
|
|
825
|
+
case "register":
|
|
826
|
+
case "domain-register":
|
|
827
|
+
return "cogcoin/register/v1";
|
|
828
|
+
case "transfer":
|
|
829
|
+
case "domain-transfer":
|
|
830
|
+
return "cogcoin/transfer/v1";
|
|
831
|
+
case "sell":
|
|
832
|
+
case "domain-sell":
|
|
833
|
+
return "cogcoin/sell/v1";
|
|
834
|
+
case "unsell":
|
|
835
|
+
case "domain-unsell":
|
|
836
|
+
return "cogcoin/unsell/v1";
|
|
837
|
+
case "buy":
|
|
838
|
+
case "domain-buy":
|
|
839
|
+
return "cogcoin/buy/v1";
|
|
840
|
+
case "send":
|
|
841
|
+
case "cog-send":
|
|
842
|
+
return "cogcoin/send/v1";
|
|
843
|
+
case "claim":
|
|
844
|
+
case "cog-claim":
|
|
845
|
+
return "cogcoin/claim/v1";
|
|
846
|
+
case "reclaim":
|
|
847
|
+
case "cog-reclaim":
|
|
848
|
+
return "cogcoin/reclaim/v1";
|
|
849
|
+
case "cog-lock":
|
|
850
|
+
return "cogcoin/cog-lock/v1";
|
|
851
|
+
case "domain-endpoint-set":
|
|
852
|
+
return "cogcoin/domain-endpoint-set/v1";
|
|
853
|
+
case "domain-endpoint-clear":
|
|
854
|
+
return "cogcoin/domain-endpoint-clear/v1";
|
|
855
|
+
case "domain-delegate-set":
|
|
856
|
+
return "cogcoin/domain-delegate-set/v1";
|
|
857
|
+
case "domain-delegate-clear":
|
|
858
|
+
return "cogcoin/domain-delegate-clear/v1";
|
|
859
|
+
case "domain-miner-set":
|
|
860
|
+
return "cogcoin/domain-miner-set/v1";
|
|
861
|
+
case "domain-miner-clear":
|
|
862
|
+
return "cogcoin/domain-miner-clear/v1";
|
|
863
|
+
case "domain-canonical":
|
|
864
|
+
return "cogcoin/domain-canonical/v1";
|
|
865
|
+
case "field-create":
|
|
866
|
+
return "cogcoin/field-create/v1";
|
|
867
|
+
case "field-set":
|
|
868
|
+
return "cogcoin/field-set/v1";
|
|
869
|
+
case "field-clear":
|
|
870
|
+
return "cogcoin/field-clear/v1";
|
|
871
|
+
case "rep-give":
|
|
872
|
+
return "cogcoin/rep-give/v1";
|
|
873
|
+
case "rep-revoke":
|
|
874
|
+
return "cogcoin/rep-revoke/v1";
|
|
875
|
+
default:
|
|
876
|
+
return null;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
export function resolveStableMiningControlJsonSchema(parsed) {
|
|
880
|
+
switch (parsed.command) {
|
|
881
|
+
case "hooks-mining-enable":
|
|
882
|
+
return "cogcoin/hooks-enable-mining/v1";
|
|
883
|
+
case "hooks-mining-disable":
|
|
884
|
+
return "cogcoin/hooks-disable-mining/v1";
|
|
885
|
+
case "mine-setup":
|
|
886
|
+
return "cogcoin/mine-setup/v1";
|
|
887
|
+
case "mine-start":
|
|
888
|
+
return "cogcoin/mine-start/v1";
|
|
889
|
+
case "mine-stop":
|
|
890
|
+
return "cogcoin/mine-stop/v1";
|
|
891
|
+
default:
|
|
892
|
+
return null;
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
export function resolvePreviewJsonSchema(parsed) {
|
|
896
|
+
const stableMutationSchema = resolveStableMutationJsonSchema(parsed);
|
|
897
|
+
const stableMiningControlSchema = resolveStableMiningControlJsonSchema(parsed);
|
|
898
|
+
switch (parsed.command) {
|
|
899
|
+
case "wallet-lock":
|
|
900
|
+
case "repair":
|
|
901
|
+
case "anchor":
|
|
902
|
+
case "domain-anchor":
|
|
903
|
+
case "register":
|
|
904
|
+
case "domain-register":
|
|
905
|
+
case "transfer":
|
|
906
|
+
case "domain-transfer":
|
|
907
|
+
case "sell":
|
|
908
|
+
case "domain-sell":
|
|
909
|
+
case "unsell":
|
|
910
|
+
case "domain-unsell":
|
|
911
|
+
case "buy":
|
|
912
|
+
case "domain-buy":
|
|
913
|
+
case "send":
|
|
914
|
+
case "cog-send":
|
|
915
|
+
case "claim":
|
|
916
|
+
case "cog-claim":
|
|
917
|
+
case "reclaim":
|
|
918
|
+
case "cog-reclaim":
|
|
919
|
+
case "cog-lock":
|
|
920
|
+
case "domain-endpoint-set":
|
|
921
|
+
case "domain-endpoint-clear":
|
|
922
|
+
case "domain-delegate-set":
|
|
923
|
+
case "domain-delegate-clear":
|
|
924
|
+
case "domain-miner-set":
|
|
925
|
+
case "domain-miner-clear":
|
|
926
|
+
case "domain-canonical":
|
|
927
|
+
case "field-create":
|
|
928
|
+
case "field-set":
|
|
929
|
+
case "field-clear":
|
|
930
|
+
case "rep-give":
|
|
931
|
+
case "rep-revoke":
|
|
932
|
+
return stableMutationSchema === null
|
|
933
|
+
? null
|
|
934
|
+
: stableMutationSchema.replace(/^cogcoin\//, "cogcoin-preview/");
|
|
935
|
+
case "hooks-mining-enable":
|
|
936
|
+
case "hooks-mining-disable":
|
|
937
|
+
case "mine-setup":
|
|
938
|
+
case "mine-start":
|
|
939
|
+
case "mine-stop":
|
|
940
|
+
return stableMiningControlSchema === null
|
|
941
|
+
? null
|
|
942
|
+
: stableMiningControlSchema.replace(/^cogcoin\//, "cogcoin-preview/");
|
|
943
|
+
default:
|
|
944
|
+
return null;
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
function createSchemaProbe(command) {
|
|
948
|
+
return {
|
|
949
|
+
command,
|
|
950
|
+
args: [],
|
|
951
|
+
help: false,
|
|
952
|
+
version: false,
|
|
953
|
+
outputMode: "json",
|
|
954
|
+
dbPath: null,
|
|
955
|
+
dataDir: null,
|
|
956
|
+
progressOutput: "auto",
|
|
957
|
+
unlockFor: null,
|
|
958
|
+
assumeYes: false,
|
|
959
|
+
forceRace: false,
|
|
960
|
+
anchorMessage: null,
|
|
961
|
+
transferTarget: null,
|
|
962
|
+
endpointText: null,
|
|
963
|
+
endpointJson: null,
|
|
964
|
+
endpointBytes: null,
|
|
965
|
+
fieldPermanent: false,
|
|
966
|
+
fieldFormat: null,
|
|
967
|
+
fieldValue: null,
|
|
968
|
+
fromIdentity: null,
|
|
969
|
+
lockRecipientDomain: null,
|
|
970
|
+
conditionHex: null,
|
|
971
|
+
untilHeight: null,
|
|
972
|
+
preimageHex: null,
|
|
973
|
+
reviewText: null,
|
|
974
|
+
locksClaimableOnly: false,
|
|
975
|
+
locksReclaimableOnly: false,
|
|
976
|
+
domainsAnchoredOnly: false,
|
|
977
|
+
domainsListedOnly: false,
|
|
978
|
+
domainsMineableOnly: false,
|
|
979
|
+
listLimit: null,
|
|
980
|
+
listAll: false,
|
|
981
|
+
verify: false,
|
|
982
|
+
follow: false,
|
|
983
|
+
};
|
|
984
|
+
}
|
|
985
|
+
function isStableJsonCommand(command) {
|
|
986
|
+
return resolveStableJsonSchema(createSchemaProbe(command)) !== null;
|
|
987
|
+
}
|
|
988
|
+
function isStableMutationJsonCommand(command) {
|
|
989
|
+
return resolveStableMutationJsonSchema(createSchemaProbe(command)) !== null;
|
|
990
|
+
}
|
|
991
|
+
function isStableMiningControlJsonCommand(command) {
|
|
992
|
+
return resolveStableMiningControlJsonSchema(createSchemaProbe(command)) !== null;
|
|
993
|
+
}
|
|
994
|
+
function isPreviewJsonCommand(command) {
|
|
995
|
+
return resolvePreviewJsonSchema(createSchemaProbe(command)) !== null;
|
|
996
|
+
}
|
|
997
|
+
export function isJsonOutputSupportedCommand(command) {
|
|
998
|
+
return isStableJsonCommand(command)
|
|
999
|
+
|| isStableMutationJsonCommand(command)
|
|
1000
|
+
|| isStableMiningControlJsonCommand(command)
|
|
1001
|
+
|| isPreviewJsonCommand(command);
|
|
1002
|
+
}
|
|
1003
|
+
export function isPreviewJsonOutputSupportedCommand(command) {
|
|
1004
|
+
return isPreviewJsonCommand(command);
|
|
1005
|
+
}
|
|
1006
|
+
export function createCommandJsonErrorEnvelope(parsed, error) {
|
|
1007
|
+
const classified = classifyCliError(error);
|
|
1008
|
+
const presentation = createCliErrorPresentation(classified.errorCode, classified.message);
|
|
1009
|
+
const humanMessage = presentation?.what ?? classified.message;
|
|
1010
|
+
const explanations = presentation?.why === null || presentation?.why === undefined ? [] : [presentation.why];
|
|
1011
|
+
const nextSteps = presentation?.next === null || presentation?.next === undefined ? [] : [presentation.next];
|
|
1012
|
+
const details = createCliErrorDetails(classified.errorCode, humanMessage, classified.message);
|
|
1013
|
+
const stableMutationSchema = resolveStableMutationJsonSchema(parsed);
|
|
1014
|
+
const stableMiningControlSchema = resolveStableMiningControlJsonSchema(parsed);
|
|
1015
|
+
const previewSchema = resolvePreviewJsonSchema(parsed);
|
|
1016
|
+
if (parsed.outputMode === "preview-json" && previewSchema !== null) {
|
|
1017
|
+
return createPreviewErrorEnvelope(previewSchema, describeCanonicalCommand(parsed), classified.errorCode, humanMessage, {
|
|
1018
|
+
explanations,
|
|
1019
|
+
nextSteps,
|
|
1020
|
+
details,
|
|
1021
|
+
});
|
|
1022
|
+
}
|
|
1023
|
+
if (stableMutationSchema !== null) {
|
|
1024
|
+
return createMutationErrorEnvelope(stableMutationSchema, describeCanonicalCommand(parsed), classified.errorCode, humanMessage, {
|
|
1025
|
+
explanations,
|
|
1026
|
+
nextSteps,
|
|
1027
|
+
details,
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
if (stableMiningControlSchema !== null) {
|
|
1031
|
+
return createMutationErrorEnvelope(stableMiningControlSchema, describeCanonicalCommand(parsed), classified.errorCode, humanMessage, {
|
|
1032
|
+
explanations,
|
|
1033
|
+
nextSteps,
|
|
1034
|
+
details,
|
|
1035
|
+
});
|
|
1036
|
+
}
|
|
1037
|
+
if (previewSchema !== null) {
|
|
1038
|
+
return createPreviewErrorEnvelope(previewSchema, describeCanonicalCommand(parsed), classified.errorCode, humanMessage, {
|
|
1039
|
+
explanations,
|
|
1040
|
+
nextSteps,
|
|
1041
|
+
details,
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
1044
|
+
return createErrorEnvelope(resolveStableJsonSchema(parsed) ?? "cogcoin/cli/v1", describeCanonicalCommand(parsed), classified.errorCode, humanMessage, {
|
|
1045
|
+
explanations,
|
|
1046
|
+
nextSteps,
|
|
1047
|
+
details,
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
function createCliErrorDetails(errorCode, humanMessage, rawMessage) {
|
|
1051
|
+
const details = {};
|
|
1052
|
+
const initMatch = /^wallet_init_confirmation_failed_word_(\d+)$/.exec(errorCode);
|
|
1053
|
+
const hooksTemplateMatch = /^mining_hooks_enable_template_created:(.+)$/.exec(rawMessage);
|
|
1054
|
+
const hooksValidationMatch = /^mining_hooks_enable_validation_failed:(.+)$/.exec(rawMessage);
|
|
1055
|
+
if (initMatch !== null) {
|
|
1056
|
+
details.wordIndex = Number.parseInt(initMatch[1], 10);
|
|
1057
|
+
}
|
|
1058
|
+
if (hooksTemplateMatch !== null) {
|
|
1059
|
+
details.hookRootPath = hooksTemplateMatch[1];
|
|
1060
|
+
}
|
|
1061
|
+
if (hooksValidationMatch !== null) {
|
|
1062
|
+
details.validationError = hooksValidationMatch[1];
|
|
1063
|
+
}
|
|
1064
|
+
if (humanMessage !== rawMessage) {
|
|
1065
|
+
details.rawMessage = rawMessage;
|
|
1066
|
+
}
|
|
1067
|
+
return details;
|
|
1068
|
+
}
|
|
1069
|
+
export function writeHandledCliError(options) {
|
|
1070
|
+
const classified = classifyCliError(options.error);
|
|
1071
|
+
if (isStructuredOutputMode(options.parsed.outputMode)) {
|
|
1072
|
+
writeJsonValue(options.stdout, createCommandJsonErrorEnvelope(options.parsed, options.error));
|
|
1073
|
+
return classified.exitCode;
|
|
1074
|
+
}
|
|
1075
|
+
const formatted = formatCliTextError(options.error);
|
|
1076
|
+
if (formatted !== null) {
|
|
1077
|
+
for (const line of formatted) {
|
|
1078
|
+
options.stderr.write(`${line}\n`);
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
else {
|
|
1082
|
+
options.stderr.write(`${classified.message}\n`);
|
|
1083
|
+
}
|
|
1084
|
+
return classified.exitCode;
|
|
1085
|
+
}
|