| 162 | */ |
| 163 | |
| 164 | string CRPCTable::help(string strCommand) const |
| 165 | { |
| 166 | string strRet; |
| 167 | string category; |
| 168 | set<rpcfn_type> setDone; |
| 169 | vector<pair<string, const CRPCCommand*> > vCommands; |
| 170 | |
| 171 | for (map<string, const CRPCCommand*>::const_iterator mi = mapCommands.begin(); mi != mapCommands.end(); ++mi) |
| 172 | vCommands.push_back(make_pair(mi->second->category + mi->first, mi->second)); |
| 173 | sort(vCommands.begin(), vCommands.end()); |
| 174 | |
| 175 | BOOST_FOREACH(const PAIRTYPE(string, const CRPCCommand*)& command, vCommands) |
| 176 | { |
| 177 | const CRPCCommand *pcmd = command.second; |
| 178 | string strMethod = pcmd->name; |
| 179 | // We already filter duplicates, but these deprecated screw up the sort order |
| 180 | if (strMethod.find("label") != string::npos) |
| 181 | continue; |
| 182 | if ((strCommand != "" || pcmd->category == "hidden") && strMethod != strCommand) |
| 183 | continue; |
| 184 | try |
| 185 | { |
| 186 | UniValue params; |
| 187 | rpcfn_type pfn = pcmd->actor; |
| 188 | if (setDone.insert(pfn).second) |
| 189 | (*pfn)(params, true); |
| 190 | } |
| 191 | catch (const std::exception& e) |
| 192 | { |
| 193 | // Help text is returned in an exception |
| 194 | string strHelp = string(e.what()); |
| 195 | if (strCommand == "") |
| 196 | { |
| 197 | if (strHelp.find('\n') != string::npos) |
| 198 | strHelp = strHelp.substr(0, strHelp.find('\n')); |
| 199 | |
| 200 | if (category != pcmd->category) |
| 201 | { |
| 202 | if (!category.empty()) |
| 203 | strRet += "\n"; |
| 204 | category = pcmd->category; |
| 205 | string firstLetter = category.substr(0,1); |
| 206 | boost::to_upper(firstLetter); |
| 207 | strRet += "== " + firstLetter + category.substr(1) + " ==\n"; |
| 208 | } |
| 209 | } |
| 210 | strRet += strHelp + "\n"; |
| 211 | } |
| 212 | } |
| 213 | if (strRet == "") |
| 214 | strRet = strprintf("help: unknown command: %s\n", strCommand); |
| 215 | strRet = strRet.substr(0,strRet.size()-1); |
| 216 | return strRet; |
| 217 | } |
| 218 | |
| 219 | UniValue help(const UniValue& params, bool fHelp) |
| 220 | { |