@@ -2444,6 +2444,10 @@ bool CWallet::DelAddressBook(const CTxDestination& address)
24442444 {
24452445 batch.EraseDestData (strAddress, item.first );
24462446 }
2447+
2448+ // Explicitly erase "used" record since we no longer store it in destdata
2449+ batch.EraseDestData (strAddress, " used" );
2450+
24472451 m_address_book.erase (address);
24482452 is_mine = IsMine (address) != ISMINE_NO;
24492453 }
@@ -2821,38 +2825,40 @@ unsigned int CWallet::ComputeTimeSmart(const CWalletTx& wtx, bool rescanning_old
28212825
28222826bool CWallet::SetAddressUsed (WalletBatch& batch, const CTxDestination& dest, bool used)
28232827{
2824- const std::string key{" used" };
2825- if (std::get_if<CNoDestination>(&dest))
2828+ if (std::get_if<CNoDestination>(&dest)) {
28262829 return false ;
2830+ }
2831+
2832+ // Update CAddressBookData
2833+ m_address_book[dest].SetInputUsed (used);
28272834
2828- if (!used) {
2829- if (auto * data = util::FindKey (m_address_book, dest)) data->destdata .erase (key);
2835+ // Update the old database records
2836+ const std::string key{" used" };
2837+ if (used) {
2838+ return batch.WriteDestData (EncodeDestination (dest), key, " 1" );
2839+ } else {
28302840 return batch.EraseDestData (EncodeDestination (dest), key);
28312841 }
2832-
2833- const std::string value{" 1" };
2834- m_address_book[dest].destdata .insert (std::make_pair (key, value));
2835- return batch.WriteDestData (EncodeDestination (dest), key, value);
28362842}
28372843
28382844void CWallet::LoadDestData (const CTxDestination &dest, const std::string &key, const std::string &value)
28392845{
2846+ // Special case for "used" since we no longer store it in destdata
2847+ if (key == " used" ) {
2848+ m_address_book[dest].SetInputUsed (value == " 1" );
2849+ return ;
2850+ }
2851+
28402852 m_address_book[dest].destdata .insert (std::make_pair (key, value));
28412853}
28422854
28432855bool CWallet::IsAddressUsed (const CTxDestination& dest) const
28442856{
2845- const std::string key{" used" };
2846- std::map<CTxDestination, CAddressBookData>::const_iterator i = m_address_book.find (dest);
2847- if (i != m_address_book.end ())
2848- {
2849- CAddressBookData::StringMap::const_iterator j = i->second .destdata .find (key);
2850- if (j != i->second .destdata .end ())
2851- {
2852- return true ;
2853- }
2857+ const CAddressBookData* entry = FindAddressBookEntry (dest, /* allow_change=*/ true );
2858+ if (!entry) {
2859+ return false ;
28542860 }
2855- return false ;
2861+ return entry-> GetInputUsed () ;
28562862}
28572863
28582864std::vector<std::string> CWallet::GetAddressReceiveRequests () const
0 commit comments