| 77 | } |
| 78 | |
| 79 | std::string CRPCTable::help(const std::string& strCommand, const JSONRPCRequest& helpreq) const |
| 80 | { |
| 81 | std::string strRet; |
| 82 | std::string category; |
| 83 | std::set<intptr_t> setDone; |
| 84 | std::vector<std::pair<std::string, const CRPCCommand*> > vCommands; |
| 85 | |
| 86 | for (const auto& entry : mapCommands) |
| 87 | vCommands.push_back(make_pair(entry.second.front()->category + entry.first, entry.second.front())); |
| 88 | sort(vCommands.begin(), vCommands.end()); |
| 89 | |
| 90 | JSONRPCRequest jreq = helpreq; |
| 91 | jreq.mode = JSONRPCRequest::GET_HELP; |
| 92 | jreq.params = UniValue(); |
| 93 | |
| 94 | for (const std::pair<std::string, const CRPCCommand*>& command : vCommands) |
| 95 | { |
| 96 | const CRPCCommand *pcmd = command.second; |
| 97 | std::string strMethod = pcmd->name; |
| 98 | if ((strCommand != "" || pcmd->category == "hidden") && strMethod != strCommand) |
| 99 | continue; |
| 100 | jreq.strMethod = strMethod; |
| 101 | try |
| 102 | { |
| 103 | UniValue unused_result; |
| 104 | if (setDone.insert(pcmd->unique_id).second) |
| 105 | pcmd->actor(jreq, unused_result, true /* last_handler */); |
| 106 | } |
| 107 | catch (const std::exception& e) |
| 108 | { |
| 109 | // Help text is returned in an exception |
| 110 | std::string strHelp = std::string(e.what()); |
| 111 | if (strCommand == "") |
| 112 | { |
| 113 | if (strHelp.find('\n') != std::string::npos) |
| 114 | strHelp = strHelp.substr(0, strHelp.find('\n')); |
| 115 | |
| 116 | if (category != pcmd->category) |
| 117 | { |
| 118 | if (!category.empty()) |
| 119 | strRet += "\n"; |
| 120 | category = pcmd->category; |
| 121 | strRet += "== " + Capitalize(category) + " ==\n"; |
| 122 | } |
| 123 | } |
| 124 | strRet += strHelp + "\n"; |
| 125 | } |
| 126 | } |
| 127 | if (strRet == "") |
| 128 | strRet = strprintf("help: unknown command: %s\n", strCommand); |
| 129 | strRet = strRet.substr(0,strRet.size()-1); |
| 130 | return strRet; |
| 131 | } |
| 132 | |
| 133 | static RPCHelpMan help() |
| 134 | { |