Skip to content

Commit 97b0753

Browse files
committed
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
1 parent 0375244 commit 97b0753

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/wallet/wallet.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,6 +2385,7 @@ bool CWallet::SetAddressBook(const CTxDestination& address, const std::string& s
23852385

23862386
bool CWallet::DelAddressBook(const CTxDestination& address)
23872387
{
2388+
const std::string& dest = EncodeDestination(address);
23882389
WalletBatch batch(GetDatabase());
23892390
{
23902391
LOCK(cs_wallet);
@@ -2396,14 +2397,30 @@ bool CWallet::DelAddressBook(const CTxDestination& address)
23962397
return false;
23972398
}
23982399
// Delete data rows associated with this address
2399-
batch.EraseAddressData(address);
2400+
if (!batch.EraseAddressData(address)) {
2401+
WalletLogPrintf("Error: cannot erase address book entry data\n");
2402+
return false;
2403+
}
2404+
2405+
// Delete purpose entry
2406+
if (!batch.ErasePurpose(dest)) {
2407+
WalletLogPrintf("Error: cannot erase address book entry purpose\n");
2408+
return false;
2409+
}
2410+
2411+
// Delete name entry
2412+
if (!batch.EraseName(dest)) {
2413+
WalletLogPrintf("Error: cannot erase address book entry name\n");
2414+
return false;
2415+
}
2416+
2417+
// finally, remove it from the map
24002418
m_address_book.erase(address);
24012419
}
24022420

2421+
// All good, signal changes
24032422
NotifyAddressBookChanged(address, "", /*is_mine=*/false, AddressPurpose::SEND, CT_DELETED);
2404-
2405-
batch.ErasePurpose(EncodeDestination(address));
2406-
return batch.EraseName(EncodeDestination(address));
2423+
return true;
24072424
}
24082425

24092426
size_t CWallet::KeypoolCountExternalKeys() const

0 commit comments

Comments
 (0)