MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / ToString

Method ToString

src/rpc/util.cpp:770–831  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

768}
769
770std::string RPCMethod::ToString() const
771{
772 std::string ret;
773
774 // Oneline summary
775 ret += m_name;
776 bool was_optional{false};
777 for (const auto& arg : m_args) {
778 if (arg.m_opts.hidden) break; // Any arg that follows is also hidden
779 const bool optional = arg.IsOptional();
780 ret += " ";
781 if (optional) {
782 if (!was_optional) ret += "( ";
783 was_optional = true;
784 } else {
785 if (was_optional) ret += ") ";
786 was_optional = false;
787 }
788 ret += arg.ToString(/*oneline=*/true);
789 }
790 if (was_optional) ret += " )";
791
792 // Description
793 CHECK_NONFATAL(!m_description.starts_with('\n')); // Historically \n was required, but reject it for new code.
794 ret += "\n\n" + TrimString(m_description) + "\n";
795
796 // Arguments
797 Sections sections;
798 Sections named_only_sections;
799 for (size_t i{0}; i < m_args.size(); ++i) {
800 const auto& arg = m_args.at(i);
801 if (arg.m_opts.hidden) break; // Any arg that follows is also hidden
802
803 // Push named argument name and description
804 sections.m_sections.emplace_back(util::ToString(i + 1) + ". " + arg.GetFirstName(), arg.ToDescriptionString(/*is_named_arg=*/true));
805 sections.m_max_pad = std::max(sections.m_max_pad, sections.m_sections.back().m_left.size());
806
807 // Recursively push nested args
808 sections.Push(arg);
809
810 // Push named-only argument sections
811 if (arg.m_type == RPCArg::Type::OBJ_NAMED_PARAMS) {
812 for (const auto& arg_inner : arg.m_inner) {
813 named_only_sections.PushSection({arg_inner.GetFirstName(), arg_inner.ToDescriptionString(/*is_named_arg=*/true)});
814 named_only_sections.Push(arg_inner);
815 }
816 }
817 }
818
819 if (!sections.m_sections.empty()) ret += "\nArguments:\n";
820 ret += sections.ToString();
821 if (!named_only_sections.m_sections.empty()) ret += "\nNamed Arguments:\n";
822 ret += named_only_sections.ToString();
823
824 // Result
825 ret += m_results.ToDescriptionString();
826
827 // Examples

Callers 15

operator()Method · 0.45
dataMethod · 0.45
focusTransactionMethod · 0.45
updateWalletMethod · 0.45
toHTMLMethod · 0.45
getTxHashMethod · 0.45
FindTxFunction · 0.45
CustomAppendMethod · 0.45
RevertBlockMethod · 0.45
ProcessBlockMethod · 0.45
RewindMethod · 0.45

Calls 15

TrimStringFunction · 0.85
JoinFunction · 0.85
IsOptionalMethod · 0.80
GetFirstNameMethod · 0.80
ToDescriptionStringMethod · 0.80
PushSectionMethod · 0.80
GetBoolArgMethod · 0.80
ToStringObjMethod · 0.80
ToStringFunction · 0.50
sizeMethod · 0.45
atMethod · 0.45
emplace_backMethod · 0.45

Tested by 1

FindTxFunction · 0.36