@@ -442,6 +442,7 @@ std::string RPCResults::ToDescriptionString() const
442442{
443443 std::string result;
444444 for (const auto & r : m_results) {
445+ if (r.m_type == RPCResult::Type::ANY) continue ; // for testing only
445446 if (r.m_cond .empty ()) {
446447 result += " \n Result:\n " ;
447448 } else {
@@ -459,7 +460,7 @@ std::string RPCExamples::ToDescriptionString() const
459460 return m_examples.empty () ? m_examples : " \n Examples:\n " + m_examples;
460461}
461462
462- UniValue RPCHelpMan::HandleRequest (const JSONRPCRequest& request)
463+ UniValue RPCHelpMan::HandleRequest (const JSONRPCRequest& request) const
463464{
464465 if (request.mode == JSONRPCRequest::GET_ARGS) {
465466 return GetArgMap ();
@@ -471,7 +472,9 @@ UniValue RPCHelpMan::HandleRequest(const JSONRPCRequest& request)
471472 if (request.mode == JSONRPCRequest::GET_HELP || !IsValidNumArgs (request.params .size ())) {
472473 throw std::runtime_error (ToString ());
473474 }
474- return m_fun (*this , request);
475+ const UniValue ret = m_fun (*this , request);
476+ CHECK_NONFATAL (std::any_of (m_results.m_results .begin (), m_results.m_results .end (), [ret](const RPCResult& res) { return res.MatchesType (ret); }));
477+ return ret;
475478}
476479
477480bool RPCHelpMan::IsValidNumArgs (size_t num_args) const
@@ -677,6 +680,9 @@ void RPCResult::ToSections(Sections& sections, const OuterType outer_type, const
677680 sections.PushSection ({indent + " ..." + maybe_separator, m_description});
678681 return ;
679682 }
683+ case Type::ANY: {
684+ CHECK_NONFATAL (false ); // Only for testing
685+ }
680686 case Type::NONE: {
681687 sections.PushSection ({indent + " null" + maybe_separator, Description (" json null" )});
682688 return ;
@@ -742,6 +748,42 @@ void RPCResult::ToSections(Sections& sections, const OuterType outer_type, const
742748 CHECK_NONFATAL (false );
743749}
744750
751+ bool RPCResult::MatchesType (const UniValue& result) const
752+ {
753+ switch (m_type) {
754+ case Type::ELISION: {
755+ return false ;
756+ }
757+ case Type::ANY: {
758+ return true ;
759+ }
760+ case Type::NONE: {
761+ return UniValue::VNULL == result.getType ();
762+ }
763+ case Type::STR:
764+ case Type::STR_HEX: {
765+ return UniValue::VSTR == result.getType ();
766+ }
767+ case Type::NUM:
768+ case Type::STR_AMOUNT:
769+ case Type::NUM_TIME: {
770+ return UniValue::VNUM == result.getType ();
771+ }
772+ case Type::BOOL: {
773+ return UniValue::VBOOL == result.getType ();
774+ }
775+ case Type::ARR_FIXED:
776+ case Type::ARR: {
777+ return UniValue::VARR == result.getType ();
778+ }
779+ case Type::OBJ_DYN:
780+ case Type::OBJ: {
781+ return UniValue::VOBJ == result.getType ();
782+ }
783+ } // no default case, so the compiler can warn about missing cases
784+ CHECK_NONFATAL (false );
785+ }
786+
745787std::string RPCArg::ToStringObj (const bool oneline) const
746788{
747789 std::string res;
0 commit comments