Skip to content

Commit

Permalink
refactor: replace usage of deterministicMNManager to new interface li…
Browse files Browse the repository at this point in the history
…stMNCollaterials
  • Loading branch information
knst committed Nov 29, 2023
1 parent 1609dba commit 71292ec
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#include <coinjoin/client.h>
#include <coinjoin/options.h>
#include <governance/governance.h>
#include <evo/deterministicmns.h>
#include <masternode/sync.h>

#include <univalue.h>
Expand Down Expand Up @@ -876,15 +875,16 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
wtx.nTimeSmart = ComputeTimeSmart(wtx);
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) {
if (IsMine(wtx.tx->vout[i]) && !IsSpent(hash, i)) {
setWalletUTXO.insert(COutPoint(hash, i));
if (CDeterministicMNManager::IsProTxWithCollateral(wtx.tx, i) || mnList.HasMNByCollateral(COutPoint(hash, i))) {
LockCoin(COutPoint(hash, i));
}
outputs.emplace_back(wtx.tx, i);
}
}
for (const auto& outPoint : m_chain->listMNCollaterials(outputs)) {
LockCoin(outPoint);
}
}

bool fUpdated = false;
Expand All @@ -907,16 +907,19 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
fUpdated = true;
}

auto mnList = deterministicMNManager->GetListAtChainTip();
for (unsigned int i = 0; i < wtx.tx->vout.size(); ++i) {
std::vector<std::pair<const CTransactionRef&, unsigned int>> outputs;
for(unsigned int i = 0; i < wtx.tx->vout.size(); ++i) {
if (IsMine(wtx.tx->vout[i]) && !IsSpent(hash, i)) {
bool new_utxo = setWalletUTXO.insert(COutPoint(hash, i)).second;
if (new_utxo && (CDeterministicMNManager::IsProTxWithCollateral(wtx.tx, i) || mnList.HasMNByCollateral(COutPoint(hash, i)))) {
LockCoin(COutPoint(hash, i));
if (new_utxo) {
outputs.emplace_back(wtx.tx, i);
fUpdated = true;
}
fUpdated |= new_utxo;
}
}
for (const auto& outPoint : m_chain->listMNCollaterials(outputs)) {
LockCoin(outPoint);
}
}

//// debug print
Expand Down Expand Up @@ -3876,18 +3879,19 @@ DBErrors CWallet::LoadWallet(bool& fFirstRunRet)
// This avoids accidental spending of collaterals. They can still be unlocked manually if a spend is really intended.
void CWallet::AutoLockMasternodeCollaterals()
{
auto mnList = deterministicMNManager->GetListAtChainTip();
std::vector<std::pair<const CTransactionRef&, unsigned int>> outputs;

LOCK(cs_wallet);
for (const auto& pair : mapWallet) {
for (unsigned int i = 0; i < pair.second.tx->vout.size(); ++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))) {
LockCoin(COutPoint(pair.first, i));
}
outputs.emplace_back(pair.second.tx, i);
}
}
}
for (const auto& outPoint : m_chain->listMNCollaterials(outputs)) {
LockCoin(outPoint);
}
}

DBErrors CWallet::ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256>& vHashOut)
Expand Down

0 comments on commit 71292ec

Please sign in to comment.