Skip to content

Commit fa09cb6

Browse files
author
MarcoFalke
committed
refactor: Introduce is_top_level_arg
1 parent fab92a5 commit fa09cb6

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/rpc/util.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ struct Sections {
388388
const auto indent = std::string(current_indent, ' ');
389389
const auto indent_next = std::string(current_indent + 2, ' ');
390390
const bool push_name{outer_type == OuterType::OBJ}; // Dictionary keys must have a name
391+
const bool is_top_level_arg{outer_type == OuterType::NONE}; // True on the first recursion
391392

392393
switch (arg.m_type) {
393394
case RPCArg::Type::STR_HEX:
@@ -396,7 +397,7 @@ struct Sections {
396397
case RPCArg::Type::AMOUNT:
397398
case RPCArg::Type::RANGE:
398399
case RPCArg::Type::BOOL: {
399-
if (outer_type == OuterType::NONE) return; // Nothing more to do for non-recursive types on first recursion
400+
if (is_top_level_arg) return; // Nothing more to do for non-recursive types on first recursion
400401
auto left = indent;
401402
if (arg.m_opts.type_str.size() != 0 && push_name) {
402403
left += "\"" + arg.GetName() + "\": " + arg.m_opts.type_str.at(0);
@@ -409,28 +410,28 @@ struct Sections {
409410
}
410411
case RPCArg::Type::OBJ:
411412
case RPCArg::Type::OBJ_USER_KEYS: {
412-
const auto right = outer_type == OuterType::NONE ? "" : arg.ToDescriptionString();
413+
const auto right = is_top_level_arg ? "" : arg.ToDescriptionString();
413414
PushSection({indent + (push_name ? "\"" + arg.GetName() + "\": " : "") + "{", right});
414415
for (const auto& arg_inner : arg.m_inner) {
415416
Push(arg_inner, current_indent + 2, OuterType::OBJ);
416417
}
417418
if (arg.m_type != RPCArg::Type::OBJ) {
418419
PushSection({indent_next + "...", ""});
419420
}
420-
PushSection({indent + "}" + (outer_type != OuterType::NONE ? "," : ""), ""});
421+
PushSection({indent + "}" + (is_top_level_arg ? "" : ","), ""});
421422
break;
422423
}
423424
case RPCArg::Type::ARR: {
424425
auto left = indent;
425426
left += push_name ? "\"" + arg.GetName() + "\": " : "";
426427
left += "[";
427-
const auto right = outer_type == OuterType::NONE ? "" : arg.ToDescriptionString();
428+
const auto right = is_top_level_arg ? "" : arg.ToDescriptionString();
428429
PushSection({left, right});
429430
for (const auto& arg_inner : arg.m_inner) {
430431
Push(arg_inner, current_indent + 2, OuterType::ARR);
431432
}
432433
PushSection({indent_next + "...", ""});
433-
PushSection({indent + "]" + (outer_type != OuterType::NONE ? "," : ""), ""});
434+
PushSection({indent + "]" + (is_top_level_arg ? "" : ","), ""});
434435
break;
435436
}
436437
} // no default case, so the compiler can warn about missing cases

0 commit comments

Comments
 (0)