Implement HasValidMN, HasValidMNByCollateral and GetValidMNByCollateral
This commit is contained in:
parent
bc29fe160e
commit
45f34e130f
@ -151,6 +151,15 @@ CDeterministicMNCPtr CDeterministicMNList::GetMNByCollateral(const COutPoint& co
|
||||
return GetUniquePropertyMN(collateralOutpoint);
|
||||
}
|
||||
|
||||
CDeterministicMNCPtr CDeterministicMNList::GetValidMNByCollateral(const COutPoint& collateralOutpoint) const
|
||||
{
|
||||
auto dmn = GetMNByCollateral(collateralOutpoint);
|
||||
if (dmn && !IsMNValid(dmn)) {
|
||||
return nullptr;
|
||||
}
|
||||
return dmn;
|
||||
}
|
||||
|
||||
static int CompareByLastPaid_GetHeight(const CDeterministicMN& dmn)
|
||||
{
|
||||
int height = dmn.pdmnState->nLastPaidHeight;
|
||||
@ -826,20 +835,6 @@ CDeterministicMNList CDeterministicMNManager::GetListAtChainTip()
|
||||
return GetListForBlock(tipBlockHash);
|
||||
}
|
||||
|
||||
bool CDeterministicMNManager::HasValidMNCollateralAtChainTip(const COutPoint& outpoint)
|
||||
{
|
||||
auto mnList = GetListAtChainTip();
|
||||
auto dmn = mnList.GetMNByCollateral(outpoint);
|
||||
return dmn && mnList.IsMNValid(dmn);
|
||||
}
|
||||
|
||||
bool CDeterministicMNManager::HasMNCollateralAtChainTip(const COutPoint& outpoint)
|
||||
{
|
||||
auto mnList = GetListAtChainTip();
|
||||
auto dmn = mnList.GetMNByCollateral(outpoint);
|
||||
return dmn != nullptr;
|
||||
}
|
||||
|
||||
bool CDeterministicMNManager::IsProTxWithCollateral(const CTransactionRef& tx, uint32_t n)
|
||||
{
|
||||
if (tx->nVersion != 3 || tx->nType != TRANSACTION_PROVIDER_REGISTER) {
|
||||
|
@ -289,10 +289,23 @@ public:
|
||||
{
|
||||
return GetMN(proTxHash) != nullptr;
|
||||
}
|
||||
bool HasValidMN(const uint256& proTxHash) const
|
||||
{
|
||||
return GetValidMN(proTxHash) != nullptr;
|
||||
}
|
||||
bool HasMNByCollateral(const COutPoint& collateralOutpoint) const
|
||||
{
|
||||
return GetMNByCollateral(collateralOutpoint) != nullptr;
|
||||
}
|
||||
bool HasValidMNByCollateral(const COutPoint& collateralOutpoint) const
|
||||
{
|
||||
return GetValidMNByCollateral(collateralOutpoint) != nullptr;
|
||||
}
|
||||
CDeterministicMNCPtr GetMN(const uint256& proTxHash) const;
|
||||
CDeterministicMNCPtr GetValidMN(const uint256& proTxHash) const;
|
||||
CDeterministicMNCPtr GetMNByOperatorKey(const CBLSPublicKey& pubKey);
|
||||
CDeterministicMNCPtr GetMNByCollateral(const COutPoint& collateralOutpoint) const;
|
||||
CDeterministicMNCPtr GetValidMNByCollateral(const COutPoint& collateralOutpoint) const;
|
||||
CDeterministicMNCPtr GetMNPayee() const;
|
||||
|
||||
/**
|
||||
@ -479,10 +492,6 @@ public:
|
||||
CDeterministicMNList GetListForBlock(const uint256& blockHash);
|
||||
CDeterministicMNList GetListAtChainTip();
|
||||
|
||||
// TODO remove after removal of old non-deterministic lists
|
||||
bool HasValidMNCollateralAtChainTip(const COutPoint& outpoint);
|
||||
bool HasMNCollateralAtChainTip(const COutPoint& outpoint);
|
||||
|
||||
// Test if given TX is a ProRegTx which also contains the collateral at index n
|
||||
bool IsProTxWithCollateral(const CTransactionRef& tx, uint32_t n);
|
||||
|
||||
|
@ -643,7 +643,7 @@ bool CMasternodeMan::Has(const COutPoint& outpoint)
|
||||
{
|
||||
LOCK(cs);
|
||||
if (deterministicMNManager->IsDIP3Active()) {
|
||||
return deterministicMNManager->HasValidMNCollateralAtChainTip(outpoint);
|
||||
return deterministicMNManager->GetListAtChainTip().HasValidMNByCollateral(outpoint);
|
||||
} else {
|
||||
return mapMasternodes.find(outpoint) != mapMasternodes.end();
|
||||
}
|
||||
|
@ -1121,10 +1121,11 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
|
||||
}
|
||||
AddToSpends(hash);
|
||||
|
||||
auto mnList = deterministicMNManager->GetListAtChainTip();
|
||||
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 (deterministicMNManager->IsProTxWithCollateral(wtx.tx, i) || deterministicMNManager->HasMNCollateralAtChainTip(COutPoint(hash, i))) {
|
||||
if (deterministicMNManager->IsProTxWithCollateral(wtx.tx, i) || mnList.HasMNByCollateral(COutPoint(hash, i))) {
|
||||
LockCoin(COutPoint(hash, i));
|
||||
}
|
||||
}
|
||||
@ -3989,11 +3990,13 @@ DBErrors CWallet::LoadWallet(bool& fFirstRunRet)
|
||||
// This avoids accidential spending of collaterals. They can still be unlocked manually if a spend is really intended.
|
||||
void CWallet::AutoLockMasternodeCollaterals()
|
||||
{
|
||||
auto mnList = deterministicMNManager->GetListAtChainTip();
|
||||
|
||||
LOCK2(cs_main, 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 (deterministicMNManager->IsProTxWithCollateral(pair.second.tx, i) || deterministicMNManager->HasMNCollateralAtChainTip(COutPoint(pair.first, i))) {
|
||||
if (deterministicMNManager->IsProTxWithCollateral(pair.second.tx, i) || mnList.HasMNByCollateral(COutPoint(pair.first, i))) {
|
||||
LockCoin(COutPoint(pair.first, i));
|
||||
}
|
||||
}
|
||||
@ -4643,11 +4646,13 @@ void CWallet::ListLockedCoins(std::vector<COutPoint>& vOutpts)
|
||||
|
||||
void CWallet::ListProTxCoins(std::vector<COutPoint>& vOutpts)
|
||||
{
|
||||
auto mnList = deterministicMNManager->GetListAtChainTip();
|
||||
|
||||
AssertLockHeld(cs_wallet);
|
||||
for (const auto &o : setWalletUTXO) {
|
||||
if (mapWallet.count(o.hash)) {
|
||||
const auto &p = mapWallet[o.hash];
|
||||
if (deterministicMNManager->IsProTxWithCollateral(p.tx, o.n) || deterministicMNManager->HasMNCollateralAtChainTip(o)) {
|
||||
if (deterministicMNManager->IsProTxWithCollateral(p.tx, o.n) || mnList.HasMNByCollateral(o)) {
|
||||
vOutpts.emplace_back(o);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user