Skip to content

Commit abac436

Browse files
committed
wallet: Avoid multiple BerkeleyBatch in DelAddressBook
1 parent 0368931 commit abac436

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/wallet/wallet.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,6 +2346,7 @@ std::map<CTxDestination, std::vector<COutput>> CWallet::ListCoins() const
23462346

23472347
const CTxOut& CWallet::FindNonChangeParentOutput(const CTransaction& tx, int output) const
23482348
{
2349+
AssertLockHeld(cs_wallet);
23492350
const CTransaction* ptx = &tx;
23502351
int n = output;
23512352
while (IsChange(ptx->vout[n]) && ptx->vin.size() > 0) {
@@ -3264,6 +3265,7 @@ bool CWallet::SetAddressBook(const CTxDestination& address, const std::string& s
32643265
bool CWallet::DelAddressBook(const CTxDestination& address)
32653266
{
32663267
bool is_mine;
3268+
WalletBatch batch(*database);
32673269
{
32683270
LOCK(cs_wallet);
32693271
// If we want to delete receiving addresses, we need to take care that DestData "used" (and possibly newer DestData) gets preserved (and the "deleted" address transformed into a change entry instead of actually being deleted)
@@ -3277,16 +3279,16 @@ bool CWallet::DelAddressBook(const CTxDestination& address)
32773279
std::string strAddress = EncodeDestination(address);
32783280
for (const std::pair<const std::string, std::string> &item : m_address_book[address].destdata)
32793281
{
3280-
WalletBatch(*database).EraseDestData(strAddress, item.first);
3282+
batch.EraseDestData(strAddress, item.first);
32813283
}
32823284
m_address_book.erase(address);
32833285
is_mine = IsMine(address) != ISMINE_NO;
32843286
}
32853287

32863288
NotifyAddressBookChanged(this, address, "", is_mine, "", CT_DELETED);
32873289

3288-
WalletBatch(*database).ErasePurpose(EncodeDestination(address));
3289-
return WalletBatch(*database).EraseName(EncodeDestination(address));
3290+
batch.ErasePurpose(EncodeDestination(address));
3291+
return batch.EraseName(EncodeDestination(address));
32903292
}
32913293

32923294
size_t CWallet::KeypoolCountExternalKeys() const

0 commit comments

Comments
 (0)