diff --git a/src/rpc/handlers/Feature.cpp b/src/rpc/handlers/Feature.cpp index 5963765c..72a47910 100644 --- a/src/rpc/handlers/Feature.cpp +++ b/src/rpc/handlers/Feature.cpp @@ -99,7 +99,10 @@ FeatureHandler::process(FeatureHandler::Input input, Context const& ctx) const ); return Output{ - .features = std::move(features), .ledgerHash = ripple::strHex(lgrInfo.hash), .ledgerIndex = lgrInfo.seq + .features = std::move(features), + .ledgerHash = ripple::strHex(lgrInfo.hash), + .ledgerIndex = lgrInfo.seq, + .inlineResult = input.feature.has_value() }; } @@ -124,12 +127,18 @@ tag_invoke(boost::json::value_from_tag, boost::json::value& jv, FeatureHandler:: { using boost::json::value_from; - jv = { - {JS(features), value_from(output.features)}, - {JS(ledger_hash), output.ledgerHash}, - {JS(ledger_index), output.ledgerIndex}, - {JS(validated), output.validated}, - }; + if (output.inlineResult) { + jv = value_from(output.features); + } else { + jv = { + {JS(features), value_from(output.features)}, + }; + } + + auto& obj = jv.as_object(); + obj[JS(ledger_hash)] = output.ledgerHash; + obj[JS(ledger_index)] = output.ledgerIndex; + obj[JS(validated)] = output.validated; } void diff --git a/src/rpc/handlers/Feature.hpp b/src/rpc/handlers/Feature.hpp index 5309f96e..0e12c960 100644 --- a/src/rpc/handlers/Feature.hpp +++ b/src/rpc/handlers/Feature.hpp @@ -71,6 +71,9 @@ public: std::string ledgerHash; uint32_t ledgerIndex{}; + // when set to true, output will be inlined in `result` instead of wrapping as `features` inside of `result`. + bool inlineResult = false; + // validated should be sent via framework bool validated = true; }; diff --git a/tests/unit/rpc/handlers/FeatureTests.cpp b/tests/unit/rpc/handlers/FeatureTests.cpp index 0f6229a5..2ef97e10 100644 --- a/tests/unit/rpc/handlers/FeatureTests.cpp +++ b/tests/unit/rpc/handlers/FeatureTests.cpp @@ -257,13 +257,11 @@ TEST_F(RPCFeatureHandlerTest, SuccessPathViaNameWithSingleSupportedAndEnabledRes auto const expectedOutput = fmt::format( R"({{ - "features": {{ - "2E2FB9CF8A44EB80F4694D38AADAE9B8B7ADAFD2F092E10068E61C98C4F092B0": - {{ - "name": "fixUniversalNumber", - "enabled": true, - "supported": true - }} + "2E2FB9CF8A44EB80F4694D38AADAE9B8B7ADAFD2F092E10068E61C98C4F092B0": + {{ + "name": "fixUniversalNumber", + "enabled": true, + "supported": true }}, "ledger_hash": "{}", "ledger_index": {}, @@ -311,13 +309,11 @@ TEST_F(RPCFeatureHandlerTest, SuccessPathViaHashWithSingleResult) auto const expectedOutput = fmt::format( R"({{ - "features": {{ - "2E2FB9CF8A44EB80F4694D38AADAE9B8B7ADAFD2F092E10068E61C98C4F092B0": - {{ - "name": "fixUniversalNumber", - "enabled": true, - "supported": true - }} + "2E2FB9CF8A44EB80F4694D38AADAE9B8B7ADAFD2F092E10068E61C98C4F092B0": + {{ + "name": "fixUniversalNumber", + "enabled": true, + "supported": true }}, "ledger_hash": "{}", "ledger_index": {},