diff --git a/src/ripple/app/ledger/InboundLedger.h b/src/ripple/app/ledger/InboundLedger.h index 8057accf3..c33845378 100644 --- a/src/ripple/app/ledger/InboundLedger.h +++ b/src/ripple/app/ledger/InboundLedger.h @@ -101,6 +101,7 @@ public: void filterNodes (std::vector& nodeIDs, std::vector& nodeHashes, std::set& recentNodes, int max, bool aggressive); + /** Return a Json::objectValue. */ Json::Value getJson (int); void runData (); diff --git a/src/ripple/app/misc/AmendmentTable.h b/src/ripple/app/misc/AmendmentTable.h index c2b45b938..1a6e80907 100644 --- a/src/ripple/app/misc/AmendmentTable.h +++ b/src/ripple/app/misc/AmendmentTable.h @@ -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 diff --git a/src/ripple/json/JsonPropertyStream.h b/src/ripple/json/JsonPropertyStream.h index 372a1d1f9..04377c782 100644 --- a/src/ripple/json/JsonPropertyStream.h +++ b/src/ripple/json/JsonPropertyStream.h @@ -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 - diff --git a/src/ripple/protocol/JsonFields.h b/src/ripple/protocol/JsonFields.h index d74b86c5d..546236c06 100644 --- a/src/ripple/protocol/JsonFields.h +++ b/src/ripple/protocol/JsonFields.h @@ -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 ); diff --git a/src/ripple/resource/impl/Logic.h b/src/ripple/resource/impl/Logic.h index c9900ce83..7b7cbaacf 100644 --- a/src/ripple/resource/impl/Logic.h +++ b/src/ripple/resource/impl/Logic.h @@ -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()); diff --git a/src/ripple/rpc/handlers/AccountInfo.cpp b/src/ripple/rpc/handlers/AccountInfo.cpp index cfd3b2485..b541a35c4 100644 --- a/src/ripple/rpc/handlers/AccountInfo.cpp +++ b/src/ripple/rpc/handlers/AccountInfo.cpp @@ -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; diff --git a/src/ripple/rpc/handlers/Connect.cpp b/src/ripple/rpc/handlers/Connect.cpp index 308132932..4519daad3 100644 --- a/src/ripple/rpc/handlers/Connect.cpp +++ b/src/ripple/rpc/handlers/Connect.cpp @@ -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 diff --git a/src/ripple/rpc/handlers/LedgerCleaner.cpp b/src/ripple/rpc/handlers/LedgerCleaner.cpp index 62b9bc865..a5591172b 100644 --- a/src/ripple/rpc/handlers/LedgerCleaner.cpp +++ b/src/ripple/rpc/handlers/LedgerCleaner.cpp @@ -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"); } diff --git a/src/ripple/rpc/handlers/SMS.cpp b/src/ripple/rpc/handlers/SMS.cpp index 8388899fc..07ad6d91e 100644 --- a/src/ripple/rpc/handlers/SMS.cpp +++ b/src/ripple/rpc/handlers/SMS.cpp @@ -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 diff --git a/src/ripple/rpc/handlers/Stop.cpp b/src/ripple/rpc/handlers/Stop.cpp index d59cb3455..f170fd9e6 100644 --- a/src/ripple/rpc/handlers/Stop.cpp +++ b/src/ripple/rpc/handlers/Stop.cpp @@ -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 diff --git a/src/ripple/rpc/handlers/UnlAdd.cpp b/src/ripple/rpc/handlers/UnlAdd.cpp index 29011396d..f478169a4 100644 --- a/src/ripple/rpc/handlers/UnlAdd.cpp +++ b/src/ripple/rpc/handlers/UnlAdd.cpp @@ -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"); } } diff --git a/src/ripple/rpc/handlers/UnlDelete.cpp b/src/ripple/rpc/handlers/UnlDelete.cpp index 39de12737..96df31b76 100644 --- a/src/ripple/rpc/handlers/UnlDelete.cpp +++ b/src/ripple/rpc/handlers/UnlDelete.cpp @@ -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"); } } diff --git a/src/ripple/rpc/handlers/UnlLoad.cpp b/src/ripple/rpc/handlers/UnlLoad.cpp index 2f68deabe..5fb946c4a 100644 --- a/src/ripple/rpc/handlers/UnlLoad.cpp +++ b/src/ripple/rpc/handlers/UnlLoad.cpp @@ -31,7 +31,7 @@ Json::Value doUnlLoad (RPC::Context& context) return rpcError (rpcLOAD_FAILED); } - return "loading"; + return RPC::makeObjectValue ("loading"); } } // ripple diff --git a/src/ripple/rpc/handlers/UnlNetwork.cpp b/src/ripple/rpc/handlers/UnlNetwork.cpp index 2e5291a83..0f433d495 100644 --- a/src/ripple/rpc/handlers/UnlNetwork.cpp +++ b/src/ripple/rpc/handlers/UnlNetwork.cpp @@ -26,7 +26,7 @@ Json::Value doUnlNetwork (RPC::Context& context) auto lock = getApp().masterLock(); getApp().getUNL ().nodeNetwork (); - return "fetching"; + return RPC::makeObjectValue ("fetching"); } } // ripple diff --git a/src/ripple/rpc/handlers/UnlReset.cpp b/src/ripple/rpc/handlers/UnlReset.cpp index 7d0892d1a..8cc3ecefa 100644 --- a/src/ripple/rpc/handlers/UnlReset.cpp +++ b/src/ripple/rpc/handlers/UnlReset.cpp @@ -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 diff --git a/src/ripple/rpc/handlers/UnlScore.cpp b/src/ripple/rpc/handlers/UnlScore.cpp index a32b1048b..b4f2881af 100644 --- a/src/ripple/rpc/handlers/UnlScore.cpp +++ b/src/ripple/rpc/handlers/UnlScore.cpp @@ -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 diff --git a/src/ripple/rpc/handlers/WalletAccounts.cpp b/src/ripple/rpc/handlers/WalletAccounts.cpp index 6acefcc40..06358d391 100644 --- a/src/ripple/rpc/handlers/WalletAccounts.cpp +++ b/src/ripple/rpc/handlers/WalletAccounts.cpp @@ -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); } } diff --git a/src/ripple/rpc/impl/AccountFromString.cpp b/src/ripple/rpc/impl/AccountFromString.cpp index ca86e4c7a..23ec825d0 100644 --- a/src/ripple/rpc/impl/AccountFromString.cpp +++ b/src/ripple/rpc/impl/AccountFromString.cpp @@ -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, diff --git a/src/ripple/rpc/impl/Handler.h b/src/ripple/rpc/impl/Handler.h index 1129d8e3b..9c00ed08f 100644 --- a/src/ripple/rpc/impl/Handler.h +++ b/src/ripple/rpc/impl/Handler.h @@ -46,6 +46,16 @@ struct Handler const Handler* getHandler(std::string name); +/** Return a Json::objectValue with a single entry. */ +template +Json::Value makeObjectValue ( + Value const& value, Json::StaticString const& field = jss::message) +{ + Json::Value result (Json::objectValue); + result[field] = value; + return result; +} + } // RPC } // ripple diff --git a/src/ripple/rpc/impl/LookupLedger.cpp b/src/ripple/rpc/impl/LookupLedger.cpp index 82fa9e7f5..79df3b5d1 100644 --- a/src/ripple/rpc/impl/LookupLedger.cpp +++ b/src/ripple/rpc/impl/LookupLedger.cpp @@ -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, diff --git a/src/ripple/rpc/impl/RPCHandler.cpp b/src/ripple/rpc/impl/RPCHandler.cpp index f42b66087..35f7273fb 100644 --- a/src/ripple/rpc/impl/RPCHandler.cpp +++ b/src/ripple/rpc/impl/RPCHandler.cpp @@ -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) { diff --git a/src/ripple/rpc/impl/TransactionSign.h b/src/ripple/rpc/impl/TransactionSign.h index 218ef1c84..732a7bb30 100644 --- a/src/ripple/rpc/impl/TransactionSign.h +++ b/src/ripple/rpc/impl/TransactionSign.h @@ -100,6 +100,8 @@ public: } // namespace RPCDetail + +/** Returns a Json::objectValue. */ Json::Value transactionSign ( Json::Value params, bool bSubmit,