Skip to content

Commit

Permalink
wallet: decouple 'IsAddressUsed' in two function so the functionality…
Browse files Browse the repository at this point in the history
… can be reused if the caller already have the address book entry.
  • Loading branch information
furszy committed Jun 1, 2022
1 parent 8dd0f28 commit 8b963a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CTxDestination, CAddressBookData>::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<std::string> CWallet::GetAddressReceiveRequests() const
Expand Down
1 change: 1 addition & 0 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
std::atomic<uint64_t> 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);
Expand Down

0 comments on commit 8b963a0

Please sign in to comment.