Skip to content

Commit a0c7290

Browse files
fanquakeknst
authored andcommitted
Merge 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
1 parent 886419c commit a0c7290

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

src/rpc/blockchain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,15 +473,15 @@ static RPCHelpMan getblockfrompeer()
473473
{
474474
return RPCHelpMan{
475475
"getblockfrompeer",
476-
"\nAttempt to fetch block from a given peer.\n"
476+
"Attempt to fetch block from a given peer.\n"
477477
"\nWe must have the header for this block, e.g. using submitheader.\n"
478478
"Subsequent calls for the same block and a new peer will cause the response from the previous peer to be ignored.\n"
479479
"\nReturns an empty JSON object if the request was successfully scheduled.",
480480
{
481481
{"block_hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash to try to fetch"},
482482
{"peer_id", RPCArg::Type::NUM, RPCArg::Optional::NO, "The peer to fetch it from (see getpeerinfo for peer IDs)"},
483483
},
484-
RPCResult{RPCResult::Type::OBJ_EMPTY, "", /*optional=*/ false, "", {}},
484+
RPCResult{RPCResult::Type::OBJ, "", /*optional=*/false, "", {}},
485485
RPCExamples{
486486
HelpExampleCli("getblockfrompeer", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\" 0")
487487
+ HelpExampleRpc("getblockfrompeer", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\" 0")

src/rpc/util.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -791,16 +791,15 @@ void RPCResult::ToSections(Sections& sections, const OuterType outer_type, const
791791
return;
792792
}
793793
case Type::OBJ_DYN:
794-
case Type::OBJ_EMPTY: {
795-
sections.PushSection({indent + maybe_key + "{}", Description("empty JSON object")});
796-
return;
797-
}
798794
case Type::OBJ: {
795+
if (m_inner.empty()) {
796+
sections.PushSection({indent + maybe_key + "{}", Description("empty JSON object")});
797+
return;
798+
}
799799
sections.PushSection({indent + maybe_key + "{", Description("json object")});
800800
for (const auto& i : m_inner) {
801801
i.ToSections(sections, OuterType::OBJ, current_indent + 2);
802802
}
803-
CHECK_NONFATAL(!m_inner.empty());
804803
if (m_type == Type::OBJ_DYN && m_inner.back().m_type != Type::ELISION) {
805804
// If the dictionary keys are dynamic, use three dots for continuation
806805
sections.PushSection({indent_next + "...", ""});
@@ -844,14 +843,24 @@ bool RPCResult::MatchesType(const UniValue& result) const
844843
return UniValue::VARR == result.getType();
845844
}
846845
case Type::OBJ_DYN:
847-
case Type::OBJ_EMPTY:
848846
case Type::OBJ: {
849847
return UniValue::VOBJ == result.getType();
850848
}
851849
} // no default case, so the compiler can warn about missing cases
852850
NONFATAL_UNREACHABLE();
853851
}
854852

853+
void RPCResult::CheckInnerDoc() const
854+
{
855+
if (m_type == Type::OBJ) {
856+
// May or may not be empty
857+
return;
858+
}
859+
// Everything else must either be empty or not
860+
const bool inner_needed{m_type == Type::ARR || m_type == Type::ARR_FIXED || m_type == Type::OBJ_DYN};
861+
CHECK_NONFATAL(inner_needed != m_inner.empty());
862+
}
863+
855864
std::string RPCArg::ToStringObj(const bool oneline) const
856865
{
857866
std::string res;

src/rpc/util.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ struct RPCResult {
250250
STR_AMOUNT, //!< Special string to represent a floating point amount
251251
STR_HEX, //!< Special string with only hex chars
252252
OBJ_DYN, //!< Special dictionary with keys that are not literals
253-
OBJ_EMPTY, //!< Special type to allow empty OBJ
254253
ARR_FIXED, //!< Special array that has a fixed number of entries
255254
NUM_TIME, //!< Special numeric to denote unix epoch time
256255
ELISION, //!< Special type to denote elision (...)
@@ -278,8 +277,7 @@ struct RPCResult {
278277
m_cond{std::move(cond)}
279278
{
280279
CHECK_NONFATAL(!m_cond.empty());
281-
const bool inner_needed{type == Type::ARR || type == Type::ARR_FIXED || type == Type::OBJ || type == Type::OBJ_DYN};
282-
CHECK_NONFATAL(inner_needed != inner.empty());
280+
CheckInnerDoc();
283281
}
284282

285283
RPCResult(
@@ -303,8 +301,7 @@ struct RPCResult {
303301
m_description{std::move(description)},
304302
m_cond{}
305303
{
306-
const bool inner_needed{type == Type::ARR || type == Type::ARR_FIXED || type == Type::OBJ || type == Type::OBJ_DYN};
307-
CHECK_NONFATAL(inner_needed != inner.empty());
304+
CheckInnerDoc();
308305
}
309306

310307
RPCResult(
@@ -322,6 +319,9 @@ struct RPCResult {
322319
std::string ToDescriptionString() const;
323320
/** Check whether the result JSON type matches. */
324321
bool MatchesType(const UniValue& result) const;
322+
323+
private:
324+
void CheckInnerDoc() const;
325325
};
326326

327327
struct RPCResults {

0 commit comments

Comments
 (0)