From 8b963a0dd9477ba9a002a639f23eac544f801794 Mon Sep 17 00:00:00 2001 From: furszy Date: Wed, 1 Jun 2022 12:49:11 -0300 Subject: [PATCH] wallet: decouple 'IsAddressUsed' in two function so the functionality can be reused if the caller already have the address book entry. --- src/wallet/wallet.cpp | 16 ++++++---------- src/wallet/wallet.h | 1 + 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 2d0ccece0..ed8755f59 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2636,19 +2636,15 @@ void CWallet::LoadDestData(const CTxDestination &dest, const std::string &key, c m_address_book[dest].destdata.insert(std::make_pair(key, value)); } +bool CWallet::IsUsedInAddrBook(const CAddressBookData& data) const +{ + return data.destdata.find("used") != data.destdata.end(); +} + bool CWallet::IsAddressUsed(const CTxDestination& dest) const { - const std::string key{"used"}; std::map::const_iterator i = m_address_book.find(dest); - if(i != m_address_book.end()) - { - CAddressBookData::StringMap::const_iterator j = i->second.destdata.find(key); - if(j != i->second.destdata.end()) - { - return true; - } - } - return false; + return i != m_address_book.end() && IsUsedInAddrBook(i->second); } std::vector CWallet::GetAddressReceiveRequests() const diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index efe2c40c6..b1b8a3fa7 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -296,6 +296,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati std::atomic m_wallet_flags{0}; bool SetAddressBookWithDB(WalletBatch& batch, const CTxDestination& address, const std::string& strName, const std::string& strPurpose); + bool IsUsedInAddrBook(const CAddressBookData& data) const; //! Unsets a wallet flag and saves it to disk void UnsetWalletFlagWithDB(WalletBatch& batch, uint64_t flag);