refactor: replace usage of deterministicMNManager to new interface listMNCollaterials

This commit is contained in:
Konstantin Akimov 2023-11-29 16:24:18 +07:00 committed by PastaPastaPasta
parent 2c61d842a9
commit e3d9327d17

View File

@ -46,7 +46,6 @@
#include <coinjoin/options.h> #include <coinjoin/options.h>
#include <evo/providertx.h> #include <evo/providertx.h>
#include <governance/governance.h> #include <governance/governance.h>
#include <evo/deterministicmns.h>
#include <masternode/sync.h> #include <masternode/sync.h>
#include <univalue.h> #include <univalue.h>
@ -880,15 +879,16 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const CWalletTx::Confirmatio
wtx.nTimeSmart = ComputeTimeSmart(wtx); wtx.nTimeSmart = ComputeTimeSmart(wtx);
AddToSpends(hash); AddToSpends(hash);
auto mnList = deterministicMNManager->GetListAtChainTip(); std::vector<std::pair<const CTransactionRef&, unsigned int>> outputs;
for(unsigned int i = 0; i < wtx.tx->vout.size(); ++i) { for(unsigned int i = 0; i < wtx.tx->vout.size(); ++i) {
if (IsMine(wtx.tx->vout[i]) && !IsSpent(hash, i)) { if (IsMine(wtx.tx->vout[i]) && !IsSpent(hash, i)) {
setWalletUTXO.insert(COutPoint(hash, i)); setWalletUTXO.insert(COutPoint(hash, i));
if (CDeterministicMNManager::IsProTxWithCollateral(wtx.tx, i) || mnList.HasMNByCollateral(COutPoint(hash, i))) { outputs.emplace_back(wtx.tx, i);
LockCoin(COutPoint(hash, i));
}
} }
} }
for (const auto& outPoint : m_chain->listMNCollaterials(outputs)) {
LockCoin(outPoint);
}
} }
if (!fInsertedNew) if (!fInsertedNew)
@ -905,16 +905,19 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const CWalletTx::Confirmatio
assert(wtx.m_confirm.block_height == confirm.block_height); assert(wtx.m_confirm.block_height == confirm.block_height);
} }
auto mnList = deterministicMNManager->GetListAtChainTip(); std::vector<std::pair<const CTransactionRef&, unsigned int>> outputs;
for (unsigned int i = 0; i < wtx.tx->vout.size(); ++i) { for(unsigned int i = 0; i < wtx.tx->vout.size(); ++i) {
if (IsMine(wtx.tx->vout[i]) && !IsSpent(hash, i)) { if (IsMine(wtx.tx->vout[i]) && !IsSpent(hash, i)) {
bool new_utxo = setWalletUTXO.insert(COutPoint(hash, i)).second; bool new_utxo = setWalletUTXO.insert(COutPoint(hash, i)).second;
if (new_utxo && (CDeterministicMNManager::IsProTxWithCollateral(wtx.tx, i) || mnList.HasMNByCollateral(COutPoint(hash, i)))) { if (new_utxo) {
LockCoin(COutPoint(hash, i)); outputs.emplace_back(wtx.tx, i);
fUpdated = true;
} }
fUpdated |= new_utxo;
} }
} }
for (const auto& outPoint : m_chain->listMNCollaterials(outputs)) {
LockCoin(outPoint);
}
} }
//// debug print //// debug print
@ -3863,18 +3866,19 @@ DBErrors CWallet::LoadWallet(bool& fFirstRunRet)
// 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()
{ {
auto mnList = deterministicMNManager->GetListAtChainTip(); std::vector<std::pair<const CTransactionRef&, unsigned int>> outputs;
LOCK(cs_wallet); LOCK(cs_wallet);
for (const auto& pair : mapWallet) { for (const auto& pair : mapWallet) {
for (unsigned int i = 0; i < pair.second.tx->vout.size(); ++i) { for (unsigned int i = 0; i < pair.second.tx->vout.size(); ++i) {
if (IsMine(pair.second.tx->vout[i]) && !IsSpent(pair.first, i)) { if (IsMine(pair.second.tx->vout[i]) && !IsSpent(pair.first, i)) {
if (CDeterministicMNManager::IsProTxWithCollateral(pair.second.tx, i) || mnList.HasMNByCollateral(COutPoint(pair.first, i))) { outputs.emplace_back(pair.second.tx, i);
LockCoin(COutPoint(pair.first, i));
}
} }
} }
} }
for (const auto& outPoint : m_chain->listMNCollaterials(outputs)) {
LockCoin(outPoint);
}
} }
DBErrors CWallet::ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256>& vHashOut) DBErrors CWallet::ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256>& vHashOut)