mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-03 01:15:53 +00:00
Add support for getting ledger_header.
This commit is contained in:
@@ -1313,13 +1313,15 @@ Json::Value RPCHandler::doCommand(const std::string& command, Json::Value& param
|
||||
cLog(lsTRACE) << "RPC:" << command;
|
||||
cLog(lsTRACE) << "RPC params:" << params;
|
||||
|
||||
mRole = role;
|
||||
|
||||
static struct {
|
||||
const char* pCommand;
|
||||
doFuncPtr dfpFunc;
|
||||
int iMinParams;
|
||||
int iMaxParams;
|
||||
bool mAdminRequired;
|
||||
bool mEvented;
|
||||
bool bAdminRequired;
|
||||
bool bEvented;
|
||||
unsigned int iOptions;
|
||||
} commandsA[] = {
|
||||
// Request-response methods
|
||||
@@ -1336,6 +1338,7 @@ Json::Value RPCHandler::doCommand(const std::string& command, Json::Value& param
|
||||
{ "ledger_closed", &RPCHandler::doLedgerClosed, 0, 0, false, false, optClosed },
|
||||
{ "ledger_current", &RPCHandler::doLedgerCurrent, 0, 0, false, false, optCurrent },
|
||||
{ "ledger_entry", &RPCHandler::doLedgerEntry, -1, -1, false, false, optCurrent },
|
||||
{ "ledger_header", &RPCHandler::doLedgerHeader, -1, -1, false, false, optCurrent },
|
||||
{ "log_level", &RPCHandler::doLogLevel, 0, 2, true },
|
||||
{ "logrotate", &RPCHandler::doLogRotate, 0, 0, true },
|
||||
{ "nickname_info", &RPCHandler::doNicknameInfo, 1, 1, false, false, optCurrent },
|
||||
@@ -1381,11 +1384,11 @@ Json::Value RPCHandler::doCommand(const std::string& command, Json::Value& param
|
||||
{
|
||||
return rpcError(rpcUNKNOWN_COMMAND);
|
||||
}
|
||||
else if (commandsA[i].mAdminRequired && role != ADMIN)
|
||||
else if (commandsA[i].bAdminRequired && mRole != ADMIN)
|
||||
{
|
||||
return rpcError(rpcNO_PERMISSION);
|
||||
}
|
||||
else if (commandsA[i].mEvented && mInfoSub == NULL)
|
||||
else if (commandsA[i].bEvented && mInfoSub == NULL)
|
||||
{
|
||||
return rpcError(rpcNO_EVENTS);
|
||||
}
|
||||
@@ -1706,15 +1709,13 @@ Json::Value RPCHandler::doTransactionEntry(const Json::Value& jvRequest)
|
||||
return jvResult;
|
||||
}
|
||||
|
||||
Json::Value RPCHandler::doLedgerEntry(const Json::Value& jvRequest)
|
||||
Json::Value RPCHandler::lookupLedger(const Json::Value& jvRequest, Ledger::pointer& lpLedger)
|
||||
{
|
||||
Json::Value jvResult;
|
||||
|
||||
uint256 uLedger = jvRequest.isMember("ledger_hash") ? uint256(jvRequest["ledger_hash"].asString()) : 0;
|
||||
uint32 uLedgerIndex = jvRequest.isMember("ledger_index") && jvRequest["ledger_index"].isNumeric() ? jvRequest["ledger_index"].asUInt() : 0;
|
||||
|
||||
Ledger::pointer lpLedger;
|
||||
|
||||
if (!!uLedger)
|
||||
{
|
||||
// Ledger directly specified.
|
||||
@@ -1757,6 +1758,17 @@ Json::Value RPCHandler::doLedgerEntry(const Json::Value& jvRequest)
|
||||
jvResult["ledger_current_index"] = uLedgerIndex;
|
||||
}
|
||||
|
||||
return jvResult;
|
||||
}
|
||||
|
||||
Json::Value RPCHandler::doLedgerEntry(const Json::Value& jvRequest)
|
||||
{
|
||||
Ledger::pointer lpLedger;
|
||||
Json::Value jvResult = lookupLedger(jvRequest, lpLedger);
|
||||
|
||||
if (!lpLedger)
|
||||
return jvResult;
|
||||
|
||||
uint256 uNodeIndex;
|
||||
bool bNodeBinary = false;
|
||||
|
||||
@@ -1952,6 +1964,25 @@ Json::Value RPCHandler::doLedgerEntry(const Json::Value& jvRequest)
|
||||
return jvResult;
|
||||
}
|
||||
|
||||
Json::Value RPCHandler::doLedgerHeader(const Json::Value& jvRequest)
|
||||
{
|
||||
Ledger::pointer lpLedger;
|
||||
Json::Value jvResult = lookupLedger(jvRequest, lpLedger);
|
||||
|
||||
if (!lpLedger)
|
||||
return jvResult;
|
||||
|
||||
Serializer s;
|
||||
|
||||
lpLedger->addRaw(s);
|
||||
|
||||
jvResult["ledger_data"] = strHex(s.peekData());
|
||||
|
||||
if (mRole == ADMIN)
|
||||
lpLedger->addJson(jvResult, 0);
|
||||
|
||||
return jvRequest;
|
||||
}
|
||||
|
||||
boost::unordered_set<RippleAddress> RPCHandler::parseAccountIds(const Json::Value& jvArray)
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@ class RPCHandler
|
||||
{
|
||||
NetworkOPs* mNetOps;
|
||||
InfoSub* mInfoSub;
|
||||
int mRole;
|
||||
|
||||
typedef Json::Value (RPCHandler::*doFuncPtr)(const Json::Value ¶ms);
|
||||
enum {
|
||||
@@ -22,6 +23,8 @@ class RPCHandler
|
||||
int getParamCount(const Json::Value& params);
|
||||
bool extractString(std::string& param, const Json::Value& params, int index);
|
||||
|
||||
Json::Value lookupLedger(const Json::Value& jvRequest, Ledger::pointer& lpLedger);
|
||||
|
||||
Json::Value getMasterGenerator(const uint256& uLedger, const RippleAddress& naRegularSeed, RippleAddress& naMasterGenerator);
|
||||
Json::Value authorize(const uint256& uLedger, const RippleAddress& naRegularSeed, const RippleAddress& naSrcAccountID,
|
||||
RippleAddress& naAccountPublic, RippleAddress& naAccountPrivate,
|
||||
@@ -86,6 +89,7 @@ class RPCHandler
|
||||
Json::Value doLedgerClosed(const Json::Value& params);
|
||||
Json::Value doLedgerCurrent(const Json::Value& params);
|
||||
Json::Value doLedgerEntry(const Json::Value& params);
|
||||
Json::Value doLedgerHeader(const Json::Value& params);
|
||||
Json::Value doTransactionEntry(const Json::Value& params);
|
||||
|
||||
Json::Value doSubscribe(const Json::Value& params);
|
||||
|
||||
@@ -551,6 +551,12 @@ Remote.prototype.request_ledger_hash = function () {
|
||||
return new Request(this, 'ledger_closed');
|
||||
};
|
||||
|
||||
// .ledger()
|
||||
// .ledger_index()
|
||||
Remote.prototype.request_ledger_header = function () {
|
||||
return new Request(this, 'ledger_header');
|
||||
};
|
||||
|
||||
// Get the current proposed ledger entry. May be closed (and revised) at any time (even before returning).
|
||||
// Only for unit testing.
|
||||
Remote.prototype.request_ledger_current = function () {
|
||||
|
||||
Reference in New Issue
Block a user