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,10 +917,13 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const CWalletTx::Confirmatio
outputs.emplace_back(wtx.tx, i);
}
}
// TODO: refactor duplicated code between CWallet::AddToWallet and CWallet::AutoLockMasternodeCollaterals
if (m_chain) {
for (const auto& outPoint : m_chain->listMNCollaterials(outputs)) {
LockCoin(outPoint);
}
}
}
if (!fInsertedNew)
{
@ -946,10 +949,13 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const CWalletTx::Confirmatio
}
}
}
// TODO: refactor duplicated code with case fInstertedNew
if (m_chain) {
for (const auto& outPoint : m_chain->listMNCollaterials(outputs)) {
LockCoin(outPoint);
}
}
}
//// debug print
WalletLogPrintf("AddToWallet %s %s%s\n", hash.ToString(), (fInsertedNew ? "new" : ""), (fUpdated ? "update" : ""));
@ -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<std::pair<const CTransactionRef&, unsigned int>> outputs;
LOCK(cs_wallet);
@ -4452,6 +4460,11 @@ void CWallet::ListLockedCoins(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;
AssertLockHeld(cs_wallet);