@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.
Files changed (289) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +136 -0
  3. package/dist/app-paths.d.ts +38 -0
  4. package/dist/app-paths.js +121 -0
  5. package/dist/art/banner.txt +13 -0
  6. package/dist/art/scroll.txt +13 -0
  7. package/dist/art/train-car.txt +6 -0
  8. package/dist/art/train-smoke.txt +6 -0
  9. package/dist/art/train.txt +6 -0
  10. package/dist/bitcoind/bootstrap/chainstate.d.ts +4 -0
  11. package/dist/bitcoind/bootstrap/chainstate.js +13 -0
  12. package/dist/bitcoind/bootstrap/constants.d.ts +7 -0
  13. package/dist/bitcoind/bootstrap/constants.js +12 -0
  14. package/dist/bitcoind/bootstrap/controller.d.ts +29 -0
  15. package/dist/bitcoind/bootstrap/controller.js +101 -0
  16. package/dist/bitcoind/bootstrap/download.d.ts +2 -0
  17. package/dist/bitcoind/bootstrap/download.js +196 -0
  18. package/dist/bitcoind/bootstrap/headers.d.ts +13 -0
  19. package/dist/bitcoind/bootstrap/headers.js +61 -0
  20. package/dist/bitcoind/bootstrap/paths.d.ts +4 -0
  21. package/dist/bitcoind/bootstrap/paths.js +15 -0
  22. package/dist/bitcoind/bootstrap/snapshot-file.d.ts +7 -0
  23. package/dist/bitcoind/bootstrap/snapshot-file.js +42 -0
  24. package/dist/bitcoind/bootstrap/state.d.ts +40 -0
  25. package/dist/bitcoind/bootstrap/state.js +70 -0
  26. package/dist/bitcoind/bootstrap/types.d.ts +28 -0
  27. package/dist/bitcoind/bootstrap/types.js +1 -0
  28. package/dist/bitcoind/bootstrap.d.ts +8 -0
  29. package/dist/bitcoind/bootstrap.js +7 -0
  30. package/dist/bitcoind/client/factory.d.ts +3 -0
  31. package/dist/bitcoind/client/factory.js +57 -0
  32. package/dist/bitcoind/client/follow-block-times.d.ts +8 -0
  33. package/dist/bitcoind/client/follow-block-times.js +25 -0
  34. package/dist/bitcoind/client/follow-loop.d.ts +10 -0
  35. package/dist/bitcoind/client/follow-loop.js +57 -0
  36. package/dist/bitcoind/client/internal-types.d.ts +63 -0
  37. package/dist/bitcoind/client/internal-types.js +18 -0
  38. package/dist/bitcoind/client/managed-client.d.ts +20 -0
  39. package/dist/bitcoind/client/managed-client.js +197 -0
  40. package/dist/bitcoind/client/rate-tracker.d.ts +2 -0
  41. package/dist/bitcoind/client/rate-tracker.js +24 -0
  42. package/dist/bitcoind/client/sync-engine.d.ts +3 -0
  43. package/dist/bitcoind/client/sync-engine.js +143 -0
  44. package/dist/bitcoind/client.d.ts +1 -0
  45. package/dist/bitcoind/client.js +1 -0
  46. package/dist/bitcoind/errors.d.ts +1 -0
  47. package/dist/bitcoind/errors.js +49 -0
  48. package/dist/bitcoind/index.d.ts +2 -0
  49. package/dist/bitcoind/index.js +1 -0
  50. package/dist/bitcoind/indexer-daemon-main.d.ts +1 -0
  51. package/dist/bitcoind/indexer-daemon-main.js +472 -0
  52. package/dist/bitcoind/indexer-daemon.d.ts +107 -0
  53. package/dist/bitcoind/indexer-daemon.js +391 -0
  54. package/dist/bitcoind/node.d.ts +8 -0
  55. package/dist/bitcoind/node.js +219 -0
  56. package/dist/bitcoind/normalize.d.ts +3 -0
  57. package/dist/bitcoind/normalize.js +47 -0
  58. package/dist/bitcoind/progress/assets.d.ts +10 -0
  59. package/dist/bitcoind/progress/assets.js +90 -0
  60. package/dist/bitcoind/progress/constants.d.ts +48 -0
  61. package/dist/bitcoind/progress/constants.js +53 -0
  62. package/dist/bitcoind/progress/controller.d.ts +28 -0
  63. package/dist/bitcoind/progress/controller.js +188 -0
  64. package/dist/bitcoind/progress/follow-scene.d.ts +40 -0
  65. package/dist/bitcoind/progress/follow-scene.js +367 -0
  66. package/dist/bitcoind/progress/formatting.d.ts +23 -0
  67. package/dist/bitcoind/progress/formatting.js +227 -0
  68. package/dist/bitcoind/progress/quote-scene.d.ts +4 -0
  69. package/dist/bitcoind/progress/quote-scene.js +137 -0
  70. package/dist/bitcoind/progress/train-scene.d.ts +9 -0
  71. package/dist/bitcoind/progress/train-scene.js +92 -0
  72. package/dist/bitcoind/progress/tty-renderer.d.ts +18 -0
  73. package/dist/bitcoind/progress/tty-renderer.js +150 -0
  74. package/dist/bitcoind/progress.d.ts +7 -0
  75. package/dist/bitcoind/progress.js +7 -0
  76. package/dist/bitcoind/quotes.d.ts +24 -0
  77. package/dist/bitcoind/quotes.js +195 -0
  78. package/dist/bitcoind/rpc.d.ts +71 -0
  79. package/dist/bitcoind/rpc.js +322 -0
  80. package/dist/bitcoind/service-paths.d.ts +19 -0
  81. package/dist/bitcoind/service-paths.js +49 -0
  82. package/dist/bitcoind/service.d.ts +40 -0
  83. package/dist/bitcoind/service.js +735 -0
  84. package/dist/bitcoind/testing.d.ts +9 -0
  85. package/dist/bitcoind/testing.js +9 -0
  86. package/dist/bitcoind/types.d.ts +396 -0
  87. package/dist/bitcoind/types.js +3 -0
  88. package/dist/bytes.d.ts +9 -0
  89. package/dist/bytes.js +36 -0
  90. package/dist/cli/commands/follow.d.ts +2 -0
  91. package/dist/cli/commands/follow.js +43 -0
  92. package/dist/cli/commands/mining-admin.d.ts +2 -0
  93. package/dist/cli/commands/mining-admin.js +92 -0
  94. package/dist/cli/commands/mining-read.d.ts +2 -0
  95. package/dist/cli/commands/mining-read.js +173 -0
  96. package/dist/cli/commands/mining-runtime.d.ts +2 -0
  97. package/dist/cli/commands/mining-runtime.js +108 -0
  98. package/dist/cli/commands/status.d.ts +2 -0
  99. package/dist/cli/commands/status.js +31 -0
  100. package/dist/cli/commands/sync.d.ts +2 -0
  101. package/dist/cli/commands/sync.js +52 -0
  102. package/dist/cli/commands/wallet-admin.d.ts +2 -0
  103. package/dist/cli/commands/wallet-admin.js +175 -0
  104. package/dist/cli/commands/wallet-mutation.d.ts +2 -0
  105. package/dist/cli/commands/wallet-mutation.js +681 -0
  106. package/dist/cli/commands/wallet-read.d.ts +2 -0
  107. package/dist/cli/commands/wallet-read.js +265 -0
  108. package/dist/cli/context.d.ts +3 -0
  109. package/dist/cli/context.js +75 -0
  110. package/dist/cli/io.d.ts +3 -0
  111. package/dist/cli/io.js +12 -0
  112. package/dist/cli/mining-format.d.ts +5 -0
  113. package/dist/cli/mining-format.js +156 -0
  114. package/dist/cli/mining-json.d.ts +49 -0
  115. package/dist/cli/mining-json.js +89 -0
  116. package/dist/cli/mutation-command-groups.d.ts +15 -0
  117. package/dist/cli/mutation-command-groups.js +71 -0
  118. package/dist/cli/mutation-json.d.ts +430 -0
  119. package/dist/cli/mutation-json.js +311 -0
  120. package/dist/cli/mutation-resolved-json.d.ts +124 -0
  121. package/dist/cli/mutation-resolved-json.js +129 -0
  122. package/dist/cli/mutation-success.d.ts +20 -0
  123. package/dist/cli/mutation-success.js +47 -0
  124. package/dist/cli/mutation-text-format.d.ts +22 -0
  125. package/dist/cli/mutation-text-format.js +171 -0
  126. package/dist/cli/mutation-text-write.d.ts +13 -0
  127. package/dist/cli/mutation-text-write.js +16 -0
  128. package/dist/cli/output.d.ts +185 -0
  129. package/dist/cli/output.js +1085 -0
  130. package/dist/cli/parse.d.ts +3 -0
  131. package/dist/cli/parse.js +971 -0
  132. package/dist/cli/preview-json.d.ts +416 -0
  133. package/dist/cli/preview-json.js +293 -0
  134. package/dist/cli/prompt.d.ts +3 -0
  135. package/dist/cli/prompt.js +33 -0
  136. package/dist/cli/read-json.d.ts +187 -0
  137. package/dist/cli/read-json.js +675 -0
  138. package/dist/cli/runner.d.ts +2 -0
  139. package/dist/cli/runner.js +129 -0
  140. package/dist/cli/signals.d.ts +3 -0
  141. package/dist/cli/signals.js +63 -0
  142. package/dist/cli/status-format.d.ts +2 -0
  143. package/dist/cli/status-format.js +48 -0
  144. package/dist/cli/types.d.ts +148 -0
  145. package/dist/cli/types.js +2 -0
  146. package/dist/cli/wallet-format.d.ts +29 -0
  147. package/dist/cli/wallet-format.js +637 -0
  148. package/dist/cli/workflow-hints.d.ts +13 -0
  149. package/dist/cli/workflow-hints.js +94 -0
  150. package/dist/cli-runner.d.ts +3 -0
  151. package/dist/cli-runner.js +3 -0
  152. package/dist/cli.d.ts +2 -0
  153. package/dist/cli.js +6 -0
  154. package/dist/client/default-client.d.ts +11 -0
  155. package/dist/client/default-client.js +118 -0
  156. package/dist/client/factory.d.ts +2 -0
  157. package/dist/client/factory.js +15 -0
  158. package/dist/client/initialization.d.ts +6 -0
  159. package/dist/client/initialization.js +30 -0
  160. package/dist/client/persistence.d.ts +5 -0
  161. package/dist/client/persistence.js +28 -0
  162. package/dist/client/store-adapter.d.ts +3 -0
  163. package/dist/client/store-adapter.js +20 -0
  164. package/dist/client.d.ts +2 -0
  165. package/dist/client.js +2 -0
  166. package/dist/index.d.ts +2 -0
  167. package/dist/index.js +1 -0
  168. package/dist/passive-status.d.ts +36 -0
  169. package/dist/passive-status.js +100 -0
  170. package/dist/sqlite/better-sqlite3.d.ts +26 -0
  171. package/dist/sqlite/better-sqlite3.js +4 -0
  172. package/dist/sqlite/checkpoints.d.ts +11 -0
  173. package/dist/sqlite/checkpoints.js +27 -0
  174. package/dist/sqlite/driver.d.ts +17 -0
  175. package/dist/sqlite/driver.js +98 -0
  176. package/dist/sqlite/index.d.ts +4 -0
  177. package/dist/sqlite/index.js +9 -0
  178. package/dist/sqlite/migrate.d.ts +2 -0
  179. package/dist/sqlite/migrate.js +37 -0
  180. package/dist/sqlite/store.d.ts +3 -0
  181. package/dist/sqlite/store.js +122 -0
  182. package/dist/sqlite/tip-meta.d.ts +26 -0
  183. package/dist/sqlite/tip-meta.js +97 -0
  184. package/dist/sqlite/types.d.ts +10 -0
  185. package/dist/sqlite/types.js +1 -0
  186. package/dist/types.d.ts +55 -0
  187. package/dist/types.js +1 -0
  188. package/dist/wallet/archive.d.ts +4 -0
  189. package/dist/wallet/archive.js +39 -0
  190. package/dist/wallet/cogop/constants.d.ts +32 -0
  191. package/dist/wallet/cogop/constants.js +32 -0
  192. package/dist/wallet/cogop/index.d.ts +32 -0
  193. package/dist/wallet/cogop/index.js +213 -0
  194. package/dist/wallet/cogop/numeric.d.ts +3 -0
  195. package/dist/wallet/cogop/numeric.js +24 -0
  196. package/dist/wallet/cogop/scriptpubkey.d.ts +2 -0
  197. package/dist/wallet/cogop/scriptpubkey.js +13 -0
  198. package/dist/wallet/cogop/validate-name.d.ts +2 -0
  199. package/dist/wallet/cogop/validate-name.js +18 -0
  200. package/dist/wallet/fs/atomic.d.ts +6 -0
  201. package/dist/wallet/fs/atomic.js +46 -0
  202. package/dist/wallet/fs/lock.d.ts +19 -0
  203. package/dist/wallet/fs/lock.js +61 -0
  204. package/dist/wallet/fs/status-file.d.ts +1 -0
  205. package/dist/wallet/fs/status-file.js +4 -0
  206. package/dist/wallet/lifecycle.d.ts +193 -0
  207. package/dist/wallet/lifecycle.js +1475 -0
  208. package/dist/wallet/material.d.ts +45 -0
  209. package/dist/wallet/material.js +118 -0
  210. package/dist/wallet/mining/config.d.ts +18 -0
  211. package/dist/wallet/mining/config.js +44 -0
  212. package/dist/wallet/mining/constants.d.ts +24 -0
  213. package/dist/wallet/mining/constants.js +24 -0
  214. package/dist/wallet/mining/control.d.ts +53 -0
  215. package/dist/wallet/mining/control.js +758 -0
  216. package/dist/wallet/mining/coordination.d.ts +40 -0
  217. package/dist/wallet/mining/coordination.js +121 -0
  218. package/dist/wallet/mining/hook-protocol.d.ts +47 -0
  219. package/dist/wallet/mining/hook-protocol.js +161 -0
  220. package/dist/wallet/mining/hook-runner.d.ts +1 -0
  221. package/dist/wallet/mining/hook-runner.js +52 -0
  222. package/dist/wallet/mining/hooks.d.ts +38 -0
  223. package/dist/wallet/mining/hooks.js +520 -0
  224. package/dist/wallet/mining/index.d.ts +8 -0
  225. package/dist/wallet/mining/index.js +6 -0
  226. package/dist/wallet/mining/runner.d.ts +155 -0
  227. package/dist/wallet/mining/runner.js +2574 -0
  228. package/dist/wallet/mining/runtime-artifacts.d.ts +17 -0
  229. package/dist/wallet/mining/runtime-artifacts.js +166 -0
  230. package/dist/wallet/mining/sentences.d.ts +23 -0
  231. package/dist/wallet/mining/sentences.js +281 -0
  232. package/dist/wallet/mining/state.d.ts +9 -0
  233. package/dist/wallet/mining/state.js +75 -0
  234. package/dist/wallet/mining/types.d.ts +141 -0
  235. package/dist/wallet/mining/types.js +1 -0
  236. package/dist/wallet/mining/visualizer.d.ts +19 -0
  237. package/dist/wallet/mining/visualizer.js +134 -0
  238. package/dist/wallet/mining/worker-main.d.ts +1 -0
  239. package/dist/wallet/mining/worker-main.js +17 -0
  240. package/dist/wallet/read/context.d.ts +20 -0
  241. package/dist/wallet/read/context.js +532 -0
  242. package/dist/wallet/read/filter.d.ts +9 -0
  243. package/dist/wallet/read/filter.js +42 -0
  244. package/dist/wallet/read/index.d.ts +4 -0
  245. package/dist/wallet/read/index.js +3 -0
  246. package/dist/wallet/read/project.d.ts +11 -0
  247. package/dist/wallet/read/project.js +300 -0
  248. package/dist/wallet/read/types.d.ts +144 -0
  249. package/dist/wallet/read/types.js +1 -0
  250. package/dist/wallet/runtime.d.ts +26 -0
  251. package/dist/wallet/runtime.js +28 -0
  252. package/dist/wallet/state/crypto.d.ts +31 -0
  253. package/dist/wallet/state/crypto.js +127 -0
  254. package/dist/wallet/state/provider.d.ts +37 -0
  255. package/dist/wallet/state/provider.js +312 -0
  256. package/dist/wallet/state/session.d.ts +12 -0
  257. package/dist/wallet/state/session.js +23 -0
  258. package/dist/wallet/state/storage.d.ts +19 -0
  259. package/dist/wallet/state/storage.js +55 -0
  260. package/dist/wallet/tx/anchor.d.ts +40 -0
  261. package/dist/wallet/tx/anchor.js +1210 -0
  262. package/dist/wallet/tx/cog.d.ts +92 -0
  263. package/dist/wallet/tx/cog.js +1055 -0
  264. package/dist/wallet/tx/common.d.ts +89 -0
  265. package/dist/wallet/tx/common.js +156 -0
  266. package/dist/wallet/tx/confirm.d.ts +15 -0
  267. package/dist/wallet/tx/confirm.js +24 -0
  268. package/dist/wallet/tx/domain-admin.d.ts +105 -0
  269. package/dist/wallet/tx/domain-admin.js +869 -0
  270. package/dist/wallet/tx/domain-market.d.ts +112 -0
  271. package/dist/wallet/tx/domain-market.js +1365 -0
  272. package/dist/wallet/tx/field.d.ts +101 -0
  273. package/dist/wallet/tx/field.js +1853 -0
  274. package/dist/wallet/tx/identity-selector.d.ts +12 -0
  275. package/dist/wallet/tx/identity-selector.js +52 -0
  276. package/dist/wallet/tx/index.d.ts +7 -0
  277. package/dist/wallet/tx/index.js +7 -0
  278. package/dist/wallet/tx/journal.d.ts +5 -0
  279. package/dist/wallet/tx/journal.js +31 -0
  280. package/dist/wallet/tx/register.d.ts +68 -0
  281. package/dist/wallet/tx/register.js +952 -0
  282. package/dist/wallet/tx/reputation.d.ts +72 -0
  283. package/dist/wallet/tx/reputation.js +693 -0
  284. package/dist/wallet/tx/targets.d.ts +7 -0
  285. package/dist/wallet/tx/targets.js +122 -0
  286. package/dist/wallet/types.d.ts +249 -0
  287. package/dist/wallet/types.js +1 -0
  288. package/dist/writing_quotes.json +1654 -0
  289. package/package.json +78 -0
@@ -0,0 +1,129 @@
1
+ import { createDefaultContext } from "./context.js";
2
+ import { writeLine } from "./io.js";
3
+ import { classifyCliError, createCommandJsonErrorEnvelope, createErrorEnvelope, formatCliTextError, inferOutputMode, isStructuredOutputMode, writeJsonValue, } from "./output.js";
4
+ import { HELP_TEXT, parseCliArgs } from "./parse.js";
5
+ import { runFollowCommand } from "./commands/follow.js";
6
+ import { runMiningAdminCommand } from "./commands/mining-admin.js";
7
+ import { runMiningReadCommand } from "./commands/mining-read.js";
8
+ import { runMiningRuntimeCommand } from "./commands/mining-runtime.js";
9
+ import { runStatusCommand } from "./commands/status.js";
10
+ import { runSyncCommand } from "./commands/sync.js";
11
+ import { runWalletAdminCommand } from "./commands/wallet-admin.js";
12
+ import { runWalletMutationCommand } from "./commands/wallet-mutation.js";
13
+ import { runWalletReadCommand } from "./commands/wallet-read.js";
14
+ export async function runCli(argv, contextOverrides = {}) {
15
+ const context = createDefaultContext(contextOverrides);
16
+ let parsed;
17
+ try {
18
+ parsed = parseCliArgs(argv);
19
+ }
20
+ catch (error) {
21
+ const classified = classifyCliError(error);
22
+ if (isStructuredOutputMode(inferOutputMode(argv))) {
23
+ writeJsonValue(context.stdout, createErrorEnvelope("cogcoin/cli/v1", `cogcoin ${argv.join(" ")}`.trim(), classified.errorCode, classified.message));
24
+ return classified.exitCode;
25
+ }
26
+ writeLine(context.stderr, classified.message);
27
+ writeLine(context.stderr, HELP_TEXT.trimEnd());
28
+ return classified.exitCode;
29
+ }
30
+ if (parsed.version) {
31
+ writeLine(context.stdout, await context.readPackageVersion());
32
+ return 0;
33
+ }
34
+ if (parsed.help || parsed.command === null) {
35
+ if (parsed.command === null && isStructuredOutputMode(parsed.outputMode)) {
36
+ writeJsonValue(context.stdout, createErrorEnvelope("cogcoin/cli/v1", "cogcoin", "cli_missing_command", "cli_missing_command"));
37
+ return 2;
38
+ }
39
+ writeLine(context.stdout, HELP_TEXT.trimEnd());
40
+ return parsed.help ? 0 : 2;
41
+ }
42
+ try {
43
+ if (parsed.command === "sync") {
44
+ return runSyncCommand(parsed, context);
45
+ }
46
+ if (parsed.command === "follow") {
47
+ return runFollowCommand(parsed, context);
48
+ }
49
+ if (parsed.command === "status") {
50
+ return runStatusCommand(parsed, context);
51
+ }
52
+ if (parsed.command === "mine"
53
+ || parsed.command === "mine-start"
54
+ || parsed.command === "mine-stop") {
55
+ return runMiningRuntimeCommand(parsed, context);
56
+ }
57
+ if (parsed.command === "hooks-mining-enable"
58
+ || parsed.command === "hooks-mining-disable"
59
+ || parsed.command === "mine-setup") {
60
+ return runMiningAdminCommand(parsed, context);
61
+ }
62
+ if (parsed.command === "init"
63
+ || parsed.command === "repair"
64
+ || parsed.command === "unlock"
65
+ || parsed.command === "wallet-export"
66
+ || parsed.command === "wallet-import"
67
+ || parsed.command === "wallet-init"
68
+ || parsed.command === "wallet-unlock"
69
+ || parsed.command === "wallet-lock") {
70
+ return runWalletAdminCommand(parsed, context);
71
+ }
72
+ if (parsed.command === "anchor"
73
+ || parsed.command === "domain-anchor"
74
+ || parsed.command === "register"
75
+ || parsed.command === "domain-register"
76
+ || parsed.command === "transfer"
77
+ || parsed.command === "domain-transfer"
78
+ || parsed.command === "sell"
79
+ || parsed.command === "domain-sell"
80
+ || parsed.command === "unsell"
81
+ || parsed.command === "domain-unsell"
82
+ || parsed.command === "buy"
83
+ || parsed.command === "domain-buy"
84
+ || parsed.command === "domain-endpoint-set"
85
+ || parsed.command === "domain-endpoint-clear"
86
+ || parsed.command === "domain-delegate-set"
87
+ || parsed.command === "domain-delegate-clear"
88
+ || parsed.command === "domain-miner-set"
89
+ || parsed.command === "domain-miner-clear"
90
+ || parsed.command === "domain-canonical"
91
+ || parsed.command === "field-create"
92
+ || parsed.command === "field-set"
93
+ || parsed.command === "field-clear"
94
+ || parsed.command === "send"
95
+ || parsed.command === "claim"
96
+ || parsed.command === "reclaim"
97
+ || parsed.command === "cog-send"
98
+ || parsed.command === "cog-claim"
99
+ || parsed.command === "cog-reclaim"
100
+ || parsed.command === "cog-lock"
101
+ || parsed.command === "rep-give"
102
+ || parsed.command === "rep-revoke") {
103
+ return runWalletMutationCommand(parsed, context);
104
+ }
105
+ if (parsed.command === "hooks-mining-status"
106
+ || parsed.command === "mine-status"
107
+ || parsed.command === "mine-log") {
108
+ return runMiningReadCommand(parsed, context);
109
+ }
110
+ return runWalletReadCommand(parsed, context);
111
+ }
112
+ catch (error) {
113
+ const classified = classifyCliError(error);
114
+ if (isStructuredOutputMode(parsed.outputMode)) {
115
+ writeJsonValue(context.stdout, createCommandJsonErrorEnvelope(parsed, error));
116
+ return classified.exitCode;
117
+ }
118
+ const formatted = formatCliTextError(error);
119
+ if (formatted !== null) {
120
+ for (const line of formatted) {
121
+ writeLine(context.stderr, line);
122
+ }
123
+ }
124
+ else {
125
+ writeLine(context.stderr, classified.message);
126
+ }
127
+ return classified.exitCode;
128
+ }
129
+ }
@@ -0,0 +1,3 @@
1
+ import type { InterruptibleOutcome, ManagedClientLike, SignalSource, StopSignalWatcher, WritableLike } from "./types.js";
2
+ export declare function createStopSignalWatcher(signalSource: SignalSource, stderr: WritableLike, client: ManagedClientLike, forceExit: (code: number) => never | void): StopSignalWatcher;
3
+ export declare function waitForCompletionOrStop<T>(promise: Promise<T>, stopWatcher: StopSignalWatcher): Promise<InterruptibleOutcome<T>>;
@@ -0,0 +1,63 @@
1
+ import { writeLine } from "./io.js";
2
+ export function createStopSignalWatcher(signalSource, stderr, client, forceExit) {
3
+ let closing = false;
4
+ let resolved = false;
5
+ let onSignal = () => { };
6
+ const cleanup = () => {
7
+ signalSource.off("SIGINT", onSignal);
8
+ signalSource.off("SIGTERM", onSignal);
9
+ };
10
+ const promise = new Promise((resolve) => {
11
+ const settle = (code) => {
12
+ if (resolved) {
13
+ return;
14
+ }
15
+ resolved = true;
16
+ cleanup();
17
+ resolve(code);
18
+ };
19
+ const onFirstSignal = () => {
20
+ closing = true;
21
+ writeLine(stderr, "Stopping managed Cogcoin client...");
22
+ void client.close().then(() => {
23
+ settle(0);
24
+ }, () => {
25
+ settle(1);
26
+ });
27
+ };
28
+ onSignal = () => {
29
+ if (!closing) {
30
+ onFirstSignal();
31
+ return;
32
+ }
33
+ settle(130);
34
+ forceExit(130);
35
+ };
36
+ });
37
+ signalSource.on("SIGINT", onSignal);
38
+ signalSource.on("SIGTERM", onSignal);
39
+ return {
40
+ cleanup,
41
+ isStopping: () => closing,
42
+ promise,
43
+ };
44
+ }
45
+ export async function waitForCompletionOrStop(promise, stopWatcher) {
46
+ const outcome = await Promise.race([
47
+ promise.then((value) => ({ kind: "completed", value }), (error) => ({ kind: "error", error })),
48
+ stopWatcher.promise.then((code) => ({ kind: "stopped", code })),
49
+ ]);
50
+ if (outcome.kind === "stopped") {
51
+ return outcome;
52
+ }
53
+ if (outcome.kind === "error") {
54
+ if (stopWatcher.isStopping()) {
55
+ return {
56
+ kind: "stopped",
57
+ code: await stopWatcher.promise,
58
+ };
59
+ }
60
+ throw outcome.error;
61
+ }
62
+ return outcome;
63
+ }
@@ -0,0 +1,2 @@
1
+ import type { inspectPassiveClientStatus } from "../passive-status.js";
2
+ export declare function formatStatusReport(status: Awaited<ReturnType<typeof inspectPassiveClientStatus>>): string;
@@ -0,0 +1,48 @@
1
+ function formatBootstrapPercent(current, total) {
2
+ if (total <= 0) {
3
+ return "0.00";
4
+ }
5
+ return ((current / total) * 100).toFixed(2);
6
+ }
7
+ export function formatStatusReport(status) {
8
+ const lines = [
9
+ "Cogcoin Client Status",
10
+ `DB path: ${status.dbPath}`,
11
+ `Bitcoin datadir: ${status.bitcoinDataDir}`,
12
+ `Store exists: ${status.storeExists ? "yes" : "no"}`,
13
+ `Store initialized: ${status.storeInitialized ? "yes" : "no"}`,
14
+ ];
15
+ if (status.storeError !== null) {
16
+ lines.push(`Store error: ${status.storeError}`);
17
+ }
18
+ if (status.indexedTip === null) {
19
+ lines.push("Indexed tip: none");
20
+ }
21
+ else {
22
+ lines.push(`Indexed tip height: ${status.indexedTip.height}`);
23
+ lines.push(`Indexed tip hash: ${status.indexedTip.blockHashHex}`);
24
+ lines.push(`Indexed tip state hash: ${status.indexedTip.stateHashHex ?? "none"}`);
25
+ }
26
+ if (status.latestCheckpoint === null) {
27
+ lines.push("Latest checkpoint: none");
28
+ }
29
+ else {
30
+ lines.push(`Latest checkpoint height: ${status.latestCheckpoint.height}`);
31
+ lines.push(`Latest checkpoint hash: ${status.latestCheckpoint.blockHashHex}`);
32
+ }
33
+ if (status.bootstrap === null) {
34
+ lines.push("Bootstrap state: none");
35
+ }
36
+ else {
37
+ lines.push(`Bootstrap phase: ${status.bootstrap.phase}`);
38
+ lines.push(`Bootstrap download: ${status.bootstrap.downloadedBytes} / ${status.bootstrap.totalBytes} bytes (${formatBootstrapPercent(status.bootstrap.downloadedBytes, status.bootstrap.totalBytes)}%)`);
39
+ lines.push(`Bootstrap validated: ${status.bootstrap.validated ? "yes" : "no"}`);
40
+ lines.push(`Bootstrap loaded: ${status.bootstrap.loadTxOutSetComplete ? "yes" : "no"}`);
41
+ lines.push(`Bootstrap base height: ${status.bootstrap.baseHeight ?? "none"}`);
42
+ lines.push(`Bootstrap tip hash: ${status.bootstrap.tipHashHex ?? "none"}`);
43
+ lines.push(`Bootstrap snapshot height: ${status.bootstrap.snapshotHeight ?? "none"}`);
44
+ lines.push(`Bootstrap last error: ${status.bootstrap.lastError ?? "none"}`);
45
+ }
46
+ lines.push("Live node: not checked (passive status)");
47
+ return lines.join("\n");
48
+ }
@@ -0,0 +1,148 @@
1
+ import type { inspectPassiveClientStatus } from "../passive-status.js";
2
+ import { openSqliteStore } from "../sqlite/index.js";
3
+ import type { ClientStoreAdapter } from "../types.js";
4
+ import type { exportWallet, WalletPrompter, importWallet, initializeWallet, lockWallet, repairWallet, unlockWallet } from "../wallet/lifecycle.js";
5
+ import type { openWalletReadContext } from "../wallet/read/index.js";
6
+ import type { WalletSecretProvider } from "../wallet/state/provider.js";
7
+ import type { disableMiningHooks, enableMiningHooks, followMiningLog, inspectMiningControlPlane, readMiningLog, runForegroundMining, setupBuiltInMining, startBackgroundMining, stopBackgroundMining } from "../wallet/mining/index.js";
8
+ import type { 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";
9
+ export type ProgressOutput = "auto" | "tty" | "none";
10
+ export type OutputMode = "text" | "json" | "preview-json";
11
+ export type CommandName = "init" | "repair" | "sync" | "status" | "follow" | "unlock" | "anchor" | "domain-anchor" | "register" | "domain-register" | "transfer" | "domain-transfer" | "sell" | "domain-sell" | "unsell" | "domain-unsell" | "buy" | "domain-buy" | "domain-endpoint-set" | "domain-endpoint-clear" | "domain-delegate-set" | "domain-delegate-clear" | "domain-miner-set" | "domain-miner-clear" | "domain-canonical" | "field-list" | "field-show" | "field-create" | "field-set" | "field-clear" | "send" | "claim" | "reclaim" | "cog-send" | "cog-claim" | "cog-reclaim" | "cog-lock" | "rep-give" | "rep-revoke" | "cog-balance" | "cog-locks" | "hooks-mining-enable" | "hooks-mining-disable" | "hooks-mining-status" | "mine" | "mine-start" | "mine-stop" | "mine-setup" | "mine-status" | "mine-log" | "wallet-export" | "wallet-import" | "wallet-init" | "wallet-lock" | "wallet-unlock" | "wallet-status" | "wallet-address" | "wallet-ids" | "address" | "ids" | "balance" | "locks" | "domain-list" | "domains" | "domain-show" | "show" | "fields" | "field";
12
+ export interface WritableLike {
13
+ isTTY?: boolean;
14
+ write(chunk: string): void;
15
+ }
16
+ export interface ReadableLike {
17
+ isTTY?: boolean;
18
+ }
19
+ export interface SignalSource {
20
+ on(event: "SIGINT" | "SIGTERM", listener: () => void): void;
21
+ off(event: "SIGINT" | "SIGTERM", listener: () => void): void;
22
+ }
23
+ export interface ParsedCliArgs {
24
+ command: CommandName | null;
25
+ args: string[];
26
+ help: boolean;
27
+ version: boolean;
28
+ outputMode: OutputMode;
29
+ dbPath: string | null;
30
+ dataDir: string | null;
31
+ progressOutput: ProgressOutput;
32
+ unlockFor: string | null;
33
+ assumeYes: boolean;
34
+ forceRace: boolean;
35
+ anchorMessage: string | null;
36
+ transferTarget: string | null;
37
+ endpointText: string | null;
38
+ endpointJson: string | null;
39
+ endpointBytes: string | null;
40
+ fieldPermanent: boolean;
41
+ fieldFormat: string | null;
42
+ fieldValue: string | null;
43
+ fromIdentity: string | null;
44
+ lockRecipientDomain: string | null;
45
+ conditionHex: string | null;
46
+ untilHeight: string | null;
47
+ preimageHex: string | null;
48
+ reviewText: string | null;
49
+ locksClaimableOnly: boolean;
50
+ locksReclaimableOnly: boolean;
51
+ domainsAnchoredOnly: boolean;
52
+ domainsListedOnly: boolean;
53
+ domainsMineableOnly: boolean;
54
+ listLimit: number | null;
55
+ listAll: boolean;
56
+ verify: boolean;
57
+ follow: boolean;
58
+ }
59
+ export interface ManagedClientLike {
60
+ syncToTip(): Promise<{
61
+ appliedBlocks: number;
62
+ rewoundBlocks: number;
63
+ endingHeight: number | null;
64
+ bestHeight: number;
65
+ }>;
66
+ playSyncCompletionScene?(): Promise<void>;
67
+ startFollowingTip(): Promise<void>;
68
+ getNodeStatus(): Promise<{
69
+ indexedTip: {
70
+ height: number;
71
+ blockHashHex: string;
72
+ stateHashHex: string | null;
73
+ } | null;
74
+ nodeBestHeight: number | null;
75
+ }>;
76
+ close(): Promise<void>;
77
+ }
78
+ export interface CliRunnerContext {
79
+ stdout?: WritableLike;
80
+ stderr?: WritableLike;
81
+ stdin?: ReadableLike;
82
+ signalSource?: SignalSource;
83
+ forceExit?: (code: number) => never | void;
84
+ openSqliteStore?: typeof openSqliteStore;
85
+ openManagedBitcoindClient?: (options: {
86
+ store: ClientStoreAdapter;
87
+ databasePath?: string;
88
+ dataDir?: string;
89
+ progressOutput?: ProgressOutput;
90
+ }) => Promise<ManagedClientLike>;
91
+ inspectPassiveClientStatus?: typeof inspectPassiveClientStatus;
92
+ openWalletReadContext?: typeof openWalletReadContext;
93
+ initializeWallet?: typeof initializeWallet;
94
+ exportWallet?: typeof exportWallet;
95
+ importWallet?: typeof importWallet;
96
+ unlockWallet?: typeof unlockWallet;
97
+ lockWallet?: typeof lockWallet;
98
+ registerDomain?: typeof registerDomain;
99
+ anchorDomain?: typeof anchorDomain;
100
+ transferDomain?: typeof transferDomain;
101
+ sellDomain?: typeof sellDomain;
102
+ buyDomain?: typeof buyDomain;
103
+ sendCog?: typeof sendCog;
104
+ claimCogLock?: typeof claimCogLock;
105
+ reclaimCogLock?: typeof reclaimCogLock;
106
+ lockCogToDomain?: typeof lockCogToDomain;
107
+ setDomainEndpoint?: typeof setDomainEndpoint;
108
+ clearDomainEndpoint?: typeof clearDomainEndpoint;
109
+ setDomainDelegate?: typeof setDomainDelegate;
110
+ clearDomainDelegate?: typeof clearDomainDelegate;
111
+ setDomainMiner?: typeof setDomainMiner;
112
+ clearDomainMiner?: typeof clearDomainMiner;
113
+ setDomainCanonical?: typeof setDomainCanonical;
114
+ createField?: typeof createField;
115
+ setField?: typeof setField;
116
+ clearField?: typeof clearField;
117
+ giveReputation?: typeof giveReputation;
118
+ revokeReputation?: typeof revokeReputation;
119
+ enableMiningHooks?: typeof enableMiningHooks;
120
+ disableMiningHooks?: typeof disableMiningHooks;
121
+ inspectMiningControlPlane?: typeof inspectMiningControlPlane;
122
+ runForegroundMining?: typeof runForegroundMining;
123
+ startBackgroundMining?: typeof startBackgroundMining;
124
+ stopBackgroundMining?: typeof stopBackgroundMining;
125
+ setupBuiltInMining?: typeof setupBuiltInMining;
126
+ readMiningLog?: typeof readMiningLog;
127
+ followMiningLog?: typeof followMiningLog;
128
+ repairWallet?: typeof repairWallet;
129
+ walletSecretProvider?: WalletSecretProvider;
130
+ createPrompter?: () => WalletPrompter;
131
+ ensureDirectory?: (path: string) => Promise<void>;
132
+ readPackageVersion?: () => Promise<string>;
133
+ resolveDefaultBitcoindDataDir?: () => string;
134
+ resolveDefaultClientDatabasePath?: () => string;
135
+ }
136
+ export interface StopSignalWatcher {
137
+ cleanup(): void;
138
+ isStopping(): boolean;
139
+ promise: Promise<number>;
140
+ }
141
+ export type InterruptibleOutcome<T> = {
142
+ kind: "completed";
143
+ value: T;
144
+ } | {
145
+ kind: "stopped";
146
+ code: number;
147
+ };
148
+ export type RequiredCliRunnerContext = Required<CliRunnerContext>;
@@ -0,0 +1,2 @@
1
+ import { openManagedBitcoindClient } from "../bitcoind/index.js";
2
+ import { openSqliteStore } from "../sqlite/index.js";
@@ -0,0 +1,29 @@
1
+ import type { WalletDomainView, WalletReadContext } from "../wallet/read/index.js";
2
+ export declare function getRepairRecommendation(context: WalletReadContext): string | null;
3
+ export declare function getMutationRecommendation(context: WalletReadContext): string | null;
4
+ export declare function formatWalletOverviewReport(context: WalletReadContext): string;
5
+ export declare function formatDetailedWalletStatusReport(context: WalletReadContext): string;
6
+ export declare function formatFundingAddressReport(context: WalletReadContext): string;
7
+ export declare function formatIdentityListReport(context: WalletReadContext, options?: {
8
+ limit?: number | null;
9
+ all?: boolean;
10
+ }): string;
11
+ export declare function formatBalanceReport(context: WalletReadContext): string;
12
+ export declare function formatLocksReport(context: WalletReadContext, options?: {
13
+ claimableOnly?: boolean;
14
+ reclaimableOnly?: boolean;
15
+ limit?: number | null;
16
+ all?: boolean;
17
+ }): string;
18
+ export declare function formatDomainsReport(context: WalletReadContext, options?: {
19
+ limit?: number | null;
20
+ all?: boolean;
21
+ domains?: WalletDomainView[] | null;
22
+ activeFilters?: string[];
23
+ }): string;
24
+ export declare function formatDomainReport(context: WalletReadContext, domainName: string): string;
25
+ export declare function formatFieldsReport(context: WalletReadContext, domainName: string, options?: {
26
+ limit?: number | null;
27
+ all?: boolean;
28
+ }): string;
29
+ export declare function formatFieldReport(context: WalletReadContext, domainName: string, fieldName: string): string;