diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -33,31 +33,31 @@ static UniValue validateaddress(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{ - "validateaddress", - "\nReturn information about the given bitcoin address.\n", - { - {"address", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "The bitcoin address to validate"}, - }} - .ToString() + - "\nResult:\n" - "{\n" - " \"isvalid\" : true|false, (boolean) If the address is " - "valid or not. If not, this is the only property returned.\n" - " \"address\" : \"address\", (string) The bitcoin address " - "validated\n" - " \"scriptPubKey\" : \"hex\", (string) The hex-encoded " - "scriptPubKey generated by the address\n" - " \"isscript\" : true|false, (boolean) If the key is a " - "script\n" - "}\n" - "\nExamples:\n" + - HelpExampleCli("validateaddress", - "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"") + - HelpExampleRpc("validateaddress", - "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"")); + throw std::runtime_error(RPCHelpMan{ + "validateaddress", + "\nReturn information about the given bitcoin address.\n", + { + {"address", RPCArg::Type::STR, /* opt */ false, + /* default_val */ "", "The bitcoin address to validate"}, + }, + RPCResult{ + "{\n" + " \"isvalid\" : true|false, (boolean) If the address is " + "valid or not. If not, this is the only property returned.\n" + " \"address\" : \"address\", (string) The bitcoin " + "address validated\n" + " \"scriptPubKey\" : \"hex\", (string) The hex-encoded " + "scriptPubKey generated by the address\n" + " \"isscript\" : true|false, (boolean) If the key is a " + "script\n" + "}\n"}, + RPCExamples{ + HelpExampleCli("validateaddress", + "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"") + + HelpExampleRpc("validateaddress", + "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"")}, + } + .ToStringWithResultsAndExamples()); } CTxDestination dest = @@ -106,33 +106,34 @@ {"key", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "The hex-encoded public key"}, }}, - }} - .ToString() + - "\nResult:\n" - "{\n" - " \"address\":\"multisigaddress\", (string) The value of the new " - "multisig address.\n" - " \"redeemScript\":\"script\" (string) The string value of " - "the hex-encoded redemption script.\n" - "}\n" - - "\nExamples:\n" - "\nCreate a multisig address from 2 public keys\n" + - HelpExampleCli("createmultisig", - "2 " - "\"[" - "\\\"03789ed0bb717d88f7d321a368d905e7430207ebbd82bd3" - "42cf11ae157a7ace5fd\\\"," - "\\\"03dbc6764b8884a92e871274b87583e6d5c2a58819473e1" - "7e107ef3f6aa5a61626\\\"]\"") + - "\nAs a JSON-RPC call\n" + - HelpExampleRpc("createmultisig", - "2, " - "\"[" - "\\\"03789ed0bb717d88f7d321a368d905e7430207ebbd82bd3" - "42cf11ae157a7ace5fd\\\"," - "\\\"03dbc6764b8884a92e871274b87583e6d5c2a58819473e1" - "7e107ef3f6aa5a61626\\\"]\""); + }, + RPCResult{"{\n" + " \"address\":\"multisigaddress\", (string) The " + "value of the new multisig address.\n" + " \"redeemScript\":\"script\" (string) The " + "string value of the hex-encoded redemption script.\n" + "}\n"}, + RPCExamples{ + "\nCreate a multisig address from 2 public keys\n" + + HelpExampleCli( + "createmultisig", + "2 " + "\"[" + "\\\"03789ed0bb717d88f7d321a368d905e7430207ebbd82bd3" + "42cf11ae157a7ace5fd\\\"," + "\\\"03dbc6764b8884a92e871274b87583e6d5c2a58819473e1" + "7e107ef3f6aa5a61626\\\"]\"") + + "\nAs a JSON-RPC call\n" + + HelpExampleRpc( + "createmultisig", + "2, " + "\"[" + "\\\"03789ed0bb717d88f7d321a368d905e7430207ebbd82bd3" + "42cf11ae157a7ace5fd\\\"," + "\\\"03dbc6764b8884a92e871274b87583e6d5c2a58819473e1" + "7e107ef3f6aa5a61626\\\"]\"")}, + } + .ToStringWithResultsAndExamples(); throw std::runtime_error(msg); } @@ -173,39 +174,41 @@ static UniValue verifymessage(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 3) { - throw std::runtime_error( - RPCHelpMan{ - "verifymessage", - "\nVerify a signed message\n", - { - {"address", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", - "The bitcoin address to use for the signature."}, - {"signature", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", - "The signature provided by the signer in base 64 encoding " - "(see signmessage)."}, - {"message", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "The message that was signed."}, - }} - .ToString() + - "\nResult:\n" - "true|false (boolean) If the signature is verified or not.\n" - "\nExamples:\n" - "\nUnlock the wallet for 30 seconds\n" + - HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") + - "\nCreate the signature\n" + - HelpExampleCli( - "signmessage", - "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"my message\"") + - "\nVerify the signature\n" + - HelpExampleCli("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4" - "XX\" \"signature\" \"my " - "message\"") + - "\nAs a JSON-RPC call\n" + - HelpExampleRpc("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4" - "XX\", \"signature\", \"my " - "message\"")); + throw std::runtime_error(RPCHelpMan{ + "verifymessage", + "\nVerify a signed message\n", + { + {"address", RPCArg::Type::STR, /* opt */ false, + /* default_val */ "", + "The bitcoin address to use for the signature."}, + {"signature", RPCArg::Type::STR, /* opt */ false, + /* default_val */ "", + "The signature provided by the signer in base 64 encoding " + "(see signmessage)."}, + {"message", RPCArg::Type::STR, /* opt */ false, + /* default_val */ "", "The message that was signed."}, + }, + RPCResult{"true|false (boolean) If the signature is verified or " + "not.\n"}, + RPCExamples{ + "\nUnlock the wallet for 30 seconds\n" + + HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") + + "\nCreate the signature\n" + + HelpExampleCli( + "signmessage", + "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"my message\"") + + "\nVerify the signature\n" + + HelpExampleCli("verifymessage", + "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4" + "XX\" \"signature\" \"my " + "message\"") + + "\nAs a JSON-RPC call\n" + + HelpExampleRpc("verifymessage", + "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4" + "XX\", \"signature\", \"my " + "message\"")}, + } + .ToStringWithResultsAndExamples()); } LOCK(cs_main); @@ -248,32 +251,31 @@ static UniValue signmessagewithprivkey(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 2) { - throw std::runtime_error( - RPCHelpMan{"signmessagewithprivkey", - "\nSign a message with the private key of an address\n", - { - {"privkey", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", - "The private key to sign the message with."}, - {"message", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", - "The message to create a signature of."}, - }} - .ToString() + - "\nResult:\n" - "\"signature\" (string) The signature of the message " - "encoded in base 64\n" - "\nExamples:\n" - "\nCreate the signature\n" + - HelpExampleCli("signmessagewithprivkey", - "\"privkey\" \"my message\"") + - "\nVerify the signature\n" + - HelpExampleCli("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4" - "XX\" \"signature\" \"my " - "message\"") + - "\nAs a JSON-RPC call\n" + - HelpExampleRpc("signmessagewithprivkey", - "\"privkey\", \"my message\"")); + throw std::runtime_error(RPCHelpMan{ + "signmessagewithprivkey", + "\nSign a message with the private key of an address\n", + { + {"privkey", RPCArg::Type::STR, /* opt */ false, + /* default_val */ "", + "The private key to sign the message with."}, + {"message", RPCArg::Type::STR, /* opt */ false, + /* default_val */ "", "The message to create a signature of."}, + }, + RPCResult{"\"signature\" (string) The signature of the " + "message encoded in base 64\n"}, + RPCExamples{"\nCreate the signature\n" + + HelpExampleCli("signmessagewithprivkey", + "\"privkey\" \"my message\"") + + "\nVerify the signature\n" + + HelpExampleCli("verifymessage", + "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4" + "XX\" \"signature\" \"my " + "message\"") + + "\nAs a JSON-RPC call\n" + + HelpExampleRpc("signmessagewithprivkey", + "\"privkey\", \"my message\"")}, + } + .ToStringWithResultsAndExamples()); } std::string strPrivkey = request.params[0].get_str(); @@ -307,7 +309,11 @@ /* default_val */ "", "Unix seconds-since-epoch timestamp\n" " Pass 0 to go back to using the system time."}, - }}.ToString()); + }, + RPCResults{}, + RPCExamples{""}, + } + .ToStringWithResultsAndExamples()); } if (!config.GetChainParams().MineBlocksOnDemand()) { @@ -364,45 +370,48 @@ * as users will undoubtedly confuse it with the other "memory pool" */ if (request.fHelp || request.params.size() > 1) { - throw std::runtime_error( - RPCHelpMan{ - "getmemoryinfo", - "Returns an object containing information about memory " - "usage.\n", - { - {"mode", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "", - "determines what kind of information is returned. This " - "argument is optional, the default mode is \"stats\".\n" - " - \"stats\" returns general statistics about memory " - "usage in the daemon.\n" - " - \"mallocinfo\" returns an XML string describing " - "low-level heap state (only available if compiled with " - "glibc 2.10+)."}, - }} - .ToString() + - "\nResult (mode \"stats\"):\n" - "{\n" - " \"locked\": { (json object) Information about " - "locked memory manager\n" - " \"used\": xxxxx, (numeric) Number of bytes used\n" - " \"free\": xxxxx, (numeric) Number of bytes available " - "in current arenas\n" - " \"total\": xxxxxxx, (numeric) Total number of bytes " - "managed\n" - " \"locked\": xxxxxx, (numeric) Amount of bytes that " - "succeeded locking. If this number is smaller than total, locking " - "pages failed at some point and key data could be swapped to " - "disk.\n" - " \"chunks_used\": xxxxx, (numeric) Number allocated chunks\n" - " \"chunks_free\": xxxxx, (numeric) Number unused chunks\n" - " }\n" - "}\n" - "\nResult (mode \"mallocinfo\"):\n" - "\"...\"\n" - "\nExamples:\n" + - HelpExampleCli("getmemoryinfo", "") + - HelpExampleRpc("getmemoryinfo", "")); + throw std::runtime_error(RPCHelpMan{ + "getmemoryinfo", + "Returns an object containing information about memory usage.\n", + { + {"mode", RPCArg::Type::STR, /* opt */ true, + /* default_val */ "", + "determines what kind of information is returned. This " + "argument is optional, the default mode is \"stats\".\n" + " - \"stats\" returns general statistics about memory usage " + "in the daemon.\n" + " - \"mallocinfo\" returns an XML string describing " + "low-level heap state (only available if compiled with glibc " + "2.10+)."}, + }, + { + RPCResult{"mode \"stats\"", + "{\n" + " \"locked\": { (json object) " + "Information about locked memory manager\n" + " \"used\": xxxxx, (numeric) Number of " + "bytes used\n" + " \"free\": xxxxx, (numeric) Number of " + "bytes available in current arenas\n" + " \"total\": xxxxxxx, (numeric) Total " + "number of bytes managed\n" + " \"locked\": xxxxxx, (numeric) Amount of " + "bytes that succeeded locking. If this number is " + "smaller than total, locking pages failed at some " + "point and key data could be swapped to disk.\n" + " \"chunks_used\": xxxxx, (numeric) Number " + "allocated chunks\n" + " \"chunks_free\": xxxxx, (numeric) Number " + "unused chunks\n" + " }\n" + "}\n"}, + RPCResult{"mode \"mallocinfo\"", + "\"...\"\n"}, + }, + RPCExamples{HelpExampleCli("getmemoryinfo", "") + + HelpExampleRpc("getmemoryinfo", "")}, + } + .ToStringWithResultsAndExamples()); } std::string mode = @@ -445,60 +454,57 @@ static UniValue logging(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() > 2) { - throw std::runtime_error( - RPCHelpMan{ - "logging", - "Gets and sets the logging configuration.\n" - "When called without an argument, returns the list of " - "categories with status that are currently being debug logged " - "or not.\n" - "When called with arguments, adds or removes categories from " - "debug logging and return the lists above.\n" - "The arguments are evaluated in order \"include\", " - "\"exclude\".\n" - "If an item is both included and excluded, it will thus end up " - "being excluded.\n" - "The valid logging categories are: " + - ListLogCategories() + - "\n" - "In addition, the following are available as category " - "names with special meanings:\n" - " - \"all\", \"1\" : represent all logging categories.\n" - " - \"none\", \"0\" : even if other logging categories " - "are specified, ignore all of them.\n", - { - {"include", - RPCArg::Type::ARR, - /* opt */ true, - /* default_val */ "", - "A json array of categories to add debug logging", - { - {"include_category", RPCArg::Type::STR, - /* opt */ false, /* default_val */ "", - "the valid logging category"}, - }}, - {"exclude", - RPCArg::Type::ARR, - /* opt */ true, - /* default_val */ "", - "A json array of categories to remove debug logging", - { - {"exclude_category", RPCArg::Type::STR, - /* opt */ false, /* default_val */ "", - "the valid logging category"}, - }}, - }} - .ToString() + - "\nResult:\n" - "{ (json object where keys are the logging " - "categories, and values indicates its status\n" - " \"category\": 0|1, (numeric) if being debug logged or not. " - "0:inactive, 1:active\n" - " ...\n" - "}\n" - "\nExamples:\n" + - HelpExampleCli("logging", "\"[\\\"all\\\"]\" \"[\\\"http\\\"]\"") + - HelpExampleRpc("logging", "[\"all\"], \"[libevent]\"")); + throw std::runtime_error(RPCHelpMan{ + "logging", + "Gets and sets the logging configuration.\n" + "When called without an argument, returns the list of categories " + "with status that are currently being debug logged or not.\n" + "When called with arguments, adds or removes categories from debug " + "logging and return the lists above.\n" + "The arguments are evaluated in order \"include\", \"exclude\".\n" + "If an item is both included and excluded, it will thus end up " + "being excluded.\n" + "The valid logging categories are: " + + ListLogCategories() + + "\n" + "In addition, the following are available as category names " + "with special meanings:\n" + " - \"all\", \"1\" : represent all logging categories.\n" + " - \"none\", \"0\" : even if other logging categories are " + "specified, ignore all of them.\n", + { + {"include", + RPCArg::Type::ARR, + /* opt */ true, + /* default_val */ "", + "A json array of categories to add debug logging", + { + {"include_category", RPCArg::Type::STR, + /* opt */ false, /* default_val */ "", + "the valid logging category"}, + }}, + {"exclude", + RPCArg::Type::ARR, + /* opt */ true, + /* default_val */ "", + "A json array of categories to remove debug logging", + { + {"exclude_category", RPCArg::Type::STR, + /* opt */ false, /* default_val */ "", + "the valid logging category"}, + }}, + }, + RPCResult{"{ (json object where keys are the " + "logging categories, and values indicates its status\n" + " \"category\": 0|1, (numeric) if being debug logged " + "or not. 0:inactive, 1:active\n" + " ...\n" + "}\n"}, + RPCExamples{HelpExampleCli("logging", + "\"[\\\"all\\\"]\" \"[\\\"http\\\"]\"") + + HelpExampleRpc("logging", "[\"all\"], \"[libevent]\"")}, + } + .ToStringWithResultsAndExamples()); } uint32_t original_log_categories = LogInstance().GetCategoryMask(); @@ -544,19 +550,18 @@ static UniValue echo(const Config &config, const JSONRPCRequest &request) { if (request.fHelp) { - throw std::runtime_error( - RPCHelpMan{ - "echo|echojson ...", - "\nSimply echo back the input arguments. This command is for " - "testing.\n" - "\nIt will return an internal bug report when exactly 100 " - "arguments are passed.\n" - "\nThe difference between echo and echojson is that echojson " - "has argument conversion enabled in the client-side table in " - "bitcoin-cli and the GUI. There is no server-side difference.", - {}} - .ToString() + - ""); + throw std::runtime_error(RPCHelpMan{ + "echo|echojson ...", + "\nSimply echo back the input arguments. This command is for " + "testing.\n" + "\nThe difference between echo and echojson is that echojson has " + "argument conversion enabled in the client-side table in " + "bitcoin-cli and the GUI. There is no server-side difference.", + {}, + RPCResults{}, + RPCExamples{""}, + } + .ToStringWithResultsAndExamples()); } CHECK_NONFATAL(request.params.size() != 100);