mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-22 03:55:53 +00:00
Split into server_info (for humans) and server_state (for machines).
Allow either without admin privileges, filter information out from non-admins. Cleanup and improve data in all cases.
This commit is contained in:
@@ -492,6 +492,7 @@ Json::Value RPCParser::parseCommand(std::string strMethod, Json::Value jvParams)
|
||||
{ "sign", &RPCParser::parseSignSubmit, 2, 2 },
|
||||
{ "submit", &RPCParser::parseSignSubmit, 1, 2 },
|
||||
{ "server_info", &RPCParser::parseAsIs, 0, 0 },
|
||||
{ "server_state", &RPCParser::parseAsIs, 0, 0 },
|
||||
{ "stop", &RPCParser::parseAsIs, 0, 0 },
|
||||
// { "transaction_entry", &RPCParser::parseTransactionEntry, -1, -1 },
|
||||
{ "tx", &RPCParser::parseTx, 1, 1 },
|
||||
|
||||
@@ -1093,7 +1093,7 @@ bool NetworkOPs::recvValidation(const SerializedValidation::pointer& val)
|
||||
return theApp->getValidations().addValidation(val);
|
||||
}
|
||||
|
||||
Json::Value NetworkOPs::getServerInfo(bool admin)
|
||||
Json::Value NetworkOPs::getServerInfo(bool human, bool admin)
|
||||
{
|
||||
Json::Value info = Json::objectValue;
|
||||
|
||||
@@ -1126,29 +1126,58 @@ Json::Value NetworkOPs::getServerInfo(bool admin)
|
||||
|
||||
Json::Value lastClose = Json::objectValue;
|
||||
lastClose["proposers"] = theApp->getOPs().getPreviousProposers();
|
||||
lastClose["converge_time"] = static_cast<double>(theApp->getOPs().getPreviousConvergeTime()) / 1000.0;
|
||||
if (human)
|
||||
lastClose["converge_time_s"] = static_cast<double>(theApp->getOPs().getPreviousConvergeTime()) / 1000.0;
|
||||
else
|
||||
lastClose["converge_time"] = Json::Int(theApp->getOPs().getPreviousConvergeTime());
|
||||
info["last_close"] = lastClose;
|
||||
|
||||
// if (mConsensus)
|
||||
// info["consensus"] = mConsensus->getJson();
|
||||
|
||||
info["load"] = theApp->getJobQueue().getJson();
|
||||
info["load_factor"] =
|
||||
static_cast<double>(theApp->getFeeTrack().getLoadBase()) / theApp->getFeeTrack().getLoadFactor();
|
||||
if (admin)
|
||||
info["load"] = theApp->getJobQueue().getJson();
|
||||
|
||||
if (!human)
|
||||
{
|
||||
info["load_base"] = theApp->getFeeTrack().getLoadBase();
|
||||
info["load_factor"] = theApp->getFeeTrack().getLoadFactor();
|
||||
}
|
||||
else
|
||||
info["load_factor"] =
|
||||
static_cast<double>(theApp->getFeeTrack().getLoadBase()) / theApp->getFeeTrack().getLoadFactor();
|
||||
|
||||
bool valid = false;
|
||||
Ledger::pointer lpClosed = getValidatedLedger();
|
||||
if (lpClosed)
|
||||
valid = true;
|
||||
else
|
||||
lpClosed = getClosedLedger();
|
||||
|
||||
Ledger::pointer lpClosed = getClosedLedger();
|
||||
if (lpClosed)
|
||||
{
|
||||
uint64 baseFee = lpClosed->getBaseFee();
|
||||
uint64 baseRef = lpClosed->getReferenceFeeUnits();
|
||||
Json::Value l(Json::objectValue);
|
||||
l["seq"] = Json::UInt(lpClosed->getLedgerSeq());
|
||||
l["hash"] = lpClosed->getHash().GetHex();
|
||||
l["base_fee"] = static_cast<double>(Json::UInt(baseFee)) / SYSTEM_CURRENCY_PARTS;
|
||||
l["reserve_base"] =
|
||||
static_cast<double>(Json::UInt(lpClosed->getReserve(0) * baseFee / baseRef)) / SYSTEM_CURRENCY_PARTS;
|
||||
l["reserve_inc"] =
|
||||
static_cast<double>(Json::UInt(lpClosed->getReserveInc() * baseFee / baseRef)) / SYSTEM_CURRENCY_PARTS;
|
||||
l["seq"] = Json::UInt(lpClosed->getLedgerSeq());
|
||||
l["hash"] = lpClosed->getHash().GetHex();
|
||||
l["validated"] = valid;
|
||||
if (!human)
|
||||
{
|
||||
l["base_fee"] = Json::Value::UInt(baseFee);
|
||||
l["reserve_base"] = Json::Value::UInt(lpClosed->getReserve(0));
|
||||
l["reserve_inc"] = Json::Value::UInt(lpClosed->getReserveInc());
|
||||
l["close_time"] = Json::Value::UInt(lpClosed->getCloseTimeNC());
|
||||
}
|
||||
else
|
||||
{
|
||||
l["base_fee_xrp"] = static_cast<double>(Json::UInt(baseFee)) / SYSTEM_CURRENCY_PARTS;
|
||||
l["reserve_base_xrp"] =
|
||||
static_cast<double>(Json::UInt(lpClosed->getReserve(0) * baseFee / baseRef)) / SYSTEM_CURRENCY_PARTS;
|
||||
l["reserve_inc_xrp"] =
|
||||
static_cast<double>(Json::UInt(lpClosed->getReserveInc() * baseFee / baseRef)) / SYSTEM_CURRENCY_PARTS;
|
||||
l["age"] = static_cast<int>(lpClosed->getCloseTimeNC()) - getCloseTimeNC();
|
||||
}
|
||||
info["closed_ledger"] = l;
|
||||
}
|
||||
|
||||
|
||||
@@ -141,6 +141,7 @@ public:
|
||||
std::string strOperatingMode();
|
||||
|
||||
Ledger::ref getClosedLedger() { return mLedgerMaster->getClosedLedger(); }
|
||||
Ledger::ref getValidatedLedger() { return mLedgerMaster->getValidatedLedger(); }
|
||||
Ledger::ref getCurrentLedger() { return mLedgerMaster->getCurrentLedger(); }
|
||||
Ledger::pointer getLedgerByHash(const uint256& hash) { return mLedgerMaster->getLedgerByHash(hash); }
|
||||
Ledger::pointer getLedgerBySeq(const uint32 seq) { return mLedgerMaster->getLedgerBySeq(seq); }
|
||||
@@ -243,7 +244,7 @@ public:
|
||||
int getPreviousConvergeTime() { return mLastCloseConvergeTime; }
|
||||
uint32 getLastCloseTime() { return mLastCloseTime; }
|
||||
void setLastCloseTime(uint32 t) { mLastCloseTime = t; }
|
||||
Json::Value getServerInfo(bool admin);
|
||||
Json::Value getServerInfo(bool human, bool admin);
|
||||
uint32 acceptLedger();
|
||||
boost::unordered_map<uint160,
|
||||
std::list<LedgerProposal::pointer> >& peekStoredProposals() { return mStoredProposals; }
|
||||
|
||||
@@ -1305,7 +1305,16 @@ Json::Value RPCHandler::doServerInfo(Json::Value)
|
||||
{
|
||||
Json::Value ret(Json::objectValue);
|
||||
|
||||
ret["info"] = theApp->getOPs().getServerInfo(mRole == ADMIN);
|
||||
ret["info"] = theApp->getOPs().getServerInfo(true, mRole == ADMIN);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Json::Value RPCHandler::doServerState(Json::Value)
|
||||
{
|
||||
Json::Value ret(Json::objectValue);
|
||||
|
||||
ret["info"] = theApp->getOPs().getServerInfo(false, mRole == ADMIN);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -2589,7 +2598,8 @@ Json::Value RPCHandler::doCommand(Json::Value& jvRequest, int iRole)
|
||||
{ "ripple_path_find", &RPCHandler::doRipplePathFind, false, optCurrent },
|
||||
{ "sign", &RPCHandler::doSign, false, optCurrent },
|
||||
{ "submit", &RPCHandler::doSubmit, false, optCurrent },
|
||||
{ "server_info", &RPCHandler::doServerInfo, true, optNone },
|
||||
{ "server_info", &RPCHandler::doServerInfo, false, optNone },
|
||||
{ "server_state", &RPCHandler::doServerState, false, optNone },
|
||||
{ "stop", &RPCHandler::doStop, true, optNone },
|
||||
{ "transaction_entry", &RPCHandler::doTransactionEntry, false, optCurrent },
|
||||
{ "tx", &RPCHandler::doTx, false, optNetwork },
|
||||
|
||||
@@ -66,7 +66,8 @@ class RPCHandler
|
||||
Json::Value doProfile(Json::Value params);
|
||||
Json::Value doRandom(Json::Value jvRequest);
|
||||
Json::Value doRipplePathFind(Json::Value jvRequest);
|
||||
Json::Value doServerInfo(Json::Value params);
|
||||
Json::Value doServerInfo(Json::Value params); // for humans
|
||||
Json::Value doServerState(Json::Value params); // for machines
|
||||
Json::Value doSessionClose(Json::Value params);
|
||||
Json::Value doSessionOpen(Json::Value params);
|
||||
Json::Value doStop(Json::Value params);
|
||||
|
||||
Reference in New Issue
Block a user