@cogcoin/client 1.0.0 → 1.0.2

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 (56) hide show
  1. package/README.md +2 -1
  2. package/dist/bitcoind/indexer-daemon.d.ts +3 -0
  3. package/dist/bitcoind/indexer-daemon.js +58 -8
  4. package/dist/bitcoind/retryable-rpc.js +3 -0
  5. package/dist/bitcoind/service.d.ts +1 -0
  6. package/dist/bitcoind/service.js +31 -9
  7. package/dist/cli/commands/mining-admin.js +9 -0
  8. package/dist/cli/commands/mining-runtime.js +114 -12
  9. package/dist/cli/commands/sync.js +1 -91
  10. package/dist/cli/commands/update.d.ts +2 -0
  11. package/dist/cli/commands/update.js +101 -0
  12. package/dist/cli/context.js +33 -1
  13. package/dist/cli/mining-format.js +28 -0
  14. package/dist/cli/mining-json.js +6 -0
  15. package/dist/cli/output.js +50 -2
  16. package/dist/cli/parse.d.ts +1 -1
  17. package/dist/cli/parse.js +5 -0
  18. package/dist/cli/prompt.js +109 -0
  19. package/dist/cli/read-json.d.ts +13 -0
  20. package/dist/cli/read-json.js +17 -0
  21. package/dist/cli/runner.js +4 -0
  22. package/dist/cli/sync-progress.d.ts +6 -0
  23. package/dist/cli/sync-progress.js +91 -0
  24. package/dist/cli/types.d.ts +8 -2
  25. package/dist/cli/update-notifier.js +7 -222
  26. package/dist/cli/update-service.d.ts +44 -0
  27. package/dist/cli/update-service.js +218 -0
  28. package/dist/cli/wallet-format.js +3 -0
  29. package/dist/client/initialization.js +5 -0
  30. package/dist/wallet/lifecycle.d.ts +10 -0
  31. package/dist/wallet/lifecycle.js +6 -0
  32. package/dist/wallet/mining/config.js +13 -3
  33. package/dist/wallet/mining/control.d.ts +2 -1
  34. package/dist/wallet/mining/control.js +143 -19
  35. package/dist/wallet/mining/index.d.ts +2 -2
  36. package/dist/wallet/mining/index.js +1 -1
  37. package/dist/wallet/mining/provider-model.d.ts +30 -0
  38. package/dist/wallet/mining/provider-model.js +134 -0
  39. package/dist/wallet/mining/runner.d.ts +105 -3
  40. package/dist/wallet/mining/runner.js +490 -88
  41. package/dist/wallet/mining/runtime-artifacts.js +1 -0
  42. package/dist/wallet/mining/sentences.d.ts +2 -2
  43. package/dist/wallet/mining/sentences.js +25 -2
  44. package/dist/wallet/mining/types.d.ts +9 -1
  45. package/dist/wallet/mining/visualizer.js +28 -5
  46. package/dist/wallet/read/context.js +3 -0
  47. package/dist/wallet/reset.js +1 -0
  48. package/dist/wallet/tx/anchor.js +1 -0
  49. package/dist/wallet/tx/bitcoin-transfer.js +1 -0
  50. package/dist/wallet/tx/cog.js +3 -0
  51. package/dist/wallet/tx/domain-admin.js +1 -0
  52. package/dist/wallet/tx/domain-market.js +3 -0
  53. package/dist/wallet/tx/field.js +1 -0
  54. package/dist/wallet/tx/register.js +1 -0
  55. package/dist/wallet/tx/reputation.js +1 -0
  56. package/package.json +3 -2
@@ -1,14 +1,17 @@
1
+ import { spawn } from "node:child_process";
1
2
  import { attachOrStartManagedBitcoindService } from "../../bitcoind/service.js";
2
3
  import { createRpcClient } from "../../bitcoind/node.js";
3
4
  import type { ProgressOutputMode } from "../../bitcoind/types.js";
4
5
  import { type FixedWalletInput, type MutationSender, type WalletMutationRpcClient } from "../tx/common.js";
6
+ import { readLockMetadata } from "../fs/lock.js";
5
7
  import type { WalletPrompter } from "../lifecycle.js";
6
8
  import { openWalletReadContext, type WalletReadContext } from "../read/index.js";
7
9
  import { type WalletRuntimePaths } from "../runtime.js";
8
10
  import { type WalletSecretProvider } from "../state/provider.js";
9
11
  import type { MiningStateRecord, OutpointRecord, WalletStateV1 } from "../types.js";
10
- import type { MiningEventRecord, MiningRuntimeStatusV1 } from "./types.js";
11
- import { type MiningFollowVisualizerState, type MiningSentenceBoardEntry } from "./visualizer.js";
12
+ import { requestMiningGenerationPreemption } from "./coordination.js";
13
+ import type { MiningControlPlaneView, MiningEventRecord, MiningRuntimeStatusV1 } from "./types.js";
14
+ import { type MiningFollowVisualizerState, type MiningSentenceBoardEntry, MiningFollowVisualizer } from "./visualizer.js";
12
15
  type MiningRpcClient = WalletMutationRpcClient & {
13
16
  getBlockchainInfo(): Promise<{
14
17
  blocks: number;
@@ -72,6 +75,39 @@ type MiningRpcClient = WalletMutationRpcClient & {
72
75
  sendRawTransaction(hex: string): Promise<string>;
73
76
  saveMempool?(): Promise<null>;
74
77
  };
78
+ interface MiningRunnerStatusOverrides {
79
+ runMode?: MiningRuntimeStatusV1["runMode"];
80
+ backgroundWorkerPid?: number | null;
81
+ backgroundWorkerRunId?: string | null;
82
+ backgroundWorkerHeartbeatAtUnixMs?: number | null;
83
+ currentPhase?: MiningRuntimeStatusV1["currentPhase"];
84
+ currentPublishState?: MiningRuntimeStatusV1["currentPublishState"];
85
+ targetBlockHeight?: number | null;
86
+ referencedBlockHashDisplay?: string | null;
87
+ currentDomainId?: number | null;
88
+ currentDomainName?: string | null;
89
+ currentSentenceDisplay?: string | null;
90
+ currentCanonicalBlend?: string | null;
91
+ currentTxid?: string | null;
92
+ currentWtxid?: string | null;
93
+ currentFeeRateSatVb?: number | null;
94
+ currentAbsoluteFeeSats?: number | null;
95
+ currentBlockFeeSpentSats?: string;
96
+ lastSuspendDetectedAtUnixMs?: number | null;
97
+ providerState?: MiningRuntimeStatusV1["providerState"];
98
+ corePublishState?: MiningRuntimeStatusV1["corePublishState"];
99
+ currentPublishDecision?: string | null;
100
+ sameDomainCompetitorSuppressed?: boolean | null;
101
+ higherRankedCompetitorDomainCount?: number | null;
102
+ dedupedCompetitorDomainCount?: number | null;
103
+ competitivenessGateIndeterminate?: boolean | null;
104
+ mempoolSequenceCacheStatus?: MiningRuntimeStatusV1["mempoolSequenceCacheStatus"];
105
+ lastMempoolSequence?: string | null;
106
+ lastCompetitivenessGateAtUnixMs?: number | null;
107
+ lastError?: string | null;
108
+ note?: string | null;
109
+ livePublishInMempool?: boolean | null;
110
+ }
75
111
  interface MiningCandidate {
76
112
  domainId: number;
77
113
  domainName: string;
@@ -97,8 +133,9 @@ type ReadyMiningReadContext = WalletReadContext & {
97
133
  interface MiningPublishSkipResult {
98
134
  state: WalletStateV1;
99
135
  txid: null;
100
- decision: "publish-skipped-stale-candidate";
136
+ decision: "publish-skipped-stale-candidate" | "publish-paused-insufficient-funds";
101
137
  note: string;
138
+ lastError?: string | null;
102
139
  skipped: true;
103
140
  retryable?: false;
104
141
  candidate: null;
@@ -123,6 +160,13 @@ interface RunnerDependencies {
123
160
  attachService?: typeof attachOrStartManagedBitcoindService;
124
161
  rpcFactory?: (config: Parameters<typeof createRpcClient>[0]) => MiningRpcClient;
125
162
  fetchImpl?: typeof fetch;
163
+ requestMiningPreemption?: typeof requestMiningGenerationPreemption;
164
+ runMiningLoopImpl?: typeof runMiningLoop;
165
+ saveStopSnapshotImpl?: typeof saveStopSnapshot;
166
+ spawnWorkerProcess?: typeof spawn;
167
+ waitForBackgroundHealthyImpl?: typeof waitForBackgroundHealthy;
168
+ shutdownGraceMs?: number;
169
+ sleepImpl?: typeof sleep;
126
170
  }
127
171
  interface MiningLoopState {
128
172
  attemptedTipKey: string | null;
@@ -137,6 +181,7 @@ export interface RunForegroundMiningOptions extends RunnerDependencies {
137
181
  databasePath: string;
138
182
  provider?: WalletSecretProvider;
139
183
  prompter: WalletPrompter;
184
+ builtInSetupEnsured?: boolean;
140
185
  stdout?: {
141
186
  write(chunk: string): void;
142
187
  };
@@ -154,6 +199,7 @@ export interface StartBackgroundMiningOptions extends RunnerDependencies {
154
199
  databasePath: string;
155
200
  provider?: WalletSecretProvider;
156
201
  prompter: WalletPrompter;
202
+ builtInSetupEnsured?: boolean;
157
203
  paths?: WalletRuntimePaths;
158
204
  }
159
205
  export interface StopBackgroundMiningOptions extends RunnerDependencies {
@@ -166,6 +212,13 @@ export interface MiningStartResult {
166
212
  started: boolean;
167
213
  snapshot: MiningRuntimeStatusV1 | null;
168
214
  }
215
+ interface MiningRuntimeTakeoverResult {
216
+ controlLockCleared: boolean;
217
+ replaced: boolean;
218
+ snapshot: MiningRuntimeStatusV1 | null;
219
+ terminatedPids: number[];
220
+ }
221
+ declare function sleep(ms: number, signal?: AbortSignal): Promise<void>;
169
222
  export declare function createMiningLoopStateForTesting(): MiningLoopState;
170
223
  export declare function resetMiningUiForTipForTesting(loopState: MiningLoopState, targetBlockHeight: number | null): void;
171
224
  export declare function resolveSettledBoardForTesting(options: {
@@ -276,6 +329,40 @@ export declare function publishCandidateForTesting(options: {
276
329
  publishAttempt?: typeof publishCandidateOnce;
277
330
  appendEventFn?: typeof appendEvent;
278
331
  }): Promise<MiningPublishOutcome>;
332
+ export declare function ensureBuiltInMiningSetupIfNeeded(options: {
333
+ provider: WalletSecretProvider;
334
+ prompter: WalletPrompter;
335
+ paths: WalletRuntimePaths;
336
+ }): Promise<boolean>;
337
+ declare function saveStopSnapshot(options: {
338
+ dataDir: string;
339
+ databasePath: string;
340
+ provider: WalletSecretProvider;
341
+ paths: WalletRuntimePaths;
342
+ runMode: "foreground" | "background";
343
+ backgroundWorkerPid: number | null;
344
+ backgroundWorkerRunId: string | null;
345
+ note: string | null;
346
+ }): Promise<void>;
347
+ declare function runMiningLoop(options: {
348
+ dataDir: string;
349
+ databasePath: string;
350
+ provider: WalletSecretProvider;
351
+ paths: WalletRuntimePaths;
352
+ runMode: "foreground" | "background";
353
+ backgroundWorkerPid: number | null;
354
+ backgroundWorkerRunId: string | null;
355
+ signal?: AbortSignal;
356
+ fetchImpl?: typeof fetch;
357
+ openReadContext: typeof openWalletReadContext;
358
+ attachService: typeof attachOrStartManagedBitcoindService;
359
+ rpcFactory: (config: Parameters<typeof createRpcClient>[0]) => MiningRpcClient;
360
+ stdout?: {
361
+ write(chunk: string): void;
362
+ };
363
+ visualizer?: MiningFollowVisualizer;
364
+ }): Promise<void>;
365
+ declare function waitForBackgroundHealthy(paths: WalletRuntimePaths): Promise<MiningRuntimeStatusV1 | null>;
279
366
  export declare function runForegroundMining(options: RunForegroundMiningOptions): Promise<void>;
280
367
  export declare function startBackgroundMining(options: StartBackgroundMiningOptions): Promise<MiningStartResult>;
281
368
  export declare function stopBackgroundMining(options: StopBackgroundMiningOptions): Promise<MiningRuntimeStatusV1 | null>;
@@ -296,7 +383,17 @@ export declare function handleDetectedMiningRuntimeResumeForTesting(options: {
296
383
  backgroundWorkerRunId: string | null;
297
384
  detectedAtUnixMs: number;
298
385
  openReadContext: typeof openWalletReadContext;
386
+ visualizer?: MiningFollowVisualizer;
299
387
  }): Promise<void>;
388
+ export declare function takeOverMiningRuntimeForTesting(options: {
389
+ paths: WalletRuntimePaths;
390
+ reason: string;
391
+ clearControlLockFile?: boolean;
392
+ controlLockMetadata?: Awaited<ReturnType<typeof readLockMetadata>>;
393
+ requestMiningPreemption?: typeof requestMiningGenerationPreemption;
394
+ shutdownGraceMs?: number;
395
+ sleepImpl?: typeof sleep;
396
+ }): Promise<MiningRuntimeTakeoverResult>;
300
397
  export declare function performMiningCycleForTesting(options: {
301
398
  dataDir: string;
302
399
  databasePath: string;
@@ -315,6 +412,11 @@ export declare function performMiningCycleForTesting(options: {
315
412
  };
316
413
  loopState?: MiningLoopState;
317
414
  }): Promise<void>;
415
+ export declare function buildPrePublishStatusOverridesForTesting(options: {
416
+ state: WalletStateV1;
417
+ candidate: MiningCandidate;
418
+ }): MiningRunnerStatusOverrides;
419
+ export declare function buildStatusSnapshotForTesting(view: MiningControlPlaneView, overrides?: MiningRunnerStatusOverrides): MiningRuntimeStatusV1;
318
420
  export declare function shouldKeepCurrentTipLivePublishForTesting(options: {
319
421
  liveState: MiningStateRecord;
320
422
  candidate: {