diff --git a/src/cpp/ripple/CallRPC.cpp b/src/cpp/ripple/CallRPC.cpp index d8b3296e68..c24f99fbb8 100644 --- a/src/cpp/ripple/CallRPC.cpp +++ b/src/cpp/ripple/CallRPC.cpp @@ -499,6 +499,7 @@ Json::Value RPCParser::parseCommand(std::string strMethod, Json::Value jvParams) { "account_offers", &RPCParser::parseAccountItems, 1, 2 }, { "account_tx", &RPCParser::parseAccountTransactions, 2, 3 }, { "connect", &RPCParser::parseConnect, 1, 2 }, + { "consensus_info", &RPCParser::parseAsIs, 0, 0 }, { "get_counts", &RPCParser::parseGetCounts, 0, 1 }, { "ledger", &RPCParser::parseLedger, 0, 2 }, { "ledger_accept", &RPCParser::parseAsIs, 0, 0 }, diff --git a/src/cpp/ripple/LedgerConsensus.cpp b/src/cpp/ripple/LedgerConsensus.cpp index f066b2f833..56f6868e51 100644 --- a/src/cpp/ripple/LedgerConsensus.cpp +++ b/src/cpp/ripple/LedgerConsensus.cpp @@ -267,6 +267,26 @@ bool LCTransaction::updateVote(int percentTime, bool proposing) return true; } +Json::Value LCTransaction::getJson() +{ + Json::Value ret(Json::objectValue); + + ret["yays"] = mYays; + ret["nays"] = mNays; + ret["our_vote"] = mOurVote; + if (!mVotes.empty()) + { + Json::Value votesj(Json::objectValue); + typedef boost::unordered_map::value_type vt; + BOOST_FOREACH(vt& vote, mVotes) + { + votesj[vote.first.GetHex()] = vote.second; + } + ret["votes"] = votesj; + } + return ret; +} + LedgerConsensus::LedgerConsensus(const uint256& prevLCLHash, Ledger::ref previousLedger, uint32 closeTime) : mState(lcsPRE_CLOSE), mCloseTime(closeTime), mPrevLedgerHash(prevLCLHash), mPreviousLedger(previousLedger), mValPublic(theConfig.VALIDATION_PUB), mValPrivate(theConfig.VALIDATION_PRIV), mConsensusFail(false), @@ -1363,7 +1383,7 @@ void LedgerConsensus::simulate() cLog(lsINFO) << "Simulation complete"; } -Json::Value LedgerConsensus::getJson() +Json::Value LedgerConsensus::getJson(bool full) { Json::Value ret(Json::objectValue); ret["proposing"] = mProposing; @@ -1388,12 +1408,88 @@ Json::Value LedgerConsensus::getJson() } int v = mDisputes.size(); - if (v != 0) + if ((v != 0) && !full) ret["disputes"] = v; if (mOurPosition) ret["our_position"] = mOurPosition->getJson(); + if (full) + { + + ret["current_ms"] = mCurrentMSeconds; + ret["close_percent"] = mClosePercent; + ret["close_resolution"] = mCloseResolution; + ret["have_time_consensus"] = mHaveCloseTimeConsensus; + ret["previous_proposers"] = mPreviousProposers; + ret["previous_mseconds"] = mPreviousMSeconds; + + if (!mPeerPositions.empty()) + { + typedef boost::unordered_map::value_type pp_t; + Json::Value ppj(Json::objectValue); + BOOST_FOREACH(pp_t& pp, mPeerPositions) + { + ppj[pp.first.GetHex()] = pp.second->getJson(); + } + ret["peer_positions"] = ppj; + } + + if (!mAcquired.empty()) + { // acquired + typedef boost::unordered_map::value_type ac_t; + Json::Value acq(Json::arrayValue); + BOOST_FOREACH(ac_t& at, mAcquired) + { + acq.append(at.first.GetHex()); + } + ret["acquired"] = acq; + } + + if (!mAcquiring.empty()) + { + typedef boost::unordered_map::value_type ac_t; + Json::Value acq(Json::arrayValue); + BOOST_FOREACH(ac_t& at, mAcquiring) + { + acq.append(at.first.GetHex()); + } + ret["acquiring"] = acq; + } + + if (!mDisputes.empty()) + { + typedef boost::unordered_map::value_type d_t; + Json::Value dsj(Json::objectValue); + BOOST_FOREACH(d_t& dt, mDisputes) + { + dsj[dt.first.GetHex()] = dt.second->getJson(); + } + ret["disputes"] = dsj; + } + + if (!mCloseTimes.empty()) + { + typedef std::map::value_type ct_t; + Json::Value ctj(Json::objectValue); + BOOST_FOREACH(ct_t& ct, mCloseTimes) + { + ctj[boost::lexical_cast(ct.first)] = ct.second; + } + ret["close_times"] = ctj; + } + + if (!mDeadNodes.empty()) + { + Json::Value dnj(Json::arrayValue); + BOOST_FOREACH(const uint160& dn, mDeadNodes) + { + dnj.append(dn.GetHex()); + } + ret["dead_nodes"] = dnj; + } + } + return ret; } diff --git a/src/cpp/ripple/LedgerConsensus.h b/src/cpp/ripple/LedgerConsensus.h index b40e182da9..15890b0899 100644 --- a/src/cpp/ripple/LedgerConsensus.h +++ b/src/cpp/ripple/LedgerConsensus.h @@ -75,6 +75,7 @@ public: void unVote(const uint160& peer); bool updateVote(int percentTime, bool proposing); + Json::Value getJson(); }; enum LCState @@ -161,7 +162,7 @@ public: LedgerConsensus(const uint256& prevLCLHash, Ledger::ref previousLedger, uint32 closeTime); int startup(); - Json::Value getJson(); + Json::Value getJson(bool full); Ledger::ref peekPreviousLedger() { return mPreviousLedger; } uint256 getLCL() { return mPrevLedgerHash; } diff --git a/src/cpp/ripple/NetworkOPs.cpp b/src/cpp/ripple/NetworkOPs.cpp index 99bebd978b..7982c7cfc8 100644 --- a/src/cpp/ripple/NetworkOPs.cpp +++ b/src/cpp/ripple/NetworkOPs.cpp @@ -1106,6 +1106,16 @@ bool NetworkOPs::recvValidation(const SerializedValidation::pointer& val) return theApp->getValidations().addValidation(val); } +Json::Value NetworkOPs::getConsensusInfo() +{ + if (mConsensus) + return mConsensus->getJson(true); + + Json::Value info = Json::objectValue; + info["consensus"] = "none"; + return info; +} + Json::Value NetworkOPs::getServerInfo(bool human, bool admin) { Json::Value info = Json::objectValue; diff --git a/src/cpp/ripple/NetworkOPs.h b/src/cpp/ripple/NetworkOPs.h index f86b61bab0..9ce5709f4b 100644 --- a/src/cpp/ripple/NetworkOPs.h +++ b/src/cpp/ripple/NetworkOPs.h @@ -250,6 +250,7 @@ public: int getPreviousConvergeTime() { return mLastCloseConvergeTime; } uint32 getLastCloseTime() { return mLastCloseTime; } void setLastCloseTime(uint32 t) { mLastCloseTime = t; } + Json::Value getConsensusInfo(); Json::Value getServerInfo(bool human, bool admin); uint32 acceptLedger(); boost::unordered_mapgetOPs().getConsensusInfo(); + + return ret; +} + Json::Value RPCHandler::doServerInfo(Json::Value) { Json::Value ret(Json::objectValue); @@ -2682,6 +2691,7 @@ Json::Value RPCHandler::doCommand(const Json::Value& jvRequest, int iRole) { "account_offers", &RPCHandler::doAccountOffers, false, optCurrent }, { "account_tx", &RPCHandler::doAccountTransactions, false, optNetwork }, { "connect", &RPCHandler::doConnect, true, optNone }, + { "consensus_info", &RPCHandler::doConsensusInfo, true, optNone }, { "get_counts", &RPCHandler::doGetCounts, true, optNone }, { "internal", &RPCHandler::doInternal, true, optNone }, { "ledger", &RPCHandler::doLedger, false, optNetwork }, diff --git a/src/cpp/ripple/RPCHandler.h b/src/cpp/ripple/RPCHandler.h index 455d6dfd47..3e584056bf 100644 --- a/src/cpp/ripple/RPCHandler.h +++ b/src/cpp/ripple/RPCHandler.h @@ -50,6 +50,7 @@ class RPCHandler Json::Value doAccountOffers(Json::Value params); Json::Value doAccountTransactions(Json::Value params); Json::Value doConnect(Json::Value params); + Json::Value doConsensusInfo(Json::Value params); #if ENABLE_INSECURE Json::Value doDataDelete(Json::Value params); Json::Value doDataFetch(Json::Value params);