Directly use deterministicMNManager in "masternode list"

Also remove GetFullMasternodeMap
This commit is contained in:
Alexander Block 2018-12-17 16:36:58 +01:00
parent 0fe97a0459
commit 4c749b7e94

View File

@ -831,21 +831,31 @@ UniValue masternodelist(const JSONRPCRequest& request)
} }
UniValue obj(UniValue::VOBJ); UniValue obj(UniValue::VOBJ);
std::map<COutPoint, CMasternode> mapMasternodes = mnodeman.GetFullMasternodeMap();
for (const auto& mnpair : mapMasternodes) {
CMasternode mn = mnpair.second;
std::string strOutpoint = mnpair.first.ToStringShort();
CScript payeeScript; auto mnList = deterministicMNManager->GetListAtChainTip();
if (deterministicMNManager->IsDeterministicMNsSporkActive()) { auto dmnToStatus = [&](const CDeterministicMNCPtr& dmn) {
auto dmn = deterministicMNManager->GetListAtChainTip().GetMNByCollateral(mn.outpoint); if (mnList.IsMNValid(dmn)) {
if (dmn) { return "ENABLED";
payeeScript = dmn->pdmnState->scriptPayout; }
} if (mnList.IsMNPoSeBanned(dmn)) {
} else { return "POSE_BANNED";
payeeScript = GetScriptForDestination(mn.keyIDCollateralAddress); }
return "UNKNOWN";
};
auto dmnToLastPaidTime = [&](const CDeterministicMNCPtr& dmn) {
if (dmn->pdmnState->nLastPaidHeight == 0) {
return (int)0;
} }
LOCK(cs_main);
const CBlockIndex* pindex = chainActive[dmn->pdmnState->nLastPaidHeight];
return (int)pindex->nTime;
};
mnList.ForEachMN(false, [&](const CDeterministicMNCPtr& dmn) {
std::string strOutpoint = dmn->collateralOutpoint.ToStringShort();
CScript payeeScript = dmn->pdmnState->scriptPayout;
CTxDestination payeeDest; CTxDestination payeeDest;
std::string payeeStr = "UNKOWN"; std::string payeeStr = "UNKOWN";
if (ExtractDestination(payeeScript, payeeDest)) { if (ExtractDestination(payeeScript, payeeDest)) {
@ -853,75 +863,75 @@ UniValue masternodelist(const JSONRPCRequest& request)
} }
if (strMode == "addr") { if (strMode == "addr") {
std::string strAddress = mn.addr.ToString(); std::string strAddress = dmn->pdmnState->ToString();
if (strFilter !="" && strAddress.find(strFilter) == std::string::npos && if (strFilter !="" && strAddress.find(strFilter) == std::string::npos &&
strOutpoint.find(strFilter) == std::string::npos) continue; strOutpoint.find(strFilter) == std::string::npos) return;
obj.push_back(Pair(strOutpoint, strAddress)); obj.push_back(Pair(strOutpoint, strAddress));
} else if (strMode == "full") { } else if (strMode == "full") {
std::ostringstream streamFull; std::ostringstream streamFull;
streamFull << std::setw(18) << streamFull << std::setw(18) <<
mn.GetStatus() << " " << dmnToStatus(dmn) << " " <<
payeeStr << " " << payeeStr << " " <<
mn.GetLastPaidTime() << " " << std::setw(6) << dmnToLastPaidTime(dmn) << " " << std::setw(6) <<
mn.GetLastPaidBlock() << " " << dmn->pdmnState->nLastPaidHeight << " " <<
mn.addr.ToString(); dmn->pdmnState->addr.ToString();
std::string strFull = streamFull.str(); std::string strFull = streamFull.str();
if (strFilter !="" && strFull.find(strFilter) == std::string::npos && if (strFilter !="" && strFull.find(strFilter) == std::string::npos &&
strOutpoint.find(strFilter) == std::string::npos) continue; strOutpoint.find(strFilter) == std::string::npos) return;
obj.push_back(Pair(strOutpoint, strFull)); obj.push_back(Pair(strOutpoint, strFull));
} else if (strMode == "info") { } else if (strMode == "info") {
std::ostringstream streamInfo; std::ostringstream streamInfo;
streamInfo << std::setw(18) << streamInfo << std::setw(18) <<
mn.GetStatus() << " " << dmnToStatus(dmn) << " " <<
payeeStr << " " << payeeStr << " " <<
mn.addr.ToString(); dmn->pdmnState->addr.ToString();
std::string strInfo = streamInfo.str(); std::string strInfo = streamInfo.str();
if (strFilter !="" && strInfo.find(strFilter) == std::string::npos && if (strFilter !="" && strInfo.find(strFilter) == std::string::npos &&
strOutpoint.find(strFilter) == std::string::npos) continue; strOutpoint.find(strFilter) == std::string::npos) return;
obj.push_back(Pair(strOutpoint, strInfo)); obj.push_back(Pair(strOutpoint, strInfo));
} else if (strMode == "json") { } else if (strMode == "json") {
std::ostringstream streamInfo; std::ostringstream streamInfo;
streamInfo << mn.addr.ToString() << " " << streamInfo << dmn->pdmnState->addr.ToString() << " " <<
CBitcoinAddress(mn.pubKeyCollateralAddress.GetID()).ToString() << " " << CBitcoinAddress(dmn->pdmnState->scriptPayout).ToString() << " " <<
mn.GetStatus() << " " << dmnToStatus(dmn) << " " <<
mn.GetLastPaidTime() << " " << dmnToLastPaidTime(dmn) << " " <<
mn.GetLastPaidBlock(); dmn->pdmnState->nLastPaidHeight;
std::string strInfo = streamInfo.str(); std::string strInfo = streamInfo.str();
if (strFilter !="" && strInfo.find(strFilter) == std::string::npos && if (strFilter !="" && strInfo.find(strFilter) == std::string::npos &&
strOutpoint.find(strFilter) == std::string::npos) continue; strOutpoint.find(strFilter) == std::string::npos) return;
UniValue objMN(UniValue::VOBJ); UniValue objMN(UniValue::VOBJ);
objMN.push_back(Pair("address", mn.addr.ToString())); objMN.push_back(Pair("address", dmn->pdmnState->addr.ToString()));
objMN.push_back(Pair("payee", CBitcoinAddress(mn.pubKeyCollateralAddress.GetID()).ToString())); objMN.push_back(Pair("payee", CBitcoinAddress(dmn->pdmnState->scriptPayout).ToString()));
objMN.push_back(Pair("status", mn.GetStatus())); objMN.push_back(Pair("status", dmnToStatus(dmn)));
objMN.push_back(Pair("lastpaidtime", mn.GetLastPaidTime())); objMN.push_back(Pair("lastpaidtime", dmnToLastPaidTime(dmn)));
objMN.push_back(Pair("lastpaidblock", mn.GetLastPaidBlock())); objMN.push_back(Pair("lastpaidblock", dmn->pdmnState->nLastPaidHeight));
obj.push_back(Pair(strOutpoint, objMN)); obj.push_back(Pair(strOutpoint, objMN));
} else if (strMode == "lastpaidblock") { } else if (strMode == "lastpaidblock") {
if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) continue; if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) return;
obj.push_back(Pair(strOutpoint, mn.GetLastPaidBlock())); obj.push_back(Pair(strOutpoint, dmn->pdmnState->nLastPaidHeight));
} else if (strMode == "lastpaidtime") { } else if (strMode == "lastpaidtime") {
if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) continue; if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) return;
obj.push_back(Pair(strOutpoint, mn.GetLastPaidTime())); obj.push_back(Pair(strOutpoint, dmnToLastPaidTime(dmn)));
} else if (strMode == "payee") { } else if (strMode == "payee") {
if (strFilter !="" && payeeStr.find(strFilter) == std::string::npos && if (strFilter !="" && payeeStr.find(strFilter) == std::string::npos &&
strOutpoint.find(strFilter) == std::string::npos) continue; strOutpoint.find(strFilter) == std::string::npos) return;
obj.push_back(Pair(strOutpoint, payeeStr)); obj.push_back(Pair(strOutpoint, payeeStr));
} else if (strMode == "keyIDOwner") { } else if (strMode == "keyIDOwner") {
if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) continue; if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) return;
obj.push_back(Pair(strOutpoint, HexStr(mn.keyIDOwner))); obj.push_back(Pair(strOutpoint, HexStr(dmn->pdmnState->keyIDOwner)));
} else if (strMode == "keyIDOperator") { } else if (strMode == "pubKeyOperator") {
if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) continue; if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) return;
obj.push_back(Pair(strOutpoint, HexStr(mn.legacyKeyIDOperator))); obj.push_back(Pair(strOutpoint, dmn->pdmnState->pubKeyOperator.ToString()));
} else if (strMode == "keyIDVoting") { } else if (strMode == "keyIDVoting") {
if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) continue; if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) return;
obj.push_back(Pair(strOutpoint, HexStr(mn.keyIDVoting))); obj.push_back(Pair(strOutpoint, HexStr(dmn->pdmnState->keyIDVoting)));
} else if (strMode == "status") { } else if (strMode == "status") {
std::string strStatus = mn.GetStatus(); std::string strStatus = dmnToStatus(dmn);
if (strFilter !="" && strStatus.find(strFilter) == std::string::npos && if (strFilter !="" && strStatus.find(strFilter) == std::string::npos &&
strOutpoint.find(strFilter) == std::string::npos) continue; strOutpoint.find(strFilter) == std::string::npos) return;
obj.push_back(Pair(strOutpoint, strStatus)); obj.push_back(Pair(strOutpoint, strStatus));
} }
} });
return obj; return obj;
} }