In many places, our code assumes that presence in the address book indicates a non-change key, and absence of an entry in mapAddressBook indicates change.
This no longer holds true after #13756 (first released in 0.19) since it added a “used” DestData populated even for change addresses. Only avoid-reuse wallets should be affected by this issue.
Thankfully, populating DestData does not write a label to the database, so we can retroactively fix this (so long as the user didn’t see the change address and manually assign it a real label).
Fixing it is accomplished by:
- Adding a new bool to CAddressBookData to track if the label has ever been assigned, either by loading one from the database, or by assigning one at runtime.
CAddressBookData::IsChange
andCWallet::FindAddressBookEntry
are new methods to assist in excluding change from code that doesn’t expect to see them.- For safety in merging,
CAddressBookData::name
has been made read-only (the actual data is stored inm_label
, a new private member, and can be changed only withsetLabel
which updates them_change
flag), andmapAddressBook
has been renamed tom_address_book
(to force old code to be rebased to compile).
A final commit also does some minor optimisation, avoiding redundant lookups in m_address_book
when we already have a pointer to the CAddressBookData
.