Skip to content

Commit

Permalink
fix: follow-up bitcoin#20773 - for collateral lock/unlock coins
Browse files Browse the repository at this point in the history
  • Loading branch information
knst committed Aug 1, 2024
1 parent d1d158c commit 63dee39
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 63dee39

Please sign in to comment.