Skip to content

Commit fa26eb5

Browse files
author
MarcoFalke
committed
rpc: RPCHelpMan: Always push_name when outer type is an object
1 parent fa652b2 commit fa26eb5

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/rpc/util.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ struct Sections {
208208
{
209209
const auto indent = std::string(current_indent, ' ');
210210
const auto indent_next = std::string(current_indent + 2, ' ');
211+
const bool push_name{outer_type == OuterType::OBJ}; // Dictionary keys must have a name
212+
211213
switch (arg.m_type) {
212214
case RPCArg::Type::STR_HEX:
213215
case RPCArg::Type::STR:
@@ -217,10 +219,10 @@ struct Sections {
217219
case RPCArg::Type::BOOL: {
218220
if (outer_type == OuterType::NAMED_ARG) return; // Nothing more to do for non-recursive types on first recursion
219221
auto left = indent;
220-
if (arg.m_type_str.size() != 0 && outer_type == OuterType::OBJ) {
222+
if (arg.m_type_str.size() != 0 && push_name) {
221223
left += "\"" + arg.m_name + "\": " + arg.m_type_str.at(0);
222224
} else {
223-
left += outer_type == OuterType::OBJ ? arg.ToStringObj(/* oneline */ false) : arg.ToString(/* oneline */ false);
225+
left += push_name ? arg.ToStringObj(/* oneline */ false) : arg.ToString(/* oneline */ false);
224226
}
225227
left += ",";
226228
PushSection({left, arg.ToDescriptionString()});
@@ -229,7 +231,7 @@ struct Sections {
229231
case RPCArg::Type::OBJ:
230232
case RPCArg::Type::OBJ_USER_KEYS: {
231233
const auto right = outer_type == OuterType::NAMED_ARG ? "" : arg.ToDescriptionString();
232-
PushSection({indent + "{", right});
234+
PushSection({indent + (push_name ? "\"" + arg.m_name + "\": " : "") + "{", right});
233235
for (const auto& arg_inner : arg.m_inner) {
234236
Push(arg_inner, current_indent + 2, OuterType::OBJ);
235237
}
@@ -241,7 +243,7 @@ struct Sections {
241243
}
242244
case RPCArg::Type::ARR: {
243245
auto left = indent;
244-
left += outer_type == OuterType::OBJ ? "\"" + arg.m_name + "\": " : "";
246+
left += push_name ? "\"" + arg.m_name + "\": " : "";
245247
left += "[";
246248
const auto right = outer_type == OuterType::NAMED_ARG ? "" : arg.ToDescriptionString();
247249
PushSection({left, right});

0 commit comments

Comments
 (0)