| 151 | */ |
| 152 | |
| 153 | std::string CRPCTable::help(const std::string& strCommand, const JSONRPCRequest& helpreq) const |
| 154 | { |
| 155 | std::string strRet; |
| 156 | std::string category; |
| 157 | std::set<rpcfn_type> setDone; |
| 158 | std::vector<std::pair<std::string, const CRPCCommand*> > vCommands; |
| 159 | |
| 160 | for (const auto& entry : mapCommands) |
| 161 | vCommands.push_back(make_pair(entry.second->category + entry.first, entry.second)); |
| 162 | sort(vCommands.begin(), vCommands.end()); |
| 163 | |
| 164 | JSONRPCRequest jreq(helpreq); |
| 165 | jreq.fHelp = true; |
| 166 | jreq.params = UniValue(); |
| 167 | |
| 168 | for (const std::pair<std::string, const CRPCCommand*>& command : vCommands) |
| 169 | { |
| 170 | const CRPCCommand *pcmd = command.second; |
| 171 | std::string strMethod = pcmd->name; |
| 172 | if ((strCommand != "" || pcmd->category == "hidden") && strMethod != strCommand) |
| 173 | continue; |
| 174 | jreq.strMethod = strMethod; |
| 175 | try |
| 176 | { |
| 177 | rpcfn_type pfn = pcmd->actor; |
| 178 | if (setDone.insert(pfn).second) |
| 179 | (*pfn)(jreq); |
| 180 | } |
| 181 | catch (const std::exception& e) |
| 182 | { |
| 183 | // Help text is returned in an exception |
| 184 | std::string strHelp = std::string(e.what()); |
| 185 | if (strCommand == "") |
| 186 | { |
| 187 | if (strHelp.find('\n') != std::string::npos) |
| 188 | strHelp = strHelp.substr(0, strHelp.find('\n')); |
| 189 | |
| 190 | if (category != pcmd->category) |
| 191 | { |
| 192 | if (!category.empty()) |
| 193 | strRet += "\n"; |
| 194 | category = pcmd->category; |
| 195 | std::string firstLetter = category.substr(0,1); |
| 196 | boost::to_upper(firstLetter); |
| 197 | strRet += "== " + firstLetter + category.substr(1) + " ==\n"; |
| 198 | } |
| 199 | } |
| 200 | strRet += strHelp + "\n"; |
| 201 | } |
| 202 | } |
| 203 | if (strRet == "") |
| 204 | strRet = strprintf("help: unknown command: %s\n", strCommand); |
| 205 | strRet = strRet.substr(0,strRet.size()-1); |
| 206 | return strRet; |
| 207 | } |
| 208 | |
| 209 | UniValue help(const JSONRPCRequest& jsonRequest) |
| 210 | { |