mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-28 06:55:50 +00:00
Make sure that handlers always return Json::objectValue.
This commit is contained in:
@@ -101,6 +101,7 @@ public:
|
||||
void filterNodes (std::vector<SHAMapNodeID>& nodeIDs, std::vector<uint256>& nodeHashes,
|
||||
std::set<SHAMapNodeID>& recentNodes, int max, bool aggressive);
|
||||
|
||||
/** Return a Json::objectValue. */
|
||||
Json::Value getJson (int);
|
||||
void runData ();
|
||||
|
||||
|
||||
@@ -144,6 +144,8 @@ public:
|
||||
virtual void reportValidations (const AmendmentSet&) = 0;
|
||||
|
||||
virtual Json::Value getJson (int) = 0;
|
||||
|
||||
/** Returns a Json::objectValue. */
|
||||
virtual Json::Value getJson (uint256 const& ) = 0;
|
||||
|
||||
virtual void
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
/** A PropertyStream::Sink which produces a Json::Value. */
|
||||
/** A PropertyStream::Sink which produces a Json::Value of type objectValue. */
|
||||
class JsonPropertyStream : public beast::PropertyStream
|
||||
{
|
||||
public:
|
||||
@@ -65,4 +65,3 @@ protected:
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ namespace jss {
|
||||
// TODO Move the string not part of the JSON-RPC API into another file
|
||||
JSS ( accepted );
|
||||
JSS ( account );
|
||||
JSS ( accounts );
|
||||
JSS ( account_hash );
|
||||
JSS ( account_index );
|
||||
JSS ( accountState );
|
||||
|
||||
@@ -239,6 +239,7 @@ public:
|
||||
return getJson (warningThreshold);
|
||||
}
|
||||
|
||||
/** Returns a Json::objectValue. */
|
||||
Json::Value getJson (int threshold)
|
||||
{
|
||||
clock_type::time_point const now (m_clock.now());
|
||||
|
||||
@@ -68,7 +68,7 @@ Json::Value doAccountInfo (RPC::Context& context)
|
||||
else
|
||||
{
|
||||
result["account"] = naAccount.humanAccountID ();
|
||||
result = rpcError (rpcACT_NOT_FOUND, result);
|
||||
RPC::inject_error (rpcACT_NOT_FOUND, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -54,7 +54,7 @@ Json::Value doConnect (RPC::Context& context)
|
||||
if (! is_unspecified (ip))
|
||||
getApp().overlay ().connect (ip.at_port(iPort));
|
||||
|
||||
return "connecting";
|
||||
return RPC::makeObjectValue ("connecting");
|
||||
}
|
||||
|
||||
} // ripple
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace ripple {
|
||||
Json::Value doLedgerCleaner (RPC::Context& context)
|
||||
{
|
||||
getApp().getLedgerMaster().doLedgerCleaner (context.params);
|
||||
return "Cleaner configured";
|
||||
return RPC::makeObjectValue ("Cleaner configured");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ Json::Value doSMS (RPC::Context& context)
|
||||
HTTPClient::sendSMS (
|
||||
getApp().getIOService (), context.params["text"].asString ());
|
||||
|
||||
return "sms dispatched";
|
||||
return RPC::makeObjectValue ("sms dispatched");
|
||||
}
|
||||
|
||||
} // ripple
|
||||
|
||||
@@ -25,7 +25,7 @@ Json::Value doStop (RPC::Context& context)
|
||||
auto lock = getApp().masterLock();
|
||||
getApp().signalStop ();
|
||||
|
||||
return SYSTEM_NAME " server stopping";
|
||||
return RPC::makeObjectValue (SYSTEM_NAME " server stopping");
|
||||
}
|
||||
|
||||
} // ripple
|
||||
|
||||
@@ -39,13 +39,13 @@ Json::Value doUnlAdd (RPC::Context& context)
|
||||
{
|
||||
getApp().getUNL ().nodeAddPublic (
|
||||
raNodePublic, UniqueNodeList::vsManual, strComment);
|
||||
return "adding node by public key";
|
||||
return RPC::makeObjectValue ("adding node by public key");
|
||||
}
|
||||
else
|
||||
{
|
||||
getApp().getUNL ().nodeAddDomain (
|
||||
strNode, UniqueNodeList::vsManual, strComment);
|
||||
return "adding node by domain";
|
||||
return RPC::makeObjectValue ("adding node by domain");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,12 +36,12 @@ Json::Value doUnlDelete (RPC::Context& context)
|
||||
if (raNodePublic.setNodePublic (strNode))
|
||||
{
|
||||
getApp().getUNL ().nodeRemovePublic (raNodePublic);
|
||||
return "removing node by public key";
|
||||
return RPC::makeObjectValue ("removing node by public key");
|
||||
}
|
||||
else
|
||||
{
|
||||
getApp().getUNL ().nodeRemoveDomain (strNode);
|
||||
return "removing node by domain";
|
||||
return RPC::makeObjectValue ("removing node by domain");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ Json::Value doUnlLoad (RPC::Context& context)
|
||||
return rpcError (rpcLOAD_FAILED);
|
||||
}
|
||||
|
||||
return "loading";
|
||||
return RPC::makeObjectValue ("loading");
|
||||
}
|
||||
|
||||
} // ripple
|
||||
|
||||
@@ -26,7 +26,7 @@ Json::Value doUnlNetwork (RPC::Context& context)
|
||||
auto lock = getApp().masterLock();
|
||||
getApp().getUNL ().nodeNetwork ();
|
||||
|
||||
return "fetching";
|
||||
return RPC::makeObjectValue ("fetching");
|
||||
}
|
||||
|
||||
} // ripple
|
||||
|
||||
@@ -25,7 +25,7 @@ Json::Value doUnlReset (RPC::Context& context)
|
||||
auto lock = getApp().masterLock();
|
||||
getApp().getUNL ().nodeReset ();
|
||||
|
||||
return "removing nodes";
|
||||
return RPC::makeObjectValue ("removing nodes");
|
||||
}
|
||||
|
||||
} // ripple
|
||||
|
||||
@@ -26,7 +26,7 @@ Json::Value doUnlScore (RPC::Context& context)
|
||||
auto lock = getApp().masterLock();
|
||||
getApp().getUNL ().nodeScore ();
|
||||
|
||||
return "scoring requested";
|
||||
return RPC::makeObjectValue ("scoring requested");
|
||||
}
|
||||
|
||||
} // ripple
|
||||
|
||||
@@ -60,18 +60,14 @@ Json::Value doWalletAccounts (RPC::Context& context)
|
||||
if (!ret.empty ())
|
||||
return ret;
|
||||
|
||||
ret["accounts"]
|
||||
ret[jss::accounts]
|
||||
= RPC::accounts (ledger, naMasterGenerator, context.netOps);
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Had accounts via seed as master, return them.
|
||||
Json::Value ret (Json::objectValue);
|
||||
|
||||
ret["accounts"] = jsonAccounts;
|
||||
|
||||
return ret;
|
||||
return RPC::makeObjectValue (jsonAccounts, jss::accounts);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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