Code cleanups for masternode rpc

- drop boost/lexical_cast
- drop c_str() where applicable
- slightly prettify descriptions and some output
This commit is contained in:
UdjinM6 2015-07-18 20:31:28 +03:00
parent aa96d701af
commit a3dfd86058

View File

@ -14,10 +14,8 @@
#include "rpcserver.h"
#include "utilmoneystr.h"
#include <boost/lexical_cast.hpp>
#include <fstream>
using namespace json_spirit;
using namespace std;
void SendMoney(const CTxDestination &address, CAmount nValue, CWalletTx& wtxNew, AvailableCoinsType coin_type=ALL_COINS)
{
@ -174,7 +172,7 @@ Value masternode(const Array& params, bool fHelp)
if (params.size() == 2)
{
if(params[1] == "enabled") return mnodeman.CountEnabled();
if(params[1] == "both") return boost::lexical_cast<std::string>(mnodeman.CountEnabled()) + " / " + boost::lexical_cast<std::string>(mnodeman.size());
if(params[1] == "both") return strprintf("%d / %d", mnodeman.CountEnabled(), mnodeman.size());
}
return mnodeman.size();
}
@ -215,7 +213,7 @@ Value masternode(const Array& params, bool fHelp)
"command needs at least 2 parameters\n");
}
std::string alias = params[1].get_str().c_str();
std::string alias = params[1].get_str();
if(pwalletMain->IsLocked()) {
SecureString strWalletPass;
@ -284,15 +282,12 @@ Value masternode(const Array& params, bool fHelp)
std::vector<CMasternodeConfig::CMasternodeEntry> mnEntries;
mnEntries = masternodeConfig.getEntries();
int total = 0;
int successful = 0;
int fail = 0;
int failed = 0;
Object resultsObj;
BOOST_FOREACH(CMasternodeConfig::CMasternodeEntry mne, masternodeConfig.getEntries()) {
total++;
std::string errorMessage;
bool result = activeMasternode.Register(mne.getIp(), mne.getPrivKey(), mne.getTxHash(), mne.getOutputIndex(), errorMessage);
@ -304,7 +299,7 @@ Value masternode(const Array& params, bool fHelp)
if(result) {
successful++;
} else {
fail++;
failed++;
statusObj.push_back(Pair("errorMessage", errorMessage));
}
@ -313,8 +308,7 @@ Value masternode(const Array& params, bool fHelp)
pwalletMain->Lock();
Object returnObj;
returnObj.push_back(Pair("overall", "Successfully started " + boost::lexical_cast<std::string>(successful) + " masternodes, failed to start " +
boost::lexical_cast<std::string>(fail) + ", total " + boost::lexical_cast<std::string>(total)));
returnObj.push_back(Pair("overall", strprintf("Successfully started %d masternodes, failed to start %d, total %d", successful, failed, successful + failed)));
returnObj.push_back(Pair("detail", resultsObj));
return returnObj;
@ -352,10 +346,10 @@ Value masternode(const Array& params, bool fHelp)
ExtractDestination(pubkey, address1);
CBitcoinAddress address2(address1);
obj.push_back(Pair("IP:port", winner->addr.ToString().c_str()));
obj.push_back(Pair("IP:port", winner->addr.ToString()));
obj.push_back(Pair("protocol", (int64_t)winner->protocolVersion));
obj.push_back(Pair("vin", winner->vin.prevout.hash.ToString().c_str()));
obj.push_back(Pair("pubkey", address2.ToString().c_str()));
obj.push_back(Pair("vin", winner->vin.prevout.hash.ToString()));
obj.push_back(Pair("pubkey", address2.ToString()));
obj.push_back(Pair("lastseen", (winner->lastPing == CMasternodePing()) ? winner->sigTime :
(int64_t)winner->lastPing.sigTime));
obj.push_back(Pair("activeseconds", (winner->lastPing == CMasternodePing()) ? 0 :
@ -380,7 +374,7 @@ Value masternode(const Array& params, bool fHelp)
for(int nHeight = chainActive.Tip()->nHeight-10; nHeight < chainActive.Tip()->nHeight+20; nHeight++)
{
obj.push_back(Pair(boost::lexical_cast<std::string>(nHeight), GetRequiredPaymentsString(nHeight).c_str()));
obj.push_back(Pair(strprintf("%d", nHeight), GetRequiredPaymentsString(nHeight)));
}
return obj;
@ -395,7 +389,7 @@ Value masternode(const Array& params, bool fHelp)
{
std::string strAddress = "";
if (params.size() == 2){
strAddress = params[1].get_str().c_str();
strAddress = params[1].get_str();
} else {
throw runtime_error(
"Masternode address required\n");
@ -436,7 +430,7 @@ Value masternode(const Array& params, bool fHelp)
Object obj;
BOOST_FOREACH(COutput& out, possibleCoins) {
obj.push_back(Pair(out.tx->GetHash().ToString().c_str(), boost::lexical_cast<std::string>(out.i)));
obj.push_back(Pair(out.tx->GetHash().ToString(), strprintf("%d", out.i)));
}
return obj;
@ -455,11 +449,11 @@ Value masternode(const Array& params, bool fHelp)
CBitcoinAddress address2(address1);
Object mnObj;
mnObj.push_back(Pair("vin", activeMasternode.vin.ToString().c_str()));
mnObj.push_back(Pair("service", activeMasternode.service.ToString().c_str()));
mnObj.push_back(Pair("vin", activeMasternode.vin.ToString()));
mnObj.push_back(Pair("service", activeMasternode.service.ToString()));
mnObj.push_back(Pair("status", activeMasternode.status));
mnObj.push_back(Pair("pubKeyMasternode", address2.ToString().c_str()));
mnObj.push_back(Pair("notCapableReason", activeMasternode.notCapableReason.c_str()));
mnObj.push_back(Pair("pubKeyMasternode", address2.ToString()));
mnObj.push_back(Pair("notCapableReason", activeMasternode.notCapableReason));
return mnObj;
}
@ -488,17 +482,17 @@ Value masternodelist(const Array& params, bool fHelp)
"\nAvailable modes:\n"
" activeseconds - Print number of seconds masternode recognized by the network as enabled\n"
" (since latest issued \"masternode start/start-many/start-alias\")\n"
" addr - Print ip address associated with a masternode (can be additionally filtered, partial match)\n"
" full - Print info in format 'status protocol pubkey IP lastseen activeseconds lastpaid'\n"
" (can be additionally filtered, partial match)\n"
" lastseen - Print timestamp of when a masternode was last seen on the network\n"
" lastpaid - The last time a node was paid on the network\n"
" protocol - Print protocol of a masternode (can be additionally filtered, exact match))\n"
" pubkey - Print public key associated with a masternode (can be additionally filtered,\n"
" partial match)\n"
" rank - Print rank of a masternode based on current block\n"
" status - Print masternode status: ENABLED / EXPIRED / VIN_SPENT / REMOVE / POS_ERROR\n"
" (can be additionally filtered, partial match)\n"
" addr - Print ip address associated with a masternode (can be additionally filtered, partial match)\n"
" lastpaid - The last time a node was paid on the network\n"
" votes - The amount of times this node has voted recently\n"
);
}
@ -518,6 +512,10 @@ Value masternodelist(const Array& params, bool fHelp)
if (strMode == "activeseconds") {
if(strFilter !="" && strVin.find(strFilter) == string::npos) continue;
obj.push_back(Pair(strVin, (int64_t)(mn.lastPing.sigTime - mn.sigTime)));
} else if (strMode == "addr") {
if(strFilter !="" && mn.vin.prevout.hash.ToString().find(strFilter) == string::npos &&
strVin.find(strFilter) == string::npos) continue;
obj.push_back(Pair(strVin, mn.addr.ToString()));
} else if (strMode == "full") {
CScript pubkey;
pubkey = GetScriptForDestination(mn.pubkey.GetID());
@ -529,10 +527,10 @@ Value masternodelist(const Array& params, bool fHelp)
addrStream << setw(21) << strVin;
std::ostringstream stringStream;
stringStream << setw(10) <<
stringStream << setw(9) <<
mn.Status() << " " <<
mn.protocolVersion << " " <<
address2.ToString() << " " <<
address2.ToString() << " " << setw(21) <<
mn.addr.ToString() << " " <<
mn.lastPing.sigTime << " " << setw(8) <<
(mn.lastPing.sigTime - mn.sigTime) << " " <<
@ -545,8 +543,12 @@ Value masternodelist(const Array& params, bool fHelp)
} else if (strMode == "lastseen") {
if(strFilter !="" && strVin.find(strFilter) == string::npos) continue;
obj.push_back(Pair(strVin, (int64_t)mn.lastPing.sigTime));
} else if (strMode == "lastpaid"){
if(strFilter !="" && mn.vin.prevout.hash.ToString().find(strFilter) == string::npos &&
strVin.find(strFilter) == string::npos) continue;
obj.push_back(Pair(strVin, (int64_t)mn.GetLastPaid()));
} else if (strMode == "protocol") {
if(strFilter !="" && strFilter != boost::lexical_cast<std::string>(mn.protocolVersion) &&
if(strFilter !="" && strFilter != strprintf("%d", mn.protocolVersion) &&
strVin.find(strFilter) == string::npos) continue;
obj.push_back(Pair(strVin, (int64_t)mn.protocolVersion));
} else if (strMode == "pubkey") {
@ -558,19 +560,11 @@ Value masternodelist(const Array& params, bool fHelp)
if(strFilter !="" && address2.ToString().find(strFilter) == string::npos &&
strVin.find(strFilter) == string::npos) continue;
obj.push_back(Pair(strVin, address2.ToString().c_str()));
obj.push_back(Pair(strVin, address2.ToString()));
} else if(strMode == "status") {
std::string strStatus = mn.Status();
if(strFilter !="" && strVin.find(strFilter) == string::npos && strStatus.find(strFilter) == string::npos) continue;
obj.push_back(Pair(strVin, strStatus.c_str()));
} else if (strMode == "addr") {
if(strFilter !="" && mn.vin.prevout.hash.ToString().find(strFilter) == string::npos &&
strVin.find(strFilter) == string::npos) continue;
obj.push_back(Pair(strVin, mn.addr.ToString().c_str()));
} else if(strMode == "lastpaid"){
if(strFilter !="" && mn.vin.prevout.hash.ToString().find(strFilter) == string::npos &&
strVin.find(strFilter) == string::npos) continue;
obj.push_back(Pair(strVin, (int64_t)mn.GetLastPaid()));
obj.push_back(Pair(strVin, strStatus));
} else if(strMode == "votes"){
if(strFilter !="" && mn.vin.prevout.hash.ToString().find(strFilter) == string::npos &&
strVin.find(strFilter) == string::npos) continue;