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