-
Notifications
You must be signed in to change notification settings - Fork 646
Description
This doc serves as the master tracking issue.
Motivation
The btcwallet package currently exposes a large, monolithic wallet.Interface with approximately 50 methods. Its primary consumer, lnd, defines its own lnwallet.WalletController interface with around 40 methods, many of which are duplicates or slight variations of the wallet.Interface methods.
This duplication and the sheer size of these interfaces make the code difficult to maintain, test, and reason about. It violates the Interface Segregation Principle and the Single Responsibility Principle.
The goal of this refactoring is to decompose these monolithic interfaces into a new set of clean, logical, and role-based interfaces within the btcwallet package. This will provide a more secure, flexible, and intuitive API for all consumers.
For a full breakdown of the design, please see the wallet architecture documentation. For the analysis of the current code structure, check this analysis.
Guiding Principles
All implementation work must adhere to the following key principles:
- Separation of Concerns: A primary goal of this refactoring is to create a clean separation between business logic (the "how") and data persistence (the "what"). The new interfaces should be implemented in a way that the database logic is fully encapsulated and abstracted, preparing for the upcoming transition to a SQL backend.
- Actor Model: Concurrency should be managed using the Actor Model to ensure thread safety and avoid complex locking.
- SOLID Principles: The implementation should follow the SOLID principles, particularly the Single Responsibility and Interface Segregation Principles.
Implementation Plan
The following is a checklist of the new interfaces to be implemented. Each item represents an ADR that can be picked up by a developer,
-
Implement and Refactor
WalletControllerInterface Design forWalletController#1030- Responsibility: Manages the wallet's lifecycle (Start, Stop, Lock, Unlock) and provides high-level status information.
-
Implement and Refactor
AccountManagerInterface Design forAccountManager#1031- Responsibility: Handles the creation, querying, and renaming of accounts, and is also responsible for querying account-specific or total wallet balances.
-
Implement and Refactor
AddressManagerInterface Design forAddressManager#1032- Responsibility: Manages the generation, import, and inspection of addresses and scripts.
-
Implement and Refactor
UtxoManagerInterface Design forUtxoManager#1033- Responsibility: Manages the wallet's UTXO set, including listing unspent outputs and managing UTXO leases.
-
Implement and Refactor
TxPublisherInterface Design forTxPublisher#1034- Responsibility: A command-oriented interface for all "write" operations related to transactions, such as creating and broadcasting them.
-
Implement and Refactor
PsbtManagerInterface Design forPsbtManager#1035- Responsibility: A dedicated interface for the multi-step PSBT workflow (Fund, Sign, Finalize).
-
Implement and Refactor
TxReaderInterface Design forTxReader#1036- Responsibility: A query-oriented interface for all "read" operations related to transaction history.
-
Implement and Refactor
SignerInterface Design forSigner#1037- Responsibility: A low-level interface providing direct access to cryptographic operations like signing and key derivation.