fix: Compatible feature response (#1539)

Fixes #1538
This commit is contained in:
Alex Kremer
2024-07-12 15:03:19 +01:00
committed by GitHub
parent 46a616cdad
commit 4f6f717bfb
3 changed files with 29 additions and 21 deletions

View File

@@ -99,7 +99,10 @@ FeatureHandler::process(FeatureHandler::Input input, Context const& ctx) const
); );
return Output{ 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,14 +127,20 @@ tag_invoke(boost::json::value_from_tag, boost::json::value& jv, FeatureHandler::
{ {
using boost::json::value_from; using boost::json::value_from;
if (output.inlineResult) {
jv = value_from(output.features);
} else {
jv = { jv = {
{JS(features), value_from(output.features)}, {JS(features), value_from(output.features)},
{JS(ledger_hash), output.ledgerHash},
{JS(ledger_index), output.ledgerIndex},
{JS(validated), output.validated},
}; };
} }
auto& obj = jv.as_object();
obj[JS(ledger_hash)] = output.ledgerHash;
obj[JS(ledger_index)] = output.ledgerIndex;
obj[JS(validated)] = output.validated;
}
void void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, FeatureHandler::Output::Feature const& feature) tag_invoke(boost::json::value_from_tag, boost::json::value& jv, FeatureHandler::Output::Feature const& feature)
{ {

View File

@@ -71,6 +71,9 @@ public:
std::string ledgerHash; std::string ledgerHash;
uint32_t ledgerIndex{}; 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 // validated should be sent via framework
bool validated = true; bool validated = true;
}; };

View File

@@ -257,13 +257,11 @@ TEST_F(RPCFeatureHandlerTest, SuccessPathViaNameWithSingleSupportedAndEnabledRes
auto const expectedOutput = fmt::format( auto const expectedOutput = fmt::format(
R"({{ R"({{
"features": {{
"2E2FB9CF8A44EB80F4694D38AADAE9B8B7ADAFD2F092E10068E61C98C4F092B0": "2E2FB9CF8A44EB80F4694D38AADAE9B8B7ADAFD2F092E10068E61C98C4F092B0":
{{ {{
"name": "fixUniversalNumber", "name": "fixUniversalNumber",
"enabled": true, "enabled": true,
"supported": true "supported": true
}}
}}, }},
"ledger_hash": "{}", "ledger_hash": "{}",
"ledger_index": {}, "ledger_index": {},
@@ -311,13 +309,11 @@ TEST_F(RPCFeatureHandlerTest, SuccessPathViaHashWithSingleResult)
auto const expectedOutput = fmt::format( auto const expectedOutput = fmt::format(
R"({{ R"({{
"features": {{
"2E2FB9CF8A44EB80F4694D38AADAE9B8B7ADAFD2F092E10068E61C98C4F092B0": "2E2FB9CF8A44EB80F4694D38AADAE9B8B7ADAFD2F092E10068E61C98C4F092B0":
{{ {{
"name": "fixUniversalNumber", "name": "fixUniversalNumber",
"enabled": true, "enabled": true,
"supported": true "supported": true
}}
}}, }},
"ledger_hash": "{}", "ledger_hash": "{}",
"ledger_index": {}, "ledger_index": {},