diff options
author | furszy <matiasfurszyfer@protonmail.com> | 2022-07-09 21:30:57 -0300 |
---|---|---|
committer | furszy <matiasfurszyfer@protonmail.com> | 2024-02-07 18:11:51 -0300 |
commit | 97b075392305becfbad4d497614478cff2d9237f (patch) | |
tree | 0dfccc5464dd7d7518cc0538885b012ca0336fa9 /src/wallet/wallet.cpp | |
parent | 03752444cd54df05a731557968d5a9f33a55c55c (diff) | |
download | bitcoin-97b075392305becfbad4d497614478cff2d9237f.tar.xz |
wallet: clean redundancies in DelAddressBook
1) Encode destination only once (instead of three).
2) Fail if the entry's linked data cannot be removed.
3) Don't remove entry from memory if db write fail.
4) Notify GUI only if removal succeeded
Diffstat (limited to 'src/wallet/wallet.cpp')
-rw-r--r-- | src/wallet/wallet.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index e03f5532fc..28c696d0dd 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2385,6 +2385,7 @@ bool CWallet::SetAddressBook(const CTxDestination& address, const std::string& s bool CWallet::DelAddressBook(const CTxDestination& address) { + const std::string& dest = EncodeDestination(address); WalletBatch batch(GetDatabase()); { LOCK(cs_wallet); @@ -2396,14 +2397,30 @@ bool CWallet::DelAddressBook(const CTxDestination& address) return false; } // Delete data rows associated with this address - batch.EraseAddressData(address); + if (!batch.EraseAddressData(address)) { + WalletLogPrintf("Error: cannot erase address book entry data\n"); + return false; + } + + // Delete purpose entry + if (!batch.ErasePurpose(dest)) { + WalletLogPrintf("Error: cannot erase address book entry purpose\n"); + return false; + } + + // Delete name entry + if (!batch.EraseName(dest)) { + WalletLogPrintf("Error: cannot erase address book entry name\n"); + return false; + } + + // finally, remove it from the map m_address_book.erase(address); } + // All good, signal changes NotifyAddressBookChanged(address, "", /*is_mine=*/false, AddressPurpose::SEND, CT_DELETED); - - batch.ErasePurpose(EncodeDestination(address)); - return batch.EraseName(EncodeDestination(address)); + return true; } size_t CWallet::KeypoolCountExternalKeys() const |