This isn't loading anything so the name is a bit odd. Perhaps instead of splitting:
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 6a40cfe97e..a633d7966e 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -2617,19 +2617,13 @@ util::Result<void> CWallet::DisplayAddress(const CTxDestination& dest)
return util::Error{_("There is no ScriptPubKeyManager for this address")};
}
-void CWallet::LoadLockedCoin(const COutPoint& coin, bool persistent)
+bool CWallet::LockCoin(const COutPoint& coin, bool persistent, bool persist_now)
{
AssertLockHeld(cs_wallet);
m_locked_coins.emplace(coin, persistent);
-}
-
-bool CWallet::LockCoin(const COutPoint& output, bool persist)
-{
- AssertLockHeld(cs_wallet);
- LoadLockedCoin(output, persist);
- if (persist) {
+ if (persistent && persist_now) {
WalletBatch batch(GetDatabase());
- return batch.WriteLockedUTXO(output);
+ return batch.WriteLockedUTXO(coin);
}
return true;
}
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index 7fe557f71d..7629de2f9a 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -548,8 +548,7 @@ public:
util::Result<void> DisplayAddress(const CTxDestination& dest) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
bool IsLockedCoin(const COutPoint& output) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
- void LoadLockedCoin(const COutPoint& coin, bool persistent) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
- bool LockCoin(const COutPoint& output, bool persist) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
+ bool LockCoin(const COutPoint& output, bool persistent, bool persist_now = true) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
bool UnlockCoin(const COutPoint& output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
bool UnlockAllCoins() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
void ListLockedCoins(std::vector<COutPoint>& vOutpts) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp
index 0f0e228fc8..58f7409b58 100644
--- a/src/wallet/walletdb.cpp
+++ b/src/wallet/walletdb.cpp
@@ -1065,14 +1065,14 @@ static DBErrors LoadTxRecords(CWallet* pwallet, DatabaseBatch& batch, std::vecto
});
result = std::max(result, tx_res.m_result);
- // Load locked utxo record
+ // Load utxo record and lock
LoadResult locked_utxo_res = LoadRecords(pwallet, batch, DBKeys::LOCKED_UTXO,
[] (CWallet* pwallet, DataStream& key, DataStream& value, std::string& err) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) {
Txid hash;
uint32_t n;
key >> hash;
key >> n;
- pwallet->LoadLockedCoin(COutPoint(hash, n), /*persistent=*/true);
+ pwallet->LockCoin(COutPoint(hash, n), /*persistent=*/true, /*persist_now=*/false);
return DBErrors::LOAD_OK;
});
result = std::max(result, locked_utxo_res.m_result);