@cogcoin/client 1.1.4 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/README.md +4 -5
  2. package/dist/bitcoind/indexer-daemon.d.ts +3 -7
  3. package/dist/bitcoind/indexer-daemon.js +43 -158
  4. package/dist/bitcoind/managed-runtime/bitcoind-policy.d.ts +16 -0
  5. package/dist/bitcoind/managed-runtime/bitcoind-policy.js +177 -0
  6. package/dist/bitcoind/managed-runtime/indexer-policy.d.ts +34 -0
  7. package/dist/bitcoind/managed-runtime/indexer-policy.js +200 -0
  8. package/dist/bitcoind/managed-runtime/status.d.ts +11 -0
  9. package/dist/bitcoind/managed-runtime/status.js +59 -0
  10. package/dist/bitcoind/managed-runtime/types.d.ts +37 -0
  11. package/dist/bitcoind/managed-runtime/types.js +1 -0
  12. package/dist/bitcoind/progress/tty-renderer.js +3 -2
  13. package/dist/bitcoind/service.d.ts +2 -7
  14. package/dist/bitcoind/service.js +46 -94
  15. package/dist/cli/command-registry.d.ts +39 -0
  16. package/dist/cli/command-registry.js +1132 -0
  17. package/dist/cli/commands/client-admin.js +6 -56
  18. package/dist/cli/commands/mining-admin.js +9 -32
  19. package/dist/cli/commands/mining-read.js +15 -56
  20. package/dist/cli/commands/mining-runtime.js +258 -57
  21. package/dist/cli/commands/service-runtime.js +1 -64
  22. package/dist/cli/commands/status.js +2 -15
  23. package/dist/cli/commands/update.js +6 -21
  24. package/dist/cli/commands/wallet-admin.js +18 -120
  25. package/dist/cli/commands/wallet-mutation.js +4 -7
  26. package/dist/cli/commands/wallet-read.js +31 -138
  27. package/dist/cli/context.js +2 -4
  28. package/dist/cli/mining-format.js +8 -2
  29. package/dist/cli/mutation-command-groups.d.ts +11 -11
  30. package/dist/cli/mutation-command-groups.js +9 -18
  31. package/dist/cli/mutation-json.d.ts +1 -17
  32. package/dist/cli/mutation-json.js +1 -28
  33. package/dist/cli/mutation-success.d.ts +0 -1
  34. package/dist/cli/mutation-success.js +0 -19
  35. package/dist/cli/output.d.ts +1 -10
  36. package/dist/cli/output.js +52 -481
  37. package/dist/cli/parse.d.ts +1 -1
  38. package/dist/cli/parse.js +38 -695
  39. package/dist/cli/runner.js +28 -113
  40. package/dist/cli/types.d.ts +7 -8
  41. package/dist/cli/update-notifier.js +1 -1
  42. package/dist/cli/wallet-format.js +1 -1
  43. package/dist/wallet/lifecycle/access.d.ts +5 -0
  44. package/dist/wallet/lifecycle/access.js +79 -0
  45. package/dist/wallet/lifecycle/context.d.ts +26 -0
  46. package/dist/wallet/lifecycle/context.js +58 -0
  47. package/dist/wallet/lifecycle/managed-core.d.ts +15 -0
  48. package/dist/wallet/lifecycle/managed-core.js +197 -0
  49. package/dist/wallet/lifecycle/repair-bitcoind.d.ts +10 -0
  50. package/dist/wallet/lifecycle/repair-bitcoind.js +142 -0
  51. package/dist/wallet/lifecycle/repair-indexer.d.ts +8 -0
  52. package/dist/wallet/lifecycle/repair-indexer.js +117 -0
  53. package/dist/wallet/lifecycle/repair-mining.d.ts +49 -0
  54. package/dist/wallet/lifecycle/repair-mining.js +304 -0
  55. package/dist/wallet/lifecycle/repair-runtime.d.ts +36 -0
  56. package/dist/wallet/lifecycle/repair-runtime.js +206 -0
  57. package/dist/wallet/lifecycle/repair.d.ts +9 -0
  58. package/dist/wallet/lifecycle/repair.js +127 -0
  59. package/dist/wallet/lifecycle/setup-prompts.d.ts +7 -0
  60. package/dist/wallet/lifecycle/setup-prompts.js +88 -0
  61. package/dist/wallet/lifecycle/setup-state.d.ts +26 -0
  62. package/dist/wallet/lifecycle/setup-state.js +159 -0
  63. package/dist/wallet/lifecycle/setup.d.ts +15 -0
  64. package/dist/wallet/lifecycle/setup.js +124 -0
  65. package/dist/wallet/lifecycle/types.d.ts +156 -0
  66. package/dist/wallet/lifecycle/types.js +1 -0
  67. package/dist/wallet/lifecycle.d.ts +4 -165
  68. package/dist/wallet/lifecycle.js +3 -1656
  69. package/dist/wallet/mining/candidate.d.ts +60 -0
  70. package/dist/wallet/mining/candidate.js +290 -0
  71. package/dist/wallet/mining/competitiveness.d.ts +22 -0
  72. package/dist/wallet/mining/competitiveness.js +640 -0
  73. package/dist/wallet/mining/control.js +7 -251
  74. package/dist/wallet/mining/cycle.d.ts +39 -0
  75. package/dist/wallet/mining/cycle.js +542 -0
  76. package/dist/wallet/mining/engine-state.d.ts +66 -0
  77. package/dist/wallet/mining/engine-state.js +211 -0
  78. package/dist/wallet/mining/engine-types.d.ts +173 -0
  79. package/dist/wallet/mining/engine-types.js +1 -0
  80. package/dist/wallet/mining/engine-utils.d.ts +7 -0
  81. package/dist/wallet/mining/engine-utils.js +75 -0
  82. package/dist/wallet/mining/events.d.ts +2 -0
  83. package/dist/wallet/mining/events.js +19 -0
  84. package/dist/wallet/mining/lifecycle.d.ts +71 -0
  85. package/dist/wallet/mining/lifecycle.js +355 -0
  86. package/dist/wallet/mining/projection.d.ts +61 -0
  87. package/dist/wallet/mining/projection.js +319 -0
  88. package/dist/wallet/mining/publish.d.ts +79 -0
  89. package/dist/wallet/mining/publish.js +614 -0
  90. package/dist/wallet/mining/runner.d.ts +12 -418
  91. package/dist/wallet/mining/runner.js +274 -3433
  92. package/dist/wallet/mining/supervisor.d.ts +134 -0
  93. package/dist/wallet/mining/supervisor.js +558 -0
  94. package/dist/wallet/mining/visualizer-sync.d.ts +42 -0
  95. package/dist/wallet/mining/visualizer-sync.js +166 -0
  96. package/dist/wallet/mining/visualizer.d.ts +1 -0
  97. package/dist/wallet/mining/visualizer.js +33 -18
  98. package/dist/wallet/read/context.js +13 -188
  99. package/dist/wallet/reset.d.ts +1 -1
  100. package/dist/wallet/reset.js +35 -11
  101. package/dist/wallet/runtime.d.ts +0 -6
  102. package/dist/wallet/runtime.js +2 -38
  103. package/dist/wallet/tx/common.d.ts +18 -0
  104. package/dist/wallet/tx/common.js +40 -26
  105. package/package.json +1 -1
  106. package/dist/wallet/state/seed-index.d.ts +0 -43
  107. package/dist/wallet/state/seed-index.js +0 -151
@@ -0,0 +1,319 @@
1
+ import { livePublishTargetsCandidateTip } from "./engine-state.js";
2
+ import { normalizeMiningPublishState, normalizeMiningStateRecord } from "./state.js";
3
+ import { MINING_WORKER_API_VERSION, MINING_WORKER_HEARTBEAT_STALE_MS, } from "./constants.js";
4
+ export function buildPrePublishStatusOverrides(options) {
5
+ const replacing = options.state.miningState.currentTxid !== null;
6
+ const replacingAcrossTips = replacing && !livePublishTargetsCandidateTip({
7
+ liveState: options.state.miningState,
8
+ candidate: options.candidate,
9
+ });
10
+ return {
11
+ currentPhase: replacing ? "replacing" : "publishing",
12
+ currentPublishDecision: replacing ? "replacing" : "publishing",
13
+ targetBlockHeight: options.candidate.targetBlockHeight,
14
+ referencedBlockHashDisplay: options.candidate.referencedBlockHashDisplay,
15
+ currentDomainId: options.candidate.domainId,
16
+ currentDomainName: options.candidate.domainName,
17
+ currentSentenceDisplay: options.candidate.sentence,
18
+ currentCanonicalBlend: options.candidate.canonicalBlend.toString(),
19
+ note: replacing
20
+ ? "Replacing the live mining transaction for the current tip."
21
+ : "Broadcasting the best mining candidate for the current tip.",
22
+ ...(replacingAcrossTips
23
+ ? {
24
+ currentPublishState: "none",
25
+ currentTxid: null,
26
+ currentWtxid: null,
27
+ livePublishInMempool: false,
28
+ currentFeeRateSatVb: null,
29
+ currentAbsoluteFeeSats: null,
30
+ currentBlockFeeSpentSats: "0",
31
+ }
32
+ : {}),
33
+ };
34
+ }
35
+ function resolveSnapshotOverride(override, fallback) {
36
+ return override === undefined ? fallback : override;
37
+ }
38
+ async function isProcessAlive(pid) {
39
+ if (pid === null) {
40
+ return false;
41
+ }
42
+ try {
43
+ process.kill(pid, 0);
44
+ return true;
45
+ }
46
+ catch (error) {
47
+ if (error instanceof Error && "code" in error && error.code === "ESRCH") {
48
+ return false;
49
+ }
50
+ return true;
51
+ }
52
+ }
53
+ function mapProviderState(provider, localState, existingRuntime) {
54
+ const miningState = localState.state?.miningState === undefined
55
+ ? null
56
+ : normalizeMiningStateRecord(localState.state.miningState);
57
+ if (existingRuntime?.currentPhase === "waiting-provider"
58
+ && existingRuntime.providerState !== null
59
+ && (miningState === null || miningState.state === "idle")) {
60
+ return existingRuntime.providerState;
61
+ }
62
+ if (miningState?.state === "paused" && miningState.pauseReason?.includes("rate-limit")) {
63
+ return "rate-limited";
64
+ }
65
+ if (miningState?.state === "paused" && miningState.pauseReason?.includes("auth")) {
66
+ return "auth-error";
67
+ }
68
+ if (miningState?.state === "paused" && miningState.pauseReason?.includes("provider")) {
69
+ return "backoff";
70
+ }
71
+ if (provider.status === "ready") {
72
+ return "ready";
73
+ }
74
+ return "unavailable";
75
+ }
76
+ function shouldReuseExistingProviderWait(options) {
77
+ return options.existingRuntime?.currentPhase === "waiting-provider"
78
+ && options.existingRuntime.providerState !== null
79
+ && (options.miningState === null || options.miningState.state === "idle");
80
+ }
81
+ function mapIndexerDaemonState(indexer) {
82
+ if (indexer.health === "wallet-root-mismatch") {
83
+ return "wallet-root-mismatch";
84
+ }
85
+ if (indexer.health === "service-version-mismatch") {
86
+ return "service-version-mismatch";
87
+ }
88
+ if (indexer.health === "schema-mismatch") {
89
+ return "schema-mismatch";
90
+ }
91
+ if (indexer.status !== null) {
92
+ switch (indexer.status.state) {
93
+ case "synced":
94
+ return indexer.health === "stale-heartbeat" ? "stale-heartbeat" : "synced";
95
+ case "catching-up":
96
+ return indexer.health === "stale-heartbeat" ? "stale-heartbeat" : "catching-up";
97
+ case "reorging":
98
+ return indexer.health === "stale-heartbeat" ? "stale-heartbeat" : "reorging";
99
+ case "starting":
100
+ case "stopping":
101
+ return indexer.health === "stale-heartbeat" ? "stale-heartbeat" : "starting";
102
+ case "failed":
103
+ return "failed";
104
+ case "schema-mismatch":
105
+ return "schema-mismatch";
106
+ case "service-version-mismatch":
107
+ return "service-version-mismatch";
108
+ default:
109
+ break;
110
+ }
111
+ }
112
+ switch (indexer.health) {
113
+ case "failed":
114
+ return "failed";
115
+ case "starting":
116
+ return "starting";
117
+ case "catching-up":
118
+ return "catching-up";
119
+ case "reorging":
120
+ return "reorging";
121
+ case "stale-heartbeat":
122
+ return "stale-heartbeat";
123
+ case "synced":
124
+ return "synced";
125
+ default:
126
+ return "unavailable";
127
+ }
128
+ }
129
+ function mapCorePublishState(nodeHealth, nodeStatus) {
130
+ if (nodeStatus === null || !nodeStatus.ready) {
131
+ return "unknown";
132
+ }
133
+ if (nodeHealth === "catching-up") {
134
+ return "ibd";
135
+ }
136
+ return "healthy";
137
+ }
138
+ async function deriveBackgroundWorkerHealth(options) {
139
+ const runtime = options.runtime;
140
+ if (runtime?.runMode !== "background") {
141
+ return null;
142
+ }
143
+ if (runtime.walletRootId !== null
144
+ && options.localState.walletRootId !== null
145
+ && runtime.walletRootId !== options.localState.walletRootId) {
146
+ return "version-mismatch";
147
+ }
148
+ if (runtime.workerApiVersion !== null && runtime.workerApiVersion !== MINING_WORKER_API_VERSION) {
149
+ return "version-mismatch";
150
+ }
151
+ if (!await isProcessAlive(runtime.backgroundWorkerPid)) {
152
+ return "stale-pid";
153
+ }
154
+ if (runtime.backgroundWorkerHeartbeatAtUnixMs === null
155
+ || (options.nowUnixMs - runtime.backgroundWorkerHeartbeatAtUnixMs) > MINING_WORKER_HEARTBEAT_STALE_MS) {
156
+ return "stale-heartbeat";
157
+ }
158
+ return "healthy";
159
+ }
160
+ export async function buildMiningRuntimeStatusSnapshot(options) {
161
+ const state = options.localState.state?.miningState === undefined
162
+ ? null
163
+ : normalizeMiningStateRecord(options.localState.state.miningState);
164
+ const backgroundWorkerHealth = await deriveBackgroundWorkerHealth({
165
+ runtime: options.existingRuntime,
166
+ localState: options.localState,
167
+ nowUnixMs: options.nowUnixMs,
168
+ });
169
+ const providerState = mapProviderState(options.provider, options.localState, options.existingRuntime);
170
+ const indexerDaemonState = mapIndexerDaemonState(options.indexer);
171
+ const corePublishState = mapCorePublishState(options.nodeHealth, options.nodeStatus);
172
+ const existing = options.existingRuntime;
173
+ const reuseExistingProviderWait = shouldReuseExistingProviderWait({
174
+ existingRuntime: existing,
175
+ miningState: state,
176
+ });
177
+ void options.bitcoind;
178
+ return {
179
+ schemaVersion: 1,
180
+ walletRootId: options.localState.walletRootId,
181
+ workerApiVersion: existing?.workerApiVersion ?? null,
182
+ workerBinaryVersion: existing?.workerBinaryVersion ?? null,
183
+ workerBuildId: existing?.workerBuildId ?? null,
184
+ updatedAtUnixMs: options.nowUnixMs,
185
+ runMode: state?.runMode ?? existing?.runMode ?? "stopped",
186
+ backgroundWorkerPid: existing?.backgroundWorkerPid ?? null,
187
+ backgroundWorkerRunId: existing?.backgroundWorkerRunId ?? null,
188
+ backgroundWorkerHeartbeatAtUnixMs: existing?.backgroundWorkerHeartbeatAtUnixMs ?? null,
189
+ backgroundWorkerHealth,
190
+ indexerDaemonState,
191
+ indexerDaemonInstanceId: options.indexer.daemonInstanceId ?? null,
192
+ indexerSnapshotSeq: options.indexer.snapshotSeq ?? null,
193
+ indexerSnapshotOpenedAtUnixMs: options.indexer.openedAtUnixMs ?? null,
194
+ indexerTruthSource: options.indexer.source ?? "none",
195
+ indexerHeartbeatAtUnixMs: options.indexer.status?.heartbeatAtUnixMs ?? null,
196
+ coreBestHeight: options.nodeStatus?.nodeBestHeight ?? options.indexer.status?.coreBestHeight ?? existing?.coreBestHeight ?? null,
197
+ coreBestHash: options.nodeStatus?.nodeBestHashHex ?? options.indexer.status?.coreBestHash ?? existing?.coreBestHash ?? null,
198
+ indexerTipHeight: options.indexer.snapshotTip?.height ?? options.indexer.status?.appliedTipHeight ?? null,
199
+ indexerTipHash: options.indexer.snapshotTip?.blockHashHex ?? options.indexer.status?.appliedTipHash ?? null,
200
+ indexerReorgDepth: options.indexer.status?.reorgDepth ?? null,
201
+ indexerTipAligned: options.tipsAligned,
202
+ corePublishState,
203
+ providerState,
204
+ lastSuspendDetectedAtUnixMs: existing?.lastSuspendDetectedAtUnixMs ?? null,
205
+ reconnectSettledUntilUnixMs: existing?.reconnectSettledUntilUnixMs ?? null,
206
+ tipSettledUntilUnixMs: existing?.tipSettledUntilUnixMs ?? null,
207
+ miningState: state?.state ?? existing?.miningState ?? "idle",
208
+ currentPhase: existing?.currentPhase ?? "idle",
209
+ currentPublishState: normalizeMiningPublishState(state?.currentPublishState ?? options.existingRuntime?.currentPublishState ?? "none"),
210
+ targetBlockHeight: state?.currentBlockTargetHeight ?? existing?.targetBlockHeight ?? null,
211
+ referencedBlockHashDisplay: state?.currentReferencedBlockHashDisplay ?? existing?.referencedBlockHashDisplay ?? null,
212
+ currentDomainId: state?.currentDomainId ?? existing?.currentDomainId ?? null,
213
+ currentDomainName: state?.currentDomain ?? existing?.currentDomainName ?? null,
214
+ currentSentenceDisplay: state?.currentSentence ?? existing?.currentSentenceDisplay ?? null,
215
+ currentCanonicalBlend: state?.currentScore ?? existing?.currentCanonicalBlend ?? null,
216
+ currentTxid: state?.currentTxid ?? existing?.currentTxid ?? null,
217
+ currentWtxid: state?.currentWtxid ?? existing?.currentWtxid ?? null,
218
+ livePublishInMempool: state?.livePublishInMempool ?? existing?.livePublishInMempool ?? null,
219
+ currentFeeRateSatVb: state?.currentFeeRateSatVb ?? existing?.currentFeeRateSatVb ?? null,
220
+ currentAbsoluteFeeSats: state?.currentAbsoluteFeeSats ?? existing?.currentAbsoluteFeeSats ?? null,
221
+ currentBlockFeeSpentSats: state?.currentBlockFeeSpentSats ?? existing?.currentBlockFeeSpentSats ?? "0",
222
+ sessionFeeSpentSats: state?.sessionFeeSpentSats ?? existing?.sessionFeeSpentSats ?? "0",
223
+ lifetimeFeeSpentSats: state?.lifetimeFeeSpentSats ?? existing?.lifetimeFeeSpentSats ?? "0",
224
+ sameDomainCompetitorSuppressed: existing?.sameDomainCompetitorSuppressed ?? null,
225
+ higherRankedCompetitorDomainCount: existing?.higherRankedCompetitorDomainCount ?? null,
226
+ dedupedCompetitorDomainCount: existing?.dedupedCompetitorDomainCount ?? null,
227
+ competitivenessGateIndeterminate: existing?.competitivenessGateIndeterminate ?? null,
228
+ mempoolSequenceCacheStatus: existing?.mempoolSequenceCacheStatus ?? null,
229
+ currentPublishDecision: state?.currentPublishDecision ?? existing?.currentPublishDecision ?? null,
230
+ lastMempoolSequence: existing?.lastMempoolSequence ?? null,
231
+ lastCompetitivenessGateAtUnixMs: existing?.lastCompetitivenessGateAtUnixMs ?? null,
232
+ pauseReason: state?.pauseReason ?? options.existingRuntime?.pauseReason ?? null,
233
+ providerConfigured: options.provider.configured,
234
+ providerKind: options.provider.provider,
235
+ bitcoindHealth: options.bitcoind.health,
236
+ bitcoindServiceState: options.nodeStatus?.serviceStatus?.state ?? null,
237
+ bitcoindReplicaStatus: options.nodeStatus?.walletReplica?.proofStatus ?? null,
238
+ nodeHealth: options.nodeHealth,
239
+ indexerHealth: options.indexer.health,
240
+ tipsAligned: options.tipsAligned,
241
+ lastEventAtUnixMs: options.lastEventAtUnixMs,
242
+ lastError: reuseExistingProviderWait
243
+ ? existing?.lastError ?? null
244
+ : existing?.currentPhase === "waiting-bitcoin-network" || existing?.currentPhase === "waiting-indexer"
245
+ ? existing?.lastError ?? options.provider.message ?? options.indexer.message ?? null
246
+ : options.provider.message ?? options.indexer.message ?? null,
247
+ note: state?.pauseReason === "zero-reward"
248
+ ? "Mining is disabled because the target block reward is zero."
249
+ : existing?.currentPhase === "resuming"
250
+ ? "Mining discarded stale in-flight work after a large local runtime gap and is rechecking health."
251
+ : reuseExistingProviderWait
252
+ ? "Mining is waiting for the sentence provider to recover."
253
+ : existing?.currentPhase === "waiting-indexer"
254
+ ? "Mining is waiting for Bitcoin Core and the indexer to align."
255
+ : existing?.currentPhase === "waiting-bitcoin-network"
256
+ ? "Mining is waiting for the local Bitcoin node to become publishable."
257
+ : state?.state === "repair-required"
258
+ ? "Mining is blocked until the current mining publish is reconciled or `cogcoin repair` completes."
259
+ : state?.state === "paused-stale" && state.livePublishInMempool
260
+ ? "A previously broadcast mining transaction is still in mempool for an older tip context. Wait for confirmation or rerun mining to replace it."
261
+ : state?.state === "paused" && state.livePublishInMempool
262
+ ? "Mining is paused, but the last mining transaction may still confirm from mempool without further fee bumps."
263
+ : state?.state === "paused"
264
+ ? "Mining is paused by another wallet command or local policy."
265
+ : options.provider.status === "missing"
266
+ ? "Run `cogcoin mine setup` to configure the built-in mining provider."
267
+ : options.indexer.health === "reorging"
268
+ ? "Mining remains stopped while the indexer replays a reorg and refreshes the coherent snapshot."
269
+ : options.indexer.health !== "synced" || options.nodeHealth !== "synced"
270
+ ? "Mining remains stopped until Bitcoin Core and the indexer are both healthy and aligned."
271
+ : null,
272
+ };
273
+ }
274
+ export function applyMiningRuntimeStatusOverrides(options) {
275
+ const overrides = options.overrides ?? {};
276
+ const resolvedCurrentPhase = resolveSnapshotOverride(overrides.currentPhase, options.runtime.currentPhase);
277
+ const clearProviderWaitCarryover = overrides.currentPhase !== undefined
278
+ && overrides.currentPhase !== "waiting-provider"
279
+ && options.runtime.currentPhase === "waiting-provider";
280
+ return {
281
+ ...options.runtime,
282
+ runMode: resolveSnapshotOverride(overrides.runMode, options.runtime.runMode),
283
+ backgroundWorkerPid: resolveSnapshotOverride(overrides.backgroundWorkerPid, options.runtime.backgroundWorkerPid),
284
+ backgroundWorkerRunId: resolveSnapshotOverride(overrides.backgroundWorkerRunId, options.runtime.backgroundWorkerRunId),
285
+ backgroundWorkerHeartbeatAtUnixMs: resolveSnapshotOverride(overrides.backgroundWorkerHeartbeatAtUnixMs, options.runtime.backgroundWorkerHeartbeatAtUnixMs),
286
+ currentPhase: resolvedCurrentPhase,
287
+ currentPublishState: resolveSnapshotOverride(overrides.currentPublishState, options.runtime.currentPublishState),
288
+ targetBlockHeight: resolveSnapshotOverride(overrides.targetBlockHeight, options.runtime.targetBlockHeight),
289
+ referencedBlockHashDisplay: resolveSnapshotOverride(overrides.referencedBlockHashDisplay, options.runtime.referencedBlockHashDisplay),
290
+ currentDomainId: resolveSnapshotOverride(overrides.currentDomainId, options.runtime.currentDomainId),
291
+ currentDomainName: resolveSnapshotOverride(overrides.currentDomainName, options.runtime.currentDomainName),
292
+ currentSentenceDisplay: resolveSnapshotOverride(overrides.currentSentenceDisplay, options.runtime.currentSentenceDisplay),
293
+ currentCanonicalBlend: resolveSnapshotOverride(overrides.currentCanonicalBlend, options.runtime.currentCanonicalBlend),
294
+ currentTxid: resolveSnapshotOverride(overrides.currentTxid, options.runtime.currentTxid),
295
+ currentWtxid: resolveSnapshotOverride(overrides.currentWtxid, options.runtime.currentWtxid),
296
+ currentFeeRateSatVb: resolveSnapshotOverride(overrides.currentFeeRateSatVb, options.runtime.currentFeeRateSatVb),
297
+ currentAbsoluteFeeSats: resolveSnapshotOverride(overrides.currentAbsoluteFeeSats, options.runtime.currentAbsoluteFeeSats),
298
+ currentBlockFeeSpentSats: resolveSnapshotOverride(overrides.currentBlockFeeSpentSats, options.runtime.currentBlockFeeSpentSats),
299
+ lastSuspendDetectedAtUnixMs: resolveSnapshotOverride(overrides.lastSuspendDetectedAtUnixMs, options.runtime.lastSuspendDetectedAtUnixMs),
300
+ reconnectSettledUntilUnixMs: resolveSnapshotOverride(overrides.reconnectSettledUntilUnixMs, options.runtime.reconnectSettledUntilUnixMs),
301
+ tipSettledUntilUnixMs: resolveSnapshotOverride(overrides.tipSettledUntilUnixMs, options.runtime.tipSettledUntilUnixMs),
302
+ providerState: resolveSnapshotOverride(overrides.providerState, clearProviderWaitCarryover
303
+ ? (options.provider.status === "ready" ? "ready" : "unavailable")
304
+ : options.runtime.providerState),
305
+ corePublishState: resolveSnapshotOverride(overrides.corePublishState, options.runtime.corePublishState),
306
+ currentPublishDecision: resolveSnapshotOverride(overrides.currentPublishDecision, options.runtime.currentPublishDecision),
307
+ sameDomainCompetitorSuppressed: resolveSnapshotOverride(overrides.sameDomainCompetitorSuppressed, options.runtime.sameDomainCompetitorSuppressed),
308
+ higherRankedCompetitorDomainCount: resolveSnapshotOverride(overrides.higherRankedCompetitorDomainCount, options.runtime.higherRankedCompetitorDomainCount),
309
+ dedupedCompetitorDomainCount: resolveSnapshotOverride(overrides.dedupedCompetitorDomainCount, options.runtime.dedupedCompetitorDomainCount),
310
+ competitivenessGateIndeterminate: resolveSnapshotOverride(overrides.competitivenessGateIndeterminate, options.runtime.competitivenessGateIndeterminate),
311
+ mempoolSequenceCacheStatus: resolveSnapshotOverride(overrides.mempoolSequenceCacheStatus, options.runtime.mempoolSequenceCacheStatus),
312
+ lastMempoolSequence: resolveSnapshotOverride(overrides.lastMempoolSequence, options.runtime.lastMempoolSequence),
313
+ lastCompetitivenessGateAtUnixMs: resolveSnapshotOverride(overrides.lastCompetitivenessGateAtUnixMs, options.runtime.lastCompetitivenessGateAtUnixMs),
314
+ lastError: resolveSnapshotOverride(overrides.lastError, clearProviderWaitCarryover ? null : options.runtime.lastError),
315
+ note: resolveSnapshotOverride(overrides.note, clearProviderWaitCarryover ? null : options.runtime.note),
316
+ livePublishInMempool: resolveSnapshotOverride(overrides.livePublishInMempool, options.runtime.livePublishInMempool),
317
+ updatedAtUnixMs: options.nowUnixMs ?? Date.now(),
318
+ };
319
+ }
@@ -0,0 +1,79 @@
1
+ import { createRpcClient } from "../../bitcoind/node.js";
2
+ import { openWalletReadContext, type WalletReadContext } from "../read/index.js";
3
+ import type { WalletRuntimePaths } from "../runtime.js";
4
+ import type { WalletSecretProvider } from "../state/provider.js";
5
+ import type { OutpointRecord, WalletStateV1 } from "../types.js";
6
+ import { type MiningCandidate, type MiningMutationPlan, type MiningPublishOutcome, type MiningRpcClient, type ReadyMiningReadContext } from "./engine-types.js";
7
+ import { type MiningEligibleAnchoredRoot } from "./candidate.js";
8
+ import type { MiningEventRecord } from "./types.js";
9
+ import type { MiningRecentWinSummary } from "./visualizer.js";
10
+ import { attachOrStartManagedBitcoindService } from "../../bitcoind/service.js";
11
+ export declare class MiningPublishRejectedError extends Error {
12
+ readonly revertedState: WalletStateV1;
13
+ constructor(message: string, revertedState: WalletStateV1);
14
+ }
15
+ export declare function createStaleMiningCandidateWaitingNote(): string;
16
+ export declare function createRetryableMiningPublishWaitingNote(): string;
17
+ export declare function createInsufficientFundsMiningPublishWaitingNote(): string;
18
+ export declare function createInsufficientFundsMiningPublishErrorMessage(): string;
19
+ export declare function resolveMiningConflictOutpoint(options: {
20
+ state: WalletStateV1;
21
+ allUtxos: Awaited<ReturnType<MiningRpcClient["listUnspent"]>>;
22
+ }): OutpointRecord | null;
23
+ export declare function createMiningPlan(options: {
24
+ state: WalletStateV1;
25
+ candidate: MiningCandidate;
26
+ conflictOutpoint: OutpointRecord | null;
27
+ allUtxos: Awaited<ReturnType<MiningRpcClient["listUnspent"]>>;
28
+ feeRateSatVb: number;
29
+ }): MiningMutationPlan;
30
+ export declare function validateMiningDraft(decoded: Awaited<ReturnType<MiningRpcClient["decodePsbt"]>>, funded: Awaited<ReturnType<MiningRpcClient["walletCreateFundedPsbt"]>>, plan: MiningMutationPlan): void;
31
+ export declare function probeMiningFundingAvailability(options: {
32
+ rpc: MiningRpcClient;
33
+ walletName: string;
34
+ state: WalletStateV1;
35
+ domains: MiningEligibleAnchoredRoot[];
36
+ referencedBlockHashDisplay: string;
37
+ targetBlockHeight: number;
38
+ }): Promise<void>;
39
+ export declare function reconcileLiveMiningState(options: {
40
+ state: WalletStateV1;
41
+ rpc: MiningRpcClient;
42
+ nodeBestHash: string | null;
43
+ nodeBestHeight: number | null;
44
+ snapshotState?: NonNullable<WalletReadContext["snapshot"]>["state"] | null;
45
+ }): Promise<{
46
+ state: WalletStateV1;
47
+ recentWin: MiningRecentWinSummary | null;
48
+ }>;
49
+ export declare function publishCandidateOnce(options: {
50
+ readContext: ReadyMiningReadContext;
51
+ candidate: MiningCandidate;
52
+ dataDir: string;
53
+ provider: WalletSecretProvider;
54
+ paths: WalletRuntimePaths;
55
+ attachService: typeof attachOrStartManagedBitcoindService;
56
+ rpcFactory: (config: Parameters<typeof createRpcClient>[0]) => MiningRpcClient;
57
+ runId: string | null;
58
+ appendEventFn?: AppendMiningEventFn;
59
+ }): Promise<{
60
+ state: WalletStateV1;
61
+ txid: string | null;
62
+ decision: string;
63
+ }>;
64
+ type AppendMiningEventFn = (paths: WalletRuntimePaths, event: MiningEventRecord) => Promise<void>;
65
+ export declare function publishCandidate(options: {
66
+ candidate: MiningCandidate;
67
+ dataDir: string;
68
+ databasePath: string;
69
+ provider: WalletSecretProvider;
70
+ paths: WalletRuntimePaths;
71
+ fallbackState: WalletStateV1;
72
+ openReadContext: typeof openWalletReadContext;
73
+ attachService: typeof attachOrStartManagedBitcoindService;
74
+ rpcFactory: (config: Parameters<typeof createRpcClient>[0]) => MiningRpcClient;
75
+ runId: string | null;
76
+ publishAttempt?: typeof publishCandidateOnce;
77
+ appendEventFn: AppendMiningEventFn;
78
+ }): Promise<MiningPublishOutcome>;
79
+ export {};