refactor: implement stealth api as rust crate #17
Merged
Conversation
This was referenced Mar 26, 2026
3be5813 to
c230e67
Compare
Collaborator
Author
|
@LORDBABUINO this and PR #19 are also open for review. |
LORDBABUINO
previously requested changes
Apr 12, 2026
# 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-apiwithPOST /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 buildto verify it compiles and runcargo test. Inspect the e2e test inapi/tests/.Run the api with
cargo run --bin stealth-apiand test that call: