fix: follow-up bitcoin#20773 - for collateral lock/unlock coins

This commit is contained in:
Konstantin Akimov 2024-07-28 16:08:59 +07:00 committed by pasta
parent 06ea87040b
commit 4125485401
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984

View File

@ -917,8 +917,11 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const CWalletTx::Confirmatio
outputs.emplace_back(wtx.tx, i); outputs.emplace_back(wtx.tx, i);
} }
} }
for (const auto& outPoint : m_chain->listMNCollaterials(outputs)) { // TODO: refactor duplicated code between CWallet::AddToWallet and CWallet::AutoLockMasternodeCollaterals
LockCoin(outPoint); 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)) { // TODO: refactor duplicated code with case fInstertedNew
LockCoin(outPoint); 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. // This avoids accidental spending of collaterals. They can still be unlocked manually if a spend is really intended.
void CWallet::AutoLockMasternodeCollaterals() void CWallet::AutoLockMasternodeCollaterals()
{ {
if (!m_chain) return;
std::vector<std::pair<const CTransactionRef&, unsigned int>> outputs; std::vector<std::pair<const CTransactionRef&, unsigned int>> outputs;
LOCK(cs_wallet); LOCK(cs_wallet);
@ -4452,6 +4460,11 @@ void CWallet::ListLockedCoins(std::vector<COutPoint>& vOutpts) const
void CWallet::ListProTxCoins(std::vector<COutPoint>& vOutpts) const void CWallet::ListProTxCoins(std::vector<COutPoint>& vOutpts) const
{ {
// TODO: refactor duplicated code between CWallet::AutoLockMasternodeCollaterals and CWallet::ListProTxCoins
if (!m_chain) {
vOutpts.clear();
return;
}
std::vector<std::pair<const CTransactionRef&, unsigned int>> outputs; std::vector<std::pair<const CTransactionRef&, unsigned int>> outputs;
AssertLockHeld(cs_wallet); AssertLockHeld(cs_wallet);