@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,265 @@
|
|
|
1
|
+
import { dirname } from "node:path";
|
|
2
|
+
import { formatBalanceReport, formatDetailedWalletStatusReport, formatDomainReport, formatDomainsReport, formatFieldReport, formatFieldsReport, formatFundingAddressReport, formatIdentityListReport, formatLocksReport, } from "../wallet-format.js";
|
|
3
|
+
import { writeLine } from "../io.js";
|
|
4
|
+
import { findWalletDomain, listDomainFields } from "../../wallet/read/index.js";
|
|
5
|
+
import { filterWalletDomains } from "../../wallet/read/index.js";
|
|
6
|
+
import { createErrorEnvelope, createSuccessEnvelope, describeCanonicalCommand, normalizeListPage, writeJsonValue, } from "../output.js";
|
|
7
|
+
import { buildAddressJson, buildBalanceJson, buildDomainsJson, buildFieldJson, buildFieldsJson, buildIdsJson, buildLocksJson, buildShowJson, buildWalletStatusJson, listFieldsForJson, listLocksForJson, } from "../read-json.js";
|
|
8
|
+
import { formatNextStepLines, getAddressNextSteps, getFundingQuickstartGuidance, getIdsNextSteps, getLocksNextSteps, } from "../workflow-hints.js";
|
|
9
|
+
function createUnknownPage(parsed, defaultLimit) {
|
|
10
|
+
return {
|
|
11
|
+
limit: parsed.listAll ? null : (parsed.listLimit ?? defaultLimit),
|
|
12
|
+
returned: 0,
|
|
13
|
+
truncated: false,
|
|
14
|
+
moreAvailable: null,
|
|
15
|
+
totalKnown: null,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function activeDomainFilters(parsed) {
|
|
19
|
+
const filters = [];
|
|
20
|
+
if (parsed.domainsAnchoredOnly) {
|
|
21
|
+
filters.push("--anchored");
|
|
22
|
+
}
|
|
23
|
+
if (parsed.domainsListedOnly) {
|
|
24
|
+
filters.push("--listed");
|
|
25
|
+
}
|
|
26
|
+
if (parsed.domainsMineableOnly) {
|
|
27
|
+
filters.push("--mineable");
|
|
28
|
+
}
|
|
29
|
+
return filters;
|
|
30
|
+
}
|
|
31
|
+
function emitJson(context, parsed, schema, result) {
|
|
32
|
+
writeJsonValue(context.stdout, createSuccessEnvelope(schema, describeCanonicalCommand(parsed), result.data, {
|
|
33
|
+
warnings: result.warnings,
|
|
34
|
+
explanations: result.explanations,
|
|
35
|
+
nextSteps: result.nextSteps,
|
|
36
|
+
}));
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
export async function runWalletReadCommand(parsed, context) {
|
|
40
|
+
const dbPath = parsed.dbPath ?? context.resolveDefaultClientDatabasePath();
|
|
41
|
+
const dataDir = parsed.dataDir ?? context.resolveDefaultBitcoindDataDir();
|
|
42
|
+
await context.ensureDirectory(dirname(dbPath));
|
|
43
|
+
const readContext = await context.openWalletReadContext({
|
|
44
|
+
dataDir,
|
|
45
|
+
databasePath: dbPath,
|
|
46
|
+
secretProvider: context.walletSecretProvider,
|
|
47
|
+
});
|
|
48
|
+
try {
|
|
49
|
+
switch (parsed.command) {
|
|
50
|
+
case "wallet-status":
|
|
51
|
+
if (parsed.outputMode === "json") {
|
|
52
|
+
return emitJson(context, parsed, "cogcoin/wallet-status/v1", buildWalletStatusJson(readContext));
|
|
53
|
+
}
|
|
54
|
+
writeLine(context.stdout, formatDetailedWalletStatusReport(readContext));
|
|
55
|
+
return 0;
|
|
56
|
+
case "wallet-address":
|
|
57
|
+
case "address":
|
|
58
|
+
if (parsed.outputMode === "json") {
|
|
59
|
+
return emitJson(context, parsed, "cogcoin/address/v1", buildAddressJson(readContext));
|
|
60
|
+
}
|
|
61
|
+
writeLine(context.stdout, formatFundingAddressReport(readContext));
|
|
62
|
+
if (readContext.model?.fundingIdentity?.address !== null && readContext.model?.fundingIdentity?.address !== undefined) {
|
|
63
|
+
writeLine(context.stdout, `Quickstart: ${getFundingQuickstartGuidance()}`);
|
|
64
|
+
}
|
|
65
|
+
for (const line of formatNextStepLines(getAddressNextSteps(readContext, readContext.model?.fundingIdentity?.address ?? null))) {
|
|
66
|
+
writeLine(context.stdout, line);
|
|
67
|
+
}
|
|
68
|
+
return 0;
|
|
69
|
+
case "wallet-ids":
|
|
70
|
+
case "ids": {
|
|
71
|
+
const defaultLimit = 100;
|
|
72
|
+
if (parsed.outputMode === "json") {
|
|
73
|
+
if (readContext.model === null) {
|
|
74
|
+
return emitJson(context, parsed, "cogcoin/ids/v1", buildIdsJson(readContext, createUnknownPage(parsed, defaultLimit), []));
|
|
75
|
+
}
|
|
76
|
+
const { items, page } = normalizeListPage(readContext.model.identities, {
|
|
77
|
+
limit: parsed.listLimit,
|
|
78
|
+
all: parsed.listAll,
|
|
79
|
+
defaultLimit,
|
|
80
|
+
});
|
|
81
|
+
return emitJson(context, parsed, "cogcoin/ids/v1", buildIdsJson(readContext, page, items));
|
|
82
|
+
}
|
|
83
|
+
writeLine(context.stdout, formatIdentityListReport(readContext, {
|
|
84
|
+
limit: parsed.listAll ? null : (parsed.listLimit ?? defaultLimit),
|
|
85
|
+
all: parsed.listAll,
|
|
86
|
+
}));
|
|
87
|
+
if (readContext.model !== null) {
|
|
88
|
+
const { items } = normalizeListPage(readContext.model.identities, {
|
|
89
|
+
limit: parsed.listLimit,
|
|
90
|
+
all: parsed.listAll,
|
|
91
|
+
defaultLimit,
|
|
92
|
+
});
|
|
93
|
+
for (const line of formatNextStepLines(getIdsNextSteps(items))) {
|
|
94
|
+
writeLine(context.stdout, line);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
99
|
+
case "balance":
|
|
100
|
+
case "cog-balance":
|
|
101
|
+
if (parsed.outputMode === "json") {
|
|
102
|
+
return emitJson(context, parsed, "cogcoin/balance/v1", buildBalanceJson(readContext));
|
|
103
|
+
}
|
|
104
|
+
writeLine(context.stdout, formatBalanceReport(readContext));
|
|
105
|
+
return 0;
|
|
106
|
+
case "locks":
|
|
107
|
+
case "cog-locks": {
|
|
108
|
+
const defaultLimit = 100;
|
|
109
|
+
if (parsed.outputMode === "json") {
|
|
110
|
+
const locks = listLocksForJson(readContext, {
|
|
111
|
+
claimableOnly: parsed.locksClaimableOnly,
|
|
112
|
+
reclaimableOnly: parsed.locksReclaimableOnly,
|
|
113
|
+
});
|
|
114
|
+
if (locks === null) {
|
|
115
|
+
return emitJson(context, parsed, "cogcoin/locks/v1", buildLocksJson(readContext, null, createUnknownPage(parsed, defaultLimit)));
|
|
116
|
+
}
|
|
117
|
+
const { items, page } = normalizeListPage(locks, {
|
|
118
|
+
limit: parsed.listLimit,
|
|
119
|
+
all: parsed.listAll,
|
|
120
|
+
defaultLimit,
|
|
121
|
+
});
|
|
122
|
+
return emitJson(context, parsed, "cogcoin/locks/v1", buildLocksJson(readContext, items, page));
|
|
123
|
+
}
|
|
124
|
+
writeLine(context.stdout, formatLocksReport(readContext, {
|
|
125
|
+
claimableOnly: parsed.locksClaimableOnly,
|
|
126
|
+
reclaimableOnly: parsed.locksReclaimableOnly,
|
|
127
|
+
limit: parsed.listAll ? null : (parsed.listLimit ?? defaultLimit),
|
|
128
|
+
all: parsed.listAll,
|
|
129
|
+
}));
|
|
130
|
+
const locks = listLocksForJson(readContext, {
|
|
131
|
+
claimableOnly: parsed.locksClaimableOnly,
|
|
132
|
+
reclaimableOnly: parsed.locksReclaimableOnly,
|
|
133
|
+
});
|
|
134
|
+
if (locks !== null) {
|
|
135
|
+
const { items } = normalizeListPage(locks, {
|
|
136
|
+
limit: parsed.listLimit,
|
|
137
|
+
all: parsed.listAll,
|
|
138
|
+
defaultLimit,
|
|
139
|
+
});
|
|
140
|
+
for (const line of formatNextStepLines(getLocksNextSteps(items))) {
|
|
141
|
+
writeLine(context.stdout, line);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return 0;
|
|
145
|
+
}
|
|
146
|
+
case "domain-list":
|
|
147
|
+
case "domains": {
|
|
148
|
+
const defaultLimit = 100;
|
|
149
|
+
const filters = activeDomainFilters(parsed);
|
|
150
|
+
const domains = filterWalletDomains(readContext, {
|
|
151
|
+
anchoredOnly: parsed.domainsAnchoredOnly,
|
|
152
|
+
listedOnly: parsed.domainsListedOnly,
|
|
153
|
+
mineableOnly: parsed.domainsMineableOnly,
|
|
154
|
+
});
|
|
155
|
+
if (parsed.outputMode === "json") {
|
|
156
|
+
if (domains === null) {
|
|
157
|
+
return emitJson(context, parsed, "cogcoin/domains/v1", buildDomainsJson(readContext, null, createUnknownPage(parsed, defaultLimit)));
|
|
158
|
+
}
|
|
159
|
+
const { items, page } = normalizeListPage(domains, {
|
|
160
|
+
limit: parsed.listLimit,
|
|
161
|
+
all: parsed.listAll,
|
|
162
|
+
defaultLimit,
|
|
163
|
+
});
|
|
164
|
+
return emitJson(context, parsed, "cogcoin/domains/v1", buildDomainsJson(readContext, items, page));
|
|
165
|
+
}
|
|
166
|
+
writeLine(context.stdout, formatDomainsReport(readContext, {
|
|
167
|
+
limit: parsed.listAll ? null : (parsed.listLimit ?? defaultLimit),
|
|
168
|
+
all: parsed.listAll,
|
|
169
|
+
domains,
|
|
170
|
+
activeFilters: filters,
|
|
171
|
+
}));
|
|
172
|
+
return 0;
|
|
173
|
+
}
|
|
174
|
+
case "domain-show":
|
|
175
|
+
case "show": {
|
|
176
|
+
const domainName = parsed.args[0];
|
|
177
|
+
const domain = findWalletDomain(readContext, domainName);
|
|
178
|
+
if (readContext.snapshot !== null && domain === null) {
|
|
179
|
+
if (parsed.outputMode === "json") {
|
|
180
|
+
writeJsonValue(context.stdout, createErrorEnvelope("cogcoin/show/v1", describeCanonicalCommand(parsed), "not_found", "Domain not found."));
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
writeLine(context.stdout, formatDomainReport(readContext, domainName));
|
|
184
|
+
}
|
|
185
|
+
return 3;
|
|
186
|
+
}
|
|
187
|
+
if (parsed.outputMode === "json") {
|
|
188
|
+
return emitJson(context, parsed, "cogcoin/show/v1", buildShowJson(readContext, domainName));
|
|
189
|
+
}
|
|
190
|
+
writeLine(context.stdout, formatDomainReport(readContext, parsed.args[0]));
|
|
191
|
+
return 0;
|
|
192
|
+
}
|
|
193
|
+
case "fields":
|
|
194
|
+
case "field-list": {
|
|
195
|
+
const defaultLimit = 100;
|
|
196
|
+
const domainName = parsed.args[0];
|
|
197
|
+
const fields = listFieldsForJson(readContext, domainName);
|
|
198
|
+
if (readContext.snapshot !== null && fields === null) {
|
|
199
|
+
if (parsed.outputMode === "json") {
|
|
200
|
+
writeJsonValue(context.stdout, createErrorEnvelope("cogcoin/fields/v1", describeCanonicalCommand(parsed), "not_found", "Domain not found."));
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
writeLine(context.stdout, formatFieldsReport(readContext, domainName, {
|
|
204
|
+
limit: parsed.listAll ? null : (parsed.listLimit ?? defaultLimit),
|
|
205
|
+
all: parsed.listAll,
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
208
|
+
return 3;
|
|
209
|
+
}
|
|
210
|
+
if (parsed.outputMode === "json") {
|
|
211
|
+
if (fields === null) {
|
|
212
|
+
return emitJson(context, parsed, "cogcoin/fields/v1", buildFieldsJson(readContext, domainName, null, createUnknownPage(parsed, defaultLimit)));
|
|
213
|
+
}
|
|
214
|
+
const { items, page } = normalizeListPage(fields, {
|
|
215
|
+
limit: parsed.listLimit,
|
|
216
|
+
all: parsed.listAll,
|
|
217
|
+
defaultLimit,
|
|
218
|
+
});
|
|
219
|
+
return emitJson(context, parsed, "cogcoin/fields/v1", buildFieldsJson(readContext, domainName, items, page));
|
|
220
|
+
}
|
|
221
|
+
writeLine(context.stdout, formatFieldsReport(readContext, domainName, {
|
|
222
|
+
limit: parsed.listAll ? null : (parsed.listLimit ?? defaultLimit),
|
|
223
|
+
all: parsed.listAll,
|
|
224
|
+
}));
|
|
225
|
+
return 0;
|
|
226
|
+
}
|
|
227
|
+
case "field":
|
|
228
|
+
case "field-show": {
|
|
229
|
+
const domainName = parsed.args[0];
|
|
230
|
+
const fieldName = parsed.args[1];
|
|
231
|
+
const domainFields = listDomainFields(readContext, domainName);
|
|
232
|
+
const field = domainFields?.find((entry) => entry.name === fieldName) ?? null;
|
|
233
|
+
if (readContext.snapshot !== null && domainFields === null) {
|
|
234
|
+
if (parsed.outputMode === "json") {
|
|
235
|
+
writeJsonValue(context.stdout, createErrorEnvelope("cogcoin/field/v1", describeCanonicalCommand(parsed), "not_found", "Domain not found."));
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
writeLine(context.stdout, formatFieldReport(readContext, domainName, fieldName));
|
|
239
|
+
}
|
|
240
|
+
return 3;
|
|
241
|
+
}
|
|
242
|
+
if (readContext.snapshot !== null && domainFields !== null && field === null) {
|
|
243
|
+
if (parsed.outputMode === "json") {
|
|
244
|
+
writeJsonValue(context.stdout, createErrorEnvelope("cogcoin/field/v1", describeCanonicalCommand(parsed), "not_found", "Field not found."));
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
writeLine(context.stdout, formatFieldReport(readContext, domainName, fieldName));
|
|
248
|
+
}
|
|
249
|
+
return 3;
|
|
250
|
+
}
|
|
251
|
+
if (parsed.outputMode === "json") {
|
|
252
|
+
return emitJson(context, parsed, "cogcoin/field/v1", buildFieldJson(readContext, domainName, fieldName));
|
|
253
|
+
}
|
|
254
|
+
writeLine(context.stdout, formatFieldReport(readContext, parsed.args[0], parsed.args[1]));
|
|
255
|
+
return 0;
|
|
256
|
+
}
|
|
257
|
+
default:
|
|
258
|
+
writeLine(context.stderr, `wallet read command not implemented: ${parsed.command}`);
|
|
259
|
+
return 5;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
finally {
|
|
263
|
+
await readContext.close();
|
|
264
|
+
}
|
|
265
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { mkdir, readFile } from "node:fs/promises";
|
|
2
|
+
import { resolveDefaultBitcoindDataDirForTesting, resolveDefaultClientDatabasePathForTesting, } from "../app-paths.js";
|
|
3
|
+
import { openManagedBitcoindClient } from "../bitcoind/index.js";
|
|
4
|
+
import { inspectPassiveClientStatus } from "../passive-status.js";
|
|
5
|
+
import { openSqliteStore } from "../sqlite/index.js";
|
|
6
|
+
import { exportWallet, importWallet, initializeWallet, lockWallet, repairWallet, unlockWallet, } from "../wallet/lifecycle.js";
|
|
7
|
+
import { openWalletReadContext } from "../wallet/read/index.js";
|
|
8
|
+
import { disableMiningHooks, enableMiningHooks, followMiningLog, inspectMiningControlPlane, readMiningLog, runForegroundMining, setupBuiltInMining, startBackgroundMining, stopBackgroundMining, } from "../wallet/mining/index.js";
|
|
9
|
+
import { createLazyDefaultWalletSecretProvider } from "../wallet/state/provider.js";
|
|
10
|
+
import { anchorDomain, buyDomain, claimCogLock, clearDomainDelegate, clearDomainEndpoint, clearDomainMiner, clearField, createField, giveReputation, lockCogToDomain, registerDomain, reclaimCogLock, revokeReputation, sendCog, setField, setDomainCanonical, setDomainDelegate, setDomainEndpoint, setDomainMiner, sellDomain, transferDomain, } from "../wallet/tx/index.js";
|
|
11
|
+
import { createTerminalPrompter } from "./prompt.js";
|
|
12
|
+
export async function readPackageVersionFromDisk() {
|
|
13
|
+
const raw = await readFile(new URL("../../package.json", import.meta.url), "utf8");
|
|
14
|
+
const parsed = JSON.parse(raw);
|
|
15
|
+
return parsed.version ?? "0.0.0";
|
|
16
|
+
}
|
|
17
|
+
export function createDefaultContext(overrides = {}) {
|
|
18
|
+
return {
|
|
19
|
+
stdout: overrides.stdout ?? process.stdout,
|
|
20
|
+
stderr: overrides.stderr ?? process.stderr,
|
|
21
|
+
stdin: overrides.stdin ?? process.stdin,
|
|
22
|
+
signalSource: overrides.signalSource ?? process,
|
|
23
|
+
forceExit: overrides.forceExit ?? ((code) => {
|
|
24
|
+
process.exit(code);
|
|
25
|
+
}),
|
|
26
|
+
openSqliteStore: overrides.openSqliteStore ?? openSqliteStore,
|
|
27
|
+
openManagedBitcoindClient: overrides.openManagedBitcoindClient ?? openManagedBitcoindClient,
|
|
28
|
+
inspectPassiveClientStatus: overrides.inspectPassiveClientStatus ?? inspectPassiveClientStatus,
|
|
29
|
+
openWalletReadContext: overrides.openWalletReadContext ?? openWalletReadContext,
|
|
30
|
+
initializeWallet: overrides.initializeWallet ?? initializeWallet,
|
|
31
|
+
exportWallet: overrides.exportWallet ?? exportWallet,
|
|
32
|
+
importWallet: overrides.importWallet ?? importWallet,
|
|
33
|
+
unlockWallet: overrides.unlockWallet ?? unlockWallet,
|
|
34
|
+
lockWallet: overrides.lockWallet ?? lockWallet,
|
|
35
|
+
registerDomain: overrides.registerDomain ?? registerDomain,
|
|
36
|
+
anchorDomain: overrides.anchorDomain ?? anchorDomain,
|
|
37
|
+
transferDomain: overrides.transferDomain ?? transferDomain,
|
|
38
|
+
sellDomain: overrides.sellDomain ?? sellDomain,
|
|
39
|
+
buyDomain: overrides.buyDomain ?? buyDomain,
|
|
40
|
+
sendCog: overrides.sendCog ?? sendCog,
|
|
41
|
+
claimCogLock: overrides.claimCogLock ?? claimCogLock,
|
|
42
|
+
reclaimCogLock: overrides.reclaimCogLock ?? reclaimCogLock,
|
|
43
|
+
lockCogToDomain: overrides.lockCogToDomain ?? lockCogToDomain,
|
|
44
|
+
setDomainEndpoint: overrides.setDomainEndpoint ?? setDomainEndpoint,
|
|
45
|
+
clearDomainEndpoint: overrides.clearDomainEndpoint ?? clearDomainEndpoint,
|
|
46
|
+
setDomainDelegate: overrides.setDomainDelegate ?? setDomainDelegate,
|
|
47
|
+
clearDomainDelegate: overrides.clearDomainDelegate ?? clearDomainDelegate,
|
|
48
|
+
setDomainMiner: overrides.setDomainMiner ?? setDomainMiner,
|
|
49
|
+
clearDomainMiner: overrides.clearDomainMiner ?? clearDomainMiner,
|
|
50
|
+
setDomainCanonical: overrides.setDomainCanonical ?? setDomainCanonical,
|
|
51
|
+
createField: overrides.createField ?? createField,
|
|
52
|
+
setField: overrides.setField ?? setField,
|
|
53
|
+
clearField: overrides.clearField ?? clearField,
|
|
54
|
+
giveReputation: overrides.giveReputation ?? giveReputation,
|
|
55
|
+
revokeReputation: overrides.revokeReputation ?? revokeReputation,
|
|
56
|
+
enableMiningHooks: overrides.enableMiningHooks ?? enableMiningHooks,
|
|
57
|
+
disableMiningHooks: overrides.disableMiningHooks ?? disableMiningHooks,
|
|
58
|
+
inspectMiningControlPlane: overrides.inspectMiningControlPlane ?? inspectMiningControlPlane,
|
|
59
|
+
runForegroundMining: overrides.runForegroundMining ?? runForegroundMining,
|
|
60
|
+
startBackgroundMining: overrides.startBackgroundMining ?? startBackgroundMining,
|
|
61
|
+
stopBackgroundMining: overrides.stopBackgroundMining ?? stopBackgroundMining,
|
|
62
|
+
setupBuiltInMining: overrides.setupBuiltInMining ?? setupBuiltInMining,
|
|
63
|
+
readMiningLog: overrides.readMiningLog ?? readMiningLog,
|
|
64
|
+
followMiningLog: overrides.followMiningLog ?? followMiningLog,
|
|
65
|
+
repairWallet: overrides.repairWallet ?? repairWallet,
|
|
66
|
+
walletSecretProvider: overrides.walletSecretProvider ?? createLazyDefaultWalletSecretProvider(),
|
|
67
|
+
createPrompter: overrides.createPrompter ?? (() => createTerminalPrompter(overrides.stdin ?? process.stdin, overrides.stdout ?? process.stdout)),
|
|
68
|
+
ensureDirectory: overrides.ensureDirectory ?? (async (path) => {
|
|
69
|
+
await mkdir(path, { recursive: true });
|
|
70
|
+
}),
|
|
71
|
+
readPackageVersion: overrides.readPackageVersion ?? readPackageVersionFromDisk,
|
|
72
|
+
resolveDefaultBitcoindDataDir: overrides.resolveDefaultBitcoindDataDir ?? resolveDefaultBitcoindDataDirForTesting,
|
|
73
|
+
resolveDefaultClientDatabasePath: overrides.resolveDefaultClientDatabasePath ?? resolveDefaultClientDatabasePathForTesting,
|
|
74
|
+
};
|
|
75
|
+
}
|
package/dist/cli/io.d.ts
ADDED
package/dist/cli/io.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function writeLine(stream, line) {
|
|
2
|
+
stream.write(`${line}\n`);
|
|
3
|
+
}
|
|
4
|
+
export function usesTtyProgress(progressOutput, stream) {
|
|
5
|
+
if (progressOutput === "none") {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
if (progressOutput === "tty") {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
return stream.isTTY === true;
|
|
12
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { MiningControlPlaneView, MiningEventRecord } from "../wallet/mining/index.js";
|
|
2
|
+
export declare function formatMiningSummaryLine(mining: MiningControlPlaneView): string;
|
|
3
|
+
export declare function formatHooksStatusReport(mining: MiningControlPlaneView): string;
|
|
4
|
+
export declare function formatMineStatusReport(mining: MiningControlPlaneView): string;
|
|
5
|
+
export declare function formatMiningEventRecord(event: MiningEventRecord): string;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
function formatMaybeIso(unixMs) {
|
|
2
|
+
return unixMs === null ? "none" : new Date(unixMs).toISOString();
|
|
3
|
+
}
|
|
4
|
+
function formatIndexerTruthSource(source) {
|
|
5
|
+
switch (source) {
|
|
6
|
+
case "lease":
|
|
7
|
+
return "coherent snapshot lease";
|
|
8
|
+
case "probe":
|
|
9
|
+
return "live daemon probe";
|
|
10
|
+
case "status-file":
|
|
11
|
+
return "advisory status file";
|
|
12
|
+
default:
|
|
13
|
+
return "none";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function formatMiningSummaryLine(mining) {
|
|
17
|
+
const hookMode = mining.hook.mode === "unavailable" ? "unavailable" : mining.hook.mode;
|
|
18
|
+
const provider = mining.provider.configured
|
|
19
|
+
? `${mining.provider.provider} configured`
|
|
20
|
+
: mining.provider.status === "error"
|
|
21
|
+
? "config unavailable"
|
|
22
|
+
: "not configured";
|
|
23
|
+
const suffix = mining.runtime.miningState === "repair-required"
|
|
24
|
+
? " next repair"
|
|
25
|
+
: mining.runtime.miningState === "paused-stale"
|
|
26
|
+
? " next wait-or-rerun"
|
|
27
|
+
: mining.runtime.miningState === "paused" && mining.runtime.liveMiningFamilyInMempool
|
|
28
|
+
? " next wait-or-rerun"
|
|
29
|
+
: mining.runtime.pauseReason === "zero-reward"
|
|
30
|
+
? " zero-reward"
|
|
31
|
+
: "";
|
|
32
|
+
return `${mining.runtime.runMode} / ${mining.runtime.miningState} / ${mining.runtime.currentPhase} hooks ${hookMode} (${mining.hook.operatorValidationState}) provider ${provider}${suffix}`;
|
|
33
|
+
}
|
|
34
|
+
export function formatHooksStatusReport(mining) {
|
|
35
|
+
const lines = ["Mining Hook Status"];
|
|
36
|
+
lines.push(`Mode: ${mining.hook.mode}`);
|
|
37
|
+
lines.push(`Entrypoint: ${mining.hook.entrypointPath}`);
|
|
38
|
+
lines.push(`Entrypoint present: ${mining.hook.entrypointExists ? "yes" : "no"}`);
|
|
39
|
+
lines.push(`Package: ${mining.hook.packageStatus}`);
|
|
40
|
+
if (mining.hook.packageMessage !== null) {
|
|
41
|
+
lines.push(`Package note: ${mining.hook.packageMessage}`);
|
|
42
|
+
}
|
|
43
|
+
lines.push(`Trust: ${mining.hook.trustStatus}`);
|
|
44
|
+
if (mining.hook.trustMessage !== null) {
|
|
45
|
+
lines.push(`Trust note: ${mining.hook.trustMessage}`);
|
|
46
|
+
}
|
|
47
|
+
lines.push(`Validation: ${mining.hook.operatorValidationState}`);
|
|
48
|
+
if (mining.hook.validationError !== null) {
|
|
49
|
+
lines.push(`Validation note: ${mining.hook.validationError}`);
|
|
50
|
+
}
|
|
51
|
+
lines.push(`Validated at: ${formatMaybeIso(mining.hook.validatedAtUnixMs)}`);
|
|
52
|
+
lines.push(`Launch fingerprint: ${mining.hook.currentLaunchFingerprint ?? "unavailable"}`);
|
|
53
|
+
lines.push(`Validated launch fingerprint: ${mining.hook.validatedLaunchFingerprint ?? "none"}`);
|
|
54
|
+
lines.push(`Full fingerprint: ${mining.hook.currentFullFingerprint ?? (mining.hook.verifyUsed ? "unavailable" : "not requested")}`);
|
|
55
|
+
lines.push(`Validated full fingerprint: ${mining.hook.validatedFullFingerprint ?? "none"}`);
|
|
56
|
+
lines.push(`Cooldown until: ${formatMaybeIso(mining.hook.cooldownUntilUnixMs)}`);
|
|
57
|
+
lines.push(`Cooldown active: ${mining.hook.cooldownActive ? "yes" : "no"}`);
|
|
58
|
+
lines.push(`Consecutive failures: ${mining.hook.consecutiveFailureCount}`);
|
|
59
|
+
return lines.join("\n");
|
|
60
|
+
}
|
|
61
|
+
export function formatMineStatusReport(mining) {
|
|
62
|
+
const lines = ["Mining Status"];
|
|
63
|
+
lines.push(`Run mode: ${mining.runtime.runMode}`);
|
|
64
|
+
lines.push(`Mining state: ${mining.runtime.miningState}`);
|
|
65
|
+
lines.push(`Current phase: ${mining.runtime.currentPhase}`);
|
|
66
|
+
if (mining.runtime.pauseReason !== null) {
|
|
67
|
+
lines.push(`Pause reason: ${mining.runtime.pauseReason}`);
|
|
68
|
+
}
|
|
69
|
+
if (mining.runtime.lastSuspendDetectedAtUnixMs !== null) {
|
|
70
|
+
lines.push(`Last suspend detected: ${formatMaybeIso(mining.runtime.lastSuspendDetectedAtUnixMs)}`);
|
|
71
|
+
}
|
|
72
|
+
lines.push(`Hook mode: ${mining.runtime.hookMode}`);
|
|
73
|
+
lines.push(`Hook validation: ${mining.hook.operatorValidationState}`);
|
|
74
|
+
lines.push(`Provider: ${mining.provider.configured ? `${mining.provider.provider} configured` : mining.provider.status}`);
|
|
75
|
+
if (mining.provider.message !== null) {
|
|
76
|
+
lines.push(`Provider note: ${mining.provider.message}`);
|
|
77
|
+
}
|
|
78
|
+
lines.push(`Provider runtime: ${mining.runtime.providerState ?? "unknown"}`);
|
|
79
|
+
lines.push(`Hook cooldown: ${mining.hook.cooldownActive ? "active" : "inactive"}`);
|
|
80
|
+
lines.push(`Managed bitcoind: ${mining.runtime.bitcoindHealth}`);
|
|
81
|
+
if (mining.runtime.bitcoindReplicaStatus !== null) {
|
|
82
|
+
lines.push(`Managed Core wallet: ${mining.runtime.bitcoindReplicaStatus}`);
|
|
83
|
+
}
|
|
84
|
+
lines.push(`Bitcoin service: ${mining.runtime.nodeHealth}`);
|
|
85
|
+
lines.push(`Indexer service: ${mining.runtime.indexerHealth}`);
|
|
86
|
+
lines.push(`Indexer truth source: ${formatIndexerTruthSource(mining.runtime.indexerTruthSource)}`);
|
|
87
|
+
if (mining.runtime.indexerDaemonInstanceId !== null) {
|
|
88
|
+
lines.push(`Indexer daemon instance: ${mining.runtime.indexerDaemonInstanceId}`);
|
|
89
|
+
}
|
|
90
|
+
if (mining.runtime.indexerSnapshotSeq !== null) {
|
|
91
|
+
lines.push(`Indexer snapshot sequence: ${mining.runtime.indexerSnapshotSeq}`);
|
|
92
|
+
}
|
|
93
|
+
if (mining.runtime.indexerReorgDepth !== null) {
|
|
94
|
+
lines.push(`Indexer reorg depth: ${mining.runtime.indexerReorgDepth}`);
|
|
95
|
+
}
|
|
96
|
+
lines.push(`Tip alignment: ${mining.runtime.tipsAligned === null ? "unknown" : mining.runtime.tipsAligned ? "aligned" : "misaligned"}`);
|
|
97
|
+
lines.push(`Core publishability: ${mining.runtime.corePublishState ?? "unknown"}`);
|
|
98
|
+
if (mining.runtime.backgroundWorkerPid !== null) {
|
|
99
|
+
lines.push(`Background worker: pid ${mining.runtime.backgroundWorkerPid} (${mining.runtime.backgroundWorkerHealth ?? "unknown"})`);
|
|
100
|
+
}
|
|
101
|
+
if (mining.runtime.currentDomainName !== null) {
|
|
102
|
+
lines.push(`Current domain: ${mining.runtime.currentDomainName}`);
|
|
103
|
+
}
|
|
104
|
+
if (mining.runtime.currentTxid !== null) {
|
|
105
|
+
lines.push(`Current txid: ${mining.runtime.currentTxid}`);
|
|
106
|
+
}
|
|
107
|
+
lines.push(`Publish state: ${mining.runtime.currentPublishState}`);
|
|
108
|
+
if (mining.runtime.currentPublishDecision !== null) {
|
|
109
|
+
lines.push(`Publish decision: ${mining.runtime.currentPublishDecision}`);
|
|
110
|
+
}
|
|
111
|
+
if (mining.runtime.sameDomainCompetitorSuppressed === true) {
|
|
112
|
+
lines.push("Competitiveness gate: suppressed by same-domain mempool incumbent");
|
|
113
|
+
}
|
|
114
|
+
else if (mining.runtime.competitivenessGateIndeterminate === true) {
|
|
115
|
+
lines.push("Competitiveness gate: indeterminate, so this tick was skipped safely");
|
|
116
|
+
}
|
|
117
|
+
else if (mining.runtime.higherRankedCompetitorDomainCount !== null) {
|
|
118
|
+
lines.push(`Higher-ranked competitor domains: ${mining.runtime.higherRankedCompetitorDomainCount}`);
|
|
119
|
+
}
|
|
120
|
+
if (mining.runtime.dedupedCompetitorDomainCount !== null) {
|
|
121
|
+
lines.push(`Deduped competitor domains: ${mining.runtime.dedupedCompetitorDomainCount}`);
|
|
122
|
+
}
|
|
123
|
+
if (mining.runtime.lastMempoolSequence !== null) {
|
|
124
|
+
lines.push(`Last mempool sequence: ${mining.runtime.lastMempoolSequence}`);
|
|
125
|
+
}
|
|
126
|
+
if (mining.runtime.mempoolSequenceCacheStatus !== null) {
|
|
127
|
+
lines.push(`Gate cache: ${mining.runtime.mempoolSequenceCacheStatus}`);
|
|
128
|
+
}
|
|
129
|
+
lines.push(`Last validation: ${formatMaybeIso(mining.runtime.lastValidationAtUnixMs)}`);
|
|
130
|
+
lines.push(`Last event: ${formatMaybeIso(mining.runtime.lastEventAtUnixMs)}`);
|
|
131
|
+
if (mining.runtime.lastError !== null) {
|
|
132
|
+
lines.push(`Last error: ${mining.runtime.lastError}`);
|
|
133
|
+
}
|
|
134
|
+
if (mining.runtime.note !== null) {
|
|
135
|
+
lines.push(`Note: ${mining.runtime.note}`);
|
|
136
|
+
}
|
|
137
|
+
if (mining.runtime.miningState === "repair-required") {
|
|
138
|
+
lines.push("Next: run `cogcoin repair` before mining again.");
|
|
139
|
+
}
|
|
140
|
+
else if (mining.runtime.pauseReason === "zero-reward") {
|
|
141
|
+
lines.push("Next: wait for the next positive-reward target height; mining resumes automatically.");
|
|
142
|
+
}
|
|
143
|
+
else if (mining.runtime.currentPhase === "resuming") {
|
|
144
|
+
lines.push("Next: wait for mining to finish rechecking health after the local runtime resumed.");
|
|
145
|
+
}
|
|
146
|
+
else if (mining.runtime.miningState === "paused-stale") {
|
|
147
|
+
lines.push("Next: wait for the live mempool family to confirm, or rerun mining after the tip settles.");
|
|
148
|
+
}
|
|
149
|
+
else if (mining.runtime.miningState === "paused" && mining.runtime.liveMiningFamilyInMempool) {
|
|
150
|
+
lines.push("Next: wait for the live mempool family to confirm, or rerun mining when you want replacements to resume.");
|
|
151
|
+
}
|
|
152
|
+
return lines.join("\n");
|
|
153
|
+
}
|
|
154
|
+
export function formatMiningEventRecord(event) {
|
|
155
|
+
return `${new Date(event.timestampUnixMs).toISOString()} ${event.level.toUpperCase()} ${event.kind} ${event.message}`;
|
|
156
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { MiningControlPlaneView, MiningRuntimeStatusV1 } from "../wallet/mining/index.js";
|
|
2
|
+
export declare function buildHooksDisableMiningData(view: MiningControlPlaneView): {
|
|
3
|
+
resultType: "state-change";
|
|
4
|
+
stateChange: {
|
|
5
|
+
kind: string;
|
|
6
|
+
before: Record<string, unknown> | null;
|
|
7
|
+
after: Record<string, unknown> | null;
|
|
8
|
+
};
|
|
9
|
+
state: Record<string, unknown>;
|
|
10
|
+
};
|
|
11
|
+
export declare function buildHooksEnableMiningData(view: MiningControlPlaneView): {
|
|
12
|
+
resultType: "state-change";
|
|
13
|
+
stateChange: {
|
|
14
|
+
kind: string;
|
|
15
|
+
before: Record<string, unknown> | null;
|
|
16
|
+
after: Record<string, unknown> | null;
|
|
17
|
+
};
|
|
18
|
+
state: Record<string, unknown>;
|
|
19
|
+
};
|
|
20
|
+
export declare function buildMineSetupData(view: MiningControlPlaneView): {
|
|
21
|
+
resultType: "state-change";
|
|
22
|
+
stateChange: {
|
|
23
|
+
kind: string;
|
|
24
|
+
before: Record<string, unknown> | null;
|
|
25
|
+
after: Record<string, unknown> | null;
|
|
26
|
+
};
|
|
27
|
+
state: Record<string, unknown>;
|
|
28
|
+
};
|
|
29
|
+
export declare function buildMineStartData(result: {
|
|
30
|
+
started: boolean;
|
|
31
|
+
snapshot: MiningRuntimeStatusV1 | null;
|
|
32
|
+
}): {
|
|
33
|
+
resultType: "state-change";
|
|
34
|
+
stateChange: {
|
|
35
|
+
kind: string;
|
|
36
|
+
before: Record<string, unknown> | null;
|
|
37
|
+
after: Record<string, unknown> | null;
|
|
38
|
+
};
|
|
39
|
+
state: Record<string, unknown>;
|
|
40
|
+
};
|
|
41
|
+
export declare function buildMineStopData(snapshot: MiningRuntimeStatusV1 | null): {
|
|
42
|
+
resultType: "state-change";
|
|
43
|
+
stateChange: {
|
|
44
|
+
kind: string;
|
|
45
|
+
before: Record<string, unknown> | null;
|
|
46
|
+
after: Record<string, unknown> | null;
|
|
47
|
+
};
|
|
48
|
+
state: Record<string, unknown>;
|
|
49
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { buildStateChangeData } from "./mutation-json.js";
|
|
2
|
+
function summarizeRuntime(snapshot) {
|
|
3
|
+
if (snapshot === null) {
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
6
|
+
return {
|
|
7
|
+
runMode: snapshot.runMode,
|
|
8
|
+
miningState: snapshot.miningState,
|
|
9
|
+
currentPhase: snapshot.currentPhase,
|
|
10
|
+
backgroundWorkerPid: snapshot.backgroundWorkerPid,
|
|
11
|
+
backgroundWorkerRunId: snapshot.backgroundWorkerRunId,
|
|
12
|
+
note: snapshot.note,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export function buildHooksDisableMiningData(view) {
|
|
16
|
+
return buildHooksStateChangeData("hooks-disable-mining", view);
|
|
17
|
+
}
|
|
18
|
+
export function buildHooksEnableMiningData(view) {
|
|
19
|
+
return buildHooksStateChangeData("hooks-enable-mining", view);
|
|
20
|
+
}
|
|
21
|
+
export function buildMineSetupData(view) {
|
|
22
|
+
const after = {
|
|
23
|
+
hook: {
|
|
24
|
+
mode: view.hook.mode,
|
|
25
|
+
validationState: view.hook.validationState,
|
|
26
|
+
operatorValidationState: view.hook.operatorValidationState,
|
|
27
|
+
validationError: view.hook.validationError,
|
|
28
|
+
cooldownActive: view.hook.cooldownActive,
|
|
29
|
+
},
|
|
30
|
+
provider: {
|
|
31
|
+
configured: view.provider.configured,
|
|
32
|
+
provider: view.provider.provider,
|
|
33
|
+
status: view.provider.status,
|
|
34
|
+
modelOverride: view.provider.modelOverride,
|
|
35
|
+
extraPromptConfigured: view.provider.extraPromptConfigured,
|
|
36
|
+
},
|
|
37
|
+
runtime: summarizeRuntime(view.runtime),
|
|
38
|
+
};
|
|
39
|
+
return buildStateChangeData({
|
|
40
|
+
kind: "mine-setup",
|
|
41
|
+
state: after,
|
|
42
|
+
after,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function buildHooksStateChangeData(kind, view) {
|
|
46
|
+
const after = {
|
|
47
|
+
hook: {
|
|
48
|
+
mode: view.hook.mode,
|
|
49
|
+
validationState: view.hook.validationState,
|
|
50
|
+
operatorValidationState: view.hook.operatorValidationState,
|
|
51
|
+
validationError: view.hook.validationError,
|
|
52
|
+
cooldownActive: view.hook.cooldownActive,
|
|
53
|
+
},
|
|
54
|
+
provider: {
|
|
55
|
+
configured: view.provider.configured,
|
|
56
|
+
provider: view.provider.provider,
|
|
57
|
+
status: view.provider.status,
|
|
58
|
+
},
|
|
59
|
+
runtime: summarizeRuntime(view.runtime),
|
|
60
|
+
};
|
|
61
|
+
return buildStateChangeData({
|
|
62
|
+
kind,
|
|
63
|
+
state: after,
|
|
64
|
+
after,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
export function buildMineStartData(result) {
|
|
68
|
+
const after = {
|
|
69
|
+
started: result.started,
|
|
70
|
+
runtime: summarizeRuntime(result.snapshot),
|
|
71
|
+
};
|
|
72
|
+
return buildStateChangeData({
|
|
73
|
+
kind: "mine-start",
|
|
74
|
+
state: after,
|
|
75
|
+
after,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
export function buildMineStopData(snapshot) {
|
|
79
|
+
const after = {
|
|
80
|
+
stopped: snapshot !== null,
|
|
81
|
+
runtime: summarizeRuntime(snapshot),
|
|
82
|
+
note: snapshot?.note ?? "Background mining was not active.",
|
|
83
|
+
};
|
|
84
|
+
return buildStateChangeData({
|
|
85
|
+
kind: "mine-stop",
|
|
86
|
+
state: after,
|
|
87
|
+
after,
|
|
88
|
+
});
|
|
89
|
+
}
|