@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Cogcoin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# `@cogcoin/client`
|
|
2
|
+
|
|
3
|
+
`@cogcoin/client@0.5.0` is the store-backed Cogcoin client package for applications that want a local wallet, durable SQLite-backed state, and a managed Bitcoin Core integration around `@cogcoin/indexer`. It publishes the reusable client APIs, the SQLite adapter, the managed `bitcoind` integration, and the first-party `cogcoin` CLI in one package.
|
|
4
|
+
|
|
5
|
+
Use Node 22 or newer.
|
|
6
|
+
|
|
7
|
+
## Links
|
|
8
|
+
|
|
9
|
+
- Website: [cogcoin.org](https://cogcoin.org)
|
|
10
|
+
- Whitepaper: [cogcoin.org/whitepaper.md](https://cogcoin.org/whitepaper.md)
|
|
11
|
+
- Source: [github.com/cogcoin/client](https://github.com/cogcoin/client)
|
|
12
|
+
- Bitcoin package: [npmjs.com/package/@cogcoin/bitcoin](https://www.npmjs.com/package/@cogcoin/bitcoin)
|
|
13
|
+
- Genesis package: [npmjs.com/package/@cogcoin/genesis](https://www.npmjs.com/package/@cogcoin/genesis)
|
|
14
|
+
- Indexer package: [npmjs.com/package/@cogcoin/indexer](https://www.npmjs.com/package/@cogcoin/indexer)
|
|
15
|
+
- Scoring package: [npmjs.com/package/@cogcoin/scoring](https://www.npmjs.com/package/@cogcoin/scoring)
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
Install the package:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @cogcoin/client
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Then, from your project root, run:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
node node_modules/@cogcoin/genesis/verify.mjs
|
|
29
|
+
npx cogcoin init
|
|
30
|
+
npx cogcoin sync
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Verify the installed genesis artifacts before using the client in a production implementation.
|
|
34
|
+
The installed package provides the `cogcoin` command for local wallet setup, sync, reads, writes, and mining workflows.
|
|
35
|
+
|
|
36
|
+
## Dependency Surface
|
|
37
|
+
|
|
38
|
+
The published package depends on:
|
|
39
|
+
|
|
40
|
+
- `@cogcoin/bitcoin@30.2.0`
|
|
41
|
+
- `@cogcoin/genesis@1.0.0`
|
|
42
|
+
- `@cogcoin/indexer@1.0.0`
|
|
43
|
+
- `@cogcoin/scoring@1.0.0`
|
|
44
|
+
- `@scure/base@^2.0.0`
|
|
45
|
+
- `@scure/bip32@^2.0.1`
|
|
46
|
+
- `@scure/bip39@^2.0.1`
|
|
47
|
+
- `better-sqlite3@12.8.0`
|
|
48
|
+
- `zeromq@6.5.0`
|
|
49
|
+
|
|
50
|
+
`@cogcoin/vectors` is kept as a repository development dependency for conformance tests and is not part of the published runtime dependency surface.
|
|
51
|
+
|
|
52
|
+
## API
|
|
53
|
+
|
|
54
|
+
Root package:
|
|
55
|
+
|
|
56
|
+
- `openClient(options)`
|
|
57
|
+
- `createClientStoreAdapter(store)`
|
|
58
|
+
|
|
59
|
+
SQLite subpath:
|
|
60
|
+
|
|
61
|
+
- `@cogcoin/client/sqlite`
|
|
62
|
+
- `openSqliteStore(options)`
|
|
63
|
+
- `migrateSqliteStore(database)`
|
|
64
|
+
|
|
65
|
+
Managed node subpath:
|
|
66
|
+
|
|
67
|
+
- `@cogcoin/client/bitcoind`
|
|
68
|
+
- `openManagedBitcoindClient(options)`
|
|
69
|
+
|
|
70
|
+
## CLI
|
|
71
|
+
|
|
72
|
+
The installed `cogcoin` command covers the first-party local wallet and node workflow:
|
|
73
|
+
|
|
74
|
+
- wallet lifecycle commands such as `init`, `unlock`, `lock`, `repair`, `export`, and `import`
|
|
75
|
+
- sync and service commands such as `status`, `sync`, and `follow`
|
|
76
|
+
- domain and field commands such as `register`, `anchor`, `show`, `domains`, `fields`, `buy`, `sell`, and `transfer`
|
|
77
|
+
- COG and reputation commands such as `send`, `cog lock`, `claim`, `reclaim`, `rep give`, and `rep revoke`
|
|
78
|
+
- mining and hook commands such as `mine`, `mine start`, `mine stop`, `mine status`, `mine log`, `mine setup`, and `hooks status`
|
|
79
|
+
|
|
80
|
+
The CLI also supports stable `--output json` and `--output preview-json` envelopes on the commands that advertise machine-readable output.
|
|
81
|
+
|
|
82
|
+
## SQLite Store
|
|
83
|
+
|
|
84
|
+
The built-in SQLite adapter persists opaque indexer bytes rather than protocol tables:
|
|
85
|
+
|
|
86
|
+
- serialized `IndexerState`
|
|
87
|
+
- serialized `BlockRecord`
|
|
88
|
+
- current tip metadata
|
|
89
|
+
- periodic checkpoints
|
|
90
|
+
|
|
91
|
+
This keeps correctness tied to `@cogcoin/indexer` rather than duplicating protocol state in SQL.
|
|
92
|
+
|
|
93
|
+
## Managed `bitcoind`
|
|
94
|
+
|
|
95
|
+
The built-in managed-node integration:
|
|
96
|
+
|
|
97
|
+
- resolves Bitcoin Core binaries through `@cogcoin/bitcoin`
|
|
98
|
+
- uses RPC for durable reads and ZMQ `hashblock` notifications for tip following
|
|
99
|
+
- launches a local full node with cookie auth
|
|
100
|
+
- defaults to an assumeutxo-first mainnet bootstrap using `https://snapshots.cogcoin.org/utxo-910000.dat`
|
|
101
|
+
- composes the existing SQLite-backed client rather than replacing it
|
|
102
|
+
|
|
103
|
+
If `dataDir` is omitted, the managed node defaults to:
|
|
104
|
+
|
|
105
|
+
- macOS: `~/Library/Application Support/Cogcoin/bitcoin`
|
|
106
|
+
- Linux: `~/.cogcoin/bitcoin`
|
|
107
|
+
- Windows: `%APPDATA%\\Cogcoin\\bitcoin`
|
|
108
|
+
|
|
109
|
+
On a fresh mainnet managed sync, `syncToTip()` or `startFollowingTip()`:
|
|
110
|
+
|
|
111
|
+
1. downloads the pinned Cogcoin UTXO snapshot with resume support
|
|
112
|
+
2. validates its known size and SHA-256
|
|
113
|
+
3. loads it with Bitcoin Core assumeutxo
|
|
114
|
+
4. continues Bitcoin sync and Cogcoin replay from the managed node until the live tip is caught up
|
|
115
|
+
|
|
116
|
+
The managed `bitcoind` client also exposes:
|
|
117
|
+
|
|
118
|
+
- `onProgress(event)` for structured bootstrap/sync progress updates
|
|
119
|
+
- `progressOutput: "auto" | "tty" | "none"` for the built-in scroll-train terminal progress UI
|
|
120
|
+
|
|
121
|
+
The default TTY progress renderer ships with the package and uses the bundled scroll, train, and quote assets from `dist/art/*` and `dist/writing_quotes.json`.
|
|
122
|
+
|
|
123
|
+
## Published Contents
|
|
124
|
+
|
|
125
|
+
- `dist/index.js`: public package entrypoint
|
|
126
|
+
- `dist/index.d.ts`: bundled type declarations
|
|
127
|
+
- `dist/cli.js`: installed `cogcoin` command
|
|
128
|
+
- `dist/bitcoind/index.js`: managed `bitcoind` subpath
|
|
129
|
+
- `dist/bitcoind/index.d.ts`: managed `bitcoind` declarations
|
|
130
|
+
- `dist/sqlite/index.js`: SQLite adapter subpath
|
|
131
|
+
- `dist/sqlite/index.d.ts`: SQLite adapter declarations
|
|
132
|
+
- `dist/writing_quotes.json`: bundled progress UI quote dataset
|
|
133
|
+
- `dist/art/*`: bundled terminal progress artwork
|
|
134
|
+
- `dist/*`: compiled ESM implementation
|
|
135
|
+
- `README.md`: package guide
|
|
136
|
+
- `LICENSE`: MIT license text
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export interface CogcoinPathResolution {
|
|
2
|
+
platform?: NodeJS.Platform;
|
|
3
|
+
env?: NodeJS.ProcessEnv;
|
|
4
|
+
homeDirectory?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface CogcoinResolvedPaths {
|
|
7
|
+
dataRoot: string;
|
|
8
|
+
configRoot: string;
|
|
9
|
+
stateRoot: string;
|
|
10
|
+
runtimeRoot: string;
|
|
11
|
+
hooksRoot: string;
|
|
12
|
+
bitcoinDataDir: string;
|
|
13
|
+
clientDataDir: string;
|
|
14
|
+
clientDatabasePath: string;
|
|
15
|
+
indexerRoot: string;
|
|
16
|
+
clientConfigPath: string;
|
|
17
|
+
walletStateDirectory: string;
|
|
18
|
+
walletStatePath: string;
|
|
19
|
+
walletStateBackupPath: string;
|
|
20
|
+
walletUnlockSessionPath: string;
|
|
21
|
+
walletControlLockPath: string;
|
|
22
|
+
bitcoindLockPath: string;
|
|
23
|
+
bitcoindStatusPath: string;
|
|
24
|
+
indexerDaemonLockPath: string;
|
|
25
|
+
indexerStatusPath: string;
|
|
26
|
+
hooksMiningDir: string;
|
|
27
|
+
hooksMiningEntrypointPath: string;
|
|
28
|
+
hooksMiningPackageJsonPath: string;
|
|
29
|
+
miningRoot: string;
|
|
30
|
+
miningStatusPath: string;
|
|
31
|
+
miningEventsPath: string;
|
|
32
|
+
miningControlLockPath: string;
|
|
33
|
+
}
|
|
34
|
+
export declare function resolveCogcoinPathsForTesting(resolution?: CogcoinPathResolution): CogcoinResolvedPaths;
|
|
35
|
+
export declare function resolveCogcoinAppRootForTesting(resolution?: CogcoinPathResolution): string;
|
|
36
|
+
export declare function resolveDefaultBitcoindDataDirForTesting(resolution?: CogcoinPathResolution): string;
|
|
37
|
+
export declare function resolveDefaultClientDatabasePathForTesting(resolution?: CogcoinPathResolution): string;
|
|
38
|
+
export declare function resolveDefaultClientDatabaseDirectoryForTesting(resolution?: CogcoinPathResolution): string;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { dirname, isAbsolute, join, win32 as win32Path } from "node:path";
|
|
3
|
+
function resolveLocalAppDataWindows(env, homeDirectory) {
|
|
4
|
+
return env.LOCALAPPDATA ?? win32Path.join(homeDirectory, "AppData", "Local");
|
|
5
|
+
}
|
|
6
|
+
function joinForPlatform(platform, ...parts) {
|
|
7
|
+
return platform === "win32" ? win32Path.join(...parts) : join(...parts);
|
|
8
|
+
}
|
|
9
|
+
function resolveAbsoluteEnvPath(value, fallbackPath) {
|
|
10
|
+
return value && isAbsolute(value) ? value : fallbackPath;
|
|
11
|
+
}
|
|
12
|
+
function resolveLinuxRoots(env, homeDirectory) {
|
|
13
|
+
const dataRoot = join(resolveAbsoluteEnvPath(env.XDG_DATA_HOME, join(homeDirectory, ".local", "share")), "cogcoin");
|
|
14
|
+
const configRoot = join(resolveAbsoluteEnvPath(env.XDG_CONFIG_HOME, join(homeDirectory, ".config")), "cogcoin");
|
|
15
|
+
const stateRoot = join(resolveAbsoluteEnvPath(env.XDG_STATE_HOME, join(homeDirectory, ".local", "state")), "cogcoin");
|
|
16
|
+
const runtimeRoot = env.XDG_RUNTIME_DIR && isAbsolute(env.XDG_RUNTIME_DIR)
|
|
17
|
+
? join(env.XDG_RUNTIME_DIR, "cogcoin")
|
|
18
|
+
: join(stateRoot, "runtime");
|
|
19
|
+
return {
|
|
20
|
+
dataRoot,
|
|
21
|
+
configRoot,
|
|
22
|
+
stateRoot,
|
|
23
|
+
runtimeRoot,
|
|
24
|
+
hooksRoot: join(configRoot, "hooks"),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function resolveCogcoinPathsForTesting(resolution = {}) {
|
|
28
|
+
const platform = resolution.platform ?? process.platform;
|
|
29
|
+
const env = resolution.env ?? process.env;
|
|
30
|
+
const homeDirectory = resolution.homeDirectory ?? homedir();
|
|
31
|
+
let dataRoot;
|
|
32
|
+
let configRoot;
|
|
33
|
+
let stateRoot;
|
|
34
|
+
let runtimeRoot;
|
|
35
|
+
let hooksRoot;
|
|
36
|
+
if (platform === "darwin") {
|
|
37
|
+
dataRoot = join(homeDirectory, "Library", "Application Support", "Cogcoin");
|
|
38
|
+
configRoot = join(dataRoot, "config");
|
|
39
|
+
stateRoot = join(dataRoot, "state");
|
|
40
|
+
runtimeRoot = join(dataRoot, "runtime");
|
|
41
|
+
hooksRoot = join(dataRoot, "hooks");
|
|
42
|
+
}
|
|
43
|
+
else if (platform === "win32") {
|
|
44
|
+
dataRoot = win32Path.join(resolveLocalAppDataWindows(env, homeDirectory), "Cogcoin");
|
|
45
|
+
configRoot = win32Path.join(dataRoot, "config");
|
|
46
|
+
stateRoot = win32Path.join(dataRoot, "state");
|
|
47
|
+
runtimeRoot = win32Path.join(dataRoot, "runtime");
|
|
48
|
+
hooksRoot = win32Path.join(dataRoot, "hooks");
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
const linuxRoots = resolveLinuxRoots(env, homeDirectory);
|
|
52
|
+
dataRoot = linuxRoots.dataRoot;
|
|
53
|
+
configRoot = linuxRoots.configRoot;
|
|
54
|
+
stateRoot = linuxRoots.stateRoot;
|
|
55
|
+
runtimeRoot = linuxRoots.runtimeRoot;
|
|
56
|
+
hooksRoot = linuxRoots.hooksRoot;
|
|
57
|
+
}
|
|
58
|
+
const bitcoinDataDir = joinForPlatform(platform, dataRoot, "bitcoin");
|
|
59
|
+
const clientDataDir = joinForPlatform(platform, dataRoot, "client");
|
|
60
|
+
const clientDatabasePath = joinForPlatform(platform, clientDataDir, "client.sqlite");
|
|
61
|
+
const indexerRoot = joinForPlatform(platform, dataRoot, "indexer");
|
|
62
|
+
const clientConfigPath = joinForPlatform(platform, configRoot, "client-config.json");
|
|
63
|
+
const walletStateDirectory = stateRoot;
|
|
64
|
+
const walletStatePath = joinForPlatform(platform, walletStateDirectory, "wallet-state.enc");
|
|
65
|
+
const walletStateBackupPath = joinForPlatform(platform, walletStateDirectory, "wallet-state.enc.bak");
|
|
66
|
+
const walletUnlockSessionPath = joinForPlatform(platform, runtimeRoot, "wallet-unlock-session.enc");
|
|
67
|
+
const walletControlLockPath = joinForPlatform(platform, runtimeRoot, "wallet-control.lock");
|
|
68
|
+
const bitcoindLockPath = joinForPlatform(platform, runtimeRoot, "bitcoind.lock");
|
|
69
|
+
const bitcoindStatusPath = joinForPlatform(platform, runtimeRoot, "bitcoind-status.json");
|
|
70
|
+
const indexerDaemonLockPath = joinForPlatform(platform, runtimeRoot, "indexer-daemon.lock");
|
|
71
|
+
const indexerStatusPath = joinForPlatform(platform, indexerRoot, "status.json");
|
|
72
|
+
const hooksMiningDir = joinForPlatform(platform, hooksRoot, "mining");
|
|
73
|
+
const hooksMiningEntrypointPath = joinForPlatform(platform, hooksMiningDir, "generate-sentences.js");
|
|
74
|
+
const hooksMiningPackageJsonPath = joinForPlatform(platform, hooksMiningDir, "package.json");
|
|
75
|
+
const miningRoot = joinForPlatform(platform, runtimeRoot, "mining");
|
|
76
|
+
const miningStatusPath = joinForPlatform(platform, miningRoot, "status.json");
|
|
77
|
+
const miningEventsPath = joinForPlatform(platform, miningRoot, "events.jsonl");
|
|
78
|
+
const miningControlLockPath = joinForPlatform(platform, runtimeRoot, "mining-control.lock");
|
|
79
|
+
return {
|
|
80
|
+
dataRoot,
|
|
81
|
+
configRoot,
|
|
82
|
+
stateRoot,
|
|
83
|
+
runtimeRoot,
|
|
84
|
+
hooksRoot,
|
|
85
|
+
bitcoinDataDir,
|
|
86
|
+
clientDataDir,
|
|
87
|
+
clientDatabasePath,
|
|
88
|
+
indexerRoot,
|
|
89
|
+
clientConfigPath,
|
|
90
|
+
walletStateDirectory,
|
|
91
|
+
walletStatePath,
|
|
92
|
+
walletStateBackupPath,
|
|
93
|
+
walletUnlockSessionPath,
|
|
94
|
+
walletControlLockPath,
|
|
95
|
+
bitcoindLockPath,
|
|
96
|
+
bitcoindStatusPath,
|
|
97
|
+
indexerDaemonLockPath,
|
|
98
|
+
indexerStatusPath,
|
|
99
|
+
hooksMiningDir,
|
|
100
|
+
hooksMiningEntrypointPath,
|
|
101
|
+
hooksMiningPackageJsonPath,
|
|
102
|
+
miningRoot,
|
|
103
|
+
miningStatusPath,
|
|
104
|
+
miningEventsPath,
|
|
105
|
+
miningControlLockPath,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
export function resolveCogcoinAppRootForTesting(resolution = {}) {
|
|
109
|
+
return resolveCogcoinPathsForTesting(resolution).dataRoot;
|
|
110
|
+
}
|
|
111
|
+
export function resolveDefaultBitcoindDataDirForTesting(resolution = {}) {
|
|
112
|
+
return resolveCogcoinPathsForTesting(resolution).bitcoinDataDir;
|
|
113
|
+
}
|
|
114
|
+
export function resolveDefaultClientDatabasePathForTesting(resolution = {}) {
|
|
115
|
+
return resolveCogcoinPathsForTesting(resolution).clientDatabasePath;
|
|
116
|
+
}
|
|
117
|
+
export function resolveDefaultClientDatabaseDirectoryForTesting(resolution = {}) {
|
|
118
|
+
const platform = resolution.platform ?? process.platform;
|
|
119
|
+
const dbPath = resolveDefaultClientDatabasePathForTesting(resolution);
|
|
120
|
+
return platform === "win32" ? win32Path.dirname(dbPath) : dirname(dbPath);
|
|
121
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
_____ _____
|
|
2
|
+
( ___ ) ( ___ )
|
|
3
|
+
| |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| |
|
|
4
|
+
| | | |
|
|
5
|
+
| | ___ ___ ___ ___ ___ ___ _ _ | |
|
|
6
|
+
| | / __| / _ \ / __| / __| / _ \ |_ _| | \| | | |
|
|
7
|
+
| | | (__ | (_) | | (_ | | (__ | (_) | | | | .` | | |
|
|
8
|
+
| | \___| \___/ \___| \___| \___/ |___| |_|\_| | |
|
|
9
|
+
| | _|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""| | |
|
|
10
|
+
| | "`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-' | |
|
|
11
|
+
| | | |
|
|
12
|
+
|___|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|___|
|
|
13
|
+
(_____) (_____)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
_____ _____
|
|
2
|
+
( ___ ) ( ___ )
|
|
3
|
+
| |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| |
|
|
4
|
+
| | | |
|
|
5
|
+
| | | |
|
|
6
|
+
| | | |
|
|
7
|
+
| | | |
|
|
8
|
+
| | | |
|
|
9
|
+
| | | |
|
|
10
|
+
| | | |
|
|
11
|
+
| | | |
|
|
12
|
+
|___|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|___|
|
|
13
|
+
(_____) (_____)
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
o ___ ___ ___ ___ ___ ___ _ _
|
|
2
|
+
o / __| / _ \ / __| / __| / _ \ |_ _| | \| |
|
|
3
|
+
__ | (__ | (_) | | (_ | | (__ | (_) | | | | .` |
|
|
4
|
+
|| \___| \___/ \___| \___| \___/ |___| |_|\_|
|
|
5
|
+
_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|
|
|
6
|
+
"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
___ ___ ___ ___ ___ ___ _ _
|
|
2
|
+
/ __| / _ \ / __| / __| / _ \ |_ _| | \| |
|
|
3
|
+
__ | (__ | (_) | | (_ | | (__ | (_) | | | | .` |
|
|
4
|
+
|| \___| \___/ \___| \___| \___/ |___| |_|\_|
|
|
5
|
+
_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|
|
|
6
|
+
"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { BitcoinRpcClient } from "../rpc.js";
|
|
2
|
+
import type { SnapshotMetadata } from "../types.js";
|
|
3
|
+
import type { BootstrapPersistentState } from "./types.js";
|
|
4
|
+
export declare function isSnapshotAlreadyLoaded(rpc: Pick<BitcoinRpcClient, "getChainStates">, snapshot: SnapshotMetadata, state: BootstrapPersistentState): Promise<boolean>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function chainStateMatches(chainState, snapshot, baseHeight, tipHashHex) {
|
|
2
|
+
if (tipHashHex !== null && chainState.snapshot_blockhash === tipHashHex) {
|
|
3
|
+
return true;
|
|
4
|
+
}
|
|
5
|
+
if (baseHeight !== null && chainState.blocks === baseHeight && chainState.validated === false) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
return chainState.blocks === snapshot.height && chainState.validated === false;
|
|
9
|
+
}
|
|
10
|
+
export async function isSnapshotAlreadyLoaded(rpc, snapshot, state) {
|
|
11
|
+
const chainStates = await rpc.getChainStates();
|
|
12
|
+
return chainStates.chainstates.some((chainState) => chainStateMatches(chainState, snapshot, state.baseHeight, state.tipHashHex));
|
|
13
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SnapshotMetadata } from "../types.js";
|
|
2
|
+
export declare const SNAPSHOT_METADATA_VERSION = 1;
|
|
3
|
+
export declare const DOWNLOAD_RETRY_BASE_MS = 1000;
|
|
4
|
+
export declare const DOWNLOAD_RETRY_MAX_MS = 30000;
|
|
5
|
+
export declare const HEADER_POLL_MS = 2000;
|
|
6
|
+
export declare const HEADER_NO_PEER_TIMEOUT_MS = 60000;
|
|
7
|
+
export declare const DEFAULT_SNAPSHOT_METADATA: SnapshotMetadata;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const SNAPSHOT_METADATA_VERSION = 1;
|
|
2
|
+
export const DOWNLOAD_RETRY_BASE_MS = 1_000;
|
|
3
|
+
export const DOWNLOAD_RETRY_MAX_MS = 30_000;
|
|
4
|
+
export const HEADER_POLL_MS = 2_000;
|
|
5
|
+
export const HEADER_NO_PEER_TIMEOUT_MS = 60_000;
|
|
6
|
+
export const DEFAULT_SNAPSHOT_METADATA = {
|
|
7
|
+
url: "https://snapshots.cogcoin.org/utxo-910000.dat",
|
|
8
|
+
filename: "utxo-910000.dat",
|
|
9
|
+
height: 910_000,
|
|
10
|
+
sha256: "6ac0208110d6d6c0783c50ea825aae32f5229cf1dcb63ac986543e95aa0306bf",
|
|
11
|
+
sizeBytes: 9_637_809_744,
|
|
12
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ClientTip } from "../../types.js";
|
|
2
|
+
import { ManagedProgressController } from "../progress.js";
|
|
3
|
+
import { BitcoinRpcClient } from "../rpc.js";
|
|
4
|
+
import type { BootstrapPhase, SnapshotMetadata } from "../types.js";
|
|
5
|
+
export declare class AssumeUtxoBootstrapController {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(options: {
|
|
8
|
+
rpc: BitcoinRpcClient;
|
|
9
|
+
dataDir: string;
|
|
10
|
+
progress: ManagedProgressController;
|
|
11
|
+
snapshot?: SnapshotMetadata;
|
|
12
|
+
fetchImpl?: typeof fetch;
|
|
13
|
+
});
|
|
14
|
+
get quoteStatePath(): string;
|
|
15
|
+
get snapshot(): SnapshotMetadata;
|
|
16
|
+
ensureReady(indexedTip: ClientTip | null, expectedChain: "main" | "regtest"): Promise<void>;
|
|
17
|
+
getStateForTesting(): Promise<{
|
|
18
|
+
metadataVersion: number;
|
|
19
|
+
snapshot: SnapshotMetadata;
|
|
20
|
+
phase: BootstrapPhase;
|
|
21
|
+
downloadedBytes: number;
|
|
22
|
+
validated: boolean;
|
|
23
|
+
loadTxOutSetComplete: boolean;
|
|
24
|
+
baseHeight: number | null;
|
|
25
|
+
tipHashHex: string | null;
|
|
26
|
+
lastError: string | null;
|
|
27
|
+
updatedAt: number;
|
|
28
|
+
}>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { createBootstrapProgressForTesting, ManagedProgressController } from "../progress.js";
|
|
2
|
+
import { BitcoinRpcClient } from "../rpc.js";
|
|
3
|
+
import { DEFAULT_SNAPSHOT_METADATA } from "./constants.js";
|
|
4
|
+
import { downloadSnapshotFileForTesting } from "./download.js";
|
|
5
|
+
import { waitForHeaders } from "./headers.js";
|
|
6
|
+
import { resolveBootstrapPaths } from "./paths.js";
|
|
7
|
+
import { loadBootstrapState, saveBootstrapState } from "./state.js";
|
|
8
|
+
import { isSnapshotAlreadyLoaded } from "./chainstate.js";
|
|
9
|
+
async function loadSnapshotIntoNode(rpc, snapshotPath) {
|
|
10
|
+
return rpc.loadTxOutSet(snapshotPath);
|
|
11
|
+
}
|
|
12
|
+
export class AssumeUtxoBootstrapController {
|
|
13
|
+
#rpc;
|
|
14
|
+
#paths;
|
|
15
|
+
#progress;
|
|
16
|
+
#snapshot;
|
|
17
|
+
#fetchImpl;
|
|
18
|
+
#statePromise = null;
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.#rpc = options.rpc;
|
|
21
|
+
this.#progress = options.progress;
|
|
22
|
+
this.#snapshot = options.snapshot ?? DEFAULT_SNAPSHOT_METADATA;
|
|
23
|
+
this.#paths = resolveBootstrapPaths(options.dataDir, this.#snapshot);
|
|
24
|
+
this.#fetchImpl = options.fetchImpl;
|
|
25
|
+
}
|
|
26
|
+
get quoteStatePath() {
|
|
27
|
+
return this.#paths.quoteStatePath;
|
|
28
|
+
}
|
|
29
|
+
get snapshot() {
|
|
30
|
+
return this.#snapshot;
|
|
31
|
+
}
|
|
32
|
+
async ensureReady(indexedTip, expectedChain) {
|
|
33
|
+
if (expectedChain !== "main") {
|
|
34
|
+
await this.#progress.setPhase("paused", {
|
|
35
|
+
...createBootstrapProgressForTesting("paused", this.#snapshot),
|
|
36
|
+
message: "Managed regtest sync does not use assumeutxo bootstrap.",
|
|
37
|
+
});
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (indexedTip !== null) {
|
|
41
|
+
await this.#progress.setPhase("follow_tip", {
|
|
42
|
+
blocks: indexedTip.height,
|
|
43
|
+
targetHeight: indexedTip.height,
|
|
44
|
+
message: "Resuming from the persisted Cogcoin indexed tip.",
|
|
45
|
+
});
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const state = await this.#loadState();
|
|
49
|
+
if (state.loadTxOutSetComplete && await isSnapshotAlreadyLoaded(this.#rpc, this.#snapshot, state)) {
|
|
50
|
+
await this.#progress.setPhase("bitcoin_sync", {
|
|
51
|
+
blocks: state.baseHeight,
|
|
52
|
+
targetHeight: state.baseHeight ?? this.#snapshot.height,
|
|
53
|
+
baseHeight: state.baseHeight,
|
|
54
|
+
tipHashHex: state.tipHashHex,
|
|
55
|
+
message: "Using the previously loaded assumeutxo chainstate.",
|
|
56
|
+
lastError: state.lastError,
|
|
57
|
+
});
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
await downloadSnapshotFileForTesting({
|
|
61
|
+
fetchImpl: this.#fetchImpl,
|
|
62
|
+
metadata: this.#snapshot,
|
|
63
|
+
paths: this.#paths,
|
|
64
|
+
progress: this.#progress,
|
|
65
|
+
state,
|
|
66
|
+
});
|
|
67
|
+
if (!await isSnapshotAlreadyLoaded(this.#rpc, this.#snapshot, state)) {
|
|
68
|
+
await waitForHeaders(this.#rpc, this.#snapshot, this.#progress);
|
|
69
|
+
await this.#progress.setPhase("load_snapshot", {
|
|
70
|
+
downloadedBytes: this.#snapshot.sizeBytes,
|
|
71
|
+
totalBytes: this.#snapshot.sizeBytes,
|
|
72
|
+
percent: 100,
|
|
73
|
+
message: "Loading the UTXO snapshot into bitcoind.",
|
|
74
|
+
});
|
|
75
|
+
const loadResult = await loadSnapshotIntoNode(this.#rpc, this.#paths.snapshotPath);
|
|
76
|
+
state.loadTxOutSetComplete = true;
|
|
77
|
+
state.baseHeight = loadResult.base_height;
|
|
78
|
+
state.tipHashHex = loadResult.tip_hash;
|
|
79
|
+
state.phase = "bitcoin_sync";
|
|
80
|
+
state.lastError = null;
|
|
81
|
+
await saveBootstrapState(this.#paths, state);
|
|
82
|
+
}
|
|
83
|
+
const info = await this.#rpc.getBlockchainInfo();
|
|
84
|
+
await this.#progress.setPhase("bitcoin_sync", {
|
|
85
|
+
blocks: info.blocks,
|
|
86
|
+
headers: info.headers,
|
|
87
|
+
targetHeight: info.headers,
|
|
88
|
+
baseHeight: state.baseHeight,
|
|
89
|
+
tipHashHex: state.tipHashHex,
|
|
90
|
+
message: "Bitcoin Core is syncing blocks after assumeutxo bootstrap.",
|
|
91
|
+
lastError: state.lastError,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async getStateForTesting() {
|
|
95
|
+
return { ...(await this.#loadState()) };
|
|
96
|
+
}
|
|
97
|
+
async #loadState() {
|
|
98
|
+
this.#statePromise ??= loadBootstrapState(this.#paths, this.#snapshot);
|
|
99
|
+
return this.#statePromise;
|
|
100
|
+
}
|
|
101
|
+
}
|