From dd610900516b615c4f1ed9d3cd279485683c4d52 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Tue, 24 Feb 2015 02:48:11 +0300 Subject: [PATCH] move list logic back to rpcdarkcsend and give it a copy of vMasternodes (json dep in mnodeman is ugly, my bad) --- src/masternodeman.cpp | 55 ------------------------------------------- src/masternodeman.h | 3 +-- src/rpcdarksend.cpp | 53 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 53 insertions(+), 58 deletions(-) diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index 321074d8b2..f65729072c 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -308,61 +308,6 @@ int CMasternodeMan::GetMasternodeRank(const CTxIn& vin, int64_t nBlockHeight, in return -1; } -json_spirit::Object CMasternodeMan::GetFilteredVector(std::string strMode, std::string strFilter) -{ - using namespace json_spirit; - Object obj; - BOOST_FOREACH(CMasternode& mn, vMasternodes) { - mn.Check(); - - std::string strAddr = mn.addr.ToString().c_str(); - if(strMode == "active"){ - if(strFilter !="" && stoi(strFilter) != mn.IsEnabled()) continue; - obj.push_back(Pair(strAddr, (int)mn.IsEnabled())); - } else if (strMode == "vin") { - if(strFilter !="" && mn.vin.prevout.hash.ToString().find(strFilter) == string::npos) continue; - obj.push_back(Pair(strAddr, mn.vin.prevout.hash.ToString().c_str())); - } else if (strMode == "pubkey") { - CScript pubkey; - pubkey.SetDestination(mn.pubkey.GetID()); - CTxDestination address1; - ExtractDestination(pubkey, address1); - CBitcoinAddress address2(address1); - - if(strFilter !="" && address2.ToString().find(strFilter) == string::npos) continue; - obj.push_back(Pair(strAddr, address2.ToString().c_str())); - } else if (strMode == "protocol") { - if(strFilter !="" && stoi(strFilter) != mn.protocolVersion) continue; - obj.push_back(Pair(strAddr, (int64_t)mn.protocolVersion)); - } else if (strMode == "lastseen") { - obj.push_back(Pair(strAddr, (int64_t)mn.lastTimeSeen)); - } else if (strMode == "activeseconds") { - obj.push_back(Pair(strAddr, (int64_t)(mn.lastTimeSeen - mn.now))); - } else if (strMode == "rank") { - obj.push_back(Pair(strAddr, (int)(mnodeman.GetMasternodeRank(mn.vin, chainActive.Tip()->nHeight)))); - } else if (strMode == "full") { - CScript pubkey; - pubkey.SetDestination(mn.pubkey.GetID()); - CTxDestination address1; - ExtractDestination(pubkey, address1); - CBitcoinAddress address2(address1); - - std::ostringstream stringStream; - stringStream << (mn.IsEnabled() ? "1" : "0") << " | " << - mn.protocolVersion << " | " << - address2.ToString() << " | " << - mn.vin.prevout.hash.ToString() << " | " << - mn.lastTimeSeen << " | " << - (mn.lastTimeSeen - mn.now); - std::string output = stringStream.str(); - stringStream << " " << strAddr; - if(strFilter !="" && stringStream.str().find(strFilter) == string::npos) continue; - obj.push_back(Pair(strAddr, output)); - } - } - return obj; -} - void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv) { diff --git a/src/masternodeman.h b/src/masternodeman.h index ab51c56868..16ff17ccf8 100644 --- a/src/masternodeman.h +++ b/src/masternodeman.h @@ -16,7 +16,6 @@ #include "base58.h" #include "main.h" #include "masternode.h" -#include "json/json_spirit_value.h" #define MASTERNODES_DUMP_SECONDS (15*60) @@ -102,7 +101,7 @@ public: int CountEnabled(); - json_spirit::Object GetFilteredVector(std::string strMode, std::string strFilter); + std::vector GetFullMasternodeVector() { return vMasternodes; } void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); diff --git a/src/rpcdarksend.cpp b/src/rpcdarksend.cpp index a664aa04d7..31890a3fd3 100644 --- a/src/rpcdarksend.cpp +++ b/src/rpcdarksend.cpp @@ -555,5 +555,56 @@ Value masternodelist(const Array& params, bool fHelp) ); } - return mnodeman.GetFilteredVector(strMode, strFilter); + Object obj; + std::vector vMasternodes = mnodeman.GetFullMasternodeVector(); + BOOST_FOREACH(CMasternode& mn, vMasternodes) { + mn.Check(); + + std::string strAddr = mn.addr.ToString().c_str(); + if(strMode == "active"){ + if(strFilter !="" && stoi(strFilter) != mn.IsEnabled()) continue; + obj.push_back(Pair(strAddr, (int)mn.IsEnabled())); + } else if (strMode == "vin") { + if(strFilter !="" && mn.vin.prevout.hash.ToString().find(strFilter) == string::npos) continue; + obj.push_back(Pair(strAddr, mn.vin.prevout.hash.ToString().c_str())); + } else if (strMode == "pubkey") { + CScript pubkey; + pubkey.SetDestination(mn.pubkey.GetID()); + CTxDestination address1; + ExtractDestination(pubkey, address1); + CBitcoinAddress address2(address1); + + if(strFilter !="" && address2.ToString().find(strFilter) == string::npos) continue; + obj.push_back(Pair(strAddr, address2.ToString().c_str())); + } else if (strMode == "protocol") { + if(strFilter !="" && stoi(strFilter) != mn.protocolVersion) continue; + obj.push_back(Pair(strAddr, (int64_t)mn.protocolVersion)); + } else if (strMode == "lastseen") { + obj.push_back(Pair(strAddr, (int64_t)mn.lastTimeSeen)); + } else if (strMode == "activeseconds") { + obj.push_back(Pair(strAddr, (int64_t)(mn.lastTimeSeen - mn.now))); + } else if (strMode == "rank") { + obj.push_back(Pair(strAddr, (int)(mnodeman.GetMasternodeRank(mn.vin, chainActive.Tip()->nHeight)))); + } else if (strMode == "full") { + CScript pubkey; + pubkey.SetDestination(mn.pubkey.GetID()); + CTxDestination address1; + ExtractDestination(pubkey, address1); + CBitcoinAddress address2(address1); + + std::ostringstream stringStream; + stringStream << (mn.IsEnabled() ? "1" : "0") << " | " << + mn.protocolVersion << " | " << + address2.ToString() << " | " << + mn.vin.prevout.hash.ToString() << " | " << + mn.lastTimeSeen << " | " << + (mn.lastTimeSeen - mn.now); + std::string output = stringStream.str(); + stringStream << " " << strAddr; + if(strFilter !="" && stringStream.str().find(strFilter) == string::npos) continue; + obj.push_back(Pair(strAddr, output)); + } + } + return obj; + }