From 63dee39080f1cb8f925df2ebd9775c5dc16660f3 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Sun, 28 Jul 2024 16:08:59 +0700 Subject: [PATCH] fix: follow-up bitcoin#20773 - for collateral lock/unlock coins --- src/wallet/wallet.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 548cad688130ec..5b6b2f940c825d 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -917,8 +917,11 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const CWalletTx::Confirmatio outputs.emplace_back(wtx.tx, i); } } - for (const auto& outPoint : m_chain->listMNCollaterials(outputs)) { - LockCoin(outPoint); + // TODO: refactor duplicated code between CWallet::AddToWallet and CWallet::AutoLockMasternodeCollaterals + if (m_chain) { + for (const auto& outPoint : m_chain->listMNCollaterials(outputs)) { + LockCoin(outPoint); + } } } @@ -946,8 +949,11 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const CWalletTx::Confirmatio } } } - for (const auto& outPoint : m_chain->listMNCollaterials(outputs)) { - LockCoin(outPoint); + // TODO: refactor duplicated code with case fInstertedNew + if (m_chain) { + for (const auto& outPoint : m_chain->listMNCollaterials(outputs)) { + LockCoin(outPoint); + } } } @@ -4018,6 +4024,8 @@ DBErrors CWallet::LoadWallet() // This avoids accidental spending of collaterals. They can still be unlocked manually if a spend is really intended. void CWallet::AutoLockMasternodeCollaterals() { + if (!m_chain) return; + std::vector> outputs; LOCK(cs_wallet); @@ -4452,6 +4460,11 @@ void CWallet::ListLockedCoins(std::vector& vOutpts) const void CWallet::ListProTxCoins(std::vector& vOutpts) const { + // TODO: refactor duplicated code between CWallet::AutoLockMasternodeCollaterals and CWallet::ListProTxCoins + if (!m_chain) { + vOutpts.clear(); + return; + } std::vector> outputs; AssertLockHeld(cs_wallet);