Publish watch-only Bitcoin positions into existing Crypto accounts
Superseded by #5673 in the native Bitcoin stack. Further review continues there on the same commit, 6d47dc9c0. This PR preserves the earlier discussion. Feature tracker.
Problem and behaviour
A complete Bitcoin wallet read gives Sure a quantity. An existing Crypto account may also have cash, trades, other assets and manual valuations. This change publishes only the BTC holding and records the wallet’s net movements as zero-cash trades. Spending 0.03001000 BTC including the network fee reduces that position by 0.03001000 BTC without changing the account’s fiat cash.
The first priced publication establishes the cash baseline. If the first price is unavailable, disconnecting preserves the previous manual valuation. Existing transactions establish the starting balance. Later confirmations, replaced transactions and chain reorganizations reconcile the journal. Adding a source changes coverage while the original connection date continues to protect published movements.
Review scope
- Start with
BitcoinWalletAccount#connect!,BitcoinWalletAccount::Processorand the shared holding and balance materializers. - Only the provider-managed security is protected against trade edits, removal and remapping. Connection status exposes counts and freshness for the API caller’s accessible accounts. Public keys and address lists stay out of that response.
- Connected wallets participate in hourly and family sync. A failure to schedule one wallet is handled independently.
- The tables and accounting migrations belong to the prerequisite PRs. This layer adds no migration.
Validation
- Rails suite on the rebased head passed with 18,657 tests, 114,134 assertions, 9 skips, zero failures or errors.
- Chromium system suite: 450 tests, 2527 assertions, 0 skips, zero failures or errors.
- RuboCop, full ERB lint, Biome and Brakeman passed.
- API documentation regenerated and verified. The request specs use the shared API-key authentication pattern.
Summary by cubic
Connects a discovered Bitcoin wallet to an existing manual Crypto account and publishes only its BTC holding, leaving cash and other assets manual.
- A first priced publication sets a cash anchor; wallet net movements become zero-cash trades, so spending BTC never changes fiat cash. Cash anchors stay out of activity and valuation lists, and anchored accounts sync in their family's time zone.
- The managed security is protected from trade edits, removal, and remapping until the wallet is disconnected. Extended public keys are encrypted at rest and never fall back to plaintext without encryption configured.
- Connected wallets sync hourly and on family sync, with a failed wallet handled independently. Wallet reads can finish across blocks found mid-sync.
- The provider connections API returns aggregated wallet status without public keys, addresses, or per-transaction data.
Summary by CodeRabbit
- New Features
- Track Bitcoin wallet balances and activity by connecting wallet addresses or watch-only extended public keys to a crypto account.
- View wallet sync status and summary details, including address counts and history freshness.
- Reconcile wallet activity with holdings and account balances.
- Bug Fixes
- Cash-balance reconciliations no longer appear as account activity or regular valuation results.
- Trades tied to managed Bitcoin positions cannot be edited or deleted; failed trade deletions now return a validation error.