Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2705,22 +2705,23 @@ bool CWallet::DisplayAddress(const CTxDestination& dest)
bool CWallet::LockCoin(const COutPoint& output, WalletBatch* batch)
{
AssertLockHeld(cs_wallet);
if (batch && !batch->WriteLockedUTXO(output)) {
return false;
}
setLockedCoins.insert(output);
RecalculateMixedCredit(output.hash);
if (batch) {
return batch->WriteLockedUTXO(output);
}
return true;
}

bool CWallet::UnlockCoin(const COutPoint& output, WalletBatch* batch)
{
AssertLockHeld(cs_wallet);
bool was_locked = setLockedCoins.erase(output);
RecalculateMixedCredit(output.hash);
if (batch && was_locked) {
return batch->EraseLockedUTXO(output);
bool was_locked = setLockedCoins.contains(output);
if (batch && was_locked && !batch->EraseLockedUTXO(output)) {
return false;
}
setLockedCoins.erase(output);
RecalculateMixedCredit(output.hash);
return true;
}

Expand All @@ -2729,10 +2730,19 @@ bool CWallet::UnlockAllCoins()
AssertLockHeld(cs_wallet);
bool success = true;
WalletBatch batch(GetDatabase());
for (auto it = setLockedCoins.begin(); it != setLockedCoins.end(); ++it) {
success &= batch.EraseLockedUTXO(*it);
std::set<uint256> affectedTxids;
for (auto it = setLockedCoins.begin(); it != setLockedCoins.end(); ) {
if (batch.EraseLockedUTXO(*it)) {
affectedTxids.insert(it->hash);
it = setLockedCoins.erase(it);
} else {
success = false;
++it;
}
}
for (const auto& txid : affectedTxids) {
RecalculateMixedCredit(txid);
}
setLockedCoins.clear();
return success;
}

Expand Down
Loading