New rpc call "masternodelist info" (#1513)
* add masternodelist info call * safe version conversion function * change default sentinel version value * fix issues
This commit is contained in:
parent
9268a336dd
commit
70eb83a5ce
@ -737,7 +737,7 @@ void CMasternodeBroadcast::Relay()
|
||||
|
||||
CMasternodePing::CMasternodePing(CTxIn& vinNew) :
|
||||
fSentinelIsCurrent(false),
|
||||
nSentinelVersion(0)
|
||||
nSentinelVersion(DEFAULT_SENTINEL_VERSION)
|
||||
{
|
||||
LOCK(cs_main);
|
||||
if (!chainActive.Tip() || chainActive.Height() < 12) return;
|
||||
|
@ -28,6 +28,9 @@ static const int MASTERNODE_POSE_BAN_MAX_SCORE = 5;
|
||||
// The Masternode Ping Class : Contains a different serialize method for sending pings from masternodes throughout the network
|
||||
//
|
||||
|
||||
// sentinel version before sentinel ping implementation
|
||||
#define DEFAULT_SENTINEL_VERSION 0x010001
|
||||
|
||||
class CMasternodePing
|
||||
{
|
||||
public:
|
||||
@ -45,7 +48,7 @@ public:
|
||||
sigTime(0),
|
||||
vchSig(),
|
||||
fSentinelIsCurrent(false),
|
||||
nSentinelVersion(0)
|
||||
nSentinelVersion(DEFAULT_SENTINEL_VERSION)
|
||||
{}
|
||||
|
||||
CMasternodePing(CTxIn& vinNew);
|
||||
@ -59,7 +62,11 @@ public:
|
||||
READWRITE(sigTime);
|
||||
READWRITE(vchSig);
|
||||
if(ser_action.ForRead() && (s.size() == 0))
|
||||
{
|
||||
fSentinelIsCurrent = false;
|
||||
nSentinelVersion = DEFAULT_SENTINEL_VERSION;
|
||||
return;
|
||||
}
|
||||
READWRITE(fSentinelIsCurrent);
|
||||
READWRITE(nSentinelVersion);
|
||||
}
|
||||
|
@ -452,7 +452,7 @@ UniValue masternodelist(const UniValue& params, bool fHelp)
|
||||
if (params.size() == 2) strFilter = params[1].get_str();
|
||||
|
||||
if (fHelp || (
|
||||
strMode != "activeseconds" && strMode != "addr" && strMode != "full" &&
|
||||
strMode != "activeseconds" && strMode != "addr" && strMode != "full" && strMode != "info" &&
|
||||
strMode != "lastseen" && strMode != "lastpaidtime" && strMode != "lastpaidblock" &&
|
||||
strMode != "protocol" && strMode != "payee" && strMode != "rank" && strMode != "status"))
|
||||
{
|
||||
@ -469,6 +469,8 @@ UniValue masternodelist(const UniValue& params, bool fHelp)
|
||||
" addr - Print ip address associated with a masternode (can be additionally filtered, partial match)\n"
|
||||
" full - Print info in format 'status protocol payee lastseen activeseconds lastpaidtime lastpaidblock IP'\n"
|
||||
" (can be additionally filtered, partial match)\n"
|
||||
" info - Print info in format 'status protocol payee lastseen activeseconds sentinelversion sentinelstate IP'\n"
|
||||
" (can be additionally filtered, partial match)\n"
|
||||
" lastpaidblock - Print the last block height a node was paid on the network\n"
|
||||
" lastpaidtime - Print the last time a node was paid on the network\n"
|
||||
" lastseen - Print timestamp of when a masternode was last seen on the network\n"
|
||||
@ -520,6 +522,21 @@ UniValue masternodelist(const UniValue& params, bool fHelp)
|
||||
if (strFilter !="" && strFull.find(strFilter) == std::string::npos &&
|
||||
strOutpoint.find(strFilter) == std::string::npos) continue;
|
||||
obj.push_back(Pair(strOutpoint, strFull));
|
||||
} else if (strMode == "info") {
|
||||
std::ostringstream streamInfo;
|
||||
streamInfo << std::setw(18) <<
|
||||
mn.GetStatus() << " " <<
|
||||
mn.nProtocolVersion << " " <<
|
||||
CBitcoinAddress(mn.pubKeyCollateralAddress.GetID()).ToString() << " " <<
|
||||
(int64_t)mn.lastPing.sigTime << " " << std::setw(8) <<
|
||||
(int64_t)(mn.lastPing.sigTime - mn.sigTime) << " " <<
|
||||
SafeIntVersionToString(mn.lastPing.nSentinelVersion) << " " <<
|
||||
(mn.lastPing.fSentinelIsCurrent ? "current" : "expired") << " " <<
|
||||
mn.addr.ToString();
|
||||
std::string strInfo = streamInfo.str();
|
||||
if (strFilter !="" && strInfo.find(strFilter) == std::string::npos &&
|
||||
strOutpoint.find(strFilter) == std::string::npos) continue;
|
||||
obj.push_back(Pair(strOutpoint, strInfo));
|
||||
} else if (strMode == "lastpaidblock") {
|
||||
if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) continue;
|
||||
obj.push_back(Pair(strOutpoint, mn.GetLastPaidBlock()));
|
||||
|
13
src/util.cpp
13
src/util.cpp
@ -990,3 +990,16 @@ std::string IntVersionToString(uint32_t nVersion)
|
||||
}
|
||||
return boost::join(tokens, ".");
|
||||
}
|
||||
|
||||
std::string SafeIntVersionToString(uint32_t nVersion)
|
||||
{
|
||||
try
|
||||
{
|
||||
return IntVersionToString(nVersion);
|
||||
}
|
||||
catch(const std::bad_cast&)
|
||||
{
|
||||
return "Invalid version";
|
||||
}
|
||||
}
|
||||
|
||||
|
10
src/util.h
10
src/util.h
@ -290,4 +290,14 @@ uint32_t StringVersionToInt(const std::string& strVersion);
|
||||
std::string IntVersionToString(uint32_t nVersion);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Copy of the IntVersionToString, that returns "Invalid version" string
|
||||
* instead of throwing std::bad_cast
|
||||
* @param nVersion 4-byte unsigned integer, most significant byte is always 0
|
||||
* @return version string in "x.x.x" format (last 3 bytes as version parts)
|
||||
* or "Invalid version" if can't cast the given value
|
||||
*/
|
||||
std::string SafeIntVersionToString(uint32_t nVersion);
|
||||
|
||||
|
||||
#endif // BITCOIN_UTIL_H
|
||||
|
Loading…
Reference in New Issue
Block a user