diff --git a/src/Ledger.h b/src/Ledger.h index 9d82641295..cb9c4cfd15 100644 --- a/src/Ledger.h +++ b/src/Ledger.h @@ -35,6 +35,7 @@ enum LedgerStateParms #define LEDGER_JSON_DUMP_TXNS 0x10000000 #define LEDGER_JSON_DUMP_STATE 0x20000000 +#define LEDGER_JSON_FULL 0x40000000 class Ledger : public boost::enable_shared_from_this { // The basic Ledger structure, can be opened, closed, or synching diff --git a/src/RPCServer.cpp b/src/RPCServer.cpp index b071c83c82..f325ce6a81 100644 --- a/src/RPCServer.cpp +++ b/src/RPCServer.cpp @@ -1410,10 +1410,20 @@ Json::Value RPCServer::doTx(Json::Value& params) return JSONRPCError(501, "not implemented"); } -// ledger +// ledger [id|current|lastclosed] [full] Json::Value RPCServer::doLedger(Json::Value& params) { - if (getParamCount(params)== 0) + + if (params.size() > 2) + { + return "invalid params"; + } + else if (!mNetOps->available()) + { + return JSONRPCError(503, "network not available"); + } + + if (getParamCount(params) == 0) { Json::Value ret(Json::objectValue), current(Json::objectValue), closed(Json::objectValue); theApp->getMasterLedger().getCurrentLedger()->addJson(current, 0); @@ -1423,7 +1433,35 @@ Json::Value RPCServer::doLedger(Json::Value& params) return ret; } - return JSONRPCError(501, "not implemented"); + std::string param; + if (!extractString(param, params, 0)) + { + return "bad params"; + } + + Ledger::pointer ledger; + if (param == "current") + ledger = theApp->getMasterLedger().getCurrentLedger(); + else if (param == "lastclosed") + ledger = theApp->getMasterLedger().getClosedLedger(); + else if (param.size() > 12) + ledger = theApp->getMasterLedger().getLedgerByHash(uint256(param)); + else + ledger = theApp->getMasterLedger().getLedgerBySeq(boost::lexical_cast(param)); + + if (!ledger) + return JSONRPCError(503, "Unable to locate ledger"); + + bool full = false; + if (extractString(param, params, 1)) + { + if (param == "full") + full = true; + } + + Json::Value ret(Json::objectValue); + ledger->addJson(ret, full ? LEDGER_JSON_FULL : 0); + return ret; } // unl_add | []