mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Make sure that handlers always return Json::objectValue.
This commit is contained in:
@@ -25,6 +25,8 @@ namespace RPC {
|
||||
// --> strIdent: public key, account ID, or regular seed.
|
||||
// --> bStrict: Only allow account id or public key.
|
||||
// <-- bIndex: true if iIndex > 0 and used the index.
|
||||
//
|
||||
// Returns a Json::objectValue, containing error information if there was one.
|
||||
Json::Value accountFromString (
|
||||
Ledger::ref lrLedger,
|
||||
RippleAddress& naAccount,
|
||||
|
||||
@@ -46,6 +46,16 @@ struct Handler
|
||||
|
||||
const Handler* getHandler(std::string name);
|
||||
|
||||
/** Return a Json::objectValue with a single entry. */
|
||||
template <class Value>
|
||||
Json::Value makeObjectValue (
|
||||
Value const& value, Json::StaticString const& field = jss::message)
|
||||
{
|
||||
Json::Value result (Json::objectValue);
|
||||
result[field] = value;
|
||||
return result;
|
||||
}
|
||||
|
||||
} // RPC
|
||||
} // ripple
|
||||
|
||||
|
||||
@@ -40,6 +40,11 @@ static const int LEDGER_VALIDATED = -3;
|
||||
//
|
||||
// In the absence of the "ledger_hash" or "ledger_index" parameters, the code
|
||||
// assumes that "ledger_index" has the value "current".
|
||||
//
|
||||
// Returns a Json::objectValue. If there was an error, it will be in that
|
||||
// return value. Otherwise, the object contains the field "validated" and
|
||||
// optionally the fields "ledger_hash", "ledger_index" and
|
||||
// "ledger_current_index", if they are defined.
|
||||
Json::Value lookupLedger (
|
||||
Json::Value const& params,
|
||||
Ledger::pointer& ledger,
|
||||
|
||||
@@ -140,17 +140,9 @@ Json::Value RPCHandler::doCommand (
|
||||
LoadEvent::autoptr ev = getApp().getJobQueue().getLoadEventAP(
|
||||
jtGENERIC, "cmd:" + strCommand);
|
||||
RPC::Context context {params, loadType, netOps_, infoSub_, role_};
|
||||
Json::Value jvRaw = handler->method_(context);
|
||||
|
||||
// Regularize result.
|
||||
if (jvRaw.isObject ())
|
||||
return jvRaw;
|
||||
|
||||
// Probably got a string.
|
||||
Json::Value jvResult (Json::objectValue);
|
||||
jvResult[jss::message] = jvRaw;
|
||||
|
||||
return jvResult;
|
||||
auto result = handler->method_(context);
|
||||
assert (result.isObject());
|
||||
return result;
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
|
||||
@@ -100,6 +100,8 @@ public:
|
||||
|
||||
} // namespace RPCDetail
|
||||
|
||||
|
||||
/** Returns a Json::objectValue. */
|
||||
Json::Value transactionSign (
|
||||
Json::Value params,
|
||||
bool bSubmit,
|
||||
|
||||
Reference in New Issue
Block a user