Skip to content

Commit e3699b7

Browse files
committed
Merge bitcoin/bitcoin#24155: doc: Fix rpc docs
fac8caa doc: Fix rpc docs (MarcoFalke) Pull request description: Broken in commit 39d9bbe. The fix removes the "type" `OBJ_EMPTY` added in commit 8d1a3e6, which isn't really a separate type and instead runs a check on `OBJ` whether it is empty or not. ACKs for top commit: Sjors: tACK fac8caa Tree-SHA512: dd978fe526a45095800249204afd26a239078e83b15124a5756ac078c473a677a3084b8f54e34d6dd5580abef7275c875a14bc9eb20d8feab066dfb0f0932967
2 parents 2935bd9 + fac8caa commit e3699b7

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

src/rpc/blockchain.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -790,15 +790,15 @@ static RPCHelpMan getblockfrompeer()
790790
{
791791
return RPCHelpMan{
792792
"getblockfrompeer",
793-
"\nAttempt to fetch block from a given peer.\n"
793+
"Attempt to fetch block from a given peer.\n"
794794
"\nWe must have the header for this block, e.g. using submitheader.\n"
795795
"Subsequent calls for the same block and a new peer will cause the response from the previous peer to be ignored.\n"
796796
"\nReturns an empty JSON object if the request was successfully scheduled.",
797797
{
798798
{"block_hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash to try to fetch"},
799799
{"peer_id", RPCArg::Type::NUM, RPCArg::Optional::NO, "The peer to fetch it from (see getpeerinfo for peer IDs)"},
800800
},
801-
RPCResult{RPCResult::Type::OBJ_EMPTY, "", /*optional=*/ false, "", {}},
801+
RPCResult{RPCResult::Type::OBJ, "", /*optional=*/false, "", {}},
802802
RPCExamples{
803803
HelpExampleCli("getblockfrompeer", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\" 0")
804804
+ HelpExampleRpc("getblockfrompeer", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\" 0")

src/rpc/util.cpp

+15-6
Original file line numberDiff line numberDiff line change
@@ -830,16 +830,15 @@ void RPCResult::ToSections(Sections& sections, const OuterType outer_type, const
830830
return;
831831
}
832832
case Type::OBJ_DYN:
833-
case Type::OBJ_EMPTY: {
834-
sections.PushSection({indent + maybe_key + "{}", Description("empty JSON object")});
835-
return;
836-
}
837833
case Type::OBJ: {
834+
if (m_inner.empty()) {
835+
sections.PushSection({indent + maybe_key + "{}", Description("empty JSON object")});
836+
return;
837+
}
838838
sections.PushSection({indent + maybe_key + "{", Description("json object")});
839839
for (const auto& i : m_inner) {
840840
i.ToSections(sections, OuterType::OBJ, current_indent + 2);
841841
}
842-
CHECK_NONFATAL(!m_inner.empty());
843842
if (m_type == Type::OBJ_DYN && m_inner.back().m_type != Type::ELISION) {
844843
// If the dictionary keys are dynamic, use three dots for continuation
845844
sections.PushSection({indent_next + "...", ""});
@@ -883,14 +882,24 @@ bool RPCResult::MatchesType(const UniValue& result) const
883882
return UniValue::VARR == result.getType();
884883
}
885884
case Type::OBJ_DYN:
886-
case Type::OBJ_EMPTY:
887885
case Type::OBJ: {
888886
return UniValue::VOBJ == result.getType();
889887
}
890888
} // no default case, so the compiler can warn about missing cases
891889
CHECK_NONFATAL(false);
892890
}
893891

892+
void RPCResult::CheckInnerDoc() const
893+
{
894+
if (m_type == Type::OBJ) {
895+
// May or may not be empty
896+
return;
897+
}
898+
// Everything else must either be empty or not
899+
const bool inner_needed{m_type == Type::ARR || m_type == Type::ARR_FIXED || m_type == Type::OBJ_DYN};
900+
CHECK_NONFATAL(inner_needed != m_inner.empty());
901+
}
902+
894903
std::string RPCArg::ToStringObj(const bool oneline) const
895904
{
896905
std::string res;

src/rpc/util.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ struct RPCResult {
240240
STR_AMOUNT, //!< Special string to represent a floating point amount
241241
STR_HEX, //!< Special string with only hex chars
242242
OBJ_DYN, //!< Special dictionary with keys that are not literals
243-
OBJ_EMPTY, //!< Special type to allow empty OBJ
244243
ARR_FIXED, //!< Special array that has a fixed number of entries
245244
NUM_TIME, //!< Special numeric to denote unix epoch time
246245
ELISION, //!< Special type to denote elision (...)
@@ -268,8 +267,7 @@ struct RPCResult {
268267
m_cond{std::move(cond)}
269268
{
270269
CHECK_NONFATAL(!m_cond.empty());
271-
const bool inner_needed{type == Type::ARR || type == Type::ARR_FIXED || type == Type::OBJ || type == Type::OBJ_DYN};
272-
CHECK_NONFATAL(inner_needed != inner.empty());
270+
CheckInnerDoc();
273271
}
274272

275273
RPCResult(
@@ -293,8 +291,7 @@ struct RPCResult {
293291
m_description{std::move(description)},
294292
m_cond{}
295293
{
296-
const bool inner_needed{type == Type::ARR || type == Type::ARR_FIXED || type == Type::OBJ || type == Type::OBJ_DYN};
297-
CHECK_NONFATAL(inner_needed != inner.empty());
294+
CheckInnerDoc();
298295
}
299296

300297
RPCResult(
@@ -312,6 +309,9 @@ struct RPCResult {
312309
std::string ToDescriptionString() const;
313310
/** Check whether the result JSON type matches. */
314311
bool MatchesType(const UniValue& result) const;
312+
313+
private:
314+
void CheckInnerDoc() const;
315315
};
316316

317317
struct RPCResults {

0 commit comments

Comments
 (0)