Make sure that handlers always return Json::objectValue.

This commit is contained in:
Tom Ritchford
2014-12-01 15:26:59 -05:00
parent b0d47ebcc6
commit 86df482842
22 changed files with 43 additions and 32 deletions

View File

@@ -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,

View File

@@ -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

View File

@@ -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,

View File

@@ -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)
{

View File

@@ -100,6 +100,8 @@ public:
} // namespace RPCDetail
/** Returns a Json::objectValue. */
Json::Value transactionSign (
Json::Value params,
bool bSubmit,