Finishing the encapsulation work started in #25337. Please review #26836 first.
Context
We are currently using the address book for different purposes and features in the wallet such us:
- Store and retrieve own receive addresses with a label.
- Store and retrieve external addresses with a label.
- Store and retrieve payment requests.
- Mark addresses/destinations as 'used' if they appear on the blockchain (part of the “avoid re-use” feature).
- Know whether an output is a change or not based on the encoded script.
Some of these points aren’t well known by many because this code has been spread and obfuscated across the wallet’s sources. (and created in a Frankenstein style).
PR Goals
Encapsulate the address book functionalities into its own AddressBookManager class, so we are able to distinguish properly the address book responsibilities and capabilities.
Be able to decouple the address book dependency on the wallet’s main mutex (up to a certain point, because we are still using the same db connection).
Clean up the wallet sources further.
Be able to unit/fuzz test the address book manager implementation isolated from the wallet flows.
And create a new class that can be easily upgraded/replaced, and even different implementations can be used in parallel in different local wallets, by just providing a different manager instance to the wallet in the constructor.
Next steps
After this PR, will be working on improve the ‘change output’ flow which, at least for now, is strictly connected to this process (goal will be to remove the strict dependency).
Pending work (still under WIP, almost there)
- Add manager class description.
- [ ] Clean CAddressBookData.
- Cover the class with unit tests.
- Double-check commits order.
- Add addrbook purposes enum.
- Make cs_addrbook RecursiveMutex a Mutex?