Skip to content

Commit 78cb45d

Browse files
committed
Merge #19738: wallet: Avoid multiple BerkeleyBatch in DelAddressBook
abac436 wallet: Avoid multiple BerkeleyBatch in DelAddressBook (João Barbosa) Pull request description: ACKs for top commit: achow101: ACK abac436 jonatack: ACK abac436 meshcollider: re-utACK abac436 Tree-SHA512: 92309fb74c48694160807326c0fe9793044a75cd77ed19400cceab54a7eefeb54ffc9334535e6021b3af7b9a364dbbeda3a9173540fff8144dfd437e96d76b5c
2 parents 56d47e1 + abac436 commit 78cb45d

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
@@ -2350,6 +2350,7 @@ std::map<CTxDestination, std::vector<COutput>> CWallet::ListCoins() const
23502350

23512351
const CTxOut& CWallet::FindNonChangeParentOutput(const CTransaction& tx, int output) const
23522352
{
2353+
AssertLockHeld(cs_wallet);
23532354
const CTransaction* ptx = &tx;
23542355
int n = output;
23552356
while (IsChange(ptx->vout[n]) && ptx->vin.size() > 0) {
@@ -3268,6 +3269,7 @@ bool CWallet::SetAddressBook(const CTxDestination& address, const std::string& s
32683269
bool CWallet::DelAddressBook(const CTxDestination& address)
32693270
{
32703271
bool is_mine;
3272+
WalletBatch batch(*database);
32713273
{
32723274
LOCK(cs_wallet);
32733275
// 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)
@@ -3281,16 +3283,16 @@ bool CWallet::DelAddressBook(const CTxDestination& address)
32813283
std::string strAddress = EncodeDestination(address);
32823284
for (const std::pair<const std::string, std::string> &item : m_address_book[address].destdata)
32833285
{
3284-
WalletBatch(*database).EraseDestData(strAddress, item.first);
3286+
batch.EraseDestData(strAddress, item.first);
32853287
}
32863288
m_address_book.erase(address);
32873289
is_mine = IsMine(address) != ISMINE_NO;
32883290
}
32893291

32903292
NotifyAddressBookChanged(this, address, "", is_mine, "", CT_DELETED);
32913293

3292-
WalletBatch(*database).ErasePurpose(EncodeDestination(address));
3293-
return WalletBatch(*database).EraseName(EncodeDestination(address));
3294+
batch.ErasePurpose(EncodeDestination(address));
3295+
return batch.EraseName(EncodeDestination(address));
32943296
}
32953297

32963298
size_t CWallet::KeypoolCountExternalKeys() const

0 commit comments

Comments
 (0)