ledger [id|current|lastclosed] [full]

Implementation is not 100% complete yet.
This commit is contained in:
JoelKatz
2012-06-09 01:49:18 -07:00
parent 40748df505
commit 5dcc7908dd
2 changed files with 42 additions and 3 deletions

View File

@@ -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<uint32>(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 <domain>|<node_public> [<comment>]