@@ -589,19 +589,24 @@ bool CWallet::IsSpent(const uint256& hash, unsigned int n) const
589589 return false ;
590590}
591591
592- void CWallet::AddToSpends (const COutPoint& outpoint, const uint256& wtxid)
592+ void CWallet::AddToSpends (const COutPoint& outpoint, const uint256& wtxid, WalletBatch* batch )
593593{
594594 mapTxSpends.insert (std::make_pair (outpoint, wtxid));
595595
596- setLockedCoins.erase (outpoint);
596+ if (batch) {
597+ UnlockCoin (outpoint, batch);
598+ } else {
599+ WalletBatch temp_batch (GetDatabase ());
600+ UnlockCoin (outpoint, &temp_batch);
601+ }
597602
598603 std::pair<TxSpends::iterator, TxSpends::iterator> range;
599604 range = mapTxSpends.equal_range (outpoint);
600605 SyncMetaData (range);
601606}
602607
603608
604- void CWallet::AddToSpends (const uint256& wtxid)
609+ void CWallet::AddToSpends (const uint256& wtxid, WalletBatch* batch )
605610{
606611 auto it = mapWallet.find (wtxid);
607612 assert (it != mapWallet.end ());
@@ -610,7 +615,7 @@ void CWallet::AddToSpends(const uint256& wtxid)
610615 return ;
611616
612617 for (const CTxIn& txin : thisTx.tx ->vin )
613- AddToSpends (txin.prevout , wtxid);
618+ AddToSpends (txin.prevout , wtxid, batch );
614619}
615620
616621bool CWallet::EncryptWallet (const SecureString& strWalletPassphrase)
@@ -910,7 +915,7 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const CWalletTx::Confirmatio
910915 wtx.nOrderPos = IncOrderPosNext (&batch);
911916 wtx.m_it_wtxOrdered = wtxOrdered.insert (std::make_pair (wtx.nOrderPos , &wtx));
912917 wtx.nTimeSmart = ComputeTimeSmart (wtx);
913- AddToSpends (hash);
918+ AddToSpends (hash, &batch );
914919 }
915920
916921 if (!fInsertedNew )
@@ -2260,22 +2265,36 @@ bool CWallet::DisplayAddress(const CTxDestination& dest)
22602265 return signer_spk_man->DisplayAddress (scriptPubKey, signer);
22612266}
22622267
2263- void CWallet::LockCoin (const COutPoint& output)
2268+ bool CWallet::LockCoin (const COutPoint& output, WalletBatch* batch )
22642269{
22652270 AssertLockHeld (cs_wallet);
22662271 setLockedCoins.insert (output);
2272+ if (batch) {
2273+ return batch->WriteLockedUTXO (output);
2274+ }
2275+ return true ;
22672276}
22682277
2269- void CWallet::UnlockCoin (const COutPoint& output)
2278+ bool CWallet::UnlockCoin (const COutPoint& output, WalletBatch* batch )
22702279{
22712280 AssertLockHeld (cs_wallet);
2272- setLockedCoins.erase (output);
2281+ bool was_locked = setLockedCoins.erase (output);
2282+ if (batch && was_locked) {
2283+ return batch->EraseLockedUTXO (output);
2284+ }
2285+ return true ;
22732286}
22742287
2275- void CWallet::UnlockAllCoins ()
2288+ bool CWallet::UnlockAllCoins ()
22762289{
22772290 AssertLockHeld (cs_wallet);
2291+ bool success = true ;
2292+ WalletBatch batch (GetDatabase ());
2293+ for (auto it = setLockedCoins.begin (); it != setLockedCoins.end (); ++it) {
2294+ success &= batch.EraseLockedUTXO (*it);
2295+ }
22782296 setLockedCoins.clear ();
2297+ return success;
22792298}
22802299
22812300bool CWallet::IsLockedCoin (uint256 hash, unsigned int n) const
0 commit comments