2019-01-29 15:53:14 +01:00
|
|
|
// Copyright (c) 2014-2019 The Dash Core developers
|
2019-01-03 21:08:34 +01:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <masternode/masternode-meta.h>
|
2019-01-03 21:08:34 +01:00
|
|
|
|
|
|
|
CMasternodeMetaMan mmetaman;
|
|
|
|
|
2020-03-19 13:51:25 +01:00
|
|
|
const std::string CMasternodeMetaMan::SERIALIZATION_VERSION_STRING = "CMasternodeMetaMan-Version-2";
|
2019-01-03 21:08:34 +01:00
|
|
|
|
|
|
|
void CMasternodeMetaInfo::AddGovernanceVote(const uint256& nGovernanceObjectHash)
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
|
|
|
// Insert a zero value, or not. Then increment the value regardless. This
|
|
|
|
// ensures the value is in the map.
|
|
|
|
const auto& pair = mapGovernanceObjectsVotedOn.emplace(nGovernanceObjectHash, 0);
|
|
|
|
pair.first->second++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMasternodeMetaInfo::RemoveGovernanceObject(const uint256& nGovernanceObjectHash)
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
|
|
|
// Whether or not the govobj hash exists in the map first is irrelevant.
|
|
|
|
mapGovernanceObjectsVotedOn.erase(nGovernanceObjectHash);
|
|
|
|
}
|
|
|
|
|
|
|
|
CMasternodeMetaInfoPtr CMasternodeMetaMan::GetMetaInfo(const uint256& proTxHash, bool fCreate)
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
|
|
|
auto it = metaInfos.find(proTxHash);
|
|
|
|
if (it != metaInfos.end()) {
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
if (!fCreate) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
it = metaInfos.emplace(proTxHash, std::make_shared<CMasternodeMetaInfo>(proTxHash)).first;
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMasternodeMetaMan::AllowMixing(const uint256& proTxHash)
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
|
|
|
auto mm = GetMetaInfo(proTxHash);
|
|
|
|
nDsqCount++;
|
|
|
|
LOCK(mm->cs);
|
|
|
|
mm->nLastDsq = nDsqCount;
|
|
|
|
mm->nMixingTxCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMasternodeMetaMan::DisallowMixing(const uint256& proTxHash)
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
|
|
|
auto mm = GetMetaInfo(proTxHash);
|
|
|
|
|
|
|
|
LOCK(mm->cs);
|
|
|
|
mm->nMixingTxCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CMasternodeMetaMan::AddGovernanceVote(const uint256& proTxHash, const uint256& nGovernanceObjectHash)
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
|
|
|
auto mm = GetMetaInfo(proTxHash);
|
|
|
|
mm->AddGovernanceVote(nGovernanceObjectHash);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMasternodeMetaMan::RemoveGovernanceObject(const uint256& nGovernanceObjectHash)
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
|
|
|
for(auto& p : metaInfos) {
|
|
|
|
p.second->RemoveGovernanceObject(nGovernanceObjectHash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<uint256> CMasternodeMetaMan::GetAndClearDirtyGovernanceObjectHashes()
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
|
|
|
std::vector<uint256> vecTmp = std::move(vecDirtyGovernanceObjectHashes);
|
|
|
|
vecDirtyGovernanceObjectHashes.clear();
|
|
|
|
return vecTmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMasternodeMetaMan::Clear()
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
|
|
|
metaInfos.clear();
|
|
|
|
vecDirtyGovernanceObjectHashes.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMasternodeMetaMan::CheckAndRemove()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CMasternodeMetaMan::ToString() const
|
|
|
|
{
|
|
|
|
std::ostringstream info;
|
|
|
|
|
|
|
|
info << "Masternodes: meta infos object count: " << (int)metaInfos.size() <<
|
|
|
|
", nDsqCount: " << (int)nDsqCount;
|
|
|
|
return info.str();
|
|
|
|
}
|