@cogcoin/client 1.1.4 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -5
- package/dist/bitcoind/progress/tty-renderer.js +3 -2
- package/dist/bitcoind/service.js +1 -1
- package/dist/cli/command-registry.d.ts +39 -0
- package/dist/cli/command-registry.js +1132 -0
- package/dist/cli/commands/client-admin.js +6 -56
- package/dist/cli/commands/mining-admin.js +9 -32
- package/dist/cli/commands/mining-read.js +15 -56
- package/dist/cli/commands/mining-runtime.js +258 -57
- package/dist/cli/commands/service-runtime.js +1 -64
- package/dist/cli/commands/status.js +2 -15
- package/dist/cli/commands/update.js +6 -21
- package/dist/cli/commands/wallet-admin.js +18 -120
- package/dist/cli/commands/wallet-mutation.js +4 -7
- package/dist/cli/commands/wallet-read.js +31 -138
- package/dist/cli/context.js +2 -4
- package/dist/cli/mining-format.js +8 -2
- package/dist/cli/mutation-command-groups.d.ts +11 -11
- package/dist/cli/mutation-command-groups.js +9 -18
- package/dist/cli/mutation-json.d.ts +1 -17
- package/dist/cli/mutation-json.js +1 -28
- package/dist/cli/mutation-success.d.ts +0 -1
- package/dist/cli/mutation-success.js +0 -19
- package/dist/cli/output.d.ts +1 -10
- package/dist/cli/output.js +52 -481
- package/dist/cli/parse.d.ts +1 -1
- package/dist/cli/parse.js +38 -695
- package/dist/cli/runner.js +28 -113
- package/dist/cli/types.d.ts +7 -8
- package/dist/cli/update-notifier.js +1 -1
- package/dist/cli/wallet-format.js +1 -1
- package/dist/wallet/lifecycle/managed-core.d.ts +23 -0
- package/dist/wallet/lifecycle/managed-core.js +257 -0
- package/dist/wallet/lifecycle/repair-mining.d.ts +49 -0
- package/dist/wallet/lifecycle/repair-mining.js +304 -0
- package/dist/wallet/lifecycle/repair-runtime.d.ts +36 -0
- package/dist/wallet/lifecycle/repair-runtime.js +206 -0
- package/dist/wallet/lifecycle/repair.d.ts +11 -0
- package/dist/wallet/lifecycle/repair.js +368 -0
- package/dist/wallet/lifecycle/setup.d.ts +16 -0
- package/dist/wallet/lifecycle/setup.js +430 -0
- package/dist/wallet/lifecycle/types.d.ts +125 -0
- package/dist/wallet/lifecycle/types.js +1 -0
- package/dist/wallet/lifecycle.d.ts +4 -165
- package/dist/wallet/lifecycle.js +3 -1656
- package/dist/wallet/mining/candidate.d.ts +60 -0
- package/dist/wallet/mining/candidate.js +290 -0
- package/dist/wallet/mining/competitiveness.d.ts +22 -0
- package/dist/wallet/mining/competitiveness.js +640 -0
- package/dist/wallet/mining/control.js +7 -251
- package/dist/wallet/mining/cycle.d.ts +39 -0
- package/dist/wallet/mining/cycle.js +542 -0
- package/dist/wallet/mining/engine-state.d.ts +66 -0
- package/dist/wallet/mining/engine-state.js +211 -0
- package/dist/wallet/mining/engine-types.d.ts +173 -0
- package/dist/wallet/mining/engine-types.js +1 -0
- package/dist/wallet/mining/engine-utils.d.ts +7 -0
- package/dist/wallet/mining/engine-utils.js +75 -0
- package/dist/wallet/mining/events.d.ts +2 -0
- package/dist/wallet/mining/events.js +19 -0
- package/dist/wallet/mining/lifecycle.d.ts +71 -0
- package/dist/wallet/mining/lifecycle.js +355 -0
- package/dist/wallet/mining/projection.d.ts +61 -0
- package/dist/wallet/mining/projection.js +319 -0
- package/dist/wallet/mining/publish.d.ts +79 -0
- package/dist/wallet/mining/publish.js +614 -0
- package/dist/wallet/mining/runner.d.ts +12 -418
- package/dist/wallet/mining/runner.js +274 -3433
- package/dist/wallet/mining/supervisor.d.ts +134 -0
- package/dist/wallet/mining/supervisor.js +558 -0
- package/dist/wallet/mining/visualizer-sync.d.ts +42 -0
- package/dist/wallet/mining/visualizer-sync.js +166 -0
- package/dist/wallet/mining/visualizer.d.ts +1 -0
- package/dist/wallet/mining/visualizer.js +33 -18
- package/dist/wallet/reset.d.ts +1 -1
- package/dist/wallet/reset.js +35 -11
- package/dist/wallet/runtime.d.ts +0 -6
- package/dist/wallet/runtime.js +2 -38
- package/dist/wallet/tx/common.d.ts +18 -0
- package/dist/wallet/tx/common.js +40 -26
- package/package.json +1 -1
- package/dist/wallet/state/seed-index.d.ts +0 -43
- package/dist/wallet/state/seed-index.js +0 -151
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import { buildInitMutationData, buildResetMutationData, buildRestoreMutationData, buildWalletDeleteMutationData, buildRepairMutationData, } from "../mutation-json.js";
|
|
2
|
-
import { buildResetPreviewData, buildRepairPreviewData, } from "../preview-json.js";
|
|
3
1
|
import { writeLine } from "../io.js";
|
|
4
|
-
import {
|
|
5
|
-
import { createPreviewSuccessEnvelope, createMutationSuccessEnvelope, describeCanonicalCommand, resolvePreviewJsonSchema, resolveStableMutationJsonSchema, writeHandledCliError, writeJsonValue, } from "../output.js";
|
|
2
|
+
import { writeHandledCliError } from "../output.js";
|
|
6
3
|
import { loadWelcomeArtText } from "../art.js";
|
|
7
|
-
import { formatNextStepLines, getFundingQuickstartGuidance, getInitNextSteps,
|
|
4
|
+
import { formatNextStepLines, getFundingQuickstartGuidance, getInitNextSteps, getSetupUnlockGuidanceLines, } from "../workflow-hints.js";
|
|
8
5
|
import { createOwnedLockCleanupSignalWatcher, waitForCompletionOrStop, } from "../signals.js";
|
|
9
6
|
import { runSyncCommand } from "./sync.js";
|
|
10
7
|
import { CLIENT_PASSWORD_SETUP_AUTO_UNLOCK_SECONDS } from "../../wallet/state/client-password.js";
|
|
11
8
|
import { withInteractiveWalletSecretProvider } from "../../wallet/state/provider.js";
|
|
12
|
-
function createCommandPrompter(
|
|
13
|
-
return
|
|
14
|
-
? createTerminalPrompter(context.stdin, context.stderr)
|
|
15
|
-
: context.createPrompter();
|
|
9
|
+
function createCommandPrompter(context) {
|
|
10
|
+
return context.createPrompter();
|
|
16
11
|
}
|
|
17
12
|
function getRepairWarnings(result) {
|
|
18
13
|
return result.miningResumeAction === "resume-failed"
|
|
@@ -38,13 +33,10 @@ function assertInitTextPreflight(options) {
|
|
|
38
33
|
if (!options.prompter.isInteractive) {
|
|
39
34
|
throw new Error("wallet_init_requires_tty");
|
|
40
35
|
}
|
|
41
|
-
if (options.runtimePaths.selectedSeedName !== "main") {
|
|
42
|
-
throw new Error("wallet_init_seed_not_supported");
|
|
43
|
-
}
|
|
44
36
|
}
|
|
45
37
|
function getResetNextSteps(result) {
|
|
46
38
|
return result.walletAction === "deleted" || result.walletAction === "not-present"
|
|
47
|
-
? ["Run `cogcoin init` to create a
|
|
39
|
+
? ["Run `cogcoin init` to create or restore a wallet."]
|
|
48
40
|
: ["Run `cogcoin sync` to bootstrap assumeutxo and the managed Bitcoin/indexer state."];
|
|
49
41
|
}
|
|
50
42
|
function getRepairNextSteps() {
|
|
@@ -168,7 +160,7 @@ function formatRepairResultText(result) {
|
|
|
168
160
|
return parts.join("\n\n");
|
|
169
161
|
}
|
|
170
162
|
export async function runWalletAdminCommand(parsed, context) {
|
|
171
|
-
const runtimePaths = context.resolveWalletRuntimePaths(
|
|
163
|
+
const runtimePaths = context.resolveWalletRuntimePaths();
|
|
172
164
|
const stopWatcher = createOwnedLockCleanupSignalWatcher(context.signalSource, context.forceExit, [
|
|
173
165
|
runtimePaths.walletControlLockPath,
|
|
174
166
|
runtimePaths.miningControlLockPath,
|
|
@@ -179,16 +171,13 @@ export async function runWalletAdminCommand(parsed, context) {
|
|
|
179
171
|
try {
|
|
180
172
|
const outcome = await waitForCompletionOrStop((async () => {
|
|
181
173
|
const provider = context.walletSecretProvider;
|
|
182
|
-
if (parsed.command === "init"
|
|
174
|
+
if (parsed.command === "init") {
|
|
183
175
|
const dataDir = parsed.dataDir ?? context.resolveDefaultBitcoindDataDir();
|
|
184
|
-
const prompter = createCommandPrompter(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
});
|
|
190
|
-
writeWelcomeArtBlock(context.stdout);
|
|
191
|
-
}
|
|
176
|
+
const prompter = createCommandPrompter(context);
|
|
177
|
+
assertInitTextPreflight({
|
|
178
|
+
prompter,
|
|
179
|
+
});
|
|
180
|
+
writeWelcomeArtBlock(context.stdout);
|
|
192
181
|
const interactiveProvider = withInteractiveWalletSecretProvider(provider, prompter);
|
|
193
182
|
const result = await context.initializeWallet({
|
|
194
183
|
dataDir,
|
|
@@ -196,18 +185,12 @@ export async function runWalletAdminCommand(parsed, context) {
|
|
|
196
185
|
prompter,
|
|
197
186
|
paths: runtimePaths,
|
|
198
187
|
});
|
|
199
|
-
const nextSteps = getInitNextSteps();
|
|
200
|
-
if (parsed.outputMode === "json") {
|
|
201
|
-
writeJsonValue(context.stdout, createMutationSuccessEnvelope(resolveStableMutationJsonSchema(parsed), describeCanonicalCommand(parsed), "initialized", buildInitMutationData(result), {
|
|
202
|
-
explanations: [getFundingQuickstartGuidance()],
|
|
203
|
-
nextSteps,
|
|
204
|
-
}));
|
|
205
|
-
return 0;
|
|
206
|
-
}
|
|
207
188
|
writeWelcomeArtBlock(context.stdout);
|
|
208
189
|
writeLine(context.stdout, result.walletAction === "already-initialized"
|
|
209
190
|
? "Wallet already initialized."
|
|
210
|
-
:
|
|
191
|
+
: result.setupMode === "restored"
|
|
192
|
+
? "Wallet restored."
|
|
193
|
+
: "Wallet initialized.");
|
|
211
194
|
if (result.walletAction === "already-initialized") {
|
|
212
195
|
writeLine(context.stdout, "");
|
|
213
196
|
writeLine(context.stdout, "Wallet");
|
|
@@ -231,62 +214,8 @@ export async function runWalletAdminCommand(parsed, context) {
|
|
|
231
214
|
shouldAutoSyncAfterInit = true;
|
|
232
215
|
return 0;
|
|
233
216
|
}
|
|
234
|
-
if (parsed.command === "restore" || parsed.command === "wallet-restore") {
|
|
235
|
-
const dataDir = parsed.dataDir ?? context.resolveDefaultBitcoindDataDir();
|
|
236
|
-
const prompter = createCommandPrompter(parsed, context);
|
|
237
|
-
const interactiveProvider = withInteractiveWalletSecretProvider(provider, prompter);
|
|
238
|
-
const result = await context.restoreWalletFromMnemonic({
|
|
239
|
-
dataDir,
|
|
240
|
-
provider: interactiveProvider,
|
|
241
|
-
prompter,
|
|
242
|
-
paths: runtimePaths,
|
|
243
|
-
});
|
|
244
|
-
const nextSteps = getRestoreNextSteps();
|
|
245
|
-
const explanations = ["Managed Bitcoin/indexer bootstrap is deferred until you run `cogcoin sync`."];
|
|
246
|
-
if (parsed.outputMode === "json") {
|
|
247
|
-
writeJsonValue(context.stdout, createMutationSuccessEnvelope(resolveStableMutationJsonSchema(parsed), describeCanonicalCommand(parsed), "restored", buildRestoreMutationData(result), {
|
|
248
|
-
explanations,
|
|
249
|
-
nextSteps,
|
|
250
|
-
warnings: result.warnings ?? [],
|
|
251
|
-
}));
|
|
252
|
-
return 0;
|
|
253
|
-
}
|
|
254
|
-
writeLine(context.stdout, `Wallet seed "${result.seedName}" restored from mnemonic.`);
|
|
255
|
-
if (result.passwordAction !== "already-configured") {
|
|
256
|
-
writeSetupUnlockGuidance(context.stdout);
|
|
257
|
-
}
|
|
258
|
-
writeLine(context.stdout, `Wallet root: ${result.walletRootId}`);
|
|
259
|
-
writeLine(context.stdout, `Funding address: ${result.fundingAddress}`);
|
|
260
|
-
writeLine(context.stdout, "Note: Managed Bitcoin/indexer bootstrap is deferred until you run `cogcoin sync`.");
|
|
261
|
-
for (const warning of result.warnings ?? []) {
|
|
262
|
-
writeLine(context.stdout, `Warning: ${warning}`);
|
|
263
|
-
}
|
|
264
|
-
for (const line of formatNextStepLines(nextSteps)) {
|
|
265
|
-
writeLine(context.stdout, line);
|
|
266
|
-
}
|
|
267
|
-
return 0;
|
|
268
|
-
}
|
|
269
|
-
if (parsed.command === "wallet-delete") {
|
|
270
|
-
const dataDir = parsed.dataDir ?? context.resolveDefaultBitcoindDataDir();
|
|
271
|
-
const prompter = createCommandPrompter(parsed, context);
|
|
272
|
-
const interactiveProvider = withInteractiveWalletSecretProvider(provider, prompter);
|
|
273
|
-
const result = await context.deleteImportedWalletSeed({
|
|
274
|
-
dataDir,
|
|
275
|
-
provider: interactiveProvider,
|
|
276
|
-
prompter,
|
|
277
|
-
assumeYes: parsed.assumeYes,
|
|
278
|
-
paths: runtimePaths,
|
|
279
|
-
});
|
|
280
|
-
if (parsed.outputMode === "json") {
|
|
281
|
-
writeJsonValue(context.stdout, createMutationSuccessEnvelope(resolveStableMutationJsonSchema(parsed), describeCanonicalCommand(parsed), "deleted", buildWalletDeleteMutationData(result)));
|
|
282
|
-
return 0;
|
|
283
|
-
}
|
|
284
|
-
writeLine(context.stdout, `Imported wallet seed "${result.seedName}" deleted.`);
|
|
285
|
-
writeLine(context.stdout, `Wallet root: ${result.walletRootId}`);
|
|
286
|
-
return 0;
|
|
287
|
-
}
|
|
288
217
|
if (parsed.command === "wallet-show-mnemonic") {
|
|
289
|
-
const prompter = createCommandPrompter(
|
|
218
|
+
const prompter = createCommandPrompter(context);
|
|
290
219
|
await context.showWalletMnemonic({
|
|
291
220
|
provider: withInteractiveWalletSecretProvider(provider, prompter),
|
|
292
221
|
prompter,
|
|
@@ -297,35 +226,18 @@ export async function runWalletAdminCommand(parsed, context) {
|
|
|
297
226
|
const dbPath = parsed.dbPath ?? context.resolveDefaultClientDatabasePath();
|
|
298
227
|
if (parsed.command === "reset") {
|
|
299
228
|
const dataDir = parsed.dataDir ?? context.resolveDefaultBitcoindDataDir();
|
|
300
|
-
|
|
301
|
-
const preview = await context.previewResetWallet({
|
|
302
|
-
dataDir,
|
|
303
|
-
provider,
|
|
304
|
-
});
|
|
305
|
-
writeJsonValue(context.stdout, createPreviewSuccessEnvelope(resolvePreviewJsonSchema(parsed), describeCanonicalCommand(parsed), "planned", buildResetPreviewData(preview)));
|
|
306
|
-
return 0;
|
|
307
|
-
}
|
|
308
|
-
const prompter = createCommandPrompter(parsed, context);
|
|
229
|
+
const prompter = createCommandPrompter(context);
|
|
309
230
|
const result = await context.resetWallet({
|
|
310
231
|
dataDir,
|
|
311
232
|
provider: withInteractiveWalletSecretProvider(provider, prompter),
|
|
312
233
|
prompter,
|
|
313
234
|
});
|
|
314
|
-
if (parsed.outputMode === "json") {
|
|
315
|
-
writeJsonValue(context.stdout, createMutationSuccessEnvelope(resolveStableMutationJsonSchema(parsed), describeCanonicalCommand(parsed), "completed", buildResetMutationData(result), {
|
|
316
|
-
warnings: getResetWarnings(result),
|
|
317
|
-
nextSteps: getResetNextSteps(result),
|
|
318
|
-
}));
|
|
319
|
-
return 0;
|
|
320
|
-
}
|
|
321
235
|
writeLine(context.stdout, formatResetResultText(result));
|
|
322
236
|
return 0;
|
|
323
237
|
}
|
|
324
238
|
if (parsed.command === "repair") {
|
|
325
239
|
const dataDir = parsed.dataDir ?? context.resolveDefaultBitcoindDataDir();
|
|
326
|
-
const repairProvider =
|
|
327
|
-
? provider
|
|
328
|
-
: withInteractiveWalletSecretProvider(provider, createCommandPrompter(parsed, context));
|
|
240
|
+
const repairProvider = withInteractiveWalletSecretProvider(provider, createCommandPrompter(context));
|
|
329
241
|
const result = await context.repairWallet({
|
|
330
242
|
dataDir,
|
|
331
243
|
databasePath: dbPath,
|
|
@@ -333,20 +245,6 @@ export async function runWalletAdminCommand(parsed, context) {
|
|
|
333
245
|
assumeYes: parsed.assumeYes,
|
|
334
246
|
paths: runtimePaths,
|
|
335
247
|
});
|
|
336
|
-
if (parsed.outputMode === "preview-json") {
|
|
337
|
-
writeJsonValue(context.stdout, createPreviewSuccessEnvelope(resolvePreviewJsonSchema(parsed), describeCanonicalCommand(parsed), "completed", buildRepairPreviewData(result), {
|
|
338
|
-
nextSteps: getRepairNextSteps(),
|
|
339
|
-
warnings: getRepairWarnings(result),
|
|
340
|
-
}));
|
|
341
|
-
return 0;
|
|
342
|
-
}
|
|
343
|
-
if (parsed.outputMode === "json") {
|
|
344
|
-
writeJsonValue(context.stdout, createMutationSuccessEnvelope(resolveStableMutationJsonSchema(parsed), "cogcoin repair", "completed", buildRepairMutationData(result), {
|
|
345
|
-
nextSteps: getRepairNextSteps(),
|
|
346
|
-
warnings: getRepairWarnings(result),
|
|
347
|
-
}));
|
|
348
|
-
return 0;
|
|
349
|
-
}
|
|
350
248
|
writeLine(context.stdout, formatRepairResultText(result));
|
|
351
249
|
return 0;
|
|
352
250
|
}
|
|
@@ -5,7 +5,6 @@ import { isAnchorMutationCommand, isBuyMutationCommand, isClaimMutationCommand,
|
|
|
5
5
|
import { commandMutationNextSteps, workflowMutationNextSteps, writeMutationCommandSuccess, } from "../mutation-success.js";
|
|
6
6
|
import { writeLine } from "../io.js";
|
|
7
7
|
import { formatBuyBuyerSummary, formatBuySellerSummary, formatBuySettlementSummary, formatCogClaimPath, formatCogSenderSummary, formatDomainAdminEffect, formatDomainAdminPayloadSummary, formatDomainAdminSenderSummary, formatDomainAdminTargetSummary, formatDomainMarketEconomicEffect, formatDomainMarketRecipientSummary, formatDomainMarketSenderSummary, formatFieldEffect, formatFieldPath, formatFieldSenderSummary, formatFieldValueSummary, formatRegisterEconomicEffect, formatRegisterSenderSummary, formatReputationEffect, formatReputationReviewSummary, formatReputationSenderSummary, } from "../mutation-text-format.js";
|
|
8
|
-
import { createTerminalPrompter } from "../prompt.js";
|
|
9
8
|
import { writeHandledCliError } from "../output.js";
|
|
10
9
|
import { getAnchorNextSteps, getRegisterNextSteps, } from "../workflow-hints.js";
|
|
11
10
|
import { createOwnedLockCleanupSignalWatcher, waitForCompletionOrStop, } from "../signals.js";
|
|
@@ -26,13 +25,11 @@ function createFieldValueSource(parsed) {
|
|
|
26
25
|
value: parsed.fieldValue,
|
|
27
26
|
};
|
|
28
27
|
}
|
|
29
|
-
function createCommandPrompter(
|
|
30
|
-
return
|
|
31
|
-
? createTerminalPrompter(context.stdin, context.stderr)
|
|
32
|
-
: context.createPrompter();
|
|
28
|
+
function createCommandPrompter(context) {
|
|
29
|
+
return context.createPrompter();
|
|
33
30
|
}
|
|
34
31
|
export async function runWalletMutationCommand(parsed, context) {
|
|
35
|
-
const runtimePaths = context.resolveWalletRuntimePaths(
|
|
32
|
+
const runtimePaths = context.resolveWalletRuntimePaths();
|
|
36
33
|
const stopWatcher = createOwnedLockCleanupSignalWatcher(context.signalSource, context.forceExit, [
|
|
37
34
|
runtimePaths.walletControlLockPath,
|
|
38
35
|
runtimePaths.miningControlLockPath,
|
|
@@ -47,7 +44,7 @@ export async function runWalletMutationCommand(parsed, context) {
|
|
|
47
44
|
}
|
|
48
45
|
const dataDir = parsed.dataDir ?? context.resolveDefaultBitcoindDataDir();
|
|
49
46
|
const dbPath = parsed.dbPath ?? context.resolveDefaultClientDatabasePath();
|
|
50
|
-
const prompter = createCommandPrompter(
|
|
47
|
+
const prompter = createCommandPrompter(context);
|
|
51
48
|
const interactive = prompter.isInteractive;
|
|
52
49
|
const provider = withInteractiveWalletSecretProvider(context.walletSecretProvider, prompter);
|
|
53
50
|
if (parsed.command === "bitcoin-transfer") {
|
|
@@ -3,19 +3,10 @@ import { formatBalanceReport, formatDetailedWalletStatusReport, formatDomainRepo
|
|
|
3
3
|
import { writeLine } from "../io.js";
|
|
4
4
|
import { findWalletDomain, listDomainFields } from "../../wallet/read/index.js";
|
|
5
5
|
import { filterWalletDomains } from "../../wallet/read/index.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { normalizeListPage } from "../output.js";
|
|
7
|
+
import { listFieldsForJson, listLocksForJson } from "../read-json.js";
|
|
8
8
|
import { formatNextStepLines, getAddressNextSteps, getFundingQuickstartGuidance, getIdsNextSteps, getLocksNextSteps, } from "../workflow-hints.js";
|
|
9
9
|
import { withInteractiveWalletSecretProvider } from "../../wallet/state/provider.js";
|
|
10
|
-
function createUnknownPage(parsed, defaultLimit) {
|
|
11
|
-
return {
|
|
12
|
-
limit: parsed.listAll ? null : (parsed.listLimit ?? defaultLimit),
|
|
13
|
-
returned: 0,
|
|
14
|
-
truncated: false,
|
|
15
|
-
moreAvailable: null,
|
|
16
|
-
totalKnown: null,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
10
|
function activeDomainFilters(parsed) {
|
|
20
11
|
const filters = [];
|
|
21
12
|
if (parsed.domainsAnchoredOnly) {
|
|
@@ -29,23 +20,13 @@ function activeDomainFilters(parsed) {
|
|
|
29
20
|
}
|
|
30
21
|
return filters;
|
|
31
22
|
}
|
|
32
|
-
function emitJson(context, parsed, schema, result) {
|
|
33
|
-
writeJsonValue(context.stdout, createSuccessEnvelope(schema, describeCanonicalCommand(parsed), result.data, {
|
|
34
|
-
warnings: result.warnings,
|
|
35
|
-
explanations: result.explanations,
|
|
36
|
-
nextSteps: result.nextSteps,
|
|
37
|
-
}));
|
|
38
|
-
return 0;
|
|
39
|
-
}
|
|
40
23
|
export async function runWalletReadCommand(parsed, context) {
|
|
41
24
|
const dbPath = parsed.dbPath ?? context.resolveDefaultClientDatabasePath();
|
|
42
25
|
const dataDir = parsed.dataDir ?? context.resolveDefaultBitcoindDataDir();
|
|
43
26
|
const packageVersion = await context.readPackageVersion();
|
|
44
|
-
const runtimePaths = context.resolveWalletRuntimePaths(
|
|
27
|
+
const runtimePaths = context.resolveWalletRuntimePaths();
|
|
45
28
|
await context.ensureDirectory(dirname(dbPath));
|
|
46
|
-
const provider =
|
|
47
|
-
? withInteractiveWalletSecretProvider(context.walletSecretProvider, context.createPrompter())
|
|
48
|
-
: context.walletSecretProvider;
|
|
29
|
+
const provider = withInteractiveWalletSecretProvider(context.walletSecretProvider, context.createPrompter());
|
|
49
30
|
const readContext = await context.openWalletReadContext({
|
|
50
31
|
dataDir,
|
|
51
32
|
databasePath: dbPath,
|
|
@@ -56,16 +37,9 @@ export async function runWalletReadCommand(parsed, context) {
|
|
|
56
37
|
try {
|
|
57
38
|
switch (parsed.command) {
|
|
58
39
|
case "wallet-status":
|
|
59
|
-
if (parsed.outputMode === "json") {
|
|
60
|
-
return emitJson(context, parsed, "cogcoin/wallet-status/v1", buildWalletStatusJson(readContext));
|
|
61
|
-
}
|
|
62
40
|
writeLine(context.stdout, formatDetailedWalletStatusReport(readContext));
|
|
63
41
|
return 0;
|
|
64
|
-
case "wallet-address":
|
|
65
42
|
case "address":
|
|
66
|
-
if (parsed.outputMode === "json") {
|
|
67
|
-
return emitJson(context, parsed, "cogcoin/address/v1", buildAddressJson(readContext));
|
|
68
|
-
}
|
|
69
43
|
writeLine(context.stdout, formatFundingAddressReport(readContext));
|
|
70
44
|
if (readContext.model?.walletAddress !== null && readContext.model?.walletAddress !== undefined) {
|
|
71
45
|
writeLine(context.stdout, `Quickstart: ${getFundingQuickstartGuidance()}`);
|
|
@@ -74,18 +48,8 @@ export async function runWalletReadCommand(parsed, context) {
|
|
|
74
48
|
writeLine(context.stdout, line);
|
|
75
49
|
}
|
|
76
50
|
return 0;
|
|
77
|
-
case "wallet-ids":
|
|
78
51
|
case "ids": {
|
|
79
52
|
const defaultLimit = 100;
|
|
80
|
-
if (parsed.outputMode === "json") {
|
|
81
|
-
return emitJson(context, parsed, "cogcoin/ids/v1", buildIdsJson(readContext, readContext.model === null
|
|
82
|
-
? createUnknownPage(parsed, defaultLimit)
|
|
83
|
-
: normalizeListPage([readContext.model.walletAddress ?? `spk:${readContext.model.walletScriptPubKeyHex}`], {
|
|
84
|
-
limit: parsed.listLimit,
|
|
85
|
-
all: parsed.listAll,
|
|
86
|
-
defaultLimit,
|
|
87
|
-
}).page));
|
|
88
|
-
}
|
|
89
53
|
writeLine(context.stdout, formatIdentityListReport(readContext, {
|
|
90
54
|
limit: parsed.listAll ? null : (parsed.listLimit ?? defaultLimit),
|
|
91
55
|
all: parsed.listAll,
|
|
@@ -98,53 +62,33 @@ export async function runWalletReadCommand(parsed, context) {
|
|
|
98
62
|
return 0;
|
|
99
63
|
}
|
|
100
64
|
case "balance":
|
|
101
|
-
case "cog-balance":
|
|
102
|
-
if (parsed.outputMode === "json") {
|
|
103
|
-
return emitJson(context, parsed, "cogcoin/balance/v1", buildBalanceJson(readContext));
|
|
104
|
-
}
|
|
105
65
|
writeLine(context.stdout, formatBalanceReport(readContext));
|
|
106
66
|
return 0;
|
|
107
67
|
case "locks":
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const locks = listLocksForJson(readContext, {
|
|
68
|
+
{
|
|
69
|
+
const defaultLimit = 100;
|
|
70
|
+
writeLine(context.stdout, formatLocksReport(readContext, {
|
|
112
71
|
claimableOnly: parsed.locksClaimableOnly,
|
|
113
72
|
reclaimableOnly: parsed.locksReclaimableOnly,
|
|
114
|
-
|
|
115
|
-
if (locks === null) {
|
|
116
|
-
return emitJson(context, parsed, "cogcoin/locks/v1", buildLocksJson(readContext, null, createUnknownPage(parsed, defaultLimit)));
|
|
117
|
-
}
|
|
118
|
-
const { items, page } = normalizeListPage(locks, {
|
|
119
|
-
limit: parsed.listLimit,
|
|
73
|
+
limit: parsed.listAll ? null : (parsed.listLimit ?? defaultLimit),
|
|
120
74
|
all: parsed.listAll,
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
writeLine(context.stdout, formatLocksReport(readContext, {
|
|
126
|
-
claimableOnly: parsed.locksClaimableOnly,
|
|
127
|
-
reclaimableOnly: parsed.locksReclaimableOnly,
|
|
128
|
-
limit: parsed.listAll ? null : (parsed.listLimit ?? defaultLimit),
|
|
129
|
-
all: parsed.listAll,
|
|
130
|
-
}));
|
|
131
|
-
const locks = listLocksForJson(readContext, {
|
|
132
|
-
claimableOnly: parsed.locksClaimableOnly,
|
|
133
|
-
reclaimableOnly: parsed.locksReclaimableOnly,
|
|
134
|
-
});
|
|
135
|
-
if (locks !== null) {
|
|
136
|
-
const { items } = normalizeListPage(locks, {
|
|
137
|
-
limit: parsed.listLimit,
|
|
138
|
-
all: parsed.listAll,
|
|
139
|
-
defaultLimit,
|
|
75
|
+
}));
|
|
76
|
+
const locks = listLocksForJson(readContext, {
|
|
77
|
+
claimableOnly: parsed.locksClaimableOnly,
|
|
78
|
+
reclaimableOnly: parsed.locksReclaimableOnly,
|
|
140
79
|
});
|
|
141
|
-
|
|
142
|
-
|
|
80
|
+
if (locks !== null) {
|
|
81
|
+
const { items } = normalizeListPage(locks, {
|
|
82
|
+
limit: parsed.listLimit,
|
|
83
|
+
all: parsed.listAll,
|
|
84
|
+
defaultLimit,
|
|
85
|
+
});
|
|
86
|
+
for (const line of formatNextStepLines(getLocksNextSteps(items))) {
|
|
87
|
+
writeLine(context.stdout, line);
|
|
88
|
+
}
|
|
143
89
|
}
|
|
90
|
+
return 0;
|
|
144
91
|
}
|
|
145
|
-
return 0;
|
|
146
|
-
}
|
|
147
|
-
case "domain-list":
|
|
148
92
|
case "domains": {
|
|
149
93
|
const defaultLimit = 100;
|
|
150
94
|
const filters = activeDomainFilters(parsed);
|
|
@@ -153,17 +97,6 @@ export async function runWalletReadCommand(parsed, context) {
|
|
|
153
97
|
listedOnly: parsed.domainsListedOnly,
|
|
154
98
|
mineableOnly: parsed.domainsMineableOnly,
|
|
155
99
|
});
|
|
156
|
-
if (parsed.outputMode === "json") {
|
|
157
|
-
if (domains === null) {
|
|
158
|
-
return emitJson(context, parsed, "cogcoin/domains/v1", buildDomainsJson(readContext, null, createUnknownPage(parsed, defaultLimit)));
|
|
159
|
-
}
|
|
160
|
-
const { items, page } = normalizeListPage(domains, {
|
|
161
|
-
limit: parsed.listLimit,
|
|
162
|
-
all: parsed.listAll,
|
|
163
|
-
defaultLimit,
|
|
164
|
-
});
|
|
165
|
-
return emitJson(context, parsed, "cogcoin/domains/v1", buildDomainsJson(readContext, items, page));
|
|
166
|
-
}
|
|
167
100
|
writeLine(context.stdout, formatDomainsReport(readContext, {
|
|
168
101
|
limit: parsed.listAll ? null : (parsed.listLimit ?? defaultLimit),
|
|
169
102
|
all: parsed.listAll,
|
|
@@ -172,52 +105,26 @@ export async function runWalletReadCommand(parsed, context) {
|
|
|
172
105
|
}));
|
|
173
106
|
return 0;
|
|
174
107
|
}
|
|
175
|
-
case "domain-show":
|
|
176
108
|
case "show": {
|
|
177
109
|
const domainName = parsed.args[0];
|
|
178
110
|
const domain = findWalletDomain(readContext, domainName);
|
|
179
111
|
if (readContext.snapshot !== null && domain === null) {
|
|
180
|
-
|
|
181
|
-
writeJsonValue(context.stdout, createErrorEnvelope("cogcoin/show/v1", describeCanonicalCommand(parsed), "not_found", "Domain not found."));
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
writeLine(context.stdout, formatDomainReport(readContext, domainName));
|
|
185
|
-
}
|
|
112
|
+
writeLine(context.stdout, formatDomainReport(readContext, domainName));
|
|
186
113
|
return 3;
|
|
187
114
|
}
|
|
188
|
-
if (parsed.outputMode === "json") {
|
|
189
|
-
return emitJson(context, parsed, "cogcoin/show/v1", buildShowJson(readContext, domainName));
|
|
190
|
-
}
|
|
191
115
|
writeLine(context.stdout, formatDomainReport(readContext, parsed.args[0]));
|
|
192
116
|
return 0;
|
|
193
117
|
}
|
|
194
|
-
case "fields":
|
|
195
|
-
case "field-list": {
|
|
118
|
+
case "fields": {
|
|
196
119
|
const defaultLimit = 100;
|
|
197
120
|
const domainName = parsed.args[0];
|
|
198
121
|
const fields = listFieldsForJson(readContext, domainName);
|
|
199
122
|
if (readContext.snapshot !== null && fields === null) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
writeLine(context.stdout, formatFieldsReport(readContext, domainName, {
|
|
205
|
-
limit: parsed.listAll ? null : (parsed.listLimit ?? defaultLimit),
|
|
206
|
-
all: parsed.listAll,
|
|
207
|
-
}));
|
|
208
|
-
}
|
|
209
|
-
return 3;
|
|
210
|
-
}
|
|
211
|
-
if (parsed.outputMode === "json") {
|
|
212
|
-
if (fields === null) {
|
|
213
|
-
return emitJson(context, parsed, "cogcoin/fields/v1", buildFieldsJson(readContext, domainName, null, createUnknownPage(parsed, defaultLimit)));
|
|
214
|
-
}
|
|
215
|
-
const { items, page } = normalizeListPage(fields, {
|
|
216
|
-
limit: parsed.listLimit,
|
|
123
|
+
writeLine(context.stdout, formatFieldsReport(readContext, domainName, {
|
|
124
|
+
limit: parsed.listAll ? null : (parsed.listLimit ?? defaultLimit),
|
|
217
125
|
all: parsed.listAll,
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
return emitJson(context, parsed, "cogcoin/fields/v1", buildFieldsJson(readContext, domainName, items, page));
|
|
126
|
+
}));
|
|
127
|
+
return 3;
|
|
221
128
|
}
|
|
222
129
|
writeLine(context.stdout, formatFieldsReport(readContext, domainName, {
|
|
223
130
|
limit: parsed.listAll ? null : (parsed.listLimit ?? defaultLimit),
|
|
@@ -225,33 +132,19 @@ export async function runWalletReadCommand(parsed, context) {
|
|
|
225
132
|
}));
|
|
226
133
|
return 0;
|
|
227
134
|
}
|
|
228
|
-
case "field":
|
|
229
|
-
case "field-show": {
|
|
135
|
+
case "field": {
|
|
230
136
|
const domainName = parsed.args[0];
|
|
231
137
|
const fieldName = parsed.args[1];
|
|
232
138
|
const domainFields = listDomainFields(readContext, domainName);
|
|
233
139
|
const field = domainFields?.find((entry) => entry.name === fieldName) ?? null;
|
|
234
140
|
if (readContext.snapshot !== null && domainFields === null) {
|
|
235
|
-
|
|
236
|
-
writeJsonValue(context.stdout, createErrorEnvelope("cogcoin/field/v1", describeCanonicalCommand(parsed), "not_found", "Domain not found."));
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
writeLine(context.stdout, formatFieldReport(readContext, domainName, fieldName));
|
|
240
|
-
}
|
|
141
|
+
writeLine(context.stdout, formatFieldReport(readContext, domainName, fieldName));
|
|
241
142
|
return 3;
|
|
242
143
|
}
|
|
243
144
|
if (readContext.snapshot !== null && domainFields !== null && field === null) {
|
|
244
|
-
|
|
245
|
-
writeJsonValue(context.stdout, createErrorEnvelope("cogcoin/field/v1", describeCanonicalCommand(parsed), "not_found", "Field not found."));
|
|
246
|
-
}
|
|
247
|
-
else {
|
|
248
|
-
writeLine(context.stdout, formatFieldReport(readContext, domainName, fieldName));
|
|
249
|
-
}
|
|
145
|
+
writeLine(context.stdout, formatFieldReport(readContext, domainName, fieldName));
|
|
250
146
|
return 3;
|
|
251
147
|
}
|
|
252
|
-
if (parsed.outputMode === "json") {
|
|
253
|
-
return emitJson(context, parsed, "cogcoin/field/v1", buildFieldJson(readContext, domainName, fieldName));
|
|
254
|
-
}
|
|
255
148
|
writeLine(context.stdout, formatFieldReport(readContext, parsed.args[0], parsed.args[1]));
|
|
256
149
|
return 0;
|
|
257
150
|
}
|
package/dist/cli/context.js
CHANGED
|
@@ -9,7 +9,7 @@ import { openManagedIndexerMonitor } from "../bitcoind/indexer-monitor.js";
|
|
|
9
9
|
import { readPackageVersionFromDisk } from "../package-version.js";
|
|
10
10
|
import { inspectPassiveClientStatus } from "../passive-status.js";
|
|
11
11
|
import { openSqliteStore } from "../sqlite/index.js";
|
|
12
|
-
import { initializeWallet,
|
|
12
|
+
import { initializeWallet, previewResetWallet, repairWallet, resetWallet, showWalletMnemonic, } from "../wallet/lifecycle.js";
|
|
13
13
|
import { resolveWalletRuntimePathsForTesting } from "../wallet/runtime.js";
|
|
14
14
|
import { openWalletReadContext } from "../wallet/read/index.js";
|
|
15
15
|
import { loadRawWalletStateEnvelope, loadWalletState } from "../wallet/state/storage.js";
|
|
@@ -65,9 +65,7 @@ export function createDefaultContext(overrides = {}) {
|
|
|
65
65
|
inspectPassiveClientStatus: overrides.inspectPassiveClientStatus ?? inspectPassiveClientStatus,
|
|
66
66
|
openWalletReadContext: overrides.openWalletReadContext ?? openWalletReadContext,
|
|
67
67
|
initializeWallet: overrides.initializeWallet ?? initializeWallet,
|
|
68
|
-
restoreWalletFromMnemonic: overrides.restoreWalletFromMnemonic ?? restoreWalletFromMnemonic,
|
|
69
68
|
previewResetWallet: overrides.previewResetWallet ?? previewResetWallet,
|
|
70
|
-
deleteImportedWalletSeed: overrides.deleteImportedWalletSeed ?? deleteImportedWalletSeed,
|
|
71
69
|
showWalletMnemonic: overrides.showWalletMnemonic ?? showWalletMnemonic,
|
|
72
70
|
registerDomain: overrides.registerDomain ?? registerDomain,
|
|
73
71
|
anchorDomain: overrides.anchorDomain ?? anchorDomain,
|
|
@@ -122,6 +120,6 @@ export function createDefaultContext(overrides = {}) {
|
|
|
122
120
|
resolveDefaultBitcoindDataDir: overrides.resolveDefaultBitcoindDataDir ?? resolveDefaultBitcoindDataDirForTesting,
|
|
123
121
|
resolveDefaultClientDatabasePath: overrides.resolveDefaultClientDatabasePath ?? resolveDefaultClientDatabasePathForTesting,
|
|
124
122
|
resolveUpdateCheckStatePath: overrides.resolveUpdateCheckStatePath ?? resolveDefaultUpdateCheckStatePathForTesting,
|
|
125
|
-
resolveWalletRuntimePaths: overrides.resolveWalletRuntimePaths ?? ((
|
|
123
|
+
resolveWalletRuntimePaths: overrides.resolveWalletRuntimePaths ?? (() => resolveWalletRuntimePathsForTesting()),
|
|
126
124
|
};
|
|
127
125
|
}
|
|
@@ -30,6 +30,11 @@ function resolveProviderNotFoundNextStep(mining) {
|
|
|
30
30
|
function resolveInsufficientFundsNextStep() {
|
|
31
31
|
return "Next: wait for enough safe BTC funding to become spendable for the next publish; mining resumes automatically.";
|
|
32
32
|
}
|
|
33
|
+
function resolveMiningRuntimeNote(mining) {
|
|
34
|
+
return mining.runtime.currentPublishDecision === "publish-paused-insufficient-funds"
|
|
35
|
+
? "Insufficient BTC to mine."
|
|
36
|
+
: mining.runtime.note;
|
|
37
|
+
}
|
|
33
38
|
export function formatMiningSummaryLine(mining) {
|
|
34
39
|
const provider = mining.provider.configured
|
|
35
40
|
? `${mining.provider.provider} configured`
|
|
@@ -127,8 +132,9 @@ export function formatMineStatusReport(mining) {
|
|
|
127
132
|
if (mining.runtime.lastError !== null) {
|
|
128
133
|
lines.push(`Last error: ${mining.runtime.lastError}`);
|
|
129
134
|
}
|
|
130
|
-
|
|
131
|
-
|
|
135
|
+
const runtimeNote = resolveMiningRuntimeNote(mining);
|
|
136
|
+
if (runtimeNote !== null) {
|
|
137
|
+
lines.push(`Note: ${runtimeNote}`);
|
|
132
138
|
}
|
|
133
139
|
if (mining.runtime.miningState === "repair-required") {
|
|
134
140
|
lines.push("Next: run `cogcoin repair` before mining again.");
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { CommandName } from "./types.js";
|
|
2
|
-
export declare const walletMutationCommands: readonly ["anchor", "
|
|
2
|
+
export declare const walletMutationCommands: readonly ["anchor", "register", "transfer", "sell", "unsell", "buy", "domain-endpoint-set", "domain-endpoint-clear", "domain-delegate-set", "domain-delegate-clear", "domain-miner-set", "domain-miner-clear", "domain-canonical", "field-create", "field-set", "field-clear", "send", "claim", "reclaim", "cog-lock", "rep-give", "rep-revoke"];
|
|
3
3
|
export type WalletMutationCommand = (typeof walletMutationCommands)[number];
|
|
4
4
|
export declare function isWalletMutationCommand(command: CommandName | null): command is WalletMutationCommand;
|
|
5
|
-
export declare function isAnchorMutationCommand(command: CommandName | null): command is "anchor"
|
|
6
|
-
export declare function isRegisterMutationCommand(command: CommandName | null): command is "register"
|
|
7
|
-
export declare function isTransferMutationCommand(command: CommandName | null): command is "transfer"
|
|
8
|
-
export declare function isSellMutationCommand(command: CommandName | null): command is "sell"
|
|
9
|
-
export declare function isUnsellMutationCommand(command: CommandName | null): command is "unsell"
|
|
10
|
-
export declare function isSellOrUnsellMutationCommand(command: CommandName | null): command is "sell" | "
|
|
11
|
-
export declare function isBuyMutationCommand(command: CommandName | null): command is "buy"
|
|
12
|
-
export declare function isSendMutationCommand(command: CommandName | null): command is "send"
|
|
13
|
-
export declare function isClaimMutationCommand(command: CommandName | null): command is "claim"
|
|
14
|
-
export declare function isReclaimMutationCommand(command: CommandName | null): command is "reclaim"
|
|
5
|
+
export declare function isAnchorMutationCommand(command: CommandName | null): command is "anchor";
|
|
6
|
+
export declare function isRegisterMutationCommand(command: CommandName | null): command is "register";
|
|
7
|
+
export declare function isTransferMutationCommand(command: CommandName | null): command is "transfer";
|
|
8
|
+
export declare function isSellMutationCommand(command: CommandName | null): command is "sell";
|
|
9
|
+
export declare function isUnsellMutationCommand(command: CommandName | null): command is "unsell";
|
|
10
|
+
export declare function isSellOrUnsellMutationCommand(command: CommandName | null): command is "sell" | "unsell";
|
|
11
|
+
export declare function isBuyMutationCommand(command: CommandName | null): command is "buy";
|
|
12
|
+
export declare function isSendMutationCommand(command: CommandName | null): command is "send";
|
|
13
|
+
export declare function isClaimMutationCommand(command: CommandName | null): command is "claim";
|
|
14
|
+
export declare function isReclaimMutationCommand(command: CommandName | null): command is "reclaim";
|
|
15
15
|
export declare function isReputationMutationCommand(command: CommandName | null): command is "rep-give" | "rep-revoke";
|