diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index c2a69b6cf98a9..d036b3b7dee12 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1693,7 +1693,10 @@ bool CWallet::ImportScriptPubKeys(const std::string& label, const std::set& vWtx) return DBErrors::LOAD_OK; } - -bool CWallet::SetAddressBook(const CTxDestination& address, const std::string& strName, const std::string& strPurpose) +bool CWallet::SetAddressBookWithDB(WalletBatch& batch, const CTxDestination& address, const std::string& strName, const std::string& strPurpose) { bool fUpdated = false; { @@ -3363,9 +3365,15 @@ bool CWallet::SetAddressBook(const CTxDestination& address, const std::string& s } NotifyAddressBookChanged(this, address, strName, ::IsMine(*this, address) != ISMINE_NO, strPurpose, (fUpdated ? CT_UPDATED : CT_NEW) ); - if (!strPurpose.empty() && !WalletBatch(*database).WritePurpose(EncodeDestination(address), strPurpose)) + if (!strPurpose.empty() && !batch.WritePurpose(EncodeDestination(address), strPurpose)) return false; - return WalletBatch(*database).WriteName(EncodeDestination(address), strName); + return batch.WriteName(EncodeDestination(address), strName); +} + +bool CWallet::SetAddressBook(const CTxDestination& address, const std::string& strName, const std::string& strPurpose) +{ + WalletBatch batch(*database); + return SetAddressBookWithDB(batch, address, strName, strPurpose); } bool CWallet::DelAddressBook(const CTxDestination& address) diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index c23c12f6aff44..36a2a98cd609f 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -733,6 +733,8 @@ class CWallet final : public CCryptoKeyStore, private interfaces::Chain::Notific void AddKeypoolPubkeyWithDB(const CPubKey& pubkey, const bool internal, WalletBatch& batch); + bool SetAddressBookWithDB(WalletBatch& batch, const CTxDestination& address, const std::string& strName, const std::string& strPurpose); + /** Interface for accessing chain state. */ interfaces::Chain& m_chain;