mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
CMasternodeMan - masternode manager class - part4 - fixed rpc/count can return "enabled only"/list can be filtered (everything should be ok)
This commit is contained in:
parent
dd1c1b7d1c
commit
9905be3793
@ -239,46 +239,20 @@ Value masternode(const Array& params, bool fHelp)
|
||||
|
||||
if (strCommand == "list")
|
||||
{
|
||||
std::string strCommand = "active";
|
||||
|
||||
if (params.size() == 2){
|
||||
strCommand = params[1].get_str().c_str();
|
||||
}
|
||||
|
||||
if (strCommand != "active" && strCommand != "vin" && strCommand != "pubkey" && strCommand != "lastseen" && strCommand != "activeseconds" && strCommand != "rank" && strCommand != "protocol"){
|
||||
throw runtime_error(
|
||||
"list supports 'active', 'vin', 'pubkey', 'lastseen', 'activeseconds', 'rank', 'protocol'\n");
|
||||
}
|
||||
|
||||
Object obj;
|
||||
BOOST_FOREACH(CMasterNode mn, vecMasternodes) {
|
||||
mn.Check();
|
||||
|
||||
if(strCommand == "active"){
|
||||
obj.push_back(Pair(mn.addr.ToString().c_str(), (int)mn.IsEnabled()));
|
||||
} else if (strCommand == "vin") {
|
||||
obj.push_back(Pair(mn.addr.ToString().c_str(), mn.vin.prevout.hash.ToString().c_str()));
|
||||
} else if (strCommand == "pubkey") {
|
||||
CScript pubkey;
|
||||
pubkey.SetDestination(mn.pubkey.GetID());
|
||||
CTxDestination address1;
|
||||
ExtractDestination(pubkey, address1);
|
||||
CBitcoinAddress address2(address1);
|
||||
|
||||
obj.push_back(Pair(mn.addr.ToString().c_str(), address2.ToString().c_str()));
|
||||
} else if (strCommand == "protocol") {
|
||||
obj.push_back(Pair(mn.addr.ToString().c_str(), (int64_t)mn.protocolVersion));
|
||||
} else if (strCommand == "lastseen") {
|
||||
obj.push_back(Pair(mn.addr.ToString().c_str(), (int64_t)mn.lastTimeSeen));
|
||||
} else if (strCommand == "activeseconds") {
|
||||
obj.push_back(Pair(mn.addr.ToString().c_str(), (int64_t)(mn.lastTimeSeen - mn.now)));
|
||||
} else if (strCommand == "rank") {
|
||||
obj.push_back(Pair(mn.addr.ToString().c_str(), (int)(GetMasternodeRank(mn.vin, chainActive.Tip()->nHeight))));
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
Array newParams(params.size() - 1);
|
||||
std::copy(params.begin() + 1, params.end(), newParams.begin());
|
||||
return masternodelist(newParams, fHelp);
|
||||
}
|
||||
|
||||
if (strCommand == "count")
|
||||
{
|
||||
if (params.size() > 2){
|
||||
throw runtime_error(
|
||||
"too many parameters\n");
|
||||
}
|
||||
if (params.size() == 2) return mnodeman.CountEnabled();
|
||||
return mnodeman.size();
|
||||
}
|
||||
if (strCommand == "count") return (int)vecMasternodes.size();
|
||||
|
||||
if (strCommand == "start")
|
||||
{
|
||||
@ -455,9 +429,9 @@ Value masternode(const Array& params, bool fHelp)
|
||||
|
||||
if (strCommand == "current")
|
||||
{
|
||||
int winner = GetCurrentMasterNode(1);
|
||||
if(winner >= 0) {
|
||||
return vecMasternodes[winner].addr.ToString().c_str();
|
||||
CMasternode* winner = mnodeman.GetCurrentMasterNode(1);
|
||||
if(winner) {
|
||||
return winner->addr.ToString().c_str();
|
||||
}
|
||||
|
||||
return "unknown";
|
||||
@ -551,3 +525,35 @@ Value masternode(const Array& params, bool fHelp)
|
||||
return Value::null;
|
||||
}
|
||||
|
||||
Value masternodelist(const Array& params, bool fHelp)
|
||||
{
|
||||
std::string strMode = "active";
|
||||
std::string strFilter = "";
|
||||
|
||||
if (params.size() >= 1) strMode = params[0].get_str();
|
||||
if (params.size() == 2) strFilter = params[1].get_str();
|
||||
|
||||
if (fHelp ||
|
||||
(strMode != "active" && strMode != "vin" && strMode != "pubkey" && strMode != "lastseen"
|
||||
&& strMode != "activeseconds" && strMode != "rank" && strMode != "protocol" && strMode != "full"))
|
||||
{
|
||||
throw runtime_error(
|
||||
"masternodelist ( \"mode\" \"filter\" )\n"
|
||||
"Get a list of masternodes in different modes\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"mode\" (string, optional, defauls = active) The mode to run list in\n"
|
||||
"2. \"filter\" (string, optional) Filter results, can be applied in few modes only\n"
|
||||
"Available modes:\n"
|
||||
" active - Print '1' if active and '0' otherwise (can be filtered, exact match)\n"
|
||||
" activeseconds - Print number of seconds masternode recognized by the network as enabled\n"
|
||||
" full - Print info in format 'active | protocol | pubkey | vin | lastseen | activeseconds' (can be filtered, partial match)\n"
|
||||
" lastseen - Print timestamp of when a masternode was last seen on the network\n"
|
||||
" protocol - Print protocol of a masternode (can be filtered, exact match)\n"
|
||||
" pubkey - Print public key associated with a masternode (can be filtered, partial match)\n"
|
||||
" rank - Print rank of a masternode based on current block\n"
|
||||
" vin - Print vin associated with a masternode (can be filtered, partial match)\n"
|
||||
);
|
||||
}
|
||||
|
||||
return mnodeman.GetFilteredVector(strMode, strFilter);
|
||||
}
|
||||
|
@ -193,6 +193,7 @@ extern json_spirit::Value verifychain(const json_spirit::Array& params, bool fHe
|
||||
extern json_spirit::Value darksend(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value spork(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value masternode(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value masternodelist(const json_spirit::Array& params, bool fHelp);
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user