diff --git a/src/Ledger.cpp b/src/Ledger.cpp index 1fda2ca217..5a7e6e2338 100644 --- a/src/Ledger.cpp +++ b/src/Ledger.cpp @@ -302,7 +302,7 @@ Ledger::pointer Ledger::loadByHash(const uint256& ledgerHash) return getSQL(sql); } -void Ledger::addJson(Json::Value& ret) +void Ledger::addJson(Json::Value& ret, int options) { Json::Value ledger(Json::objectValue); @@ -321,6 +321,22 @@ void Ledger::addJson(Json::Value& ret) else ledger["Closed"] = false; if (mCloseTime != 0) ledger["CloseTime"] = boost::posix_time::to_simple_string(ptFromSeconds(mCloseTime)); + if ((options & LEDGER_JSON_DUMP_TXNS) != 0) + { + Json::Value txns(Json::arrayValue); + for (SHAMapItem::pointer item = mTransactionMap->peekFirstItem(); !!item; + item = mTransactionMap->peekNextItem(item->getTag())) + txns.append(item->getTag().GetHex()); + ledger["Transactions"] = txns; + } + if ((options & LEDGER_JSON_DUMP_STATE) != 0) + { + Json::Value state(Json::arrayValue); + for (SHAMapItem::pointer item = mAccountStateMap->peekFirstItem(); !!item; + item = mAccountStateMap->peekNextItem(item->getTag())) + state.append(item->getTag().GetHex()); + ledger["AccounState"] = state; + } ret[boost::lexical_cast(mLedgerSeq)] = ledger; } diff --git a/src/Ledger.h b/src/Ledger.h index d4fe92f460..00750ea9c2 100644 --- a/src/Ledger.h +++ b/src/Ledger.h @@ -32,6 +32,9 @@ enum LedgerStateParms lepERROR = 32, // error }; +#define LEDGER_JSON_DUMP_TXNS 0x10000000 +#define LEDGER_JSON_DUMP_STATE 0x20000000 + class Ledger : public boost::enable_shared_from_this { // The basic Ledger structure, can be opened, closed, or synching friend class TransactionEngine; @@ -206,7 +209,7 @@ public: bool isCompatible(boost::shared_ptr other); // bool signLedger(std::vector &signature, const LocalHanko &hanko); - void addJson(Json::Value&); + void addJson(Json::Value&, int options); static bool unitTest(); }; diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index d1bae73334..91a393a05c 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -3,6 +3,8 @@ #include #include +#include "../json/writer.h" + #include "Application.h" #include "NetworkOPs.h" #include "LedgerTiming.h" @@ -661,6 +663,17 @@ void LedgerConsensus::accept(SHAMap::pointer set) Ledger::pointer newLCL = boost::make_shared(false, boost::ref(*mPreviousLedger)); +#ifdef DEBUG + Json::StyledStreamWriter ssw; + if (1) + { + Log(lsTRACE) << "newLCL before transactions"; + Json::Value p; + newLCL->addJson(p, LEDGER_JSON_DUMP_TXNS | LEDGER_JSON_DUMP_STATE); + ssw.write(std::cerr, p); + } +#endif + std::deque failedTransactions; applyTransactions(set, newLCL, failedTransactions); newLCL->setClosed(); @@ -668,8 +681,27 @@ void LedgerConsensus::accept(SHAMap::pointer set) newLCL->updateHash(); uint256 newLCLHash = newLCL->getHash(); +#ifdef DEBUG + if (1) + { + Log(lsTRACE) << "newLCL after transactions"; + Json::Value p; + newLCL->addJson(p, LEDGER_JSON_DUMP_TXNS | LEDGER_JSON_DUMP_STATE); + ssw.write(std::cerr, p); + } +#endif + Ledger::pointer newOL = boost::make_shared(true, boost::ref(*newLCL)); +#ifdef DEBUG + if (1) + { + Log(lsTRACE) << "newOL before transactions"; + Json::Value p; + newOL->addJson(p, LEDGER_JSON_DUMP_TXNS | LEDGER_JSON_DUMP_STATE); + ssw.write(std::cerr, p); + } +#endif ScopedLock sl = theApp->getMasterLedger().getLock(); applyTransactions(theApp->getMasterLedger().getCurrentLedger()->peekTransactionMap(), @@ -677,6 +709,16 @@ void LedgerConsensus::accept(SHAMap::pointer set) theApp->getMasterLedger().pushLedger(newLCL, newOL); mState = lcsACCEPTED; +#ifdef DEBUG + if (1) + { + Log(lsTRACE) << "newOL after transactions"; + Json::Value p; + newOL->addJson(p, LEDGER_JSON_DUMP_TXNS | LEDGER_JSON_DUMP_STATE); + ssw.write(std::cerr, p); + } +#endif + sl.unlock(); SerializedValidation v(newLCLHash, mOurPosition->peekKey(), true); diff --git a/src/RPCServer.cpp b/src/RPCServer.cpp index 1460767f1b..0a2f4a87a3 100644 --- a/src/RPCServer.cpp +++ b/src/RPCServer.cpp @@ -1206,8 +1206,8 @@ Json::Value RPCServer::doLedger(Json::Value& params) if (getParamCount(params)== 0) { Json::Value ret(Json::objectValue), current(Json::objectValue), closed(Json::objectValue); - theApp->getMasterLedger().getCurrentLedger()->addJson(current); - theApp->getMasterLedger().getClosedLedger()->addJson(closed); + theApp->getMasterLedger().getCurrentLedger()->addJson(current, 0); + theApp->getMasterLedger().getClosedLedger()->addJson(closed, 0); ret["open"] = current; ret["closed"] = closed; return ret;