From 144b2f85da4d51bf7d72b987888ddcaf5b429eed Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sat, 22 Feb 2020 01:52:47 +0000 Subject: [PATCH] Wallet: Require usage of new CAddressBookData::setLabel to change label --- src/wallet/wallet.cpp | 2 +- src/wallet/wallet.h | 10 ++++++++-- src/wallet/walletdb.cpp | 4 +++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 6737270e52e..6b061308ecd 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3193,7 +3193,7 @@ bool CWallet::SetAddressBookWithDB(WalletBatch& batch, const CTxDestination& add LOCK(cs_wallet); std::map::iterator mi = m_address_book.find(address); fUpdated = mi != m_address_book.end(); - m_address_book[address].name = strName; + m_address_book[address].SetLabel(strName); if (!strPurpose.empty()) /* update purpose only if requested */ m_address_book[address].purpose = strPurpose; } diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index c6f288a4806..47268ba88c5 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -181,14 +181,20 @@ public: /** Address book data */ class CAddressBookData { +private: + std::string m_label; public: - std::string name; + const std::string& name; std::string purpose; - CAddressBookData() : purpose("unknown") {} + CAddressBookData() : name(m_label), purpose("unknown") {} typedef std::map StringMap; StringMap destdata; + + void SetLabel(const std::string& label) { + m_label = label; + } }; struct CRecipient diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 2e08a044da2..568b21ed00c 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -206,7 +206,9 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, if (strType == DBKeys::NAME) { std::string strAddress; ssKey >> strAddress; - ssValue >> pwallet->m_address_book[DecodeDestination(strAddress)].name; + std::string label; + ssValue >> label; + pwallet->m_address_book[DecodeDestination(strAddress)].SetLabel(label); } else if (strType == DBKeys::PURPOSE) { std::string strAddress; ssKey >> strAddress;