| 432 | } |
| 433 | |
| 434 | json_spirit::Value CRPCTable::execute(const string& strMethod, |
| 435 | const json_spirit::Array& params) const { |
| 436 | // Find method |
| 437 | const CRPCCommand* pcmd = tableRPC[strMethod]; |
| 438 | if (!pcmd) |
| 439 | throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found"); |
| 440 | |
| 441 | if (pcmd->reqWallet && !pWalletMain) |
| 442 | throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (disabled)"); |
| 443 | |
| 444 | // Observe safe mode |
| 445 | if (!SysCfg().GetBoolArg("-disablesafemode", false) && !pcmd->okSafeMode) |
| 446 | throw JSONRPCError(RPC_FORBIDDEN_BY_SAFE_MODE, "Banned RPC method"); |
| 447 | |
| 448 | auto whitelist = SysCfg().GetMultiArgs("-rpcwhitelistcmd"); |
| 449 | if (!whitelist.empty()) { |
| 450 | // check whilelist |
| 451 | bool found = false; |
| 452 | for (auto whiteItem : whitelist) { |
| 453 | if (whiteItem == strMethod) { |
| 454 | found = true; |
| 455 | break; |
| 456 | } |
| 457 | } |
| 458 | if (!found) |
| 459 | throw JSONRPCError(RPC_FORBIDDEN_BY_SAFE_MODE, strprintf("Banned RPC method=%s by whitelist", strMethod)); |
| 460 | } else { |
| 461 | // check blacklist |
| 462 | auto blacklist = SysCfg().GetMultiArgs("-rpcblacklistcmd"); |
| 463 | for (auto blackItem : blacklist) { |
| 464 | if (blackItem == strMethod) |
| 465 | throw JSONRPCError(RPC_FORBIDDEN_BY_SAFE_MODE, strprintf("Banned RPC method=%s by blacklist", strMethod)); |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | try { |
| 470 | // Execute |
| 471 | Value result; |
| 472 | { |
| 473 | if (pcmd->threadSafe) |
| 474 | result = pcmd->actor(params, false); |
| 475 | else if (!pWalletMain) { |
| 476 | LOCK(cs_main); |
| 477 | result = pcmd->actor(params, false); |
| 478 | } else { |
| 479 | LOCK2(cs_main, pWalletMain->cs_wallet); |
| 480 | result = pcmd->actor(params, false); |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | return result; |
| 485 | } catch (std::exception& e) { |
| 486 | throw JSONRPCError(RPC_MISC_ERROR, e.what()); |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | string HelpExampleCli(string methodname, string args) { |
| 491 | return "> ./coind " + methodname + " " + args + "\n"; |
no test coverage detected