Skip to content

refactor: implement stealth api as rust crate #17

Merged
LORDBABUINO merged 16 commits into
stealth-bitcoin:mainfrom
satsfy:add-api
May 26, 2026
Merged

refactor: implement stealth api as rust crate #17
LORDBABUINO merged 16 commits into
stealth-bitcoin:mainfrom
satsfy:add-api

Conversation

@satsfy

@satsfy satsfy commented Mar 26, 2026

Copy link
Copy Markdown
Collaborator

Depends on #16 (it will be in draft mode until its merged)

Solves #10. This PR is a combination of rust refactors from @brenorb in #15 and me.

Implements an HTTP API for stealth as rust create stealth-api with POST /api/wallet/scan, request validation, structured error responses, RPC autodetection, and regtest end-to-end tests.

Replaces instructions on README on how to use stealth api.

Reviewer Notes

Open the branch locally, run cargo build to verify it compiles and run cargo test. Inspect the e2e test in api/tests/.

Run the api with cargo run --bin stealth-api and test that call:

curl 'http://localhost:20899/api/wallet/scan' \
  -H 'content-type: application/json' \
  -d '{"descriptor":"wpkh(xpub.../0/*)"}' | jq

@satsfy satsfy changed the title Add api refactor: implement stealth api as rust crate Mar 26, 2026
@satsfy satsfy force-pushed the add-api branch 2 times, most recently from 3be5813 to c230e67 Compare April 5, 2026 23:28
@satsfy satsfy marked this pull request as ready for review April 5, 2026 23:31
@satsfy

satsfy commented Apr 9, 2026

Copy link
Copy Markdown
Collaborator Author

@LORDBABUINO this and PR #19 are also open for review.

Comment thread api/src/main.rs Outdated
Comment thread api/src/lib.rs
Comment thread api/src/routes/wallet.rs
Comment thread api/tests/e2e_regtest_scan.rs Outdated
Comment thread api/src/preflight.rs Outdated
Comment thread README.md Outdated
Comment thread README.md
Comment thread api/src/main.rs
# Conflicts:
#	Cargo.toml
#	README.md
#	bitcoin.conf.example
The second loop is unreachable: the first loop returns as soon as it
finds an existing candidate. Collapse to a single iterator chain.
Browser-based frontends need CORS to call the API. Apply
tower_http::cors::CorsLayer::permissive() at the router level so
the frontend (and other origins during development) can reach the
scan endpoint.
The if-chain and counter pattern is a 5-arm tuple match in disguise.
Pattern match on (descriptor, descriptors, utxos) directly: every
valid case picks exactly one variant, the empty tuple is a clear
missing-input error, and the wildcard catches mutual-exclusion
violations.
Replace the inline cookie split with stealth_bitcoincore::read_cookie_file,
which already implements the same parsing with proper error handling.
Removes duplication and keeps the cookie format in one place.
The Bitcoin Core node is the authority on descriptor validity.
Reimplementing descriptor shape/prefix/checksum checks here creates
a divergence risk with the node's own validator and adds maintenance
surface for no real safety gain. Invalid descriptors now fail at the
node, surfaced through AnalysisError.

- delete api/src/preflight.rs and its module declaration
- drop ValidationError from ApiError (no remaining producers)
- remove the validate() call from the scan handler
- drop the two tests that asserted preflight-specific rejection codes
Replace the inline cat heredoc with a single cp instruction so the
example config stays canonical (the file is already in the repo and
also drives ./scripts/setup.sh).
Replace the giant inline bootstrap-and-scan bash block with the
setup.sh script that already does the same thing (and is maintained
alongside the regtest harness). The reader sees four short steps —
setup, start API, scan, CLI alternative — instead of 40 lines of
shell to copy-paste correctly.
Replace the hand-rolled INI parser in read_bitcoin_conf_credentials
with the rust-ini crate (imported as 'ini'). The function shrinks
from ~35 lines to 6 and we stop maintaining INI parsing semantics
in this repo.
@LORDBABUINO LORDBABUINO dismissed their stale review May 26, 2026 17:12

all concerns addressed

@LORDBABUINO LORDBABUINO merged commit cba5c74 into stealth-bitcoin:main May 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants