diff --git a/src/rpc/abc.cpp b/src/rpc/abc.cpp --- a/src/rpc/abc.cpp +++ b/src/rpc/abc.cpp @@ -14,15 +14,15 @@ static UniValue getexcessiveblock(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 0) { - throw std::runtime_error( - RPCHelpMan{ - "getexcessiveblock", "\nReturn the excessive block size.", {}} - .ToString() + - "\nResult\n" - " excessiveBlockSize (integer) block size in bytes\n" - "\nExamples:\n" + - HelpExampleCli("getexcessiveblock", "") + - HelpExampleRpc("getexcessiveblock", "")); + throw std::runtime_error(RPCHelpMan{ + "getexcessiveblock", + "\nReturn the excessive block size.", + {}, + RPCResult{" excessiveBlockSize (integer) block size in bytes\n"}, + RPCExamples{HelpExampleCli("getexcessiveblock", "") + + HelpExampleRpc("getexcessiveblock", "")}, + } + .ToString()); } UniValue ret(UniValue::VOBJ); @@ -33,24 +33,22 @@ static UniValue setexcessiveblock(Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{ - "setexcessiveblock", - "\nSet the excessive block size. Excessive blocks will not be " - "used in the active chain or relayed. This discourages the " - "propagation of blocks that you consider excessively large.", - { - {"blockSize", RPCArg::Type::NUM, /* opt */ false, - /* default_value */ "", - "Excessive block size in bytes. Must be greater than " + - std::to_string(LEGACY_MAX_BLOCK_SIZE) + "."}, - }} - .ToString() + - "\nResult\n" - " blockSize (integer) excessive block size in bytes\n" - "\nExamples:\n" + - HelpExampleCli("setexcessiveblock", "25000000") + - HelpExampleRpc("setexcessiveblock", "25000000")); + throw std::runtime_error(RPCHelpMan{ + "setexcessiveblock", + "\nSet the excessive block size. Excessive blocks will not be " + "used in the active chain or relayed. This discourages the " + "propagation of blocks that you consider excessively large.", + { + {"blockSize", RPCArg::Type::NUM, /* opt */ false, + /* default_value */ "", + "Excessive block size in bytes. Must be greater than " + + std::to_string(LEGACY_MAX_BLOCK_SIZE) + "."}, + }, + RPCResult{" blockSize (integer) excessive block size in bytes\n"}, + RPCExamples{HelpExampleCli("setexcessiveblock", "25000000") + + HelpExampleRpc("setexcessiveblock", "25000000")}, + } + .ToString()); } int64_t ebs = 0; diff --git a/src/rpc/avalanche.cpp b/src/rpc/avalanche.cpp --- a/src/rpc/avalanche.cpp +++ b/src/rpc/avalanche.cpp @@ -14,12 +14,14 @@ static UniValue getavalanchekey(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 0) { - throw std::runtime_error( - RPCHelpMan{"getavalanchekey", - "\nReturns the key used to sign avalanche messages.\n", - {}} - .ToString() + - "\nExamples:\n" + HelpExampleRpc("getavalanchekey", "")); + throw std::runtime_error(RPCHelpMan{ + "getavalanchekey", + "\nReturns the key used to sign avalanche messages.\n", + {}, + RPCResults{}, + RPCExamples{HelpExampleRpc("getavalanchekey", "")}, + } + .ToString()); } if (!g_avalanche) { diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -154,17 +154,15 @@ static UniValue getblockcount(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 0) { - throw std::runtime_error( - RPCHelpMan{ - "getblockcount", - "\nReturns the number of blocks in the longest blockchain.\n", - {}} - .ToString() + - "\nResult:\n" - "n (numeric) The current block count\n" - "\nExamples:\n" + - HelpExampleCli("getblockcount", "") + - HelpExampleRpc("getblockcount", "")); + throw std::runtime_error(RPCHelpMan{ + "getblockcount", + "\nReturns the number of blocks in the longest blockchain.\n", + {}, + RPCResult{"n (numeric) The current block count\n"}, + RPCExamples{HelpExampleCli("getblockcount", "") + + HelpExampleRpc("getblockcount", "")}, + } + .ToString()); } LOCK(cs_main); @@ -174,17 +172,16 @@ static UniValue getbestblockhash(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 0) { - throw std::runtime_error( - RPCHelpMan{"getbestblockhash", - "\nReturns the hash of the best (tip) block in the " - "longest blockchain.\n", - {}} - .ToString() + - "\nResult:\n" - "\"hex\" (string) the block hash hex-encoded\n" - "\nExamples:\n" + - HelpExampleCli("getbestblockhash", "") + - HelpExampleRpc("getbestblockhash", "")); + throw std::runtime_error(RPCHelpMan{ + "getbestblockhash", + "\nReturns the hash of the best (tip) block in the " + "longest blockchain.\n", + {}, + RPCResult{"\"hex\" (string) the block hash, hex-encoded\n"}, + RPCExamples{HelpExampleCli("getbestblockhash", "") + + HelpExampleRpc("getbestblockhash", "")}, + } + .ToString()); } LOCK(cs_main); @@ -194,13 +191,15 @@ UniValue getfinalizedblockhash(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 0) { - throw std::runtime_error( - RPCHelpMan{"getfinalizedblockhash", - "\nReturns the hash of the currently finalized block\n", - {}} - .ToString() + - "\nResult:\n" - "\"hex\" (string) the block hash hex-encoded\n"); + throw std::runtime_error(RPCHelpMan{ + "getfinalizedblockhash", + "\nReturns the hash of the currently finalized block\n", + {}, + RPCResult{"\"hex\" (string) the block hash hex-encoded\n"}, + RPCExamples{HelpExampleCli("getfinalizedblockhash", "") + + HelpExampleRpc("getfinalizedblockhash", "")}, + } + .ToString()); } LOCK(cs_main); @@ -223,28 +222,26 @@ static UniValue waitfornewblock(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() > 1) { - throw std::runtime_error( - RPCHelpMan{"waitfornewblock", - "\nWaits for a specific new block and returns useful " - "info about it.\n" - "\nReturns the current block on timeout or exit.\n", - { - {"timeout", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "", - "Time in milliseconds to wait for a response. 0 " - "indicates no timeout."}, - }} - .ToString() + - "\nResult:\n" - "{ (json object)\n" - " \"hash\" : { (string) The blockhash\n" - " \"height\" : { (int) Block height\n" - "}\n" - "\nExamples:\n" + - HelpExampleCli("waitfornewblock", "1000") + - HelpExampleRpc("waitfornewblock", "1000")); + throw std::runtime_error(RPCHelpMan{ + "waitfornewblock", + "\nWaits for a specific new block and returns useful " + "info about it.\n" + "\nReturns the current block on timeout or exit.\n", + { + {"timeout", RPCArg::Type::NUM, /* opt */ true, + /* default_val */ "", + "Time in milliseconds to wait for a response. 0 " + "indicates no timeout."}, + }, + RPCResult{"{ (json object)\n" + " \"hash\" : { (string) The blockhash\n" + " \"height\" : { (int) Block height\n" + "}\n"}, + RPCExamples{HelpExampleCli("waitfornewblock", "1000") + + HelpExampleRpc("waitfornewblock", "1000")}, + } + .ToString()); } - int timeout = 0; if (!request.params[0].isNull()) { timeout = request.params[0].get_int(); @@ -278,32 +275,33 @@ const JSONRPCRequest &request) { if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) { - throw std::runtime_error( - RPCHelpMan{"waitforblock", - "\nWaits for a specific new block and returns useful " - "info about it.\n" - "\nReturns the current block on timeout or exit.\n", - { - {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "Block hash to wait for."}, - {"timeout", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "0", - "Time in milliseconds to wait for a response. 0 " - "indicates no timeout."}, - }} - .ToString() + - "\nResult:\n" - "{ (json object)\n" - " \"hash\" : { (string) The blockhash\n" - " \"height\" : { (int) Block height\n" - "}\n" - "\nExamples:\n" + - HelpExampleCli("waitforblock", "\"0000000000079f8ef3d2c688c244eb7a4" - "570b24c9ed7b4a8c619eb02596f8862\", " - "1000") + - HelpExampleRpc("waitforblock", "\"0000000000079f8ef3d2c688c244eb7a4" - "570b24c9ed7b4a8c619eb02596f8862\", " - "1000")); + throw std::runtime_error(RPCHelpMan{ + "waitforblock", + "\nWaits for a specific new block and returns useful " + "info about it.\n" + "\nReturns the current block on timeout or exit.\n", + { + {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, + /* default_val */ "", "Block hash to wait for."}, + {"timeout", RPCArg::Type::NUM, /* opt */ true, + /* default_val */ "0", + "Time in milliseconds to wait for a response. 0 " + "indicates no timeout."}, + }, + RPCResult{"{ (json object)\n" + " \"hash\" : { (string) The blockhash\n" + " \"height\" : { (int) Block height\n" + "}\n"}, + RPCExamples{HelpExampleCli("waitforblock", + "\"0000000000079f8ef3d2c688c244eb7a4" + "570b24c9ed7b4a8c619eb02596f8862\", " + "1000") + + HelpExampleRpc("waitforblock", + "\"0000000000079f8ef3d2c688c244eb7a4" + "570b24c9ed7b4a8c619eb02596f8862\", " + "1000")}, + } + .ToString()); } int timeout = 0; @@ -340,28 +338,27 @@ const JSONRPCRequest &request) { if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) { - throw std::runtime_error( - RPCHelpMan{"waitforblockheight", - "\nWaits for (at least) block height and returns the " - "height and hash\nof the current tip.\n" - "\nReturns the current block on timeout or exit.\n", - { - {"height", RPCArg::Type::NUM, /* opt */ false, - /* default_val */ "", "Block height to wait for."}, - {"timeout", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "0", - "Time in milliseconds to wait for a response. 0 " - "indicates no timeout."}, - }} - .ToString() + - "\nResult:\n" - "{ (json object)\n" - " \"hash\" : { (string) The blockhash\n" - " \"height\" : { (int) Block height\n" - "}\n" - "\nExamples:\n" + - HelpExampleCli("waitforblockheight", "\"100\", 1000") + - HelpExampleRpc("waitforblockheight", "\"100\", 1000")); + throw std::runtime_error(RPCHelpMan{ + "waitforblockheight", + "\nWaits for (at least) block height and returns the " + "height and hash\nof the current tip.\n" + "\nReturns the current block on timeout or exit.\n", + { + {"height", RPCArg::Type::NUM, /* opt */ false, + /* default_val */ "", "Block height to wait for."}, + {"timeout", RPCArg::Type::NUM, /* opt */ true, + /* default_val */ "0", + "Time in milliseconds to wait for a response. 0 " + "indicates no timeout."}, + }, + RPCResult{"{ (json object)\n" + " \"hash\" : { (string) The blockhash\n" + " \"height\" : { (int) Block height\n" + "}\n"}, + RPCExamples{HelpExampleCli("waitforblockheight", "\"100\", 1000") + + HelpExampleRpc("waitforblockheight", "\"100\", 1000")}, + } + .ToString()); } int timeout = 0; @@ -397,16 +394,16 @@ syncwithvalidationinterfacequeue(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() > 0) { - throw std::runtime_error( - RPCHelpMan{ - "syncwithvalidationinterfacequeue", - "\nWaits for the validation interface queue to catch up on " - "everything that was there when we entered this function.\n", - {}} - .ToString() + - "\nExamples:\n" + - HelpExampleCli("syncwithvalidationinterfacequeue", "") + - HelpExampleRpc("syncwithvalidationinterfacequeue", "")); + throw std::runtime_error(RPCHelpMan{ + "syncwithvalidationinterfacequeue", + "\nWaits for the validation interface queue to catch up on " + "everything that was there when we entered this function.\n", + {}, + RPCResults{}, + RPCExamples{HelpExampleCli("syncwithvalidationinterfacequeue", "") + + HelpExampleRpc("syncwithvalidationinterfacequeue", "")}, + } + .ToString()); } SyncWithValidationInterfaceQueue(); return NullUniValue; @@ -415,19 +412,17 @@ static UniValue getdifficulty(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 0) { - throw std::runtime_error( - RPCHelpMan{"getdifficulty", - "\nReturns the proof-of-work difficulty as a " - "multiple of the minimum difficulty.\n", - {}} - .ToString() + - "\nResult:\n" - "n.nnn (numeric) the proof-of-work " - "difficulty as a multiple of the minimum " - "difficulty.\n" - "\nExamples:\n" + - HelpExampleCli("getdifficulty", "") + - HelpExampleRpc("getdifficulty", "")); + throw std::runtime_error(RPCHelpMan{ + "getdifficulty", + "\nReturns the proof-of-work difficulty as a multiple of the " + "minimum difficulty.\n", + {}, + RPCResult{"n.nnn (numeric) the proof-of-work difficulty as a " + "multiple of the minimum difficulty.\n"}, + RPCExamples{HelpExampleCli("getdifficulty", "") + + HelpExampleRpc("getdifficulty", "")}, + } + .ToString()); } LOCK(cs_main); @@ -559,33 +554,33 @@ static UniValue getrawmempool(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() > 1) { - throw std::runtime_error( - RPCHelpMan{"getrawmempool", - "\nReturns all transaction ids in memory pool as a json " - "array of string transaction ids.\n" - "\nHint: use getmempoolentry to fetch a specific " - "transaction from the mempool.\n", - { - {"verbose", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "false", - "True for a json object, false for array of " - "transaction ids"}, - }} - .ToString() + - "\nResult: (for verbose = false):\n" - "[ (json array of string)\n" - " \"transactionid\" (string) The transaction id\n" - " ,...\n" - "]\n" - "\nResult: (for verbose = true):\n" - "{ (json object)\n" - " \"transactionid\" : { (json object)\n" + - EntryDescriptionString() + - " }, ...\n" - "}\n" - "\nExamples:\n" + - HelpExampleCli("getrawmempool", "true") + - HelpExampleRpc("getrawmempool", "true")); + throw std::runtime_error(RPCHelpMan{ + "getrawmempool", + "\nReturns all transaction ids in memory pool as a json " + "array of string transaction ids.\n" + "\nHint: use getmempoolentry to fetch a specific " + "transaction from the mempool.\n", + { + {"verbose", RPCArg::Type::BOOL, /* opt */ true, + /* default_val */ "false", + "True for a json object, false for array of " + "transaction ids"}, + }, + RPCResult{"for verbose = false", + "[ (json array of string)\n" + " \"transactionid\" (string) The transaction id\n" + " ,...\n" + "]\n" + "\nResult: (for verbose = true):\n" + "{ (json object)\n" + " \"transactionid\" : { (json object)\n" + + EntryDescriptionString() + + " }, ...\n" + "}\n"}, + RPCExamples{HelpExampleCli("getrawmempool", "true") + + HelpExampleRpc("getrawmempool", "true")}, + } + .ToString()); } bool fVerbose = false; @@ -600,35 +595,38 @@ const JSONRPCRequest &request) { if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) { - throw std::runtime_error( - RPCHelpMan{"getmempoolancestors", - "\nIf txid is in the mempool, returns all in-mempool " - "ancestors.\n", - { - {"txid", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", - "The transaction id (must be in mempool)"}, - {"verbose", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "false", - "True for a json object, false for array of " - "transaction ids"}, - }} - .ToString() + - "\nResult (for verbose = false):\n" - "[ (json array of strings)\n" - " \"transactionid\" (string) The transaction id of an " - "in-mempool ancestor transaction\n" - " ,...\n" - "]\n" - "\nResult (for verbose = true):\n" - "{ (json object)\n" - " \"transactionid\" : { (json object)\n" + - EntryDescriptionString() + - " }, ...\n" - "}\n" - "\nExamples:\n" + - HelpExampleCli("getmempoolancestors", "\"mytxid\"") + - HelpExampleRpc("getmempoolancestors", "\"mytxid\"")); + throw std::runtime_error(RPCHelpMan{ + "getmempoolancestors", + "\nIf txid is in the mempool, returns all in-mempool " + "ancestors.\n", + { + {"txid", RPCArg::Type::STR_HEX, /* opt */ false, + /* default_val */ "", + "The transaction id (must be in mempool)"}, + {"verbose", RPCArg::Type::BOOL, /* opt */ true, + /* default_val */ "false", + "True for a json object, false for array of " + "transaction ids"}, + }, + { + RPCResult{"for verbose = false", + "[ (json array of strings)\n" + " \"transactionid\" (string) The " + "transaction id of an " + "in-mempool ancestor transaction\n" + " ,...\n" + "]\n"}, + RPCResult{"for verbose = true", + "{ (json object)\n" + " \"transactionid\" : { (json object)\n" + + EntryDescriptionString() + + " }, ...\n" + "}\n"}, + }, + RPCExamples{HelpExampleCli("getmempoolancestors", "\"mytxid\"") + + HelpExampleRpc("getmempoolancestors", "\"mytxid\"")}, + } + .ToString()); } bool fVerbose = false; @@ -676,35 +674,38 @@ const JSONRPCRequest &request) { if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) { - throw std::runtime_error( - RPCHelpMan{"getmempooldescendants", - "\nIf txid is in the mempool, returns all in-mempool " - "descendants.\n", - { - {"txid", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", - "The transaction id (must be in mempool)"}, - {"verbose", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "false", - "True for a json object, false for array of " - "transaction ids"}, - }} - .ToString() + - "\nResult (for verbose = false):\n" - "[ (json array of strings)\n" - " \"transactionid\" (string) The transaction id of an " - "in-mempool descendant transaction\n" - " ,...\n" - "]\n" - "\nResult (for verbose = true):\n" - "{ (json object)\n" - " \"transactionid\" : { (json object)\n" + - EntryDescriptionString() + - " }, ...\n" - "}\n" - "\nExamples:\n" + - HelpExampleCli("getmempooldescendants", "\"mytxid\"") + - HelpExampleRpc("getmempooldescendants", "\"mytxid\"")); + throw std::runtime_error(RPCHelpMan{ + "getmempooldescendants", + "\nIf txid is in the mempool, returns all in-mempool " + "descendants.\n", + { + {"txid", RPCArg::Type::STR_HEX, /* opt */ false, + /* default_val */ "", + "The transaction id (must be in mempool)"}, + {"verbose", RPCArg::Type::BOOL, /* opt */ true, + /* default_val */ "false", + "True for a json object, false for array of " + "transaction ids"}, + }, + { + RPCResult{"for verbose = false", + "[ (json array of strings)\n" + " \"transactionid\" (string) The " + "transaction id of an " + "in-mempool descendant transaction\n" + " ,...\n" + "]\n"}, + RPCResult{"for verbose = true", + "{ (json object)\n" + " \"transactionid\" : { (json object)\n" + + EntryDescriptionString() + + " }, ...\n" + "}\n"}, + }, + RPCExamples{HelpExampleCli("getmempooldescendants", "\"mytxid\"") + + HelpExampleRpc("getmempooldescendants", "\"mytxid\"")}, + } + .ToString()); } bool fVerbose = false; @@ -750,22 +751,20 @@ static UniValue getmempoolentry(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{"getmempoolentry", - "\nReturns mempool data for given transaction\n", - { - {"txid", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", - "The transaction id (must be in mempool)"}, - }} - .ToString() + - "\nResult:\n" - "{ (json object)\n" + - EntryDescriptionString() + - "}\n" - "\nExamples:\n" + - HelpExampleCli("getmempoolentry", "\"mytxid\"") + - HelpExampleRpc("getmempoolentry", "\"mytxid\"")); + throw std::runtime_error(RPCHelpMan{ + "getmempoolentry", + "\nReturns mempool data for given transaction\n", + { + {"txid", RPCArg::Type::STR_HEX, /* opt */ false, + /* default_val */ "", + "The transaction id (must be in mempool)"}, + }, + RPCResult{"{ (json object)\n" + + EntryDescriptionString() + "}\n"}, + RPCExamples{HelpExampleCli("getmempoolentry", "\"mytxid\"") + + HelpExampleRpc("getmempoolentry", "\"mytxid\"")}, + } + .ToString()); } TxId txid(ParseHashV(request.params[0], "parameter 1")); @@ -787,20 +786,19 @@ static UniValue getblockhash(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{"getblockhash", - "\nReturns hash of block in best-block-chain at height " - "provided.\n", - { - {"height", RPCArg::Type::NUM, /* opt */ false, - /* default_val */ "", "The height index"}, - }} - .ToString() + - "\nResult:\n" - "\"hash\" (string) The block hash\n" - "\nExamples:\n" + - HelpExampleCli("getblockhash", "1000") + - HelpExampleRpc("getblockhash", "1000")); + throw std::runtime_error(RPCHelpMan{ + "getblockhash", + "\nReturns hash of block in best-block-chain at height " + "provided.\n", + { + {"height", RPCArg::Type::NUM, /* opt */ false, + /* default_val */ "", "The height index"}, + }, + RPCResult{"\"hash\" (string) The block hash\n"}, + RPCExamples{HelpExampleCli("getblockhash", "1000") + + HelpExampleRpc("getblockhash", "1000")}, + } + .ToString()); } LOCK(cs_main); @@ -818,58 +816,73 @@ const JSONRPCRequest &request) { if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) { - throw std::runtime_error( - RPCHelpMan{ - "getblockheader", - "\nIf verbose is false, returns a string that is " - "serialized, hex-encoded data for blockheader 'hash'.\n" - "If verbose is true, returns an Object with information " - "about blockheader .\n", - { - {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "The block hash"}, - {"verbose", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "true", - "true for a json object, false for the hex-encoded data"}, - }} - .ToString() + - "\nResult (for verbose = true):\n" - "{\n" - " \"hash\" : \"hash\", (string) the block hash (same as " - "provided)\n" - " \"confirmations\" : n, (numeric) The number of confirmations, " - "or -1 if the block is not on the main chain\n" - " \"height\" : n, (numeric) The block height or index\n" - " \"version\" : n, (numeric) The block version\n" - " \"versionHex\" : \"00000000\", (string) The block version " - "formatted in hexadecimal\n" - " \"merkleroot\" : \"xxxx\", (string) The merkle root\n" - " \"time\" : ttt, (numeric) The block time in seconds " - "since epoch (Jan 1 1970 GMT)\n" - " \"mediantime\" : ttt, (numeric) The median block time in " - "seconds since epoch (Jan 1 1970 GMT)\n" - " \"nonce\" : n, (numeric) The nonce\n" - " \"bits\" : \"1d00ffff\", (string) The bits\n" - " \"difficulty\" : x.xxx, (numeric) The difficulty\n" - " \"chainwork\" : \"0000...1f3\" (string) Expected number of " - "hashes required to produce the current chain (in hex)\n" - " \"nTx\" : n, (numeric) The number of transactions " - "in the block.\n" - " \"previousblockhash\" : \"hash\", (string) The hash of the " - "previous block\n" - " \"nextblockhash\" : \"hash\", (string) The hash of the " - "next block\n" - "}\n" - "\nResult (for verbose=false):\n" - "\"data\" (string) A string that is serialized, " - "hex-encoded data for block 'hash'.\n" - "\nExamples:\n" + - HelpExampleCli("getblockheader", "\"00000000c937983704a73af28acdec3" - "7b049d214adbda81d7e2a3dd146f6ed09" - "\"") + - HelpExampleRpc("getblockheader", "\"00000000c937983704a73af28acdec3" - "7b049d214adbda81d7e2a3dd146f6ed09" - "\"")); + throw std::runtime_error(RPCHelpMan{ + "getblockheader", + "\nIf verbose is false, returns a string that is " + "serialized, hex-encoded data for blockheader 'hash'.\n" + "If verbose is true, returns an Object with information " + "about blockheader .\n", + { + {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, + /* default_val */ "", "The block hash"}, + {"verbose", RPCArg::Type::BOOL, /* opt */ true, + /* default_val */ "true", + "true for a json object, false for the hex-encoded data"}, + }, + { + RPCResult{ + "for verbose = true", + "{\n" + " \"hash\" : \"hash\", (string) the block hash (same " + "as " + "provided)\n" + " \"confirmations\" : n, (numeric) The number of " + "confirmations, " + "or -1 if the block is not on the main chain\n" + " \"height\" : n, (numeric) The block height or " + "index\n" + " \"version\" : n, (numeric) The block version\n" + " \"versionHex\" : \"00000000\", (string) The block " + "version " + "formatted in hexadecimal\n" + " \"merkleroot\" : \"xxxx\", (string) The merkle root\n" + " \"time\" : ttt, (numeric) The block time in " + "seconds " + "since epoch (Jan 1 1970 GMT)\n" + " \"mediantime\" : ttt, (numeric) The median block " + "time in " + "seconds since epoch (Jan 1 1970 GMT)\n" + " \"nonce\" : n, (numeric) The nonce\n" + " \"bits\" : \"1d00ffff\", (string) The bits\n" + " \"difficulty\" : x.xxx, (numeric) The difficulty\n" + " \"chainwork\" : \"0000...1f3\" (string) Expected " + "number of " + "hashes required to produce the current chain (in hex)\n" + " \"nTx\" : n, (numeric) The number of " + "transactions " + "in the block.\n" + " \"previousblockhash\" : \"hash\", (string) The hash of " + "the " + "previous block\n" + " \"nextblockhash\" : \"hash\", (string) The hash of " + "the " + "next block\n" + "}\n"}, + RPCResult{"for verbose=false):\n" + "\"data\" (string) A string that is " + "serialized, " + "hex-encoded data for block 'hash'.\n"}, + }, + RPCExamples{HelpExampleCli("getblockheader", + "\"00000000c937983704a73af28acdec3" + "7b049d214adbda81d7e2a3dd146f6ed09" + "\"") + + HelpExampleRpc("getblockheader", + "\"00000000c937983704a73af28acdec3" + "7b049d214adbda81d7e2a3dd146f6ed09" + "\"")}, + } + .ToString()); } BlockHash hash(ParseHashV(request.params[0], "hash")); @@ -923,74 +936,94 @@ static UniValue getblock(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) { - throw std::runtime_error( - RPCHelpMan{ - "getblock", - "\nIf verbosity is 0 or false, returns a string that is " - "serialized, hex-encoded data for block 'hash'.\n" - "If verbosity is 1 or true, returns an Object with information " - "about block .\n" - "If verbosity is 2, returns an Object with information about " - "block and information about each transaction.\n", - { - {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "The block hash"}, - {"verbosity", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "1", - "0 for hex-encoded data, 1 for a json object, and 2 for " - "json object with transaction data"}, - }} - .ToString() + - "\nResult (for verbosity = 0):\n" - "\"data\" (string) A string that is serialized, " - "hex-encoded data for block 'hash'.\n" - "\nResult (for verbosity = 1):\n" - "{\n" - " \"hash\" : \"hash\", (string) The block hash (same as " - "provided)\n" - " \"confirmations\" : n, (numeric) The number of confirmations, " - "or -1 if the block is not on the main chain\n" - " \"size\" : n, (numeric) The block size\n" - " \"height\" : n, (numeric) The block height or index\n" - " \"version\" : n, (numeric) The block version\n" - " \"versionHex\" : \"00000000\", (string) The block version " - "formatted in hexadecimal\n" - " \"merkleroot\" : \"xxxx\", (string) The merkle root\n" - " \"tx\" : [ (array of string) The transaction ids\n" - " \"transactionid\" (string) The transaction id\n" - " ,...\n" - " ],\n" - " \"time\" : ttt, (numeric) The block time in seconds " - "since epoch (Jan 1 1970 GMT)\n" - " \"mediantime\" : ttt, (numeric) The median block time in " - "seconds since epoch (Jan 1 1970 GMT)\n" - " \"nonce\" : n, (numeric) The nonce\n" - " \"bits\" : \"1d00ffff\", (string) The bits\n" - " \"difficulty\" : x.xxx, (numeric) The difficulty\n" - " \"chainwork\" : \"xxxx\", (string) Expected number of hashes " - "required to produce the chain up to this block (in hex)\n" - " \"nTx\" : n, (numeric) The number of transactions " - "in the block.\n" - " \"previousblockhash\" : \"hash\", (string) The hash of the " - "previous block\n" - " \"nextblockhash\" : \"hash\" (string) The hash of the " - "next block\n" - "}\n" - "\nResult (for verbosity = 2):\n" - "{\n" - " ..., Same output as verbosity = 1\n" - " \"tx\" : [ (array of Objects) The transactions in " - "the format of the getrawtransaction RPC; different from verbosity " - "= 1 \"tx\" result\n" - " ...\n" - " ],\n" - " ... Same output as verbosity = 1\n" - "}\n" - "\nExamples:\n" + - HelpExampleCli("getblock", "\"00000000c937983704a73af28acdec37b049d" + throw std::runtime_error(RPCHelpMan{ + "getblock", + "\nIf verbosity is 0 or false, returns a string that is " + "serialized, hex-encoded data for block 'hash'.\n" + "If verbosity is 1 or true, returns an Object with information " + "about block .\n" + "If verbosity is 2, returns an Object with information about " + "block and information about each transaction.\n", + { + {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, + /* default_val */ "", "The block hash"}, + {"verbosity", RPCArg::Type::NUM, /* opt */ true, + /* default_val */ "1", + "0 for hex-encoded data, 1 for a json object, and 2 for " + "json object with transaction data"}, + }, + { + RPCResult{"for verbosity = 0", + "\"data\" (string) A string that " + "is serialized, " + "hex-encoded data for block 'hash'.\n" + "\nResult (for verbosity = 1):\n"}, + RPCResult{ + "for verbosity = 1", + "{\n" + " \"hash\" : \"hash\", (string) The block hash " + "(same as " + "provided)\n" + " \"confirmations\" : n, (numeric) The number of " + "confirmations, " + "or -1 if the block is not on the main chain\n" + " \"size\" : n, (numeric) The block size\n" + " \"height\" : n, (numeric) The block height or " + "index\n" + " \"version\" : n, (numeric) The block version\n" + " \"versionHex\" : \"00000000\", (string) The block " + "version " + "formatted in hexadecimal\n" + " \"merkleroot\" : \"xxxx\", (string) The merkle root\n" + " \"tx\" : [ (array of string) The " + "transaction ids\n" + " \"transactionid\" (string) The transaction id\n" + " ,...\n" + " ],\n" + " \"time\" : ttt, (numeric) The block time in " + "seconds " + "since epoch (Jan 1 1970 GMT)\n" + " \"mediantime\" : ttt, (numeric) The median block " + "time in " + "seconds since epoch (Jan 1 1970 GMT)\n" + " \"nonce\" : n, (numeric) The nonce\n" + " \"bits\" : \"1d00ffff\", (string) The bits\n" + " \"difficulty\" : x.xxx, (numeric) The difficulty\n" + " \"chainwork\" : \"xxxx\", (string) Expected number of " + "hashes " + "required to produce the chain up to this block (in hex)\n" + " \"nTx\" : n, (numeric) The number of " + "transactions " + "in the block.\n" + " \"previousblockhash\" : \"hash\", (string) The hash of " + "the " + "previous block\n" + " \"nextblockhash\" : \"hash\" (string) The hash of " + "the " + "next block\n" + "}\n"}, + RPCResult{ + "for verbosity = 2", + "{\n" + " ..., Same output as verbosity = 1\n" + " \"tx\" : [ (array of Objects) The " + "transactions in " + "the format of the getrawtransaction RPC; different from " + "verbosity " + "= 1 \"tx\" result\n" + " ...\n" + " ],\n" + " ... Same output as verbosity = 1\n" + "}\n"}, + }, + RPCExamples{HelpExampleCli("getblock", + "\"00000000c937983704a73af28acdec37b049d" "214adbda81d7e2a3dd146f6ed09\"") + - HelpExampleRpc("getblock", "\"00000000c937983704a73af28acdec37b049d" - "214adbda81d7e2a3dd146f6ed09\"")); + HelpExampleRpc("getblock", + "\"00000000c937983704a73af28acdec37b049d" + "214adbda81d7e2a3dd146f6ed09\"")}, + } + .ToString()); } LOCK(cs_main); @@ -1103,21 +1136,20 @@ static UniValue pruneblockchain(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{"pruneblockchain", - "", - { - {"height", RPCArg::Type::NUM, /* opt */ false, - /* default_val */ "", - "The block height to prune up to. May be set to a " - "discrete height, or a unix timestamp\n"}, - }} - .ToString() + - "\nResult:\n" - "n (numeric) Height of the last block pruned.\n" - "\nExamples:\n" + - HelpExampleCli("pruneblockchain", "1000") + - HelpExampleRpc("pruneblockchain", "1000")); + throw std::runtime_error(RPCHelpMan{ + "pruneblockchain", + "", + { + {"height", RPCArg::Type::NUM, /* opt */ false, + /* default_val */ "", + "The block height to prune up to. May be set to a " + "discrete height, or a unix timestamp\n"}, + }, + RPCResult{"n (numeric) Height of the last block pruned.\n"}, + RPCExamples{HelpExampleCli("pruneblockchain", "1000") + + HelpExampleRpc("pruneblockchain", "1000")}, + } + .ToString()); } if (!fPruneMode) { @@ -1170,30 +1202,34 @@ static UniValue gettxoutsetinfo(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 0) { - throw std::runtime_error( - RPCHelpMan{"gettxoutsetinfo", - "\nReturns statistics about the unspent transaction " - "output set.\n" - "Note this call may take some time.\n", - {}} - .ToString() + - "\nResult:\n" - "{\n" - " \"height\":n, (numeric) The current block height (index)\n" - " \"bestblock\": \"hex\", (string) the best block hash hex\n" - " \"transactions\": n, (numeric) The number of transactions\n" - " \"txouts\": n, (numeric) The number of output " - "transactions\n" - " \"bogosize\": n, (numeric) A database-independent " - "metric for UTXO set size\n" - " \"hash_serialized\": \"hash\", (string) The serialized hash\n" - " \"disk_size\": n, (numeric) The estimated size of the " - "chainstate on disk\n" - " \"total_amount\": x.xxx (numeric) The total amount\n" - "}\n" - "\nExamples:\n" + - HelpExampleCli("gettxoutsetinfo", "") + - HelpExampleRpc("gettxoutsetinfo", "")); + throw std::runtime_error(RPCHelpMan{ + "gettxoutsetinfo", + "\nReturns statistics about the unspent transaction output set.\n" + "Note this call may take some time.\n", + {}, + RPCResult{ + "{\n" + " \"height\":n, (numeric) The current block height " + "(index)\n" + " \"bestblock\": \"hex\", (string) the best block hash hex\n" + " \"transactions\": n, (numeric) The number of " + "transactions\n" + " \"txouts\": n, (numeric) The number of output " + "transactions\n" + " \"bogosize\": n, (numeric) A database-independent " + "metric for UTXO set size\n" + " \"hash_serialized\": \"hash\", (string) The serialized " + "hash\n" + " \"disk_size\": n, (numeric) The estimated size of " + "the " + "chainstate on disk\n" + " \"total_amount\": x.xxx (numeric) The total " + "amount\n" + "}\n"}, + RPCExamples{HelpExampleCli("gettxoutsetinfo", "") + + HelpExampleRpc("gettxoutsetinfo", "")}, + } + .ToString()); } UniValue ret(UniValue::VOBJ); @@ -1218,51 +1254,52 @@ UniValue gettxout(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() < 2 || request.params.size() > 3) { - throw std::runtime_error( - RPCHelpMan{ - "gettxout", - "\nReturns details about an unspent transaction output.\n", - { - {"txid", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "The transaction id"}, - {"n", RPCArg::Type::NUM, /* opt */ false, - /* default_val */ "", "vout number"}, - {"include_mempool", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "true", - "Whether to include the mempool. Note that an unspent " - "output that is spent in the mempool won't appear."}, - }} - .ToString() + - "\nResult:\n" - "{\n" - " \"bestblock\" : \"hash\", (string) the block hash\n" - " \"confirmations\" : n, (numeric) The number of " - "confirmations\n" - " \"value\" : x.xxx, (numeric) The transaction value " - "in " + - CURRENCY_UNIT + - "\n" - " \"scriptPubKey\" : { (json object)\n" - " \"asm\" : \"code\", (string) \n" - " \"hex\" : \"hex\", (string) \n" - " \"reqSigs\" : n, (numeric) Number of required " - "signatures\n" - " \"type\" : \"pubkeyhash\", (string) The type, eg pubkeyhash\n" - " \"addresses\" : [ (array of string) array of " - "bitcoin addresses\n" - " \"address\" (string) bitcoin address\n" - " ,...\n" - " ]\n" - " },\n" - " \"coinbase\" : true|false (boolean) Coinbase or not\n" - "}\n" - - "\nExamples:\n" - "\nGet unspent transactions\n" + - HelpExampleCli("listunspent", "") + "\nView the details\n" + - HelpExampleCli("gettxout", "\"txid\" 1") + - "\nAs a JSON-RPC call\n" + - HelpExampleRpc("gettxout", "\"txid\", 1")); + throw std::runtime_error(RPCHelpMan{ + "gettxout", + "\nReturns details about an unspent transaction output.\n", + { + {"txid", RPCArg::Type::STR_HEX, /* opt */ false, + /* default_val */ "", "The transaction id"}, + {"n", RPCArg::Type::NUM, /* opt */ false, + /* default_val */ "", "vout number"}, + {"include_mempool", RPCArg::Type::BOOL, /* opt */ true, + /* default_val */ "true", + "Whether to include the mempool. Note that an unspent " + "output that is spent in the mempool won't appear."}, + }, + RPCResult{ + "{\n" + " \"bestblock\" : \"hash\", (string) the block hash\n" + " \"confirmations\" : n, (numeric) The number of " + "confirmations\n" + " \"value\" : x.xxx, (numeric) The transaction " + "value " + "in " + + CURRENCY_UNIT + + "\n" + " \"scriptPubKey\" : { (json object)\n" + " \"asm\" : \"code\", (string) \n" + " \"hex\" : \"hex\", (string) \n" + " \"reqSigs\" : n, (numeric) Number of required " + "signatures\n" + " \"type\" : \"pubkeyhash\", (string) The type, eg " + "pubkeyhash\n" + " \"addresses\" : [ (array of string) array of " + "bitcoin addresses\n" + " \"address\" (string) bitcoin address\n" + " ,...\n" + " ]\n" + " },\n" + " \"coinbase\" : true|false (boolean) Coinbase or not\n" + "}\n"}, + RPCExamples{"\nGet unspent transactions\n" + + HelpExampleCli("listunspent", "") + + "\nView the details\n" + + HelpExampleCli("gettxout", "\"txid\" 1") + + "\nAs a JSON-RPC call\n" + + HelpExampleRpc("gettxout", "\"txid\", 1")}, + } + .ToString()); } LOCK(cs_main); @@ -1312,24 +1349,22 @@ int nCheckLevel = gArgs.GetArg("-checklevel", DEFAULT_CHECKLEVEL); int nCheckDepth = gArgs.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS); if (request.fHelp || request.params.size() > 2) { - throw std::runtime_error( - RPCHelpMan{ - "verifychain", - "\nVerifies blockchain database.\n", - { - {"checklevel", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ strprintf("%d, range=0-4", nCheckLevel), - "How thorough the block verification is."}, - {"nblocks", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ strprintf("%d, 0=all", nCheckDepth), - "The number of blocks to check."}, - }} - .ToString() + - "\nResult:\n" - "true|false (boolean) Verified or not\n" - "\nExamples:\n" + - HelpExampleCli("verifychain", "") + - HelpExampleRpc("verifychain", "")); + throw std::runtime_error(RPCHelpMan{ + "verifychain", + "\nVerifies blockchain database.\n", + { + {"checklevel", RPCArg::Type::NUM, /* opt */ true, + /* default_val */ strprintf("%d, range=0-4", nCheckLevel), + "How thorough the block verification is."}, + {"nblocks", RPCArg::Type::NUM, /* opt */ true, + /* default_val */ strprintf("%d, 0=all", nCheckDepth), + "The number of blocks to check."}, + }, + RPCResult{"true|false (boolean) Verified or not\n"}, + RPCExamples{HelpExampleCli("verifychain", "") + + HelpExampleRpc("verifychain", "")}, + } + .ToString()); } LOCK(cs_main); @@ -1410,48 +1445,56 @@ UniValue getblockchaininfo(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 0) { - throw std::runtime_error( - RPCHelpMan{"getblockchaininfo", - "Returns an object containing various state info " - "regarding blockchain processing.\n", - {}} - .ToString() + - "\nResult:\n" - "{\n" - " \"chain\": \"xxxx\", (string) current network name " - "as defined in BIP70 (main, test, regtest)\n" - " \"blocks\": xxxxxx, (numeric) the current number of " - "blocks processed in the server\n" - " \"headers\": xxxxxx, (numeric) the current number of " - "headers we have validated\n" - " \"bestblockhash\": \"...\", (string) the hash of the " - "currently best block\n" - " \"difficulty\": xxxxxx, (numeric) the current " - "difficulty\n" - " \"mediantime\": xxxxxx, (numeric) median time for the " - "current best block\n" - " \"verificationprogress\": xxxx, (numeric) estimate of " - "verification progress [0..1]\n" - " \"initialblockdownload\": xxxx, (bool) (debug information) " - "estimate of whether this node is in Initial Block Download mode.\n" - " \"chainwork\": \"xxxx\" (string) total amount of work " - "in active chain, in hexadecimal\n" - " \"size_on_disk\": xxxxxx, (numeric) the estimated size of " - "the block and undo files on disk\n" - " \"pruned\": xx, (boolean) if the blocks are " - "subject to pruning\n" - " \"pruneheight\": xxxxxx, (numeric) lowest-height " - "complete block stored (only present if pruning is enabled)\n" - " \"automatic_pruning\": xx, (boolean) whether automatic " - "pruning is enabled (only present if pruning is enabled)\n" - " \"prune_target_size\": xxxxxx, (numeric) the target size " - "used by pruning (only present if automatic pruning is enabled)\n" - " \"warnings\" : \"...\", (string) any network and " - "blockchain warnings.\n" - "}\n" - "\nExamples:\n" + - HelpExampleCli("getblockchaininfo", "") + - HelpExampleRpc("getblockchaininfo", "")); + throw std::runtime_error(RPCHelpMan{ + "getblockchaininfo", + "Returns an object containing various state info " + "regarding blockchain processing.\n", + {}, + RPCResult{ + "{\n" + " \"chain\": \"xxxx\", (string) current network " + "name " + "as defined in BIP70 (main, test, regtest)\n" + " \"blocks\": xxxxxx, (numeric) the current " + "number of " + "blocks processed in the server\n" + " \"headers\": xxxxxx, (numeric) the current " + "number of " + "headers we have validated\n" + " \"bestblockhash\": \"...\", (string) the hash of the " + "currently best block\n" + " \"difficulty\": xxxxxx, (numeric) the current " + "difficulty\n" + " \"mediantime\": xxxxxx, (numeric) median time for " + "the " + "current best block\n" + " \"verificationprogress\": xxxx, (numeric) estimate of " + "verification progress [0..1]\n" + " \"initialblockdownload\": xxxx, (bool) (debug information) " + "estimate of whether this node is in Initial Block Download " + "mode.\n" + " \"chainwork\": \"xxxx\" (string) total amount of " + "work " + "in active chain, in hexadecimal\n" + " \"size_on_disk\": xxxxxx, (numeric) the estimated " + "size of " + "the block and undo files on disk\n" + " \"pruned\": xx, (boolean) if the blocks are " + "subject to pruning\n" + " \"pruneheight\": xxxxxx, (numeric) lowest-height " + "complete block stored (only present if pruning is enabled)\n" + " \"automatic_pruning\": xx, (boolean) whether automatic " + "pruning is enabled (only present if pruning is enabled)\n" + " \"prune_target_size\": xxxxxx, (numeric) the target size " + "used by pruning (only present if automatic pruning is " + "enabled)\n" + " \"warnings\" : \"...\", (string) any network and " + "blockchain warnings.\n" + "}\n"}, + RPCExamples{HelpExampleCli("getblockchaininfo", "") + + HelpExampleRpc("getblockchaininfo", "")}, + } + .ToString()); } LOCK(cs_main); @@ -1517,47 +1560,54 @@ static UniValue getchaintips(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 0) { - throw std::runtime_error( - RPCHelpMan{ - "getchaintips", - "Return information about all known tips in the block tree, " - "including the main chain as well as orphaned branches.\n", - {}} - .ToString() + - "\nResult:\n" - "[\n" - " {\n" - " \"height\": xxxx, (numeric) height of the chain tip\n" - " \"hash\": \"xxxx\", (string) block hash of the tip\n" - " \"branchlen\": 0 (numeric) zero for main chain\n" - " \"status\": \"active\" (string) \"active\" for the main " - "chain\n" - " },\n" - " {\n" - " \"height\": xxxx,\n" - " \"hash\": \"xxxx\",\n" - " \"branchlen\": 1 (numeric) length of branch " - "connecting the tip to the main chain\n" - " \"status\": \"xxxx\" (string) status of the chain " - "(active, valid-fork, valid-headers, headers-only, invalid)\n" - " }\n" - "]\n" - "Possible values for status:\n" - "1. \"invalid\" This branch contains at least one " - "invalid block\n" - "2. \"parked\" This branch contains at least one " - "parked block\n" - "3. \"headers-only\" Not all blocks for this branch are " - "available, but the headers are valid\n" - "4. \"valid-headers\" All blocks are available for this " - "branch, but they were never fully validated\n" - "5. \"valid-fork\" This branch is not part of the " - "active chain, but is fully validated\n" - "6. \"active\" This is the tip of the active main " - "chain, which is certainly valid\n" - "\nExamples:\n" + - HelpExampleCli("getchaintips", "") + - HelpExampleRpc("getchaintips", "")); + throw std::runtime_error(RPCHelpMan{ + "getchaintips", + "Return information about all known tips in the block tree, " + "including the main chain as well as orphaned branches.\n", + {}, + RPCResult{ + "[\n" + " {\n" + " \"height\": xxxx, (numeric) height of the chain " + "tip\n" + " \"hash\": \"xxxx\", (string) block hash of the " + "tip\n" + " \"branchlen\": 0 (numeric) zero for main chain\n" + " \"status\": \"active\" (string) \"active\" for the " + "main " + "chain\n" + " },\n" + " {\n" + " \"height\": xxxx,\n" + " \"hash\": \"xxxx\",\n" + " \"branchlen\": 1 (numeric) length of branch " + "connecting the tip to the main chain\n" + " \"status\": \"xxxx\" (string) status of the chain " + "(active, valid-fork, valid-headers, headers-only, invalid)\n" + " }\n" + "]\n" + "Possible values for status:\n" + "1. \"invalid\" This branch contains at least " + "one " + "invalid block\n" + "2. \"parked\" This branch contains at least " + "one " + "parked block\n" + "3. \"headers-only\" Not all blocks for this branch " + "are " + "available, but the headers are valid\n" + "4. \"valid-headers\" All blocks are available for " + "this " + "branch, but they were never fully validated\n" + "5. \"valid-fork\" This branch is not part of the " + "active chain, but is fully validated\n" + "6. \"active\" This is the tip of the active " + "main " + "chain, which is certainly valid\n"}, + RPCExamples{HelpExampleCli("getchaintips", "") + + HelpExampleRpc("getchaintips", "")}, + } + .ToString()); } LOCK(cs_main); @@ -1660,32 +1710,38 @@ static UniValue getmempoolinfo(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 0) { - throw std::runtime_error( - RPCHelpMan{"getmempoolinfo", - "\nReturns details on the active state of the TX memory " - "pool.\n", - {}} - .ToString() + - "\nResult:\n" - "{\n" - " \"loaded\": true|false (boolean) True if the mempool is " - "fully loaded\n" - " \"size\": xxxxx, (numeric) Current tx count\n" - " \"bytes\": xxxxx, (numeric) Transaction size.\n" - " \"usage\": xxxxx, (numeric) Total memory usage for " - "the mempool\n" - " \"maxmempool\": xxxxx, (numeric) Maximum memory usage " - "for the mempool\n" - " \"mempoolminfee\": xxxxx (numeric) Minimum fee rate in " + - CURRENCY_UNIT + - "/kB for tx to be accepted. Is the maximum of minrelaytxfee and " - "minimum mempool fee\n" - " \"minrelaytxfee\": xxxxx (numeric) Current minimum relay " - "fee for transactions\n" - "}\n" - "\nExamples:\n" + - HelpExampleCli("getmempoolinfo", "") + - HelpExampleRpc("getmempoolinfo", "")); + throw std::runtime_error(RPCHelpMan{ + "getmempoolinfo", + "\nReturns details on the active state of the TX memory " + "pool.\n", + {}, + RPCResult{ + "{\n" + " \"loaded\": true|false (boolean) True if the " + "mempool is " + "fully loaded\n" + " \"size\": xxxxx, (numeric) Current tx count\n" + " \"bytes\": xxxxx, (numeric) Transaction size.\n" + " \"usage\": xxxxx, (numeric) Total memory usage " + "for " + "the mempool\n" + " \"maxmempool\": xxxxx, (numeric) Maximum memory " + "usage " + "for the mempool\n" + " \"mempoolminfee\": xxxxx (numeric) Minimum fee rate " + "in " + + CURRENCY_UNIT + + "/kB for tx to be accepted. Is the maximum of minrelaytxfee " + "and " + "minimum mempool fee\n" + " \"minrelaytxfee\": xxxxx (numeric) Current minimum " + "relay " + "fee for transactions\n" + "}\n"}, + RPCExamples{HelpExampleCli("getmempoolinfo", "") + + HelpExampleRpc("getmempoolinfo", "")}, + } + .ToString()); } return MempoolInfoToJSON(::g_mempool); @@ -1694,24 +1750,24 @@ static UniValue preciousblock(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{"preciousblock", - "\nTreats a block as if it were received before others " - "with the same work.\n" - "\nA later preciousblock call can override the effect " - "of an earlier one.\n" - "\nThe effects of preciousblock are not retained across " - "restarts.\n", - { - {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", - "the hash of the block to mark as precious"}, - }} - .ToString() + - "\nResult:\n" - "\nExamples:\n" + - HelpExampleCli("preciousblock", "\"blockhash\"") + - HelpExampleRpc("preciousblock", "\"blockhash\"")); + throw std::runtime_error(RPCHelpMan{ + "preciousblock", + "\nTreats a block as if it were received before others " + "with the same work.\n" + "\nA later preciousblock call can override the effect " + "of an earlier one.\n" + "\nThe effects of preciousblock are not retained across " + "restarts.\n", + { + {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, + /* default_val */ "", + "the hash of the block to mark as precious"}, + }, + RPCResults{}, + RPCExamples{HelpExampleCli("preciousblock", "\"blockhash\"") + + HelpExampleRpc("preciousblock", "\"blockhash\"")}, + } + .ToString()); } BlockHash hash(ParseHashV(request.params[0], "blockhash")); @@ -1737,23 +1793,22 @@ UniValue finalizeblock(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{ - "finalizeblock", - "\nTreats a block as final. It cannot be reorged. Any chain\n" - "that does not contain this block is invalid. Used on a less\n" - "work chain, it can effectively PUTS YOU OUT OF CONSENSUS.\n" - "USE WITH CAUTION!\n", - { - {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", - "the hash of the block to mark as invalid"}, - }} - .ToString() + - "\nResult:\n" - "\nExamples:\n" + - HelpExampleCli("finalizeblock", "\"blockhash\"") + - HelpExampleRpc("finalizeblock", "\"blockhash\"")); + throw std::runtime_error(RPCHelpMan{ + "finalizeblock", + "\nTreats a block as final. It cannot be reorged. Any chain\n" + "that does not contain this block is invalid. Used on a less\n" + "work chain, it can effectively PUTS YOU OUT OF CONSENSUS.\n" + "USE WITH CAUTION!\n", + { + {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, + /* default_val */ "", + "the hash of the block to mark as invalid"}, + }, + RPCResults{}, + RPCExamples{HelpExampleCli("invalidateblock", "\"blockhash\"") + + HelpExampleRpc("invalidateblock", "\"blockhash\"")}, + } + .ToString()); } std::string strHash = request.params[0].get_str(); @@ -1784,20 +1839,20 @@ static UniValue invalidateblock(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{"invalidateblock", - "\nPermanently marks a block as invalid, as if it " - "violated a consensus rule.\n", - { - {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", - "the hash of the block to mark as invalid"}, - }} - .ToString() + - "\nResult:\n" - "\nExamples:\n" + - HelpExampleCli("invalidateblock", "\"blockhash\"") + - HelpExampleRpc("invalidateblock", "\"blockhash\"")); + throw std::runtime_error(RPCHelpMan{ + "invalidateblock", + "\nPermanently marks a block as invalid, as if it " + "violated a consensus rule.\n", + { + {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, + /* default_val */ "", + "the hash of the block to mark as invalid"}, + }, + RPCResults{}, + RPCExamples{HelpExampleCli("invalidateblock", "\"blockhash\"") + + HelpExampleRpc("invalidateblock", "\"blockhash\"")}, + } + .ToString()); } const BlockHash hash(ParseHashV(request.params[0], "blockhash")); @@ -1826,19 +1881,18 @@ UniValue parkblock(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{ - "parkblock", - "\nMarks a block as parked.\n", - { - {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "the hash of the block to park"}, - }} - .ToString() + - "\nResult:\n" - "\nExamples:\n" + - HelpExampleCli("parkblock", "\"blockhash\"") + - HelpExampleRpc("parkblock", "\"blockhash\"")); + throw std::runtime_error(RPCHelpMan{ + "parkblock", + "\nMarks a block as parked.\n", + { + {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, + /* default_val */ "", "the hash of the block to park"}, + }, + RPCResults{}, + RPCExamples{HelpExampleCli("parkblock", "\"blockhash\"") + + HelpExampleRpc("parkblock", "\"blockhash\"")}, + } + .ToString()); } const std::string strHash = request.params[0].get_str(); @@ -1870,22 +1924,20 @@ static UniValue reconsiderblock(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{ - "reconsiderblock", - "\nRemoves invalidity status of a block and its descendants, " - "reconsider them for activation.\n" - "This can be used to undo the effects of invalidateblock.\n", - { - {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", - "the hash of the block to reconsider"}, - }} - .ToString() + - "\nResult:\n" - "\nExamples:\n" + - HelpExampleCli("reconsiderblock", "\"blockhash\"") + - HelpExampleRpc("reconsiderblock", "\"blockhash\"")); + throw std::runtime_error(RPCHelpMan{ + "reconsiderblock", + "\nRemoves invalidity status of a block and its descendants, " + "reconsider them for activation.\n" + "This can be used to undo the effects of invalidateblock.\n", + { + {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, + /* default_val */ "", "the hash of the block to reconsider"}, + }, + RPCResults{}, + RPCExamples{HelpExampleCli("reconsiderblock", "\"blockhash\"") + + HelpExampleRpc("reconsiderblock", "\"blockhash\"")}, + } + .ToString()); } const BlockHash hash(ParseHashV(request.params[0], "blockhash")); @@ -1912,21 +1964,20 @@ UniValue unparkblock(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{ - "unparkblock", - "\nRemoves parked status of a block and its descendants, " - "reconsider them for activation.\n" - "This can be used to undo the effects of parkblock.\n", - { - {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "the hash of the block to unpark"}, - }} - .ToString() + - "\nResult:\n" - "\nExamples:\n" + - HelpExampleCli("unparkblock", "\"blockhash\"") + - HelpExampleRpc("unparkblock", "\"blockhash\"")); + throw std::runtime_error(RPCHelpMan{ + "unparkblock", + "\nRemoves parked status of a block and its descendants, " + "reconsider them for activation.\n" + "This can be used to undo the effects of parkblock.\n", + { + {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, + /* default_val */ "", "the hash of the block to unpark"}, + }, + RPCResults{}, + RPCExamples{HelpExampleCli("unparkblock", "\"blockhash\"") + + HelpExampleRpc("unparkblock", "\"blockhash\"")}, + } + .ToString()); } const std::string strHash = request.params[0].get_str(); @@ -1955,42 +2006,48 @@ static UniValue getchaintxstats(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() > 2) { - throw std::runtime_error( - RPCHelpMan{"getchaintxstats", - "\nCompute statistics about the total number and rate " - "of transactions in the chain.\n", - { - {"nblocks", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "one month", - "Size of the window in number of blocks"}, - {"blockhash", RPCArg::Type::STR_HEX, /* opt */ true, - /* default_val */ "", - "The hash of the block that ends the window."}, - }} - .ToString() + - "\nResult:\n" - "{\n" - " \"time\": xxxxx, (numeric) The " - "timestamp for the final block in the window in UNIX format.\n" - " \"txcount\": xxxxx, (numeric) The total " - "number of transactions in the chain up to that point.\n" - " \"window_final_block_hash\": \"...\", (string) The hash of " - "the final block in the window.\n" - " \"window_block_count\": xxxxx, (numeric) Size of " - "the window in number of blocks.\n" - " \"window_tx_count\": xxxxx, (numeric) The number " - "of transactions in the window. Only returned if " - "\"window_block_count\" is > 0.\n" - " \"window_interval\": xxxxx, (numeric) The elapsed " - "time in the window in seconds. Only returned if " - "\"window_block_count\" is > 0.\n" - " \"txrate\": x.xx, (numeric) The average " - "rate of transactions per second in the window. Only returned if " - "\"window_interval\" is > 0.\n" - "}\n" - "\nExamples:\n" + - HelpExampleCli("getchaintxstats", "") + - HelpExampleRpc("getchaintxstats", "2016")); + throw std::runtime_error(RPCHelpMan{ + "getchaintxstats", + "\nCompute statistics about the total number and rate " + "of transactions in the chain.\n", + { + {"nblocks", RPCArg::Type::NUM, /* opt */ true, + /* default_val */ "one month", + "Size of the window in number of blocks"}, + {"blockhash", RPCArg::Type::STR_HEX, /* opt */ true, + /* default_val */ "chain tip", + "The hash of the block that ends the window."}, + }, + RPCResult{ + "{\n" + " \"time\": xxxxx, (numeric) The " + "timestamp for the final block in the window in UNIX format.\n" + " \"txcount\": xxxxx, (numeric) The " + "total " + "number of transactions in the chain up to that point.\n" + " \"window_final_block_hash\": \"...\", (string) The " + "hash of " + "the final block in the window.\n" + " \"window_block_count\": xxxxx, (numeric) Size of " + "the window in number of blocks.\n" + " \"window_tx_count\": xxxxx, (numeric) The " + "number " + "of transactions in the window. Only returned if " + "\"window_block_count\" is > 0.\n" + " \"window_interval\": xxxxx, (numeric) The " + "elapsed " + "time in the window in seconds. Only returned if " + "\"window_block_count\" is > 0.\n" + " \"txrate\": x.xx, (numeric) The " + "average " + "rate of transactions per second in the window. Only returned " + "if " + "\"window_interval\" is > 0.\n" + "}\n"}, + RPCExamples{HelpExampleCli("getchaintxstats", "") + + HelpExampleRpc("getchaintxstats", "2016")}, + } + .ToString()); } const CBlockIndex *pindex; @@ -2084,91 +2141,105 @@ const JSONRPCRequest &request) { if (request.fHelp || request.params.size() < 1 || request.params.size() > 4) { - throw std::runtime_error( - RPCHelpMan{ - "getblockstats", - "\nCompute per block statistics for a given window. All " - "amounts are in " + - CURRENCY_UNIT + - ".\n" - "It won't work for some heights with pruning.\n" - "It won't work without -txindex for utxo_size_inc, *fee or " - "*feerate stats.\n", - { - {"hash_or_height", - RPCArg::Type::NUM, - /* opt */ false, - /* default_val */ "", - "The block hash or height of the target block", - "", - {"", "string or numeric"}}, - {"stats", - RPCArg::Type::ARR, - /* opt */ true, - /* default_val */ "", - "Values to plot, by default all values (see result below)", - { - {"height", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "", "Selected statistic"}, - {"time", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "", "Selected statistic"}, - }, - "stats"}, - }} - .ToString() + - "\nResult:\n" - "{ (json object)\n" - " \"avgfee\": x.xxx, (numeric) Average fee in the block\n" - " \"avgfeerate\": x.xxx, (numeric) Average feerate (in " + - CURRENCY_UNIT + - " per byte)\n" - " \"avgtxsize\": xxxxx, (numeric) Average transaction size\n" - " \"blockhash\": xxxxx, (string) The block hash (to check " - "for potential reorgs)\n" - " \"height\": xxxxx, (numeric) The height of the block\n" - " \"ins\": xxxxx, (numeric) The number of inputs " - "(excluding coinbase)\n" - " \"maxfee\": xxxxx, (numeric) Maximum fee in the block\n" - " \"maxfeerate\": xxxxx, (numeric) Maximum feerate (in " + - CURRENCY_UNIT + - " per byte)\n" - " \"maxtxsize\": xxxxx, (numeric) Maximum transaction size\n" - " \"medianfee\": x.xxx, (numeric) Truncated median fee in " - "the block\n" - " \"medianfeerate\": x.xxx, (numeric) Truncated median feerate " - "(in " + - CURRENCY_UNIT + - " per byte)\n" - " \"mediantime\": xxxxx, (numeric) The block median time " - "past\n" - " \"mediantxsize\": xxxxx, (numeric) Truncated median " - "transaction size\n" - " \"minfee\": x.xxx, (numeric) Minimum fee in the block\n" - " \"minfeerate\": xx.xx, (numeric) Minimum feerate (in " + - CURRENCY_UNIT + - " per byte)\n" - " \"mintxsize\": xxxxx, (numeric) Minimum transaction size\n" - " \"outs\": xxxxx, (numeric) The number of outputs\n" - " \"subsidy\": x.xxx, (numeric) The block subsidy\n" - " \"time\": xxxxx, (numeric) The block time\n" - " \"total_out\": x.xxx, (numeric) Total amount in all " - "outputs (excluding coinbase and thus reward [ie subsidy + " - "totalfee])\n" - " \"total_size\": xxxxx, (numeric) Total size of all " - "non-coinbase transactions\n" - " \"totalfee\": x.xxx, (numeric) The fee total\n" - " \"txs\": xxxxx, (numeric) The number of " - "transactions (excluding coinbase)\n" - " \"utxo_increase\": xxxxx, (numeric) The increase/decrease in " - "the number of unspent outputs\n" - " \"utxo_size_inc\": xxxxx, (numeric) The increase/decrease in " - "size for the utxo index (not discounting op_return and similar)\n" - "}\n" - "\nExamples:\n" + - HelpExampleCli("getblockstats", - "1000 '[\"minfeerate\",\"avgfeerate\"]'") + - HelpExampleRpc("getblockstats", - "1000 '[\"minfeerate\",\"avgfeerate\"]'")); + throw std::runtime_error(RPCHelpMan{ + "getblockstats", + "\nCompute per block statistics for a given window. All " + "amounts are in " + + CURRENCY_UNIT + + ".\n" + "It won't work for some heights with pruning.\n" + "It won't work without -txindex for utxo_size_inc, *fee or " + "*feerate stats.\n", + { + {"hash_or_height", + RPCArg::Type::NUM, + /* opt */ false, + /* default_val */ "", + "The block hash or height of the target block", + "", + {"", "string or numeric"}}, + {"stats", + RPCArg::Type::ARR, + /* opt */ true, + /* default_val */ "", + "Values to plot, by default all values (see result below)", + { + {"height", RPCArg::Type::STR, /* opt */ true, + /* default_val */ "", "Selected statistic"}, + {"time", RPCArg::Type::STR, /* opt */ true, + /* default_val */ "", "Selected statistic"}, + }, + "stats"}, + }, + RPCResult{ + "{ (json object)\n" + " \"avgfee\": x.xxx, (numeric) Average fee in the " + "block\n" + " \"avgfeerate\": x.xxx, (numeric) Average feerate (in " + + CURRENCY_UNIT + + " per byte)\n" + " \"avgtxsize\": xxxxx, (numeric) Average transaction " + "size\n" + " \"blockhash\": xxxxx, (string) The block hash (to " + "check " + "for potential reorgs)\n" + " \"height\": xxxxx, (numeric) The height of the " + "block\n" + " \"ins\": xxxxx, (numeric) The number of inputs " + "(excluding coinbase)\n" + " \"maxfee\": xxxxx, (numeric) Maximum fee in the " + "block\n" + " \"maxfeerate\": xxxxx, (numeric) Maximum feerate (in " + + CURRENCY_UNIT + + " per byte)\n" + " \"maxtxsize\": xxxxx, (numeric) Maximum transaction " + "size\n" + " \"medianfee\": x.xxx, (numeric) Truncated median fee " + "in " + "the block\n" + " \"medianfeerate\": x.xxx, (numeric) Truncated median " + "feerate " + "(in " + + CURRENCY_UNIT + + " per byte)\n" + " \"mediantime\": xxxxx, (numeric) The block median time " + "past\n" + " \"mediantxsize\": xxxxx, (numeric) Truncated median " + "transaction size\n" + " \"minfee\": x.xxx, (numeric) Minimum fee in the " + "block\n" + " \"minfeerate\": xx.xx, (numeric) Minimum feerate (in " + + CURRENCY_UNIT + + " per byte)\n" + " \"mintxsize\": xxxxx, (numeric) Minimum transaction " + "size\n" + " \"outs\": xxxxx, (numeric) The number of " + "outputs\n" + " \"subsidy\": x.xxx, (numeric) The block subsidy\n" + " \"time\": xxxxx, (numeric) The block time\n" + " \"total_out\": x.xxx, (numeric) Total amount in all " + "outputs (excluding coinbase and thus reward [ie subsidy + " + "totalfee])\n" + " \"total_size\": xxxxx, (numeric) Total size of all " + "non-coinbase transactions\n" + " \"totalfee\": x.xxx, (numeric) The fee total\n" + " \"txs\": xxxxx, (numeric) The number of " + "transactions (excluding coinbase)\n" + " \"utxo_increase\": xxxxx, (numeric) The increase/decrease " + "in " + "the number of unspent outputs\n" + " \"utxo_size_inc\": xxxxx, (numeric) The increase/decrease " + "in " + "size for the utxo index (not discounting op_return and " + "similar)\n" + "}\n"}, + RPCExamples{ + HelpExampleCli("getblockstats", + "1000 '[\"minfeerate\",\"avgfeerate\"]'") + + HelpExampleRpc("getblockstats", + "1000 '[\"minfeerate\",\"avgfeerate\"]'")}, + } + .ToString()); } LOCK(cs_main); @@ -2385,14 +2456,16 @@ static UniValue savemempool(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 0) { - throw std::runtime_error( - RPCHelpMan{"savemempool", - "\nDumps the mempool to disk. It will fail until the " - "previous dump is fully loaded.\n", - {}} - .ToString() + - "\nExamples:\n" + HelpExampleCli("savemempool", "") + - HelpExampleRpc("savemempool", "")); + throw std::runtime_error(RPCHelpMan{ + "savemempool", + "\nDumps the mempool to disk. It will fail until the " + "previous dump is fully loaded.\n", + {}, + RPCResults{}, + RPCExamples{HelpExampleCli("savemempool", "") + + HelpExampleRpc("savemempool", "")}, + } + .ToString()); } if (!::g_mempool.IsLoaded()) { @@ -2477,97 +2550,102 @@ const JSONRPCRequest &request) { if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) { - throw std::runtime_error( - RPCHelpMan{ - "scantxoutset", - "\nEXPERIMENTAL warning: this call may be removed or changed " - "in future releases.\n" - "\nScans the unspent transaction output set for entries that " - "match certain output descriptors.\n" - "Examples of output descriptors are:\n" - " addr(
) Outputs whose " - "scriptPubKey corresponds to the specified address does not " - "include P2PK)\n" - " raw() Outputs whose " - "scriptPubKey equals the specified hex scripts\n" - " combo() P2PK and P2PKH " - "outputs for the given pubkey\n" - " pkh() P2PKH outputs for " - "the given pubkey\n" - " sh(multi(,,,...)) P2SH-multisig " - "outputs for the given threshold and pubkeys\n" - "\nIn the above, either refers to a fixed public key " - "in hexadecimal notation, or to an xpub/xprv optionally " - "followed by one\n" - "or more path elements separated by \"/\", and optionally " - "ending in \"/*\" (unhardened), or \"/*'\" or \"/*h\" " - "(hardened) to specify all\n" - "unhardened or hardened child keys.\n" - "In the latter case, a range needs to be specified by below if " - "different from 1000.\n" - "For more information on output descriptors, see the " - "documentation in the doc/descriptors.md file.\n", - { - {"action", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", - "The action to execute\n" - " \"start\" for " - "starting a scan\n" - " \"abort\" for " - "aborting the current scan (returns true when abort was " - "successful)\n" - " \"status\" for " - "progress report (in %) of the current scan"}, - {"scanobjects", - RPCArg::Type::ARR, - /* opt */ false, - /* default_val */ "", - "Array of scan objects\n" - " Every scan object is " - "either a string descriptor or an object:", + throw std::runtime_error(RPCHelpMan{ + "scantxoutset", + "\nEXPERIMENTAL warning: this call may be removed or changed " + "in future releases.\n" + "\nScans the unspent transaction output set for entries that " + "match certain output descriptors.\n" + "Examples of output descriptors are:\n" + " addr(
) Outputs whose " + "scriptPubKey corresponds to the specified address does not " + "include P2PK)\n" + " raw() Outputs whose " + "scriptPubKey equals the specified hex scripts\n" + " combo() P2PK and P2PKH " + "outputs for the given pubkey\n" + " pkh() P2PKH outputs for " + "the given pubkey\n" + " sh(multi(,,,...)) P2SH-multisig " + "outputs for the given threshold and pubkeys\n" + "\nIn the above, either refers to a fixed public key " + "in hexadecimal notation, or to an xpub/xprv optionally " + "followed by one\n" + "or more path elements separated by \"/\", and optionally " + "ending in \"/*\" (unhardened), or \"/*'\" or \"/*h\" " + "(hardened) to specify all\n" + "unhardened or hardened child keys.\n" + "In the latter case, a range needs to be specified by below if " + "different from 1000.\n" + "For more information on output descriptors, see the " + "documentation in the doc/descriptors.md file.\n", + { + {"action", RPCArg::Type::STR, /* opt */ false, + /* default_val */ "", + "The action to execute\n" + " \"start\" for " + "starting a scan\n" + " \"abort\" for " + "aborting the current scan (returns true when abort was " + "successful)\n" + " \"status\" for " + "progress report (in %) of the current scan"}, + {"scanobjects", + RPCArg::Type::ARR, + /* opt */ false, + /* default_val */ "", + "Array of scan objects\n" + " Every scan object is " + "either a string descriptor or an object:", + { + {"descriptor", RPCArg::Type::STR, /* opt */ true, + /* default_val */ "", "An output descriptor"}, { - {"descriptor", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "", "An output descriptor"}, + "", + RPCArg::Type::OBJ, + /* opt */ true, + /* default_val */ "", + "An object with output descriptor and metadata", { - "", - RPCArg::Type::OBJ, - /* opt */ true, - /* default_val */ "", - "An object with output descriptor and metadata", - { - {"desc", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "An output descriptor"}, - {"range", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "1000", - "Up to what child index HD chains should be " - "explored"}, - }, + {"desc", RPCArg::Type::STR, /* opt */ false, + /* default_val */ "", "An output descriptor"}, + {"range", RPCArg::Type::NUM, /* opt */ true, + /* default_val */ "1000", + "Up to what child index HD chains should be " + "explored"}, }, }, - "[scanobjects,...]"}, - }} - .ToString() + - "\nResult:\n" - "{\n" - " \"unspents\": [\n" - " {\n" - " \"txid\" : \"transactionid\", (string) The transaction " - "id\n" - " \"vout\": n, (numeric) the vout value\n" - " \"scriptPubKey\" : \"script\", (string) the script key\n" - " \"amount\" : x.xxx, (numeric) The total amount " - "in " + - CURRENCY_UNIT + - " of the unspent output\n" - " \"height\" : n, (numeric) Height of the " - "unspent transaction output\n" - " }\n" - " ,...], \n" - " \"total_amount\" : x.xxx, (numeric) The total amount of " - "all found unspent outputs in " + - CURRENCY_UNIT + - "\n" - "]\n"); + }, + "[scanobjects,...]"}, + }, + RPCResult{ + "{\n" + " \"unspents\": [\n" + " {\n" + " \"txid\" : \"transactionid\", (string) The " + "transaction " + "id\n" + " \"vout\": n, (numeric) the vout value\n" + " \"scriptPubKey\" : \"script\", (string) the script " + "key\n" + " \"amount\" : x.xxx, (numeric) The total " + "amount " + "in " + + CURRENCY_UNIT + + " of the unspent output\n" + " \"height\" : n, (numeric) Height of the " + "unspent transaction output\n" + " }\n" + " ,...], \n" + " \"total_amount\" : x.xxx, (numeric) The total " + "amount of " + "all found unspent outputs in " + + CURRENCY_UNIT + + "\n" + "]\n"}, + RPCExamples{""}, + } + .ToString()); } RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VARR}); diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -87,29 +87,28 @@ static UniValue getnetworkhashps(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() > 2) { - throw std::runtime_error( - RPCHelpMan{"getnetworkhashps", - "\nReturns the estimated network hashes per second " - "based on the last n blocks.\n" - "Pass in [blocks] to override # of blocks, -1 specifies " - "since last difficulty change.\n" - "Pass in [height] to estimate the network speed at the " - "time when a certain block was found.\n", - { - {"nblocks", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "120", - "The number of blocks, or -1 for blocks since last " - "difficulty change."}, - {"height", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "-1", - "To estimate at the time of the given height."}, - }} - .ToString() + - "\nResult:\n" - "x (numeric) Hashes per second estimated\n" - "\nExamples:\n" + - HelpExampleCli("getnetworkhashps", "") + - HelpExampleRpc("getnetworkhashps", "")); + throw std::runtime_error(RPCHelpMan{ + "getnetworkhashps", + "\nReturns the estimated network hashes per second " + "based on the last n blocks.\n" + "Pass in [blocks] to override # of blocks, -1 specifies " + "since last difficulty change.\n" + "Pass in [height] to estimate the network speed at the " + "time when a certain block was found.\n", + { + {"nblocks", RPCArg::Type::NUM, /* opt */ true, + /* default_val */ "120", + "The number of blocks, or -1 for blocks since last " + "difficulty change."}, + {"height", RPCArg::Type::NUM, /* opt */ true, + /* default_val */ "-1", + "To estimate at the time of the given height."}, + }, + RPCResult{"x (numeric) Hashes per second estimated\n"}, + RPCExamples{HelpExampleCli("getnetworkhashps", "") + + HelpExampleRpc("getnetworkhashps", "")}, + } + .ToString()); } LOCK(cs_main); @@ -189,28 +188,30 @@ const JSONRPCRequest &request) { if (request.fHelp || request.params.size() < 2 || request.params.size() > 3) { - throw std::runtime_error( - RPCHelpMan{ - "generatetoaddress", - "\nMine blocks immediately to a specified address before the " - "RPC call returns)\n", - { - {"nblocks", RPCArg::Type::NUM, /* opt */ false, - /* default_val */ "", - "How many blocks are generated immediately."}, - {"address", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", - "The address to send the newly generated bitcoin to."}, - {"maxtries", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "1000000", - "How many iterations to try."}, - }} - .ToString() + - "\nResult:\n" - "[ blockhashes ] (array) hashes of blocks generated\n" - "\nExamples:\n" - "\nGenerate 11 blocks to myaddress\n" + - HelpExampleCli("generatetoaddress", "11 \"myaddress\"")); + throw std::runtime_error(RPCHelpMan{ + "generatetoaddress", + "\nMine blocks immediately to a specified address before the " + "RPC call returns)\n", + { + {"nblocks", RPCArg::Type::NUM, /* opt */ false, + /* default_val */ "", + "How many blocks are generated immediately."}, + {"address", RPCArg::Type::STR, /* opt */ false, + /* default_val */ "", + "The address to send the newly generated bitcoin to."}, + {"maxtries", RPCArg::Type::NUM, /* opt */ true, + /* default_val */ "1000000", "How many iterations to try."}, + }, + RPCResult{ + "[ blockhashes ] (array) hashes of blocks generated\n"}, + RPCExamples{ + "\nGenerate 11 blocks to myaddress\n" + + HelpExampleCli("generatetoaddress", "11 \"myaddress\"") + + "If you are running the bitcoin core wallet, you can get a new " + "address to send the newly generated bitcoin to with:\n" + + HelpExampleCli("getnewaddress", "")}, + } + .ToString()); } int nGenerate = request.params[0].get_int(); @@ -236,30 +237,34 @@ static UniValue getmininginfo(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 0) { - throw std::runtime_error( - RPCHelpMan{"getmininginfo", - "\nReturns a json object containing mining-related " - "information.", - {}} - .ToString() + - "\nResult:\n" - "{\n" - " \"blocks\": nnn, (numeric) The current block\n" - " \"currentblocksize\": nnn, (numeric) The last block size\n" - " \"currentblocktx\": nnn, (numeric) The last block " - "transaction\n" - " \"difficulty\": xxx.xxxxx (numeric) The current difficulty\n" - " \"networkhashps\": nnn, (numeric) The network hashes per " - "second\n" - " \"pooledtx\": n (numeric) The size of the mempool\n" - " \"chain\": \"xxxx\", (string) current network name as " - "defined in BIP70 (main, test, regtest)\n" - " \"warnings\": \"...\" (string) any network and " - "blockchain warnings\n" - "}\n" - "\nExamples:\n" + - HelpExampleCli("getmininginfo", "") + - HelpExampleRpc("getmininginfo", "")); + throw std::runtime_error(RPCHelpMan{ + "getmininginfo", + "\nReturns a json object containing mining-related " + "information.", + {}, + RPCResult{ + "{\n" + " \"blocks\": nnn, (numeric) The current block\n" + " \"currentblocksize\": nnn, (numeric) The last block size\n" + " \"currentblocktx\": nnn, (numeric) The last block " + "transaction\n" + " \"difficulty\": xxx.xxxxx (numeric) The current " + "difficulty\n" + " \"networkhashps\": nnn, (numeric) The network hashes " + "per " + "second\n" + " \"pooledtx\": n (numeric) The size of the " + "mempool\n" + " \"chain\": \"xxxx\", (string) current network " + "name as " + "defined in BIP70 (main, test, regtest)\n" + " \"warnings\": \"...\" (string) any network and " + "blockchain warnings\n" + "}\n"}, + RPCExamples{HelpExampleCli("getmininginfo", "") + + HelpExampleRpc("getmininginfo", "")}, + } + .ToString()); } LOCK(cs_main); @@ -282,39 +287,39 @@ static UniValue prioritisetransaction(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 3) { - throw std::runtime_error( - RPCHelpMan{ - "prioritisetransaction", - "Accepts the transaction into mined blocks at a higher " - "(or lower) priority\n", - { - {"txid", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "The transaction id."}, - {"dummy", RPCArg::Type::NUM, /* opt */ false, - /* default_val */ "", - "API-Compatibility for previous API. Must be zero or " - "null.\n" - " DEPRECATED. For forward compatibility " - "use named arguments and omit this parameter."}, - {"fee_delta", RPCArg::Type::NUM, /* opt */ false, - /* default_val */ "", - "The fee value (in satoshis) to add (or subtract, if " - "negative).\n" - " Note, that this value is not a " - "fee rate. It is a value to modify absolute fee of the " - "TX.\n" - " The fee is not actually paid, " - "only the algorithm for selecting transactions into a " - "block\n" - " considers the transaction as it would " - "have paid a higher (or lower) fee."}, - }} - .ToString() + - "\nResult:\n" - "true (boolean) Returns true\n" - "\nExamples:\n" + - HelpExampleCli("prioritisetransaction", "\"txid\" 0.0 10000") + - HelpExampleRpc("prioritisetransaction", "\"txid\", 0.0, 10000")); + throw std::runtime_error(RPCHelpMan{ + "prioritisetransaction", + "Accepts the transaction into mined blocks at a higher " + "(or lower) priority\n", + { + {"txid", RPCArg::Type::STR_HEX, /* opt */ false, + /* default_val */ "", "The transaction id."}, + {"dummy", RPCArg::Type::NUM, /* opt */ false, + /* default_val */ "", + "API-Compatibility for previous API. Must be zero or " + "null.\n" + " DEPRECATED. For forward compatibility " + "use named arguments and omit this parameter."}, + {"fee_delta", RPCArg::Type::NUM, /* opt */ false, + /* default_val */ "", + "The fee value (in satoshis) to add (or subtract, if " + "negative).\n" + " Note, that this value is not a " + "fee rate. It is a value to modify absolute fee of the " + "TX.\n" + " The fee is not actually paid, " + "only the algorithm for selecting transactions into a " + "block\n" + " considers the transaction as it would " + "have paid a higher (or lower) fee."}, + }, + RPCResult{"true (boolean) Returns true\n"}, + RPCExamples{ + HelpExampleCli("prioritisetransaction", "\"txid\" 0.0 10000") + + HelpExampleRpc("prioritisetransaction", + "\"txid\", 0.0, 10000")}, + } + .ToString()); } LOCK(cs_main); @@ -359,129 +364,155 @@ static UniValue getblocktemplate(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() > 1) { - throw std::runtime_error( - RPCHelpMan{ - "getblocktemplate", - "\nIf the request parameters include a 'mode' key, that is " - "used to explicitly select between the default 'template' " - "request or a 'proposal'.\n" - "It returns data needed to construct a block to work on.\n" - "For full specification, see BIPs 22, 23, 9, and 145:\n" - " " - "https://github.com/bitcoin/bips/blob/master/" - "bip-0022.mediawiki\n" - " " - "https://github.com/bitcoin/bips/blob/master/" - "bip-0023.mediawiki\n" - " " - "https://github.com/bitcoin/bips/blob/master/" - "bip-0009.mediawiki#getblocktemplate_changes\n" - " ", - { - {"template_request", - RPCArg::Type::OBJ, - /* opt */ true, - /* default_val */ "", - "A json object in the following spec", + throw std::runtime_error(RPCHelpMan{ + "getblocktemplate", + "\nIf the request parameters include a 'mode' key, that is " + "used to explicitly select between the default 'template' " + "request or a 'proposal'.\n" + "It returns data needed to construct a block to work on.\n" + "For full specification, see BIPs 22, 23, 9, and 145:\n" + " " + "https://github.com/bitcoin/bips/blob/master/" + "bip-0022.mediawiki\n" + " " + "https://github.com/bitcoin/bips/blob/master/" + "bip-0023.mediawiki\n" + " " + "https://github.com/bitcoin/bips/blob/master/" + "bip-0009.mediawiki#getblocktemplate_changes\n" + " ", + { + {"template_request", + RPCArg::Type::OBJ, + /* opt */ true, + /* default_val */ "", + "A json object in the following spec", + { + {"mode", RPCArg::Type::STR, /* opt */ true, + /* default_val */ "", + "This must be set to \"template\", \"proposal\" (see " + "BIP 23), or omitted"}, { - {"mode", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "", - "This must be set to \"template\", \"proposal\" (see " - "BIP 23), or omitted"}, + "capabilities", + RPCArg::Type::ARR, + /* opt */ true, + /* default_val */ "", + "A list of strings", { - "capabilities", - RPCArg::Type::ARR, - /* opt */ true, - /* default_val */ "", - "A list of strings", - { - {"support", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "", - "client side supported feature, 'longpoll', " - "'coinbasetxn', 'coinbasevalue', 'proposal', " - "'serverlist', 'workid'"}, - }, + {"support", RPCArg::Type::STR, /* opt */ true, + /* default_val */ "", + "client side supported feature, 'longpoll', " + "'coinbasetxn', 'coinbasevalue', 'proposal', " + "'serverlist', 'workid'"}, }, }, - "\"template_request\""}, - }} - .ToString() + - "\nResult:\n" - "{\n" - " \"version\" : n, (numeric) The preferred " - "block version\n" - " \"previousblockhash\" : \"xxxx\", (string) The hash of " - "current highest block\n" - " \"transactions\" : [ (array) contents of " - "non-coinbase transactions that should be included in the next " - "block\n" - " {\n" - " \"data\" : \"xxxx\", (string) transaction " - "data encoded in hexadecimal (byte-for-byte)\n" - " \"txid\" : \"xxxx\", (string) transaction id " - "encoded in little-endian hexadecimal\n" - " \"hash\" : \"xxxx\", (string) hash encoded " - "in little-endian hexadecimal (including witness data)\n" - " \"depends\" : [ (array) array of numbers " - "\n" - " n (numeric) transactions " - "before this one (by 1-based index in 'transactions' list) that " - "must be present in the final block if this one is\n" - " ,...\n" - " ],\n" - " \"fee\": n, (numeric) difference in " - "value between transaction inputs and outputs (in satoshis); for " - "coinbase transactions, this is a negative Number of the total " - "collected block fees (ie, not including the block subsidy); if " - "key is not present, fee is unknown and clients MUST NOT assume " - "there isn't one\n" - " \"sigops\" : n, (numeric) total SigOps " - "count, as counted for purposes of block limits; if key is not " - "present, sigop count is unknown and clients MUST NOT assume it is " - "zero\n" - " \"required\" : true|false (boolean) if provided and " - "true, this transaction must be in the final block\n" - " }\n" - " ,...\n" - " ],\n" - " \"coinbaseaux\" : { (json object) data that " - "should be included in the coinbase's scriptSig content\n" - " \"flags\" : \"xx\" (string) key name is to " - "be ignored, and value included in scriptSig\n" - " },\n" - " \"coinbasevalue\" : n, (numeric) maximum allowable " - "input to coinbase transaction, including the generation award and " - "transaction fees (in satoshis)\n" - " \"coinbasetxn\" : { ... }, (json object) information " - "for coinbase transaction\n" - " \"target\" : \"xxxx\", (string) The hash target\n" - " \"mintime\" : xxx, (numeric) The minimum " - "timestamp appropriate for next block time in seconds since epoch " - "(Jan 1 1970 GMT)\n" - " \"mutable\" : [ (array of string) list of " - "ways the block template may be changed \n" - " \"value\" (string) A way the block " - "template may be changed, e.g. 'time', 'transactions', " - "'prevblock'\n" - " ,...\n" - " ],\n" - " \"noncerange\" : \"00000000ffffffff\",(string) A range of valid " - "nonces\n" - " \"sigoplimit\" : n, (numeric) limit of sigops " - "in blocks\n" - " \"sizelimit\" : n, (numeric) limit of block " - "size\n" - " \"curtime\" : ttt, (numeric) current timestamp " - "in seconds since epoch (Jan 1 1970 GMT)\n" - " \"bits\" : \"xxxxxxxx\", (string) compressed " - "target of next block\n" - " \"height\" : n (numeric) The height of the " - "next block\n" - "}\n" - - "\nExamples:\n" + - HelpExampleCli("getblocktemplate", "") + - HelpExampleRpc("getblocktemplate", "")); + }, + "\"template_request\""}, + }, + RPCResult{ + "{\n" + " \"version\" : n, (numeric) The preferred " + "block version\n" + " \"previousblockhash\" : \"xxxx\", (string) The hash of " + "current highest block\n" + " \"transactions\" : [ (array) contents of " + "non-coinbase transactions that should be included in the next " + "block\n" + " {\n" + " \"data\" : \"xxxx\", (string) " + "transaction " + "data encoded in hexadecimal (byte-for-byte)\n" + " \"txid\" : \"xxxx\", (string) " + "transaction id " + "encoded in little-endian hexadecimal\n" + " \"hash\" : \"xxxx\", (string) hash " + "encoded " + "in little-endian hexadecimal (including witness data)\n" + " \"depends\" : [ (array) array of " + "numbers " + "\n" + " n (numeric) " + "transactions " + "before this one (by 1-based index in 'transactions' list) " + "that " + "must be present in the final block if this one is\n" + " ,...\n" + " ],\n" + " \"fee\": n, (numeric) difference " + "in " + "value between transaction inputs and outputs (in satoshis); " + "for " + "coinbase transactions, this is a negative Number of the total " + "collected block fees (ie, not including the block subsidy); " + "if " + "key is not present, fee is unknown and clients MUST NOT " + "assume " + "there isn't one\n" + " \"sigops\" : n, (numeric) total " + "SigOps " + "count, as counted for purposes of block limits; if key is not " + "present, sigop count is unknown and clients MUST NOT assume " + "it is " + "zero\n" + " \"required\" : true|false (boolean) if provided " + "and " + "true, this transaction must be in the final block\n" + " }\n" + " ,...\n" + " ],\n" + " \"coinbaseaux\" : { (json object) data that " + "should be included in the coinbase's scriptSig content\n" + " \"flags\" : \"xx\" (string) key name " + "is to " + "be ignored, and value included in scriptSig\n" + " },\n" + " \"coinbasevalue\" : n, (numeric) maximum " + "allowable " + "input to coinbase transaction, including the generation award " + "and " + "transaction fees (in satoshis)\n" + " \"coinbasetxn\" : { ... }, (json object) " + "information " + "for coinbase transaction\n" + " \"target\" : \"xxxx\", (string) The hash " + "target\n" + " \"mintime\" : xxx, (numeric) The minimum " + "timestamp appropriate for next block time in seconds since " + "epoch " + "(Jan 1 1970 GMT)\n" + " \"mutable\" : [ (array of string) list " + "of " + "ways the block template may be changed \n" + " \"value\" (string) A way the " + "block " + "template may be changed, e.g. 'time', 'transactions', " + "'prevblock'\n" + " ,...\n" + " ],\n" + " \"noncerange\" : \"00000000ffffffff\",(string) A range of " + "valid " + "nonces\n" + " \"sigoplimit\" : n, (numeric) limit of " + "sigops " + "in blocks\n" + " \"sizelimit\" : n, (numeric) limit of " + "block " + "size\n" + " \"curtime\" : ttt, (numeric) current " + "timestamp " + "in seconds since epoch (Jan 1 1970 GMT)\n" + " \"bits\" : \"xxxxxxxx\", (string) compressed " + "target of next block\n" + " \"height\" : n (numeric) The height of " + "the " + "next block\n" + "}\n"}, + RPCExamples{HelpExampleCli("getblocktemplate", + "{\"rules\": [\"segwit\"]}") + + HelpExampleRpc("getblocktemplate", + "{\"rules\": [\"segwit\"]}")}, + } + .ToString()); } LOCK(cs_main); @@ -736,25 +767,24 @@ // We allow 2 arguments for compliance with BIP22. Argument 2 is ignored. if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) { - throw std::runtime_error( - RPCHelpMan{"submitblock", - "\nAttempts to submit new block to network.\n" - "See https://en.bitcoin.it/wiki/BIP_0022 for full " - "specification.\n", - { - {"hexdata", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", - "the hex-encoded block data to submit"}, - {"dummy", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "", - "dummy value, for compatibility with BIP22. This " - "value is ignored."}, - }} - .ToString() + - "\nResult:\n" - "\nExamples:\n" + - HelpExampleCli("submitblock", "\"mydata\"") + - HelpExampleRpc("submitblock", "\"mydata\"")); + throw std::runtime_error(RPCHelpMan{ + "submitblock", + "\nAttempts to submit new block to network.\n" + "See https://en.bitcoin.it/wiki/BIP_0022 for full " + "specification.\n", + { + {"hexdata", RPCArg::Type::STR_HEX, /* opt */ false, + /* default_val */ "", "the hex-encoded block data to submit"}, + {"dummy", RPCArg::Type::STR, /* opt */ true, + /* default_val */ "", + "dummy value, for compatibility with BIP22. This " + "value is ignored."}, + }, + RPCResults{}, + RPCExamples{HelpExampleCli("submitblock", "\"mydata\"") + + HelpExampleRpc("submitblock", "\"mydata\"")}, + } + .ToString()); } std::shared_ptr blockptr = std::make_shared(); @@ -808,22 +838,20 @@ static UniValue submitheader(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{ - "submitheader", - "\nDecode the given hexdata as a header and submit it as a " - "candidate chain tip if valid." - "\nThrows when the header is invalid.\n", - { - {"hexdata", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "the hex-encoded block header data"}, - }} - .ToString() + - "\nResult:\n" - "None" - "\nExamples:\n" + - HelpExampleCli("submitheader", "\"aabbcc\"") + - HelpExampleRpc("submitheader", "\"aabbcc\"")); + throw std::runtime_error(RPCHelpMan{ + "submitheader", + "\nDecode the given hexdata as a header and submit it as a " + "candidate chain tip if valid." + "\nThrows when the header is invalid.\n", + { + {"hexdata", RPCArg::Type::STR_HEX, /* opt */ false, + /* default_val */ "", "the hex-encoded block header data"}, + }, + RPCResult{"None"}, + RPCExamples{HelpExampleCli("submitheader", "\"aabbcc\"") + + HelpExampleRpc("submitheader", "\"aabbcc\"")}, + } + .ToString()); } CBlockHeader h; @@ -855,16 +883,15 @@ static UniValue estimatefee(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() > 0) { - throw std::runtime_error( - RPCHelpMan{"estimatefee", - "\nEstimates the approximate fee per kilobyte needed " - "for a transaction\n", - {}} - .ToString() + - "\nResult:\n" - "n (numeric) estimated fee-per-kilobyte\n" - "\nExample:\n" + - HelpExampleCli("estimatefee", "")); + throw std::runtime_error(RPCHelpMan{ + "estimatefee", + "\nEstimates the approximate fee per kilobyte needed " + "for a transaction\n", + {}, + RPCResult{"n (numeric) estimated fee-per-kilobyte\n"}, + RPCExamples{HelpExampleCli("estimatefee", "")}, + } + .ToString()); } return ValueFromAmount(g_mempool.estimateFee().GetFeePerK()); diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -32,31 +32,32 @@ 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\"")}, + } + .ToString()); } CTxDestination dest = @@ -105,33 +106,36 @@ {"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\\\"]\"")}, + } + .ToString(); throw std::runtime_error(msg); } @@ -170,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\"")}, + } + .ToString()); } LOCK(cs_main); @@ -245,32 +251,32 @@ 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\"")}, + } + .ToString()); } std::string strPrivkey = request.params[0].get_str(); @@ -304,7 +310,11 @@ /* default_val */ "", "Unix seconds-since-epoch timestamp\n" " Pass 0 to go back to using the system time."}, - }}.ToString()); + }, + RPCResults{}, + RPCExamples{""}, + } + .ToString()); } if (!config.GetChainParams().MineBlocksOnDemand()) { @@ -361,45 +371,55 @@ * 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", "")}, + } + .ToString()); } std::string mode = @@ -442,60 +462,59 @@ 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]\"")}, + } + .ToString()); } uint32_t original_log_categories = LogInstance().GetCategoryMask(); @@ -541,17 +560,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" - "\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{""}, + } + .ToString()); } return request.params; diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -29,16 +29,15 @@ static UniValue getconnectioncount(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 0) { - throw std::runtime_error( - RPCHelpMan{"getconnectioncount", - "\nReturns the number of connections to other nodes.\n", - {}} - .ToString() + - "\nResult:\n" - "n (numeric) The connection count\n" - "\nExamples:\n" + - HelpExampleCli("getconnectioncount", "") + - HelpExampleRpc("getconnectioncount", "")); + throw std::runtime_error(RPCHelpMan{ + "getconnectioncount", + "\nReturns the number of connections to other nodes.\n", + {}, + RPCResult{"n (numeric) The connection count\n"}, + RPCExamples{HelpExampleCli("getconnectioncount", "") + + HelpExampleRpc("getconnectioncount", "")}, + } + .ToString()); } if (!g_connman) { @@ -52,19 +51,20 @@ static UniValue ping(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 0) { - throw std::runtime_error( - RPCHelpMan{ - "ping", - "\nRequests that a ping be sent to all other nodes, to measure " - "ping time.\n" - "Results provided in getpeerinfo, pingtime and pingwait fields " - "are decimal seconds.\n" - "Ping command is handled in queue with all other commands, so " - "it measures processing backlog, not just network ping.\n", - {}} - .ToString() + - "\nExamples:\n" + HelpExampleCli("ping", "") + - HelpExampleRpc("ping", "")); + throw std::runtime_error(RPCHelpMan{ + "ping", + "\nRequests that a ping be sent to all other nodes, to measure " + "ping time.\n" + "Results provided in getpeerinfo, pingtime and pingwait fields " + "are decimal seconds.\n" + "Ping command is handled in queue with all other commands, so " + "it measures processing backlog, not just network ping.\n", + {}, + RPCResults{}, + RPCExamples{HelpExampleCli("ping", "") + + HelpExampleRpc("ping", "")}, + } + .ToString()); } if (!g_connman) { @@ -81,84 +81,100 @@ static UniValue getpeerinfo(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 0) { - throw std::runtime_error( - RPCHelpMan{"getpeerinfo", - "\nReturns data about each connected network node as a " - "json array of objects.\n", - {}} - .ToString() + - "\nResult:\n" - "[\n" - " {\n" - " \"id\": n, (numeric) Peer index\n" - " \"addr\":\"host:port\", (string) The IP address and port " - "of the peer\n" - " \"addrbind\":\"ip:port\", (string) Bind address of the " - "connection to the peer\n" - " \"addrlocal\":\"ip:port\", (string) Local address as " - "reported by the peer\n" - " \"services\":\"xxxxxxxxxxxxxxxx\", (string) The services " - "offered\n" - " \"relaytxes\":true|false, (boolean) Whether peer has asked " - "us to relay transactions to it\n" - " \"lastsend\": ttt, (numeric) The time in seconds " - "since epoch (Jan 1 1970 GMT) of the last send\n" - " \"lastrecv\": ttt, (numeric) The time in seconds " - "since epoch (Jan 1 1970 GMT) of the last receive\n" - " \"bytessent\": n, (numeric) The total bytes sent\n" - " \"bytesrecv\": n, (numeric) The total bytes " - "received\n" - " \"conntime\": ttt, (numeric) The connection time in " - "seconds since epoch (Jan 1 1970 GMT)\n" - " \"timeoffset\": ttt, (numeric) The time offset in " - "seconds\n" - " \"pingtime\": n, (numeric) ping time (if " - "available)\n" - " \"minping\": n, (numeric) minimum observed ping " - "time (if any at all)\n" - " \"pingwait\": n, (numeric) ping wait (if " - "non-zero)\n" - " \"version\": v, (numeric) The peer version, such " - "as 70001\n" - " \"subver\": \"/Satoshi:0.8.5/\", (string) The string " - "version\n" - " \"inbound\": true|false, (boolean) Inbound (true) or " - "Outbound (false)\n" - " \"addnode\": true|false, (boolean) Whether connection was " - "due to addnode/-connect or if it was an automatic/inbound " - "connection\n" - " \"startingheight\": n, (numeric) The starting height " - "(block) of the peer\n" - " \"banscore\": n, (numeric) The ban score\n" - " \"synced_headers\": n, (numeric) The last header we " - "have in common with this peer\n" - " \"synced_blocks\": n, (numeric) The last block we have " - "in common with this peer\n" - " \"inflight\": [\n" - " n, (numeric) The heights of blocks " - "we're currently asking from this peer\n" - " ...\n" - " ],\n" - " \"whitelisted\": true|false, (boolean) Whether the peer is " - "whitelisted\n" - " \"minfeefilter\": n, (numeric) The minimum fee rate " - "for transactions this peer accepts\n" - " \"bytessent_per_msg\": {\n" - " \"addr\": n, (numeric) The total bytes sent " - "aggregated by message type\n" - " ...\n" - " },\n" - " \"bytesrecv_per_msg\": {\n" - " \"addr\": n, (numeric) The total bytes " - "received aggregated by message type\n" - " ...\n" - " }\n" - " }\n" - " ,...\n" - "]\n" - "\nExamples:\n" + - HelpExampleCli("getpeerinfo", "") + - HelpExampleRpc("getpeerinfo", "")); + throw std::runtime_error(RPCHelpMan{ + "getpeerinfo", + "\nReturns data about each connected network node as a " + "json array of objects.\n", + {}, + RPCResult{ + "[\n" + " {\n" + " \"id\": n, (numeric) Peer index\n" + " \"addr\":\"host:port\", (string) The IP address and " + "port " + "of the peer\n" + " \"addrbind\":\"ip:port\", (string) Bind address of the " + "connection to the peer\n" + " \"addrlocal\":\"ip:port\", (string) Local address as " + "reported by the peer\n" + " \"services\":\"xxxxxxxxxxxxxxxx\", (string) The " + "services " + "offered\n" + " \"relaytxes\":true|false, (boolean) Whether peer has " + "asked " + "us to relay transactions to it\n" + " \"lastsend\": ttt, (numeric) The time in " + "seconds " + "since epoch (Jan 1 1970 GMT) of the last send\n" + " \"lastrecv\": ttt, (numeric) The time in " + "seconds " + "since epoch (Jan 1 1970 GMT) of the last receive\n" + " \"bytessent\": n, (numeric) The total bytes " + "sent\n" + " \"bytesrecv\": n, (numeric) The total bytes " + "received\n" + " \"conntime\": ttt, (numeric) The connection " + "time in " + "seconds since epoch (Jan 1 1970 GMT)\n" + " \"timeoffset\": ttt, (numeric) The time offset in " + "seconds\n" + " \"pingtime\": n, (numeric) ping time (if " + "available)\n" + " \"minping\": n, (numeric) minimum observed " + "ping " + "time (if any at all)\n" + " \"pingwait\": n, (numeric) ping wait (if " + "non-zero)\n" + " \"version\": v, (numeric) The peer version, " + "such " + "as 70001\n" + " \"subver\": \"/Satoshi:0.8.5/\", (string) The string " + "version\n" + " \"inbound\": true|false, (boolean) Inbound (true) or " + "Outbound (false)\n" + " \"addnode\": true|false, (boolean) Whether connection " + "was " + "due to addnode/-connect or if it was an automatic/inbound " + "connection\n" + " \"startingheight\": n, (numeric) The starting " + "height " + "(block) of the peer\n" + " \"banscore\": n, (numeric) The ban score\n" + " \"synced_headers\": n, (numeric) The last header we " + "have in common with this peer\n" + " \"synced_blocks\": n, (numeric) The last block we " + "have " + "in common with this peer\n" + " \"inflight\": [\n" + " n, (numeric) The heights of " + "blocks " + "we're currently asking from this peer\n" + " ...\n" + " ],\n" + " \"whitelisted\": true|false, (boolean) Whether the peer " + "is " + "whitelisted\n" + " \"minfeefilter\": n, (numeric) The minimum fee " + "rate " + "for transactions this peer accepts\n" + " \"bytessent_per_msg\": {\n" + " \"addr\": n, (numeric) The total bytes " + "sent " + "aggregated by message type\n" + " ...\n" + " },\n" + " \"bytesrecv_per_msg\": {\n" + " \"addr\": n, (numeric) The total bytes " + "received aggregated by message type\n" + " ...\n" + " }\n" + " }\n" + " ,...\n" + "]\n"}, + RPCExamples{HelpExampleCli("getpeerinfo", "") + + HelpExampleRpc("getpeerinfo", "")}, + } + .ToString()); } if (!g_connman) { @@ -254,29 +270,29 @@ if (request.fHelp || request.params.size() != 2 || (strCommand != "onetry" && strCommand != "add" && strCommand != "remove")) { - throw std::runtime_error( - RPCHelpMan{ - "addnode", - "\nAttempts to add or remove a node from the addnode list.\n" - "Or try a connection to a node once.\n" - "Nodes added using addnode (or -connect) are protected from " - "DoS disconnection and are not required to be\n" - "full nodes as other outbound peers are (though such peers " - "will not be synced from).\n", - { - {"node", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", - "The node (see getpeerinfo for nodes)"}, - {"command", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", - "'add' to add a node to the list, 'remove' to remove a " - "node from the list, 'onetry' to try a connection to the " - "node once"}, - }} - .ToString() + - "\nExamples:\n" + - HelpExampleCli("addnode", "\"192.168.0.6:8333\" \"onetry\"") + - HelpExampleRpc("addnode", "\"192.168.0.6:8333\", \"onetry\"")); + throw std::runtime_error(RPCHelpMan{ + "addnode", + "\nAttempts to add or remove a node from the addnode list.\n" + "Or try a connection to a node once.\n" + "Nodes added using addnode (or -connect) are protected from " + "DoS disconnection and are not required to be\n" + "full nodes as other outbound peers are (though such peers " + "will not be synced from).\n", + { + {"node", RPCArg::Type::STR, /* opt */ false, + /* default_val */ "", "The node (see getpeerinfo for nodes)"}, + {"command", RPCArg::Type::STR, /* opt */ false, + /* default_val */ "", + "'add' to add a node to the list, 'remove' to remove a " + "node from the list, 'onetry' to try a connection to the " + "node once"}, + }, + RPCResults{}, + RPCExamples{ + HelpExampleCli("addnode", "\"192.168.0.6:8333\" \"onetry\"") + + HelpExampleRpc("addnode", "\"192.168.0.6:8333\", \"onetry\"")}, + } + .ToString()); } if (!g_connman) { @@ -310,27 +326,28 @@ const JSONRPCRequest &request) { if (request.fHelp || request.params.size() == 0 || request.params.size() >= 3) { - throw std::runtime_error( - RPCHelpMan{ - "disconnectnode", - "\nImmediately disconnects from the specified peer node.\n" - "\nStrictly one out of 'address' and 'nodeid' can be provided " - "to identify the node.\n" - "\nTo disconnect by nodeid, either set 'address' to the empty " - "string, or call using the named 'nodeid' argument only.\n", - { - {"address", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "", "The IP address/port of the node"}, - {"nodeid", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "", - "The node ID (see getpeerinfo for node IDs)"}, - }} - .ToString() + - "\nExamples:\n" + - HelpExampleCli("disconnectnode", "\"192.168.0.6:8333\"") + - HelpExampleCli("disconnectnode", "\"\" 1") + - HelpExampleRpc("disconnectnode", "\"192.168.0.6:8333\"") + - HelpExampleRpc("disconnectnode", "\"\", 1")); + throw std::runtime_error(RPCHelpMan{ + "disconnectnode", + "\nImmediately disconnects from the specified peer node.\n" + "\nStrictly one out of 'address' and 'nodeid' can be provided " + "to identify the node.\n" + "\nTo disconnect by nodeid, either set 'address' to the empty " + "string, or call using the named 'nodeid' argument only.\n", + { + {"address", RPCArg::Type::STR, /* opt */ true, + /* default_val */ "", "The IP address/port of the node"}, + {"nodeid", RPCArg::Type::NUM, /* opt */ true, + /* default_val */ "", + "The node ID (see getpeerinfo for node IDs)"}, + }, + RPCResults{}, + RPCExamples{ + HelpExampleCli("disconnectnode", "\"192.168.0.6:8333\"") + + HelpExampleCli("disconnectnode", "\"\" 1") + + HelpExampleRpc("disconnectnode", "\"192.168.0.6:8333\"") + + HelpExampleRpc("disconnectnode", "\"\", 1")}, + } + .ToString()); } if (!g_connman) { @@ -369,39 +386,42 @@ static UniValue getaddednodeinfo(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() > 1) { - throw std::runtime_error( - RPCHelpMan{"getaddednodeinfo", - "\nReturns information about the given added node, or " - "all added nodes\n" - "(note that onetry addnodes are not listed here)\n", - { - {"node", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "", - "If provided, return information about this " - "specific node, otherwise all nodes are returned."}, - }} - .ToString() + - "\nResult:\n" - "[\n" - " {\n" - " \"addednode\" : \"192.168.0.201\", (string) The node IP " - "address or name (as provided to addnode)\n" - " \"connected\" : true|false, (boolean) If connected\n" - " \"addresses\" : [ (list of objects) Only " - "when connected = true\n" - " {\n" - " \"address\" : \"192.168.0.201:8333\", (string) The " - "bitcoin server IP and port we're connected to\n" - " \"connected\" : \"outbound\" (string) " - "connection, inbound or outbound\n" - " }\n" - " ]\n" - " }\n" - " ,...\n" - "]\n" - "\nExamples:\n" + - HelpExampleCli("getaddednodeinfo", "\"192.168.0.201\"") + - HelpExampleRpc("getaddednodeinfo", "\"192.168.0.201\"")); + throw std::runtime_error(RPCHelpMan{ + "getaddednodeinfo", + "\nReturns information about the given added node, or " + "all added nodes\n" + "(note that onetry addnodes are not listed here)\n", + { + {"node", RPCArg::Type::STR, /* opt */ true, + /* default_val */ "", + "If provided, return information about this " + "specific node, otherwise all nodes are returned."}, + }, + RPCResult{ + "[\n" + " {\n" + " \"addednode\" : \"192.168.0.201\", (string) The node IP " + "address or name (as provided to addnode)\n" + " \"connected\" : true|false, (boolean) If " + "connected\n" + " \"addresses\" : [ (list of objects) " + "Only " + "when connected = true\n" + " {\n" + " \"address\" : \"192.168.0.201:8333\", (string) The " + "bitcoin server IP and port we're connected to\n" + " \"connected\" : \"outbound\" (string) " + "connection, inbound or outbound\n" + " }\n" + " ]\n" + " }\n" + " ,...\n" + "]\n"}, + RPCExamples{ + HelpExampleCli("getaddednodeinfo", "\"192.168.0.201\"") + + HelpExampleRpc("getaddednodeinfo", "\"192.168.0.201\"")}, + } + .ToString()); } if (!g_connman) { @@ -450,38 +470,43 @@ static UniValue getnettotals(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() > 0) { - throw std::runtime_error( - RPCHelpMan{"getnettotals", - "\nReturns information about network traffic, including " - "bytes in, bytes out,\n" - "and current time.\n", - {}} - .ToString() + - "\nResult:\n" - "{\n" - " \"totalbytesrecv\": n, (numeric) Total bytes received\n" - " \"totalbytessent\": n, (numeric) Total bytes sent\n" - " \"timemillis\": t, (numeric) Current UNIX time in " - "milliseconds\n" - " \"uploadtarget\":\n" - " {\n" - " \"timeframe\": n, (numeric) Length of " - "the measuring timeframe in seconds\n" - " \"target\": n, (numeric) Target in " - "bytes\n" - " \"target_reached\": true|false, (boolean) True if " - "target is reached\n" - " \"serve_historical_blocks\": true|false, (boolean) True if " - "serving historical blocks\n" - " \"bytes_left_in_cycle\": t, (numeric) Bytes " - "left in current time cycle\n" - " \"time_left_in_cycle\": t (numeric) Seconds " - "left in current time cycle\n" - " }\n" - "}\n" - "\nExamples:\n" + - HelpExampleCli("getnettotals", "") + - HelpExampleRpc("getnettotals", "")); + throw std::runtime_error(RPCHelpMan{ + "getnettotals", + "\nReturns information about network traffic, including " + "bytes in, bytes out,\n" + "and current time.\n", + {}, + RPCResult{ + "{\n" + " \"totalbytesrecv\": n, (numeric) Total bytes received\n" + " \"totalbytessent\": n, (numeric) Total bytes sent\n" + " \"timemillis\": t, (numeric) Current UNIX time in " + "milliseconds\n" + " \"uploadtarget\":\n" + " {\n" + " \"timeframe\": n, (numeric) " + "Length of " + "the measuring timeframe in seconds\n" + " \"target\": n, (numeric) " + "Target in " + "bytes\n" + " \"target_reached\": true|false, (boolean) True " + "if " + "target is reached\n" + " \"serve_historical_blocks\": true|false, (boolean) True " + "if " + "serving historical blocks\n" + " \"bytes_left_in_cycle\": t, (numeric) Bytes " + "left in current time cycle\n" + " \"time_left_in_cycle\": t (numeric) " + "Seconds " + "left in current time cycle\n" + " }\n" + "}\n"}, + RPCExamples{HelpExampleCli("getnettotals", "") + + HelpExampleRpc("getnettotals", "")}, + } + .ToString()); } if (!g_connman) { @@ -534,72 +559,79 @@ static UniValue getnetworkinfo(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 0) { - throw std::runtime_error( - RPCHelpMan{"getnetworkinfo", - "Returns an object containing various state info " - "regarding P2P networking.\n", - {}} - .ToString() + - "\nResult:\n" - "{\n" - " \"version\": xxxxx, (numeric) the server " - "version\n" - " \"subversion\": \"/Satoshi:x.x.x/\", (string) the server " - "subversion string\n" - " \"protocolversion\": xxxxx, (numeric) the protocol " - "version\n" - " \"localservices\": \"xxxxxxxxxxxxxxxx\", (string) the services " - "we offer to the network\n" - " \"localrelay\": true|false, (bool) true if " - "transaction relay is requested from peers\n" - " \"timeoffset\": xxxxx, (numeric) the time " - "offset\n" - " \"connections\": xxxxx, (numeric) the number " - "of connections\n" - " \"networkactive\": true|false, (bool) whether p2p " - "networking is enabled\n" - " \"networks\": [ (array) information " - "per network\n" - " {\n" - " \"name\": \"xxx\", (string) network " - "(ipv4, ipv6 or onion)\n" - " \"limited\": true|false, (boolean) is the " - "network limited using -onlynet?\n" - " \"reachable\": true|false, (boolean) is the " - "network reachable?\n" - " \"proxy\": \"host:port\" (string) the proxy " - "that is used for this network, or empty if none\n" - " \"proxy_randomize_credentials\": true|false, (string) " - "Whether randomized credentials are used\n" - " }\n" - " ,...\n" - " ],\n" - " \"relayfee\": x.xxxxxxxx, (numeric) minimum " - "relay fee for transactions in " + - CURRENCY_UNIT + - "/kB\n" - " \"excessutxocharge\": x.xxxxxxxx, (numeric) minimum " - "charge for excess utxos in " + - CURRENCY_UNIT + - "\n" - " \"localaddresses\": [ " - "(array) list of local addresses\n" - " {\n" - " \"address\": \"xxxx\", " - "(string) network address\n" - " \"port\": xxx, " - "(numeric) network port\n" - " \"score\": xxx " - "(numeric) relative score\n" - " }\n" - " ,...\n" - " ]\n" - " \"warnings\": \"...\" (string) any network " - "and blockchain warnings\n" - "}\n" - "\nExamples:\n" + - HelpExampleCli("getnetworkinfo", "") + - HelpExampleRpc("getnetworkinfo", "")); + throw std::runtime_error(RPCHelpMan{ + "getnetworkinfo", + "Returns an object containing various state info " + "regarding P2P networking.\n", + {}, + RPCResult{ + "{\n" + " \"version\": xxxxx, (numeric) the " + "server " + "version\n" + " \"subversion\": \"/Satoshi:x.x.x/\", (string) the " + "server " + "subversion string\n" + " \"protocolversion\": xxxxx, (numeric) the " + "protocol " + "version\n" + " \"localservices\": \"xxxxxxxxxxxxxxxx\", (string) the " + "services " + "we offer to the network\n" + " \"localrelay\": true|false, (bool) true if " + "transaction relay is requested from peers\n" + " \"timeoffset\": xxxxx, (numeric) the time " + "offset\n" + " \"connections\": xxxxx, (numeric) the " + "number " + "of connections\n" + " \"networkactive\": true|false, (bool) whether p2p " + "networking is enabled\n" + " \"networks\": [ (array) " + "information " + "per network\n" + " {\n" + " \"name\": \"xxx\", (string) network " + "(ipv4, ipv6 or onion)\n" + " \"limited\": true|false, (boolean) is the " + "network limited using -onlynet?\n" + " \"reachable\": true|false, (boolean) is the " + "network reachable?\n" + " \"proxy\": \"host:port\" (string) the proxy " + "that is used for this network, or empty if none\n" + " \"proxy_randomize_credentials\": true|false, (string) " + "Whether randomized credentials are used\n" + " }\n" + " ,...\n" + " ],\n" + " \"relayfee\": x.xxxxxxxx, (numeric) minimum " + "relay fee for transactions in " + + CURRENCY_UNIT + + "/kB\n" + " \"excessutxocharge\": x.xxxxxxxx, (numeric) minimum " + "charge for excess utxos in " + + CURRENCY_UNIT + + "\n" + " \"localaddresses\": [ " + "(array) list of local addresses\n" + " {\n" + " \"address\": \"xxxx\", " + "(string) network address\n" + " \"port\": xxx, " + "(numeric) network port\n" + " \"score\": xxx " + "(numeric) relative score\n" + " }\n" + " ,...\n" + " ]\n" + " \"warnings\": \"...\" (string) any " + "network " + "and blockchain warnings\n" + "}\n"}, + RPCExamples{HelpExampleCli("getnetworkinfo", "") + + HelpExampleRpc("getnetworkinfo", "")}, + } + .ToString()); } LOCK(cs_main); @@ -647,38 +679,38 @@ if (request.fHelp || request.params.size() < 2 || (strCommand != "add" && strCommand != "remove")) { - throw std::runtime_error( - RPCHelpMan{ - "setban", - "\nAttempts to add or remove an IP/Subnet from the " - "banned list.\n", - { - {"subnet", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", - "The IP/Subnet (see getpeerinfo for nodes IP) with an " - "optional netmask (default is /32 = single IP)"}, - {"command", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", - "'add' to add an IP/Subnet to the list, 'remove' to " - "remove an IP/Subnet from the list"}, - {"bantime", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "", - "time in seconds how long (or until when if [absolute] is " - "set) the IP is banned (0 or empty means using the " - "default time of 24h which can also be overwritten by the " - "-bantime startup argument)"}, - {"absolute", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "", - "If set, the bantime must be an absolute timestamp in " - "seconds since epoch (Jan 1 1970 GMT)"}, - }} - .ToString() + - "\nExamples:\n" + - HelpExampleCli("setban", "\"192.168.0.6\" \"add\" 86400") + - HelpExampleCli("setban", "\"192.168.0.0/24\" \"add\"") + - HelpExampleRpc("setban", "\"192.168.0.6\", \"add\", 86400")); + throw std::runtime_error(RPCHelpMan{ + "setban", + "\nAttempts to add or remove an IP/Subnet from the " + "banned list.\n", + { + {"subnet", RPCArg::Type::STR, /* opt */ false, + /* default_val */ "", + "The IP/Subnet (see getpeerinfo for nodes IP) with an " + "optional netmask (default is /32 = single IP)"}, + {"command", RPCArg::Type::STR, /* opt */ false, + /* default_val */ "", + "'add' to add an IP/Subnet to the list, 'remove' to " + "remove an IP/Subnet from the list"}, + {"bantime", RPCArg::Type::NUM, /* opt */ true, + /* default_val */ "", + "time in seconds how long (or until when if [absolute] is " + "set) the IP is banned (0 or empty means using the " + "default time of 24h which can also be overwritten by the " + "-bantime startup argument)"}, + {"absolute", RPCArg::Type::BOOL, /* opt */ true, + /* default_val */ "", + "If set, the bantime must be an absolute timestamp in " + "seconds since epoch (Jan 1 1970 GMT)"}, + }, + RPCResults{}, + RPCExamples{ + HelpExampleCli("setban", "\"192.168.0.6\" \"add\" 86400") + + HelpExampleCli("setban", "\"192.168.0.0/24\" \"add\"") + + HelpExampleRpc("setban", "\"192.168.0.6\", \"add\", 86400")}, + } + .ToString()); } - if (!g_banman) { throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded"); @@ -747,11 +779,15 @@ static UniValue listbanned(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 0) { - throw std::runtime_error( - RPCHelpMan{"listbanned", "\nList all banned IPs/Subnets.\n", {}} - .ToString() + - "\nExamples:\n" + HelpExampleCli("listbanned", "") + - HelpExampleRpc("listbanned", "")); + throw std::runtime_error(RPCHelpMan{ + "listbanned", + "\nList all banned IPs/Subnets.\n", + {}, + RPCResults{}, + RPCExamples{HelpExampleCli("listbanned", "") + + HelpExampleRpc("listbanned", "")}, + } + .ToString()); } if (!g_banman) { @@ -780,11 +816,15 @@ static UniValue clearbanned(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 0) { - throw std::runtime_error( - RPCHelpMan{"clearbanned", "\nClear all banned IPs.\n", {}} - .ToString() + - "\nExamples:\n" + HelpExampleCli("clearbanned", "") + - HelpExampleRpc("clearbanned", "")); + throw std::runtime_error(RPCHelpMan{ + "clearbanned", + "\nClear all banned IPs.\n", + {}, + RPCResults{}, + RPCExamples{HelpExampleCli("clearbanned", "") + + HelpExampleRpc("clearbanned", "")}, + } + .ToString()); } if (!g_banman) { throw JSONRPCError( @@ -807,7 +847,11 @@ {"state", RPCArg::Type::BOOL, /* opt */ false, /* default_val */ "", "true to enable networking, false to disable"}, - }}.ToString()); + }, + RPCResults{}, + RPCExamples{""}, + } + .ToString()); } if (!g_connman) { @@ -824,36 +868,40 @@ static UniValue getnodeaddresses(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() > 1) { - throw std::runtime_error( - RPCHelpMan{"getnodeaddresses", - "\nReturn known addresses which can potentially be used " - "to find new nodes in the network\n", - { - {"count", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "1", - "How many addresses to return. Limited to the " - "smaller of " + - std::to_string(ADDRMAN_GETADDR_MAX) + " or " + - std::to_string(ADDRMAN_GETADDR_MAX_PCT) + - "% of all known addresses."}, - }} - .ToString() + - "\nResult:\n" - "[\n" - " {\n" - " \"time\": ttt, (numeric) Timestamp in seconds " - "since epoch (Jan 1 1970 GMT) keeping track of when the node was " - "last seen\n" - " \"services\": n, (numeric) The services offered\n" - " \"address\": \"host\", (string) The address of the " - "node\n" - " \"port\": n (numeric) The port of the node\n" - " }\n" - " ,....\n" - "]\n" - "\nExamples:\n" + - HelpExampleCli("getnodeaddresses", "8") + - HelpExampleRpc("getnodeaddresses", "8")); + throw std::runtime_error(RPCHelpMan{ + "getnodeaddresses", + "\nReturn known addresses which can potentially be used " + "to find new nodes in the network\n", + { + {"count", RPCArg::Type::NUM, /* opt */ true, + /* default_val */ "1", + "How many addresses to return. Limited to the " + "smaller of " + + std::to_string(ADDRMAN_GETADDR_MAX) + " or " + + std::to_string(ADDRMAN_GETADDR_MAX_PCT) + + "% of all known addresses."}, + }, + RPCResult{"[\n" + " {\n" + " \"time\": ttt, (numeric) Timestamp " + "in seconds " + "since epoch (Jan 1 1970 GMT) keeping track of when the " + "node was " + "last seen\n" + " \"services\": n, (numeric) The " + "services offered\n" + " \"address\": \"host\", (string) The " + "address of the " + "node\n" + " \"port\": n (numeric) The port of " + "the node\n" + " }\n" + " ,....\n" + "]\n"}, + RPCExamples{HelpExampleCli("getnodeaddresses", "8") + + HelpExampleRpc("getnodeaddresses", "8")}, + } + .ToString()); } if (!g_connman) { throw JSONRPCError( diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -66,106 +66,124 @@ const JSONRPCRequest &request) { if (request.fHelp || request.params.size() < 1 || request.params.size() > 3) { - throw std::runtime_error( - RPCHelpMan{ - "getrawtransaction", - "\nNOTE: By default this function only works for " - "mempool transactions. If the -txindex option is\n" - "enabled, it also works for blockchain transactions. If " - "the block which contains the transaction\n" - "is known, its hash can be provided even for nodes " - "without -txindex. Note that if a blockhash is\n" - "provided, only that block will be searched and if the " - "transaction is in the mempool or other\n" - "blocks, or if this node does not have the given block " - "available, the transaction will not be found.\n" - "DEPRECATED: for now, it also works for transactions with " - "unspent outputs.\n" - - "\nReturn the raw transaction data.\n" - "\nIf verbose is 'true', returns an Object with information " - "about 'txid'.\n" - "If verbose is 'false' or omitted, returns a string that is " - "serialized, hex-encoded data for 'txid'.\n", - { - {"txid", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "The transaction id"}, - {"verbose", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "false", - "If false, return a string, otherwise return a json " - "object"}, - {"blockhash", RPCArg::Type::STR_HEX, /* opt */ true, - /* default_val */ "", - "The block in which to look for the transaction"}, - }} - .ToString() + - "\nResult (if verbose is not set or set to false):\n" - "\"data\" (string) The serialized, hex-encoded data for " - "'txid'\n" - - "\nResult (if verbose is set to true):\n" - "{\n" - " \"in_active_chain\": b, (bool) Whether specified block is in " - "the active chain or not (only present with explicit \"blockhash\" " - "argument)\n" - " \"hex\" : \"data\", (string) The serialized, hex-encoded " - "data for 'txid'\n" - " \"txid\" : \"id\", (string) The transaction id (same as " - "provided)\n" - " \"hash\" : \"id\", (string) The transaction hash " - "(differs from txid for witness transactions)\n" - " \"size\" : n, (numeric) The serialized transaction " - "size\n" - " \"version\" : n, (numeric) The version\n" - " \"locktime\" : ttt, (numeric) The lock time\n" - " \"vin\" : [ (array of json objects)\n" - " {\n" - " \"txid\": \"id\", (string) The transaction id\n" - " \"vout\": n, (numeric) \n" - " \"scriptSig\": { (json object) The script\n" - " \"asm\": \"asm\", (string) asm\n" - " \"hex\": \"hex\" (string) hex\n" - " },\n" - " \"sequence\": n (numeric) The script sequence number\n" - " }\n" - " ,...\n" - " ],\n" - " \"vout\" : [ (array of json objects)\n" - " {\n" - " \"value\" : x.xxx, (numeric) The value in " + - CURRENCY_UNIT + - "\n" - " \"n\" : n, (numeric) index\n" - " \"scriptPubKey\" : { (json object)\n" - " \"asm\" : \"asm\", (string) the asm\n" - " \"hex\" : \"hex\", (string) the hex\n" - " \"reqSigs\" : n, (numeric) The required sigs\n" - " \"type\" : \"pubkeyhash\", (string) The type, eg " - "'pubkeyhash'\n" - " \"addresses\" : [ (json array of string)\n" - " \"address\" (string) bitcoin address\n" - " ,...\n" - " ]\n" - " }\n" - " }\n" - " ,...\n" - " ],\n" - " \"blockhash\" : \"hash\", (string) the block hash\n" - " \"confirmations\" : n, (numeric) The confirmations\n" - " \"time\" : ttt, (numeric) The transaction time in " - "seconds since epoch (Jan 1 1970 GMT)\n" - " \"blocktime\" : ttt (numeric) The block time in seconds " - "since epoch (Jan 1 1970 GMT)\n" - "}\n" - - "\nExamples:\n" + - HelpExampleCli("getrawtransaction", "\"mytxid\"") + - HelpExampleCli("getrawtransaction", "\"mytxid\" true") + - HelpExampleRpc("getrawtransaction", "\"mytxid\", true") + - HelpExampleCli("getrawtransaction", - "\"mytxid\" false \"myblockhash\"") + - HelpExampleCli("getrawtransaction", - "\"mytxid\" true \"myblockhash\"")); + throw std::runtime_error(RPCHelpMan{ + "getrawtransaction", + "\nNOTE: By default this function only works for " + "mempool transactions. If the -txindex option is\n" + "enabled, it also works for blockchain transactions. If " + "the block which contains the transaction\n" + "is known, its hash can be provided even for nodes " + "without -txindex. Note that if a blockhash is\n" + "provided, only that block will be searched and if the " + "transaction is in the mempool or other\n" + "blocks, or if this node does not have the given block " + "available, the transaction will not be found.\n" + "DEPRECATED: for now, it also works for transactions with " + "unspent outputs.\n" + + "\nReturn the raw transaction data.\n" + "\nIf verbose is 'true', returns an Object with information " + "about 'txid'.\n" + "If verbose is 'false' or omitted, returns a string that is " + "serialized, hex-encoded data for 'txid'.\n", + { + {"txid", RPCArg::Type::STR_HEX, /* opt */ false, + /* default_val */ "", "The transaction id"}, + {"verbose", RPCArg::Type::BOOL, /* opt */ true, + /* default_val */ "false", + "If false, return a string, otherwise return a json " + "object"}, + {"blockhash", RPCArg::Type::STR_HEX, /* opt */ true, + /* default_val */ "", + "The block in which to look for the transaction"}, + }, + { + RPCResult{"if verbose is not set or set to false", + "\"data\" (string) The serialized, hex-encoded " + "data for 'txid'\n"}, + RPCResult{ + "if verbose is set to true", + "{\n" + " \"in_active_chain\": b, (bool) Whether specified block " + "is in " + "the active chain or not (only present with explicit " + "\"blockhash\" " + "argument)\n" + " \"hex\" : \"data\", (string) The serialized, " + "hex-encoded " + "data for 'txid'\n" + " \"txid\" : \"id\", (string) The transaction id " + "(same as " + "provided)\n" + " \"hash\" : \"id\", (string) The transaction hash " + "(differs from txid for witness transactions)\n" + " \"size\" : n, (numeric) The serialized " + "transaction " + "size\n" + " \"version\" : n, (numeric) The version\n" + " \"locktime\" : ttt, (numeric) The lock time\n" + " \"vin\" : [ (array of json objects)\n" + " {\n" + " \"txid\": \"id\", (string) The transaction id\n" + " \"vout\": n, (numeric) \n" + " \"scriptSig\": { (json object) The script\n" + " \"asm\": \"asm\", (string) asm\n" + " \"hex\": \"hex\" (string) hex\n" + " },\n" + " \"sequence\": n (numeric) The script sequence " + "number\n" + " }\n" + " ,...\n" + " ],\n" + " \"vout\" : [ (array of json objects)\n" + " {\n" + " \"value\" : x.xxx, (numeric) The value " + "in " + + CURRENCY_UNIT + + "\n" + " \"n\" : n, (numeric) index\n" + " \"scriptPubKey\" : { (json object)\n" + " \"asm\" : \"asm\", (string) the " + "asm\n" + " \"hex\" : \"hex\", (string) the " + "hex\n" + " \"reqSigs\" : n, (numeric) The " + "required sigs\n" + " \"type\" : \"pubkeyhash\", (string) The " + "type, eg " + "'pubkeyhash'\n" + " \"addresses\" : [ (json array of " + "string)\n" + " \"address\" (string) bitcoin " + "address\n" + " ,...\n" + " ]\n" + " }\n" + " }\n" + " ,...\n" + " ],\n" + " \"blockhash\" : \"hash\", (string) the block " + "hash\n" + " \"confirmations\" : n, (numeric) The " + "confirmations\n" + " \"time\" : ttt, (numeric) The " + "transaction time in " + "seconds since epoch (Jan 1 1970 GMT)\n" + " \"blocktime\" : ttt (numeric) The block " + "time in seconds " + "since epoch (Jan 1 1970 GMT)\n" + "}\n"}, + }, + RPCExamples{ + HelpExampleCli("getrawtransaction", "\"mytxid\"") + + HelpExampleCli("getrawtransaction", "\"mytxid\" true") + + HelpExampleRpc("getrawtransaction", "\"mytxid\", true") + + HelpExampleCli("getrawtransaction", + "\"mytxid\" false \"myblockhash\"") + + HelpExampleCli("getrawtransaction", + "\"mytxid\" true \"myblockhash\"")}, + } + .ToString()); } bool in_active_chain = true; @@ -245,40 +263,40 @@ const JSONRPCRequest &request) { if (request.fHelp || (request.params.size() != 1 && request.params.size() != 2)) { - throw std::runtime_error( - RPCHelpMan{ - "gettxoutproof", - "\nReturns a hex-encoded proof that \"txid\" was " - "included in a block.\n" - "\nNOTE: By default this function only works sometimes. " - "This is when there is an\n" - "unspent output in the utxo for this transaction. To " - "make it always work,\n" - "you need to maintain a transaction index, using the " - "-txindex command line option or\n" - "specify the block in which the transaction is included " - "manually (by blockhash).\n", + throw std::runtime_error(RPCHelpMan{ + "gettxoutproof", + "\nReturns a hex-encoded proof that \"txid\" was " + "included in a block.\n" + "\nNOTE: By default this function only works sometimes. " + "This is when there is an\n" + "unspent output in the utxo for this transaction. To " + "make it always work,\n" + "you need to maintain a transaction index, using the " + "-txindex command line option or\n" + "specify the block in which the transaction is included " + "manually (by blockhash).\n", + { { + "txids", + RPCArg::Type::ARR, + /* opt */ false, + /* default_val */ "", + "A json array of txids to filter", { - "txids", - RPCArg::Type::ARR, - /* opt */ false, - /* default_val */ "", - "A json array of txids to filter", - { - {"txid", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "A transaction hash"}, - }, + {"txid", RPCArg::Type::STR_HEX, /* opt */ false, + /* default_val */ "", "A transaction hash"}, }, - {"blockhash", RPCArg::Type::STR_HEX, /* opt */ true, - /* default_val */ "", - "If specified, looks for txid in the block with this " - "hash"}, - }} - .ToString() + - "\nResult:\n" - "\"data\" (string) A string that is a serialized, " - "hex-encoded data for the proof.\n"); + }, + {"blockhash", RPCArg::Type::STR_HEX, /* opt */ true, + /* default_val */ "", + "If specified, looks for txid in the block with this " + "hash"}, + }, + RPCResult{"\"data\" (string) A string that is a " + "serialized, hex-encoded data for the proof.\n"}, + RPCExamples{""}, + } + .ToString()); } std::set setTxIds; @@ -373,21 +391,23 @@ static UniValue verifytxoutproof(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{"verifytxoutproof", - "\nVerifies that a proof points to a transaction in a " - "block, returning the transaction it commits to\n" - "and throwing an RPC error if the block is not in our " - "best chain\n", - { - {"proof", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", - "The hex-encoded proof generated by gettxoutproof"}, - }} - .ToString() + - "\nResult:\n" - "[\"txid\"] (array, strings) The txid(s) which the proof " - "commits to, or empty array if the proof can not be validated.\n"); + throw std::runtime_error(RPCHelpMan{ + "verifytxoutproof", + "\nVerifies that a proof points to a transaction in a " + "block, returning the transaction it commits to\n" + "and throwing an RPC error if the block is not in our " + "best chain\n", + { + {"proof", RPCArg::Type::STR_HEX, /* opt */ false, + /* default_val */ "", + "The hex-encoded proof generated by gettxoutproof"}, + }, + RPCResult{"[\"txid\"] (array, strings) The txid(s) which the " + "proof commits to, or empty array if the proof can not " + "be validated.\n"}, + RPCExamples{""}, + } + .ToString()); } CDataStream ssMB(ParseHexV(request.params[0], "proof"), SER_NETWORK, @@ -550,107 +570,105 @@ const JSONRPCRequest &request) { if (request.fHelp || request.params.size() < 2 || request.params.size() > 3) { - throw std::runtime_error( - RPCHelpMan{ - "createrawtransaction", - "\nCreate a transaction spending the given inputs and creating " - "new outputs.\n" - "Outputs can be addresses or data.\n" - "Returns hex-encoded raw transaction.\n" - "Note that the transaction's inputs are not signed, and\n" - "it is not stored in the wallet or transmitted to the " - "network.\n", + throw std::runtime_error(RPCHelpMan{ + "createrawtransaction", + "\nCreate a transaction spending the given inputs and creating " + "new outputs.\n" + "Outputs can be addresses or data.\n" + "Returns hex-encoded raw transaction.\n" + "Note that the transaction's inputs are not signed, and\n" + "it is not stored in the wallet or transmitted to the " + "network.\n", + { { + "inputs", + RPCArg::Type::ARR, + /* opt */ false, + /* default_val */ "", + "A json array of json objects", { - "inputs", - RPCArg::Type::ARR, - /* opt */ false, - /* default_val */ "", - "A json array of json objects", { + "", + RPCArg::Type::OBJ, + /* opt */ false, + /* default_val */ "", + "", { - "", - RPCArg::Type::OBJ, - /* opt */ false, - /* default_val */ "", - "", - { - {"txid", RPCArg::Type::STR_HEX, - /* opt */ false, /* default_val */ "", - "The transaction id"}, - {"vout", RPCArg::Type::NUM, /* opt */ false, - /* default_val */ "", "The output number"}, - {"sequence", RPCArg::Type::NUM, - /* opt */ true, /* default_val */ "", - "The sequence number"}, - }, + {"txid", RPCArg::Type::STR_HEX, + /* opt */ false, /* default_val */ "", + "The transaction id"}, + {"vout", RPCArg::Type::NUM, /* opt */ false, + /* default_val */ "", "The output number"}, + {"sequence", RPCArg::Type::NUM, + /* opt */ true, /* default_val */ "", + "The sequence number"}, }, }, }, + }, + { + "outputs", + RPCArg::Type::ARR, + /* opt */ false, + /* default_val */ "", + "a json array with outputs (key-value pairs).\n" + "For compatibility reasons, a dictionary, which holds " + "the key-value pairs directly, is also\n" + " accepted as second " + "parameter.", { - "outputs", - RPCArg::Type::ARR, - /* opt */ false, - /* default_val */ "", - "a json array with outputs (key-value pairs).\n" - "For compatibility reasons, a dictionary, which holds " - "the key-value pairs directly, is also\n" - " accepted as second " - "parameter.", { + "", + RPCArg::Type::OBJ, + /* opt */ true, + /* default_val */ "", + "", { - "", - RPCArg::Type::OBJ, - /* opt */ true, - /* default_val */ "", - "", - { - {"address", RPCArg::Type::AMOUNT, - /* opt */ false, /* default_val */ "", - "A key-value pair. The key (string) is " - "the bitcoin address, the value (float or " - "string) is the amount in " + - CURRENCY_UNIT}, - }, + {"address", RPCArg::Type::AMOUNT, + /* opt */ false, /* default_val */ "", + "A key-value pair. The key (string) is " + "the bitcoin address, the value (float or " + "string) is the amount in " + + CURRENCY_UNIT}, }, + }, + { + "", + RPCArg::Type::OBJ, + /* opt */ true, + /* default_val */ "", + "", { - "", - RPCArg::Type::OBJ, - /* opt */ true, - /* default_val */ "", - "", - { - {"data", RPCArg::Type::STR_HEX, - /* opt */ false, /* default_val */ "", - "A key-value pair. The key must be " - "\"data\", the value is hex-encoded data"}, - }, + {"data", RPCArg::Type::STR_HEX, + /* opt */ false, /* default_val */ "", + "A key-value pair. The key must be " + "\"data\", the value is hex-encoded data"}, }, }, }, - {"locktime", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "0", - "Raw locktime. Non-0 value also locktime-activates " - "inputs"}, - }} - .ToString() + - "\nResult:\n" - "\"transaction\" (string) hex string of the " - "transaction\n" - - "\nExamples:\n" + - HelpExampleCli("createrawtransaction", - "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" " - "\"[{\\\"address\\\":0.01}]\"") + - HelpExampleCli("createrawtransaction", - "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" " - "\"[{\\\"data\\\":\\\"00010203\\\"}]\"") + - HelpExampleRpc("createrawtransaction", - "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", " - "\"[{\\\"address\\\":0.01}]\"") + - HelpExampleRpc("createrawtransaction", - "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", " - "\"[{\\\"data\\\":\\\"00010203\\\"}]\"")); + }, + {"locktime", RPCArg::Type::NUM, /* opt */ true, + /* default_val */ "0", + "Raw locktime. Non-0 value also locktime-activates " + "inputs"}, + }, + RPCResult{"\"transaction\" (string) hex string of the " + "transaction\n"}, + RPCExamples{ + HelpExampleCli("createrawtransaction", + "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]" + "\" \"[{\\\"address\\\":0.01}]\"") + + HelpExampleCli("createrawtransaction", + "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]" + "\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"") + + HelpExampleRpc("createrawtransaction", + "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]" + "\", \"[{\\\"address\\\":0.01}]\"") + + HelpExampleRpc("createrawtransaction", + "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]" + "\", \"[{\\\"data\\\":\\\"00010203\\\"}]\"")}, + } + .ToString()); } RPCTypeCheck(request.params, @@ -669,61 +687,63 @@ static UniValue decoderawtransaction(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{"decoderawtransaction", - "\nReturn a JSON object representing the serialized, " - "hex-encoded transaction.\n", - { - {"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "The transaction hex string"}, - }} - .ToString() + - "\nResult:\n" - "{\n" - " \"txid\" : \"id\", (string) The transaction id\n" - " \"hash\" : \"id\", (string) The transaction hash " - "(differs from txid for witness transactions)\n" - " \"size\" : n, (numeric) The transaction size\n" - " \"version\" : n, (numeric) The version\n" - " \"locktime\" : ttt, (numeric) The lock time\n" - " \"vin\" : [ (array of json objects)\n" - " {\n" - " \"txid\": \"id\", (string) The transaction id\n" - " \"vout\": n, (numeric) The output number\n" - " \"scriptSig\": { (json object) The script\n" - " \"asm\": \"asm\", (string) asm\n" - " \"hex\": \"hex\" (string) hex\n" - " },\n" - " \"sequence\": n (numeric) The script sequence number\n" - " }\n" - " ,...\n" - " ],\n" - " \"vout\" : [ (array of json objects)\n" - " {\n" - " \"value\" : x.xxx, (numeric) The value in " + - CURRENCY_UNIT + - "\n" - " \"n\" : n, (numeric) index\n" - " \"scriptPubKey\" : { (json object)\n" - " \"asm\" : \"asm\", (string) the asm\n" - " \"hex\" : \"hex\", (string) the hex\n" - " \"reqSigs\" : n, (numeric) The required sigs\n" - " \"type\" : \"pubkeyhash\", (string) The type, eg " - "'pubkeyhash'\n" - " \"addresses\" : [ (json array of string)\n" - " \"12tvKAXCxZjSmdNbao16dKXC8tRWfcF5oc\" (string) " - "bitcoin address\n" - " ,...\n" - " ]\n" - " }\n" - " }\n" - " ,...\n" - " ],\n" - "}\n" - - "\nExamples:\n" + - HelpExampleCli("decoderawtransaction", "\"hexstring\"") + - HelpExampleRpc("decoderawtransaction", "\"hexstring\"")); + throw std::runtime_error(RPCHelpMan{ + "decoderawtransaction", + "\nReturn a JSON object representing the serialized, " + "hex-encoded transaction.\n", + { + {"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, + /* default_val */ "", "The transaction hex string"}, + }, + RPCResult{ + "{\n" + " \"txid\" : \"id\", (string) The transaction id\n" + " \"hash\" : \"id\", (string) The transaction hash " + "(differs from txid for witness transactions)\n" + " \"size\" : n, (numeric) The transaction size\n" + " \"version\" : n, (numeric) The version\n" + " \"locktime\" : ttt, (numeric) The lock time\n" + " \"vin\" : [ (array of json objects)\n" + " {\n" + " \"txid\": \"id\", (string) The transaction id\n" + " \"vout\": n, (numeric) The output number\n" + " \"scriptSig\": { (json object) The script\n" + " \"asm\": \"asm\", (string) asm\n" + " \"hex\": \"hex\" (string) hex\n" + " },\n" + " \"sequence\": n (numeric) The script sequence " + "number\n" + " }\n" + " ,...\n" + " ],\n" + " \"vout\" : [ (array of json objects)\n" + " {\n" + " \"value\" : x.xxx, (numeric) The value in " + + CURRENCY_UNIT + + "\n" + " \"n\" : n, (numeric) index\n" + " \"scriptPubKey\" : { (json object)\n" + " \"asm\" : \"asm\", (string) the asm\n" + " \"hex\" : \"hex\", (string) the hex\n" + " \"reqSigs\" : n, (numeric) The required " + "sigs\n" + " \"type\" : \"pubkeyhash\", (string) The type, eg " + "'pubkeyhash'\n" + " \"addresses\" : [ (json array of string)\n" + " \"12tvKAXCxZjSmdNbao16dKXC8tRWfcF5oc\" (string) " + "bitcoin address\n" + " ,...\n" + " ]\n" + " }\n" + " }\n" + " ,...\n" + " ],\n" + "}\n"}, + RPCExamples{ + HelpExampleCli("decoderawtransaction", "\"hexstring\"") + + HelpExampleRpc("decoderawtransaction", "\"hexstring\"")}, + } + .ToString()); } RPCTypeCheck(request.params, {UniValue::VSTR}); @@ -743,31 +763,32 @@ static UniValue decodescript(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{"decodescript", - "\nDecode a hex-encoded script.\n", - { - {"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "the hex-encoded script"}, - }} - .ToString() + - "\nResult:\n" - "{\n" - " \"asm\":\"asm\", (string) Script public key\n" - " \"hex\":\"hex\", (string) hex-encoded public key\n" - " \"type\":\"type\", (string) The output type\n" - " \"reqSigs\": n, (numeric) The required signatures\n" - " \"addresses\": [ (json array of string)\n" - " \"address\" (string) bitcoin address\n" - " ,...\n" - " ],\n" - " \"p2sh\",\"address\" (string) address of P2SH script wrapping " - "this redeem script (not returned if the script is already a " - "P2SH).\n" - "}\n" - "\nExamples:\n" + - HelpExampleCli("decodescript", "\"hexstring\"") + - HelpExampleRpc("decodescript", "\"hexstring\"")); + throw std::runtime_error(RPCHelpMan{ + "decodescript", + "\nDecode a hex-encoded script.\n", + { + {"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, + /* default_val */ "", "the hex-encoded script"}, + }, + RPCResult{ + "{\n" + " \"asm\":\"asm\", (string) Script public key\n" + " \"hex\":\"hex\", (string) hex-encoded public key\n" + " \"type\":\"type\", (string) The output type\n" + " \"reqSigs\": n, (numeric) The required signatures\n" + " \"addresses\": [ (json array of string)\n" + " \"address\" (string) bitcoin address\n" + " ,...\n" + " ],\n" + " \"p2sh\",\"address\" (string) address of P2SH script " + "wrapping " + "this redeem script (not returned if the script is already a " + "P2SH).\n" + "}\n"}, + RPCExamples{HelpExampleCli("decodescript", "\"hexstring\"") + + HelpExampleRpc("decodescript", "\"hexstring\"")}, + } + .ToString()); } RPCTypeCheck(request.params, {UniValue::VSTR}); @@ -814,36 +835,34 @@ static UniValue combinerawtransaction(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{"combinerawtransaction", - "\nCombine multiple partially signed transactions into " - "one transaction.\n" - "The combined transaction may be another partially " - "signed transaction or a \n" - "fully signed transaction.", - { - { - "txs", - RPCArg::Type::ARR, - /* opt */ false, - /* default_val */ "", - "A json array of hex strings of partially " - "signed transactions", - { - {"hexstring", RPCArg::Type::STR_HEX, - /* opt */ false, /* default_val */ "", - "A transaction hash"}, - }, - }, - }} - .ToString() + - "\nResult:\n" - "\"hex\" (string) The hex-encoded raw transaction with " - "signature(s)\n" - - "\nExamples:\n" + - HelpExampleCli("combinerawtransaction", - "[\"myhex1\", \"myhex2\", \"myhex3\"]")); + throw std::runtime_error(RPCHelpMan{ + "combinerawtransaction", + "\nCombine multiple partially signed transactions into " + "one transaction.\n" + "The combined transaction may be another partially " + "signed transaction or a \n" + "fully signed transaction.", + { + { + "txs", + RPCArg::Type::ARR, + /* opt */ false, + /* default_val */ "", + "A json array of hex strings of partially " + "signed transactions", + { + {"hexstring", RPCArg::Type::STR_HEX, + /* opt */ false, /* default_val */ "", + "A transaction hash"}, + }, + }, + }, + RPCResult{"\"hex\" (string) The hex-encoded raw " + "transaction with signature(s)\n"}, + RPCExamples{HelpExampleCli("combinerawtransaction", + "[\"myhex1\", \"myhex2\", \"myhex3\"]")}, + } + .ToString()); } UniValue txs = request.params[0].get_array(); @@ -1092,105 +1111,110 @@ const JSONRPCRequest &request) { if (request.fHelp || request.params.size() < 2 || request.params.size() > 4) { - throw std::runtime_error( - RPCHelpMan{ - "signrawtransactionwithkey", - "\nSign inputs for raw transaction (serialized, hex-encoded).\n" - "The second argument is an array of base58-encoded private\n" - "keys that will be the only keys used to sign the " - "transaction.\n" - "The third optional argument (may be null) is an array of " - "previous transaction outputs that\n" - "this transaction depends on but may not yet be in the block " - "chain.\n", + throw std::runtime_error(RPCHelpMan{ + "signrawtransactionwithkey", + "\nSign inputs for raw transaction (serialized, hex-encoded).\n" + "The second argument is an array of base58-encoded private\n" + "keys that will be the only keys used to sign the " + "transaction.\n" + "The third optional argument (may be null) is an array of " + "previous transaction outputs that\n" + "this transaction depends on but may not yet be in the block " + "chain.\n", + { + {"hexstring", RPCArg::Type::STR, /* opt */ false, + /* default_val */ "", "The transaction hex string"}, { - {"hexstring", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "The transaction hex string"}, + "privkeys", + RPCArg::Type::ARR, + /* opt */ false, + /* default_val */ "", + "A json array of base58-encoded private keys for " + "signing", { - "privkeys", - RPCArg::Type::ARR, - /* opt */ false, - /* default_val */ "", - "A json array of base58-encoded private keys for " - "signing", - { - {"privatekey", RPCArg::Type::STR_HEX, - /* opt */ false, /* default_val */ "", - "private key in base58-encoding"}, - }, + {"privatekey", RPCArg::Type::STR_HEX, + /* opt */ false, /* default_val */ "", + "private key in base58-encoding"}, }, + }, + { + "prevtxs", + RPCArg::Type::ARR, + /* opt */ true, + /* default_val */ "", + "A json array of previous dependent transaction " + "outputs", { - "prevtxs", - RPCArg::Type::ARR, - /* opt */ true, - /* default_val */ "", - "A json array of previous dependent transaction " - "outputs", { + "", + RPCArg::Type::OBJ, + /* opt */ true, + /* default_val */ "", + "", { - "", - RPCArg::Type::OBJ, - /* opt */ true, - /* default_val */ "", - "", - { - {"txid", RPCArg::Type::STR_HEX, - /* opt */ false, /* default_val */ "", - "The transaction id"}, - {"vout", RPCArg::Type::NUM, /* opt */ false, - /* default_val */ "", "The output number"}, - {"scriptPubKey", RPCArg::Type::STR_HEX, - /* opt */ false, /* default_val */ "", - "script key"}, - {"redeemScript", RPCArg::Type::STR_HEX, - /* opt */ true, /* default_val */ "", - "(required for P2SH or P2WSH) redeem " - "script"}, - {"amount", RPCArg::Type::AMOUNT, - /* opt */ false, /* default_val */ "", - "The amount spent"}, - }, + {"txid", RPCArg::Type::STR_HEX, + /* opt */ false, /* default_val */ "", + "The transaction id"}, + {"vout", RPCArg::Type::NUM, /* opt */ false, + /* default_val */ "", "The output number"}, + {"scriptPubKey", RPCArg::Type::STR_HEX, + /* opt */ false, /* default_val */ "", + "script key"}, + {"redeemScript", RPCArg::Type::STR_HEX, + /* opt */ true, /* default_val */ "", + "(required for P2SH or P2WSH) redeem " + "script"}, + {"amount", RPCArg::Type::AMOUNT, + /* opt */ false, /* default_val */ "", + "The amount spent"}, }, }, }, - {"sighashtype", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "ALL|FORKID", - "The signature hash type. Must be one of:\n" - " \"ALL|FORKID\"\n" - " \"NONE|FORKID\"\n" - " \"SINGLE|FORKID\"\n" - " \"ALL|FORKID|ANYONECANPAY\"\n" - " \"NONE|FORKID|ANYONECANPAY\"\n" - " \"SINGLE|FORKID|ANYONECANPAY\"\n"}, - }} - .ToString() + - "\nResult:\n" - "{\n" - " \"hex\" : \"value\", (string) The hex-encoded " - "raw transaction with signature(s)\n" - " \"complete\" : true|false, (boolean) If the " - "transaction has a complete set of signatures\n" - " \"errors\" : [ (json array of objects) " - "Script verification errors (if there are any)\n" - " {\n" - " \"txid\" : \"hash\", (string) The hash of the " - "referenced, previous transaction\n" - " \"vout\" : n, (numeric) The index of the " - "output to spent and used as input\n" - " \"scriptSig\" : \"hex\", (string) The hex-encoded " - "signature script\n" - " \"sequence\" : n, (numeric) Script sequence " - "number\n" - " \"error\" : \"text\" (string) Verification or " - "signing error related to the input\n" - " }\n" - " ,...\n" - " ]\n" - "}\n" - - "\nExamples:\n" + - HelpExampleCli("signrawtransactionwithkey", "\"myhex\"") + - HelpExampleRpc("signrawtransactionwithkey", "\"myhex\"")); + }, + {"sighashtype", RPCArg::Type::STR, /* opt */ true, + /* default_val */ "ALL|FORKID", + "The signature hash type. Must be one of:\n" + " \"ALL|FORKID\"\n" + " \"NONE|FORKID\"\n" + " \"SINGLE|FORKID\"\n" + " \"ALL|FORKID|ANYONECANPAY\"\n" + " \"NONE|FORKID|ANYONECANPAY\"\n" + " \"SINGLE|FORKID|ANYONECANPAY\"\n"}, + }, + RPCResult{ + "{\n" + " \"hex\" : \"value\", (string) The " + "hex-encoded " + "raw transaction with signature(s)\n" + " \"complete\" : true|false, (boolean) If the " + "transaction has a complete set of signatures\n" + " \"errors\" : [ (json array of objects) " + "Script verification errors (if there are any)\n" + " {\n" + " \"txid\" : \"hash\", (string) The hash of " + "the " + "referenced, previous transaction\n" + " \"vout\" : n, (numeric) The index of " + "the " + "output to spent and used as input\n" + " \"scriptSig\" : \"hex\", (string) The " + "hex-encoded " + "signature script\n" + " \"sequence\" : n, (numeric) Script " + "sequence " + "number\n" + " \"error\" : \"text\" (string) Verification " + "or " + "signing error related to the input\n" + " }\n" + " ,...\n" + " ]\n" + "}\n"}, + RPCExamples{ + HelpExampleCli("signrawtransactionwithkey", "\"myhex\"") + + HelpExampleRpc("signrawtransactionwithkey", "\"myhex\"")}, + } + .ToString()); } RPCTypeCheck( @@ -1222,34 +1246,34 @@ const JSONRPCRequest &request) { if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) { - throw std::runtime_error( - RPCHelpMan{"sendrawtransaction", - "\nSubmits raw transaction (serialized, hex-encoded) to " - "local node and network.\n" - "\nAlso see createrawtransaction and " - "signrawtransactionwithkey calls.\n", - { - {"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", - "The hex string of the raw transaction"}, - {"allowhighfees", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "false", "Allow high fees"}, - }} - .ToString() + - "\nResult:\n" - "\"hex\" (string) The transaction hash in hex\n" - "\nExamples:\n" - "\nCreate a transaction\n" + - HelpExampleCli( - "createrawtransaction", - "\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" " - "\"{\\\"myaddress\\\":0.01}\"") + - "Sign the transaction, and get back the hex\n" + - HelpExampleCli("signrawtransactionwithwallet", "\"myhex\"") + - "\nSend the transaction (signed hex)\n" + - HelpExampleCli("sendrawtransaction", "\"signedhex\"") + - "\nAs a JSON-RPC call\n" + - HelpExampleRpc("sendrawtransaction", "\"signedhex\"")); + throw std::runtime_error(RPCHelpMan{ + "sendrawtransaction", + "\nSubmits raw transaction (serialized, hex-encoded) to " + "local node and network.\n" + "\nAlso see createrawtransaction and " + "signrawtransactionwithkey calls.\n", + { + {"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, + /* default_val */ "", "The hex string of the raw transaction"}, + {"allowhighfees", RPCArg::Type::BOOL, /* opt */ true, + /* default_val */ "false", "Allow high fees"}, + }, + RPCResult{ + "\"hex\" (string) The transaction hash in hex\n"}, + RPCExamples{ + "\nCreate a transaction\n" + + HelpExampleCli( + "createrawtransaction", + "\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" " + "\"{\\\"myaddress\\\":0.01}\"") + + "Sign the transaction, and get back the hex\n" + + HelpExampleCli("signrawtransactionwithwallet", "\"myhex\"") + + "\nSend the transaction (signed hex)\n" + + HelpExampleCli("sendrawtransaction", "\"signedhex\"") + + "\nAs a JSON-RPC call\n" + + HelpExampleRpc("sendrawtransaction", "\"signedhex\"")}, + } + .ToString()); } std::promise promise; @@ -1336,55 +1360,58 @@ const JSONRPCRequest &request) { if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) { - throw std::runtime_error( - RPCHelpMan{"testmempoolaccept", - "\nReturns if raw transaction (serialized, hex-encoded) " - "would be accepted by mempool.\n" - "\nThis checks if the transaction violates the " - "consensus or policy rules.\n" - "\nSee sendrawtransaction call.\n", - { - { - "rawtxs", - RPCArg::Type::ARR, - /* opt */ false, - /* default_val */ "", - "An array of hex strings of raw transactions.\n" - " Length " - "must be one for now.", - { - {"rawtx", RPCArg::Type::STR_HEX, - /* opt */ false, /* default_val */ "", ""}, - }, - }, - {"allowhighfees", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "false", "Allow high fees"}, - }} - .ToString() + - "\nResult:\n" - "[ (array) The result of the mempool acceptance " - "test for each raw transaction in the input array.\n" - " Length is exactly one for now.\n" - " {\n" - " \"txid\" (string) The transaction hash in hex\n" - " \"allowed\" (boolean) If the mempool allows this tx to " - "be inserted\n" - " \"reject-reason\" (string) Rejection string (only present when " - "'allowed' is false)\n" - " }\n" - "]\n" - "\nExamples:\n" - "\nCreate a transaction\n" + - HelpExampleCli( - "createrawtransaction", - "\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" " - "\"{\\\"myaddress\\\":0.01}\"") + - "Sign the transaction, and get back the hex\n" + - HelpExampleCli("signrawtransactionwithwallet", "\"myhex\"") + - "\nTest acceptance of the transaction (signed hex)\n" + - HelpExampleCli("testmempoolaccept", "\"signedhex\"") + - "\nAs a JSON-RPC call\n" + - HelpExampleRpc("testmempoolaccept", "[\"signedhex\"]")); + throw std::runtime_error(RPCHelpMan{ + "testmempoolaccept", + "\nReturns if raw transaction (serialized, hex-encoded) " + "would be accepted by mempool.\n" + "\nThis checks if the transaction violates the " + "consensus or policy rules.\n" + "\nSee sendrawtransaction call.\n", + { + { + "rawtxs", + RPCArg::Type::ARR, + /* opt */ false, + /* default_val */ "", + "An array of hex strings of raw transactions.\n" + " Length " + "must be one for now.", + { + {"rawtx", RPCArg::Type::STR_HEX, + /* opt */ false, /* default_val */ "", ""}, + }, + }, + {"allowhighfees", RPCArg::Type::BOOL, /* opt */ true, + /* default_val */ "false", "Allow high fees"}, + }, + RPCResult{ + "[ (array) The result of the mempool " + "acceptance test for each raw transaction in the input array.\n" + " Length is exactly one for now.\n" + " {\n" + " \"txid\" (string) The transaction hash in hex\n" + " \"allowed\" (boolean) If the mempool allows this tx " + "to " + "be inserted\n" + " \"reject-reason\" (string) Rejection string (only present " + "when " + "'allowed' is false)\n" + " }\n" + "]\n"}, + RPCExamples{ + "\nCreate a transaction\n" + + HelpExampleCli( + "createrawtransaction", + "\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" " + "\"{\\\"myaddress\\\":0.01}\"") + + "Sign the transaction, and get back the hex\n" + + HelpExampleCli("signrawtransactionwithwallet", "\"myhex\"") + + "\nTest acceptance of the transaction (signed hex)\n" + + HelpExampleCli("testmempoolaccept", "[\"signedhex\"]") + + "\nAs a JSON-RPC call\n" + + HelpExampleRpc("testmempoolaccept", "[\"signedhex\"]")}, + } + .ToString()); } RPCTypeCheck(request.params, {UniValue::VARR, UniValue::VBOOL}); @@ -1457,118 +1484,133 @@ static UniValue decodepsbt(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{"decodepsbt", - "\nReturn a JSON object representing the serialized, " - "base64-encoded partially signed Bitcoin transaction.\n", - { - {"psbt", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "The PSBT base64 string"}, - }} - .ToString() + - "\nResult:\n" - "{\n" - " \"tx\" : { (json object) The decoded " - "network-serialized unsigned transaction.\n" - " ... The layout is the " - "same as the output of decoderawtransaction.\n" - " },\n" - " \"unknown\" : { (json object) The unknown global " - "fields\n" - " \"key\" : \"value\" (key-value pair) An unknown " - "key-value pair\n" - " ...\n" - " },\n" - " \"inputs\" : [ (array of json objects)\n" - " {\n" - " \"utxo\" : { (json object, optional) Transaction " - "output for UTXOs\n" - " \"amount\" : x.xxx, (numeric) The value in " + - CURRENCY_UNIT + - "\n" - " \"scriptPubKey\" : { (json object)\n" - " \"asm\" : \"asm\", (string) The asm\n" - " \"hex\" : \"hex\", (string) The hex\n" - " \"type\" : \"pubkeyhash\", (string) The type, eg " - "'pubkeyhash'\n" - " \"address\" : \"address\" (string) Bitcoin address " - "if there is one\n" - " }\n" - " },\n" - " \"partial_signatures\" : { (json object, " - "optional)\n" - " \"pubkey\" : \"signature\", (string) The public " - "key and signature that corresponds to it.\n" - " ,...\n" - " }\n" - " \"sighash\" : \"type\", (string, optional) " - "The sighash type to be used\n" - " \"redeem_script\" : { (json object, optional)\n" - " \"asm\" : \"asm\", (string) The asm\n" - " \"hex\" : \"hex\", (string) The hex\n" - " \"type\" : \"pubkeyhash\", (string) The type, eg " - "'pubkeyhash'\n" - " }\n" - " \"bip32_derivs\" : { (json object, optional)\n" - " \"pubkey\" : { (json object, " - "optional) The public key with the derivation path as the value.\n" - " \"master_fingerprint\" : \"fingerprint\" (string) " - "The fingerprint of the master key\n" - " \"path\" : \"path\", (string) " - "The path\n" - " }\n" - " ,...\n" - " }\n" - " \"final_scriptsig\" : { (json object, optional)\n" - " \"asm\" : \"asm\", (string) The asm\n" - " \"hex\" : \"hex\", (string) The hex\n" - " }\n" - " \"unknown\" : { (json object) The unknown " - "global fields\n" - " \"key\" : \"value\" (key-value pair) An " - "unknown key-value pair\n" - " ...\n" - " },\n" - " }\n" - " ,...\n" - " ]\n" - " \"outputs\" : [ (array of json objects)\n" - " {\n" - " \"redeem_script\" : { (json object, optional)\n" - " \"asm\" : \"asm\", (string) The asm\n" - " \"hex\" : \"hex\", (string) The hex\n" - " \"type\" : \"pubkeyhash\", (string) The type, eg " - "'pubkeyhash'\n" - " }\n" - " \"bip32_derivs\" : [ (array of json objects, " - "optional)\n" - " {\n" - " \"pubkey\" : \"pubkey\", (string) " - "The public key this path corresponds to\n" - " \"master_fingerprint\" : \"fingerprint\" (string) " - "The fingerprint of the master key\n" - " \"path\" : \"path\", (string) " - "The path\n" - " }\n" - " }\n" - " ,...\n" - " ],\n" - " \"unknown\" : { (json object) The unknown " - "global fields\n" - " \"key\" : \"value\" (key-value pair) An " - "unknown key-value pair\n" - " ...\n" - " },\n" - " }\n" - " ,...\n" - " ]\n" - " \"fee\" : fee (numeric, optional) The " - "transaction fee paid if all UTXOs slots in the PSBT have been " - "filled.\n" - "}\n" - - "\nExamples:\n" + - HelpExampleCli("decodepsbt", "\"psbt\"")); + throw std::runtime_error(RPCHelpMan{ + "decodepsbt", + "\nReturn a JSON object representing the serialized, " + "base64-encoded partially signed Bitcoin transaction.\n", + { + {"psbt", RPCArg::Type::STR, /* opt */ false, + /* default_val */ "", "The PSBT base64 string"}, + }, + RPCResult{ + "{\n" + " \"tx\" : { (json object) The decoded " + "network-serialized unsigned transaction.\n" + " ... The layout is " + "the " + "same as the output of decoderawtransaction.\n" + " },\n" + " \"unknown\" : { (json object) The unknown " + "global " + "fields\n" + " \"key\" : \"value\" (key-value pair) An " + "unknown " + "key-value pair\n" + " ...\n" + " },\n" + " \"inputs\" : [ (array of json objects)\n" + " {\n" + " \"utxo\" : { (json object, optional) " + "Transaction " + "output for UTXOs\n" + " \"amount\" : x.xxx, (numeric) The value " + "in " + + CURRENCY_UNIT + + "\n" + " \"scriptPubKey\" : { (json object)\n" + " \"asm\" : \"asm\", (string) The asm\n" + " \"hex\" : \"hex\", (string) The hex\n" + " \"type\" : \"pubkeyhash\", (string) The type, eg " + "'pubkeyhash'\n" + " \"address\" : \"address\" (string) Bitcoin " + "address " + "if there is one\n" + " }\n" + " },\n" + " \"partial_signatures\" : { (json object, " + "optional)\n" + " \"pubkey\" : \"signature\", (string) The " + "public " + "key and signature that corresponds to it.\n" + " ,...\n" + " }\n" + " \"sighash\" : \"type\", (string, " + "optional) " + "The sighash type to be used\n" + " \"redeem_script\" : { (json object, optional)\n" + " \"asm\" : \"asm\", (string) The asm\n" + " \"hex\" : \"hex\", (string) The hex\n" + " \"type\" : \"pubkeyhash\", (string) The type, eg " + "'pubkeyhash'\n" + " }\n" + " \"bip32_derivs\" : { (json object, optional)\n" + " \"pubkey\" : { (json object, " + "optional) The public key with the derivation path as the " + "value.\n" + " \"master_fingerprint\" : \"fingerprint\" " + "(string) " + "The fingerprint of the master key\n" + " \"path\" : \"path\", " + "(string) " + "The path\n" + " }\n" + " ,...\n" + " }\n" + " \"final_scriptsig\" : { (json object, optional)\n" + " \"asm\" : \"asm\", (string) The asm\n" + " \"hex\" : \"hex\", (string) The hex\n" + " }\n" + " \"unknown\" : { (json object) The " + "unknown " + "global fields\n" + " \"key\" : \"value\" (key-value pair) An " + "unknown key-value pair\n" + " ...\n" + " },\n" + " }\n" + " ,...\n" + " ]\n" + " \"outputs\" : [ (array of json objects)\n" + " {\n" + " \"redeem_script\" : { (json object, optional)\n" + " \"asm\" : \"asm\", (string) The asm\n" + " \"hex\" : \"hex\", (string) The hex\n" + " \"type\" : \"pubkeyhash\", (string) The type, eg " + "'pubkeyhash'\n" + " }\n" + " \"bip32_derivs\" : [ (array of json objects, " + "optional)\n" + " {\n" + " \"pubkey\" : \"pubkey\", " + "(string) " + "The public key this path corresponds to\n" + " \"master_fingerprint\" : \"fingerprint\" " + "(string) " + "The fingerprint of the master key\n" + " \"path\" : \"path\", " + "(string) " + "The path\n" + " }\n" + " }\n" + " ,...\n" + " ],\n" + " \"unknown\" : { (json object) The " + "unknown " + "global fields\n" + " \"key\" : \"value\" (key-value pair) An " + "unknown key-value pair\n" + " ...\n" + " },\n" + " }\n" + " ,...\n" + " ]\n" + " \"fee\" : fee (numeric, optional) The " + "transaction fee paid if all UTXOs slots in the PSBT have been " + "filled.\n" + "}\n"}, + RPCExamples{HelpExampleCli("decodepsbt", "\"psbt\"")}, + } + .ToString()); } RPCTypeCheck(request.params, {UniValue::VSTR}); @@ -1735,33 +1777,32 @@ static UniValue combinepsbt(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{ - "combinepsbt", - "\nCombine multiple partially signed Bitcoin transactions into " - "one transaction.\n" - "Implements the Combiner role.\n", + throw std::runtime_error(RPCHelpMan{ + "combinepsbt", + "\nCombine multiple partially signed Bitcoin transactions into " + "one transaction.\n" + "Implements the Combiner role.\n", + { { + "txs", + RPCArg::Type::ARR, + /* opt */ false, + /* default_val */ "", + "A json array of base64 strings of partially signed " + "transactions", { - "txs", - RPCArg::Type::ARR, - /* opt */ false, - /* default_val */ "", - "A json array of base64 strings of partially signed " - "transactions", - { - {"psbt", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "A base64 string of a PSBT"}, - }, + {"psbt", RPCArg::Type::STR, /* opt */ false, + /* default_val */ "", "A base64 string of a PSBT"}, }, - }} - .ToString() + - "\nResult:\n" - " \"psbt\" (string) The base64-encoded partially signed " - "transaction\n" - "\nExamples:\n" + - HelpExampleCli("combinepsbt", - "[\"mybase64_1\", \"mybase64_2\", \"mybase64_3\"]")); + }, + }, + RPCResult{" \"psbt\" (string) The base64-encoded " + "partially signed transaction\n"}, + RPCExamples{HelpExampleCli( + "combinepsbt", + "[\"mybase64_1\", \"mybase64_2\", \"mybase64_3\"]")}, + } + .ToString()); } RPCTypeCheck(request.params, {UniValue::VARR}, true); @@ -1805,39 +1846,40 @@ const JSONRPCRequest &request) { if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) { - throw std::runtime_error( - RPCHelpMan{"finalizepsbt", - "Finalize the inputs of a PSBT. If the transaction is " - "fully signed, it will produce a\n" - "network serialized transaction which can be broadcast " - "with sendrawtransaction. Otherwise a PSBT will be\n" - "created which has the final_scriptSigfields filled for " - "inputs that are complete.\n" - "Implements the Finalizer and Extractor roles.\n", - { - {"psbt", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "A base64 string of a PSBT"}, - {"extract", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "true", - "If true and the transaction is complete,\n" - " extract and return " - "the complete transaction in normal network " - "serialization instead of the PSBT."}, - }} - .ToString() + - "\nResult:\n" - "{\n" - " \"psbt\" : \"value\", (string) The base64-encoded " - "partially signed transaction if not extracted\n" - " \"hex\" : \"value\", (string) The hex-encoded network " - "transaction if extracted\n" - " \"complete\" : true|false, (boolean) If the transaction has a " - "complete set of signatures\n" - " ]\n" - "}\n" - - "\nExamples:\n" + - HelpExampleCli("finalizepsbt", "\"psbt\"")); + throw std::runtime_error(RPCHelpMan{ + "finalizepsbt", + "Finalize the inputs of a PSBT. If the transaction is " + "fully signed, it will produce a\n" + "network serialized transaction which can be broadcast " + "with sendrawtransaction. Otherwise a PSBT will be\n" + "created which has the final_scriptSigfields filled for " + "inputs that are complete.\n" + "Implements the Finalizer and Extractor roles.\n", + { + {"psbt", RPCArg::Type::STR, /* opt */ false, + /* default_val */ "", "A base64 string of a PSBT"}, + {"extract", RPCArg::Type::BOOL, /* opt */ true, + /* default_val */ "true", + "If true and the transaction is complete,\n" + " extract and return " + "the complete transaction in normal network " + "serialization instead of the PSBT."}, + }, + RPCResult{ + "{\n" + " \"psbt\" : \"value\", (string) The base64-encoded " + "partially signed transaction if not extracted\n" + " \"hex\" : \"value\", (string) The hex-encoded " + "network " + "transaction if extracted\n" + " \"complete\" : true|false, (boolean) If the transaction " + "has a " + "complete set of signatures\n" + " ]\n" + "}\n"}, + RPCExamples{HelpExampleCli("finalizepsbt", "\"psbt\"")}, + } + .ToString()); } RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL}, true); @@ -1884,93 +1926,91 @@ const JSONRPCRequest &request) { if (request.fHelp || request.params.size() < 2 || request.params.size() > 3) { - throw std::runtime_error( - RPCHelpMan{ - "createpsbt", - "\nCreates a transaction in the Partially Signed " - "Transaction format.\n" - "Implements the Creator role.\n", + throw std::runtime_error(RPCHelpMan{ + "createpsbt", + "\nCreates a transaction in the Partially Signed " + "Transaction format.\n" + "Implements the Creator role.\n", + { { + "inputs", + RPCArg::Type::ARR, + /* opt */ false, + /* default_val */ "", + "A json array of json objects", { - "inputs", - RPCArg::Type::ARR, - /* opt */ false, - /* default_val */ "", - "A json array of json objects", { + "", + RPCArg::Type::OBJ, + /* opt */ false, + /* default_val */ "", + "", { - "", - RPCArg::Type::OBJ, - /* opt */ false, - /* default_val */ "", - "", - { - {"txid", RPCArg::Type::STR_HEX, - /* opt */ false, /* default_val */ "", - "The transaction id"}, - {"vout", RPCArg::Type::NUM, /* opt */ false, - /* default_val */ "", "The output number"}, - {"sequence", RPCArg::Type::NUM, - /* opt */ true, /* default_val */ "", - "The sequence number"}, - }, + {"txid", RPCArg::Type::STR_HEX, + /* opt */ false, /* default_val */ "", + "The transaction id"}, + {"vout", RPCArg::Type::NUM, /* opt */ false, + /* default_val */ "", "The output number"}, + {"sequence", RPCArg::Type::NUM, + /* opt */ true, /* default_val */ "", + "The sequence number"}, }, }, }, + }, + { + "outputs", + RPCArg::Type::ARR, + /* opt */ false, + /* default_val */ "", + "a json array with outputs (key-value pairs).\n" + "For compatibility reasons, a dictionary, which holds " + "the key-value pairs directly, is also\n" + " accepted as second " + "parameter.", { - "outputs", - RPCArg::Type::ARR, - /* opt */ false, - /* default_val */ "", - "a json array with outputs (key-value pairs).\n" - "For compatibility reasons, a dictionary, which holds " - "the key-value pairs directly, is also\n" - " accepted as second " - "parameter.", { + "", + RPCArg::Type::OBJ, + /* opt */ true, + /* default_val */ "", + "", { - "", - RPCArg::Type::OBJ, - /* opt */ true, - /* default_val */ "", - "", - { - {"address", RPCArg::Type::AMOUNT, - /* opt */ false, /* default_val */ "", - "A key-value pair. The key (string) is " - "the bitcoin address, the value (float or " - "string) is the amount in " + - CURRENCY_UNIT}, - }, + {"address", RPCArg::Type::AMOUNT, + /* opt */ false, /* default_val */ "", + "A key-value pair. The key (string) is " + "the bitcoin address, the value (float or " + "string) is the amount in " + + CURRENCY_UNIT}, }, + }, + { + "", + RPCArg::Type::OBJ, + /* opt */ true, + /* default_val */ "", + "", { - "", - RPCArg::Type::OBJ, - /* opt */ true, - /* default_val */ "", - "", - { - {"data", RPCArg::Type::STR_HEX, - /* opt */ false, /* default_val */ "", - "A key-value pair. The key must be " - "\"data\", the value is hex-encoded data"}, - }, + {"data", RPCArg::Type::STR_HEX, + /* opt */ false, /* default_val */ "", + "A key-value pair. The key must be " + "\"data\", the value is hex-encoded data"}, }, }, }, - {"locktime", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "0", - "Raw locktime. Non-0 value also locktime-activates " - "inputs"}, - }} - .ToString() + - "\nResult:\n" - " \"psbt\" (string) The resulting raw transaction " - "(base64-encoded string)\n" - "\nExamples:\n" + - HelpExampleCli("createpsbt", - "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" " - "\"[{\\\"data\\\":\\\"00010203\\\"}]\"")); + }, + {"locktime", RPCArg::Type::NUM, /* opt */ true, + /* default_val */ "0", + "Raw locktime. Non-0 value also locktime-activates " + "inputs"}, + }, + RPCResult{" \"psbt\" (string) The resulting raw " + "transaction (base64-encoded string)\n"}, + RPCExamples{HelpExampleCli( + "createpsbt", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]" + "\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"")}, + } + .ToString()); } RPCTypeCheck(request.params, @@ -2006,36 +2046,34 @@ const JSONRPCRequest &request) { if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) { - throw std::runtime_error( - RPCHelpMan{ - "converttopsbt", - "\nConverts a network serialized transaction to a PSBT. " - "This should be used only with createrawtransaction and " - "fundrawtransaction\n" - "createpsbt and walletcreatefundedpsbt should be used " - "for new applications.\n", - { - {"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", - "The hex string of a raw transaction"}, - {"permitsigdata", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "false", - "If true, any signatures in the input will be discarded " - "and conversion.\n" - " will continue. If false, " - "RPC will fail if any signatures are present."}, - }} - .ToString() + - "\nResult:\n" - " \"psbt\" (string) The resulting raw transaction " - "(base64-encoded string)\n" - "\nExamples:\n" - "\nCreate a transaction\n" + - HelpExampleCli("createrawtransaction", - "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" " - "\"[{\\\"data\\\":\\\"00010203\\\"}]\"") + - "\nConvert the transaction to a PSBT\n" + - HelpExampleCli("converttopsbt", "\"rawtransaction\"")); + throw std::runtime_error(RPCHelpMan{ + "converttopsbt", + "\nConverts a network serialized transaction to a PSBT. " + "This should be used only with createrawtransaction and " + "fundrawtransaction\n" + "createpsbt and walletcreatefundedpsbt should be used " + "for new applications.\n", + { + {"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, + /* default_val */ "", "The hex string of a raw transaction"}, + {"permitsigdata", RPCArg::Type::BOOL, /* opt */ true, + /* default_val */ "false", + "If true, any signatures in the input will be discarded " + "and conversion.\n" + " will continue. If false, " + "RPC will fail if any signatures are present."}, + }, + RPCResult{" \"psbt\" (string) The resulting raw " + "transaction (base64-encoded string)\n"}, + RPCExamples{ + "\nCreate a transaction\n" + + HelpExampleCli("createrawtransaction", + "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]" + "\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"") + + "\nConvert the transaction to a PSBT\n" + + HelpExampleCli("converttopsbt", "\"rawtransaction\"")}, + } + .ToString()); } RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL}, true); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -283,17 +283,17 @@ static UniValue help(Config &config, const JSONRPCRequest &jsonRequest) { if (jsonRequest.fHelp || jsonRequest.params.size() > 1) { - throw std::runtime_error( - RPCHelpMan{ - "help", - "\nList all commands, or get help for a specified command.\n", - { - {"command", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "", "The command to get help on"}, - }} - .ToString() + - "\nResult:\n" - "\"text\" (string) The help text\n"); + throw std::runtime_error(RPCHelpMan{ + "help", + "\nList all commands, or get help for a specified command.\n", + { + {"command", RPCArg::Type::STR, /* opt */ true, + /* default_val */ "", "The command to get help on"}, + }, + RPCResult{"\"text\" (string) The help text\n"}, + RPCExamples{""}, + } + .ToString()); } std::string strCommand; @@ -310,10 +310,15 @@ // For instance, 'stop 1000' makes the call wait 1 second before returning // to the client (intended for testing) if (jsonRequest.fHelp || jsonRequest.params.size() > 1) { - throw std::runtime_error( - RPCHelpMan{"stop", "\nStop Bitcoin server.", {}}.ToString()); + throw std::runtime_error(RPCHelpMan{ + "stop", + "\nStop Bitcoin server.", + {}, + RPCResults{}, + RPCExamples{""}, + } + .ToString()); } - // Event loop will exit after current HTTP requests have been handled, so // this reply will get back to the client. StartShutdown(); @@ -326,15 +331,16 @@ static UniValue uptime(const Config &config, const JSONRPCRequest &jsonRequest) { if (jsonRequest.fHelp || jsonRequest.params.size() > 0) { - throw std::runtime_error( - RPCHelpMan{ - "uptime", "\nReturns the total uptime of the server.\n", {}} - .ToString() + - "\nResult:\n" - "ttt (numeric) The number of seconds " - "that the server has been running\n" - "\nExamples:\n" + - HelpExampleCli("uptime", "") + HelpExampleRpc("uptime", "")); + throw std::runtime_error(RPCHelpMan{ + "uptime", + "\nReturns the total uptime of the server.\n", + {}, + RPCResult{"ttt (numeric) The number of seconds that the " + "server has been running\n"}, + RPCExamples{HelpExampleCli("uptime", "") + + HelpExampleRpc("uptime", "")}, + } + .ToString()); } return GetTime() - GetStartupTime(); @@ -346,7 +352,11 @@ throw std::runtime_error(RPCHelpMan{ "getrpcinfo", "\nReturns details of the RPC server.\n", - {}}.ToString()); + {}, + RPCResults{}, + RPCExamples{""}, + } + .ToString()); } LOCK(g_rpc_server_info.mutex); diff --git a/src/rpc/util.h b/src/rpc/util.h --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -107,11 +107,48 @@ std::string ToDescriptionString(bool implicitly_required = false) const; }; +struct RPCResult { + const std::string m_cond; + const std::string m_result; + + explicit RPCResult(std::string result) + : m_cond{}, m_result{std::move(result)} { + assert(!m_result.empty()); + } + + RPCResult(std::string cond, std::string result) + : m_cond{std::move(cond)}, m_result{std::move(result)} { + assert(!m_cond.empty()); + assert(!m_result.empty()); + } +}; + +struct RPCResults { + const std::vector m_results; + + RPCResults() : m_results{} {} + + RPCResults(RPCResult result) : m_results{{result}} {} + + RPCResults(std::initializer_list results) : m_results{results} {} + + /** + * Return the description string. + */ + std::string ToDescriptionString() const; +}; + +struct RPCExamples { + const std::string m_examples; + RPCExamples(std::string examples) : m_examples(std::move(examples)) {} + std::string ToDescriptionString() const; +}; + class RPCHelpMan { public: - RPCHelpMan(const std::string &name, const std::string &description, - const std::vector &args) - : m_name{name}, m_description{description}, m_args{args} {} + RPCHelpMan(std::string name, std::string description, + std::vector args, RPCResults results, + RPCExamples examples); std::string ToString() const; @@ -119,6 +156,8 @@ const std::string m_name; const std::string m_description; const std::vector m_args; + const RPCResults m_results; + const RPCExamples m_examples; }; #endif // BITCOIN_RPC_UTIL_H diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -254,6 +254,36 @@ } }; +RPCHelpMan::RPCHelpMan(std::string name, std::string description, + std::vector args, RPCResults results, + RPCExamples examples) + : m_name{std::move(name)}, m_description{std::move(description)}, + m_args{std::move(args)}, m_results{std::move(results)}, + m_examples{std::move(examples)} { + std::set named_args; + for (const auto &arg : m_args) { + // Should have unique named arguments + assert(named_args.insert(arg.m_name).second); + } +} + +std::string RPCResults::ToDescriptionString() const { + std::string result; + for (const auto &r : m_results) { + if (r.m_cond.empty()) { + result += "\nResult:\n"; + } else { + result += "\nResult (" + r.m_cond + "):\n"; + } + result += r.m_result; + } + return result; +} + +std::string RPCExamples::ToDescriptionString() const { + return m_examples.empty() ? m_examples : "\nExamples:\n" + m_examples; +} + std::string RPCHelpMan::ToString() const { std::string ret; @@ -310,6 +340,12 @@ } ret += sections.ToString(); + // Result + ret += m_results.ToDescriptionString(); + + // Examples + ret += m_examples.ToDescriptionString(); + return ret; } diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -100,40 +100,42 @@ if (request.fHelp || request.params.size() < 1 || request.params.size() > 3) { - throw std::runtime_error( - RPCHelpMan{ - "importprivkey", - "\nAdds a private key (as returned by dumpprivkey) to " - "your wallet. Requires a new wallet backup.\n" - "Hint: use importmulti to import more than one private key.\n", - { - {"privkey", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "The private key (see dumpprivkey)"}, - {"label", RPCArg::Type::STR, /* opt */ true, - /* default_val */ - "current label if address exists, otherwise \"\"", - "An optional label"}, - {"rescan", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "true", - "Rescan the wallet for transactions"}, - }} - .ToString() + + throw std::runtime_error(RPCHelpMan{ + "importprivkey", + "\nAdds a private key (as returned by dumpprivkey) to " + "your wallet. Requires a new wallet backup.\n" + "Hint: use importmulti to import more than one private key.\n" "\nNote: This call can take minutes to complete if rescan is true, " "during that time, other rpc calls\n" "may report that the imported key exists but related transactions " "are still missing, leading to temporarily incorrect/bogus " - "balances and unspent outputs until rescan completes.\n" - "\nExamples:\n" - "\nDump a private key\n" + - HelpExampleCli("dumpprivkey", "\"myaddress\"") + - "\nImport the private key with rescan\n" + - HelpExampleCli("importprivkey", "\"mykey\"") + - "\nImport using a label and without rescan\n" + - HelpExampleCli("importprivkey", "\"mykey\" \"testing\" false") + - "\nImport using default blank label and without rescan\n" + - HelpExampleCli("importprivkey", "\"mykey\" \"\" false") + - "\nAs a JSON-RPC call\n" + - HelpExampleRpc("importprivkey", "\"mykey\", \"testing\", false")); + "balances and unspent outputs until rescan completes.\n", + { + {"privkey", RPCArg::Type::STR, /* opt */ false, + /* default_val */ "", "The private key (see dumpprivkey)"}, + {"label", RPCArg::Type::STR, /* opt */ true, + /* default_val */ + "current label if address exists, otherwise \"\"", + "An optional label"}, + {"rescan", RPCArg::Type::BOOL, /* opt */ true, + /* default_val */ "true", + "Rescan the wallet for transactions"}, + }, + RPCResults{}, + RPCExamples{ + "\nDump a private key\n" + + HelpExampleCli("dumpprivkey", "\"myaddress\"") + + "\nImport the private key with rescan\n" + + HelpExampleCli("importprivkey", "\"mykey\"") + + "\nImport using a label and without rescan\n" + + HelpExampleCli("importprivkey", "\"mykey\" \"testing\" false") + + "\nImport using default blank label and without rescan\n" + + HelpExampleCli("importprivkey", "\"mykey\" \"\" false") + + "\nAs a JSON-RPC call\n" + + HelpExampleRpc("importprivkey", + "\"mykey\", \"testing\", false")}, + } + .ToString()); } if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { @@ -221,18 +223,20 @@ } if (request.fHelp || request.params.size() > 0) { - throw std::runtime_error( - RPCHelpMan{"abortrescan", - "\nStops current wallet rescan triggered by " - "an RPC call, e.g. by an importprivkey call.\n", - {}} - .ToString() + - "\nExamples:\n" - "\nImport a private key\n" + - HelpExampleCli("importprivkey", "\"mykey\"") + - "\nAbort the running wallet rescan\n" + - HelpExampleCli("abortrescan", "") + "\nAs a JSON-RPC call\n" + - HelpExampleRpc("abortrescan", "")); + throw std::runtime_error(RPCHelpMan{ + "abortrescan", + "\nStops current wallet rescan triggered by " + "an RPC call, e.g. by an importprivkey call.\n", + {}, + RPCResults{}, + RPCExamples{"\nImport a private key\n" + + HelpExampleCli("importprivkey", "\"mykey\"") + + "\nAbort the running wallet rescan\n" + + HelpExampleCli("abortrescan", "") + + "\nAs a JSON-RPC call\n" + + HelpExampleRpc("abortrescan", "")}, + } + .ToString()); } if (!pwallet->IsScanning() || pwallet->IsAbortingRescan()) { @@ -295,25 +299,11 @@ if (request.fHelp || request.params.size() < 1 || request.params.size() > 4) { - throw std::runtime_error( - RPCHelpMan{"importaddress", - "\nAdds an address or script (in hex) that can be " - "watched as if it were in your wallet but cannot be " - "used to spend. Requires a new wallet backup.\n", - { - {"address", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", - "The Bitcoin address (or hex-encoded script)"}, - {"label", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "\"\"", "An optional label"}, - {"rescan", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "true", - "Rescan the wallet for transactions"}, - {"p2sh", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "false", - "Add the P2SH version of the script as well"}, - }} - .ToString() + + throw std::runtime_error(RPCHelpMan{ + "importaddress", + "\nAdds an address or script (in hex) that can be " + "watched as if it were in your wallet but cannot be " + "used to spend. Requires a new wallet backup.\n" "\nNote: This call can take minutes to complete if rescan is true, " "during that time, other rpc calls\n" "may report that the imported address exists but related " @@ -324,15 +314,31 @@ "instead of this.\n" "\nNote: If you import a non-standard raw script in hex form, " "outputs sending to it will be treated\n" - "as change, and not show up in many RPCs.\n" - "\nExamples:\n" - "\nImport an address with rescan\n" + - HelpExampleCli("importaddress", "\"myaddress\"") + - "\nImport using a label without rescan\n" + - HelpExampleCli("importaddress", "\"myaddress\" \"testing\" false") + - "\nAs a JSON-RPC call\n" + - HelpExampleRpc("importaddress", - "\"myaddress\", \"testing\", false")); + "as change, and not show up in many RPCs.\n", + { + {"address", RPCArg::Type::STR, /* opt */ false, + /* default_val */ "", + "The Bitcoin address (or hex-encoded script)"}, + {"label", RPCArg::Type::STR, /* opt */ true, + /* default_val */ "\"\"", "An optional label"}, + {"rescan", RPCArg::Type::BOOL, /* opt */ true, + /* default_val */ "true", + "Rescan the wallet for transactions"}, + {"p2sh", RPCArg::Type::BOOL, /* opt */ true, + /* default_val */ "false", + "Add the P2SH version of the script as well"}, + }, + RPCResults{}, + RPCExamples{"\nImport an address with rescan\n" + + HelpExampleCli("importaddress", "\"myaddress\"") + + "\nImport using a label without rescan\n" + + HelpExampleCli("importaddress", + "\"myaddress\" \"testing\" false") + + "\nAs a JSON-RPC call\n" + + HelpExampleRpc("importaddress", + "\"myaddress\", \"testing\", false")}, + } + .ToString()); } std::string strLabel; @@ -420,7 +426,11 @@ /* default_val */ "", "The hex output from gettxoutproof that contains the " "transaction"}, - }}.ToString()); + }, + RPCResults{}, + RPCExamples{""}, + } + .ToString()); } CMutableTransaction tx; @@ -488,26 +498,29 @@ } if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{ - "removeprunedfunds", - "\nDeletes the specified transaction from the wallet. Meant " - "for use with pruned wallets and as a companion to " - "importprunedfunds. This will affect wallet balances.\n", - { - {"txid", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", - "The hex-encoded id of the transaction you are deleting"}, - }} - .ToString() + - "\nExamples:\n" + - HelpExampleCli("removeprunedfunds", "\"a8d0c0184dde994a09ec054286f1" - "ce581bebf46446a512166eae762873" - "4ea0a5\"") + - "\nAs a JSON-RPC call\n" + - HelpExampleRpc("removeprunedfunds", - "\"a8d0c0184dde994a09ec054286f1ce581bebf46446a512166" - "eae7628734ea0a5\"")); + throw std::runtime_error(RPCHelpMan{ + "removeprunedfunds", + "\nDeletes the specified transaction from the wallet. Meant " + "for use with pruned wallets and as a companion to " + "importprunedfunds. This will affect wallet balances.\n", + { + {"txid", RPCArg::Type::STR_HEX, /* opt */ false, + /* default_val */ "", + "The hex-encoded id of the transaction you are deleting"}, + }, + RPCResults{}, + RPCExamples{ + HelpExampleCli("removeprunedfunds", + "\"a8d0c0184dde994a09ec054286f1" + "ce581bebf46446a512166eae762873" + "4ea0a5\"") + + "\nAs a JSON-RPC call\n" + + HelpExampleRpc( + "removeprunedfunds", + "\"a8d0c0184dde994a09ec054286f1ce581bebf46446a512166" + "eae7628734ea0a5\"")}, + } + .ToString()); } auto locked_chain = pwallet->chain().lock(); @@ -540,34 +553,37 @@ if (request.fHelp || request.params.size() < 1 || request.params.size() > 4) { - throw std::runtime_error( - RPCHelpMan{"importpubkey", - "\nAdds a public key (in hex) that can be watched as if " - "it were in your wallet but cannot be used to spend. " - "Requires a new wallet backup.\n", - { - {"pubkey", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "The hex-encoded public key"}, - {"label", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "\"\"", "An optional label"}, - {"rescan", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "true", - "Rescan the wallet for transactions"}, - }} - .ToString() + + throw std::runtime_error(RPCHelpMan{ + "importpubkey", + "\nAdds a public key (in hex) that can be watched as if " + "it were in your wallet but cannot be used to spend. " + "Requires a new wallet backup.\n" "\nNote: This call can take minutes to complete if rescan is true, " "during that time, other rpc calls\n" "may report that the imported pubkey exists but related " "transactions are still missing, leading to temporarily " "incorrect/bogus balances and unspent outputs until rescan " - "completes.\n" - "\nExamples:\n" - "\nImport a public key with rescan\n" + - HelpExampleCli("importpubkey", "\"mypubkey\"") + - "\nImport using a label without rescan\n" + - HelpExampleCli("importpubkey", "\"mypubkey\" \"testing\" false") + - "\nAs a JSON-RPC call\n" + - HelpExampleRpc("importpubkey", "\"mypubkey\", \"testing\", false")); + "completes.\n", + { + {"pubkey", RPCArg::Type::STR, /* opt */ false, + /* default_val */ "", "The hex-encoded public key"}, + {"label", RPCArg::Type::STR, /* opt */ true, + /* default_val */ "\"\"", "An optional label"}, + {"rescan", RPCArg::Type::BOOL, /* opt */ true, + /* default_val */ "true", + "Rescan the wallet for transactions"}, + }, + RPCResults{}, + RPCExamples{"\nImport a public key with rescan\n" + + HelpExampleCli("importpubkey", "\"mypubkey\"") + + "\nImport using a label without rescan\n" + + HelpExampleCli("importpubkey", + "\"mypubkey\" \"testing\" false") + + "\nAs a JSON-RPC call\n" + + HelpExampleRpc("importpubkey", + "\"mypubkey\", \"testing\", false")}, + } + .ToString()); } std::string strLabel; @@ -630,22 +646,23 @@ } if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{ - "importwallet", - "\nImports keys from a wallet dump file (see dumpwallet). " - "Requires a new wallet backup to include imported keys.\n", - { - {"filename", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "The wallet file"}, - }} - .ToString() + - "\nExamples:\n" - "\nDump the wallet\n" + - HelpExampleCli("dumpwallet", "\"test\"") + "\nImport the wallet\n" + - HelpExampleCli("importwallet", "\"test\"") + - "\nImport using the json rpc call\n" + - HelpExampleRpc("importwallet", "\"test\"")); + throw std::runtime_error(RPCHelpMan{ + "importwallet", + "\nImports keys from a wallet dump file (see dumpwallet). " + "Requires a new wallet backup to include imported keys.\n", + { + {"filename", RPCArg::Type::STR, /* opt */ false, + /* default_val */ "", "The wallet file"}, + }, + RPCResults{}, + RPCExamples{"\nDump the wallet\n" + + HelpExampleCli("dumpwallet", "\"test\"") + + "\nImport the wallet\n" + + HelpExampleCli("importwallet", "\"test\"") + + "\nImport using the json rpc call\n" + + HelpExampleRpc("importwallet", "\"test\"")}, + } + .ToString()); } if (fPruneMode) { @@ -832,22 +849,21 @@ } if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{"dumpprivkey", - "\nReveals the private key corresponding to 'address'.\n" - "Then the importprivkey can be used with this output\n", - { - {"address", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", - "The bitcoin address for the private key"}, - }} - .ToString() + - "\nResult:\n" - "\"key\" (string) The private key\n" - "\nExamples:\n" + - HelpExampleCli("dumpprivkey", "\"myaddress\"") + - HelpExampleCli("importprivkey", "\"mykey\"") + - HelpExampleRpc("dumpprivkey", "\"myaddress\"")); + throw std::runtime_error(RPCHelpMan{ + "dumpprivkey", + "\nReveals the private key corresponding to 'address'.\n" + "Then the importprivkey can be used with this output\n", + { + {"address", RPCArg::Type::STR, /* opt */ false, + /* default_val */ "", + "The bitcoin address for the private key"}, + }, + RPCResult{"\"key\" (string) The private key\n"}, + RPCExamples{HelpExampleCli("dumpprivkey", "\"myaddress\"") + + HelpExampleCli("importprivkey", "\"mykey\"") + + HelpExampleRpc("dumpprivkey", "\"myaddress\"")}, + } + .ToString()); } auto locked_chain = pwallet->chain().lock(); @@ -882,35 +898,34 @@ } if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{ - "dumpwallet", - "\nDumps all wallet keys in a human-readable format to " - "a server-side file. This does not allow overwriting " - "existing files.\n" - "Imported scripts are included in the dumpsfile, but " - "corresponding addresses may not be added automatically " - "by importwallet.\n" - "Note that if your wallet contains keys which are not " - "derived from your HD seed (e.g. imported keys), these " - "are not covered by\n" - "only backing up the seed itself, and must be backed up " - "too (e.g. ensure you back up the whole dumpfile).\n", - { - {"filename", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", - "The filename with path (either absolute or relative to " - "bitcoind)"}, - }} - .ToString() + - "\nResult:\n" - "{ (json object)\n" - " \"filename\" : { (string) The filename with full " - "absolute path\n" - "}\n" - "\nExamples:\n" + - HelpExampleCli("dumpwallet", "\"test\"") + - HelpExampleRpc("dumpwallet", "\"test\"")); + throw std::runtime_error(RPCHelpMan{ + "dumpwallet", + "\nDumps all wallet keys in a human-readable format to " + "a server-side file. This does not allow overwriting " + "existing files.\n" + "Imported scripts are included in the dumpsfile, but " + "corresponding addresses may not be added automatically " + "by importwallet.\n" + "Note that if your wallet contains keys which are not " + "derived from your HD seed (e.g. imported keys), these " + "are not covered by\n" + "only backing up the seed itself, and must be backed up " + "too (e.g. ensure you back up the whole dumpfile).\n", + { + {"filename", RPCArg::Type::STR, /* opt */ false, + /* default_val */ "", + "The filename with path (either absolute or relative to " + "bitcoind)"}, + }, + RPCResult{ + "{ (json object)\n" + " \"filename\" : { (string) The filename with full " + "absolute path\n" + "}\n"}, + RPCExamples{HelpExampleCli("dumpwallet", "\"test\"") + + HelpExampleRpc("dumpwallet", "\"test\"")}, + } + .ToString()); } auto locked_chain = pwallet->chain().lock(); @@ -1430,144 +1445,147 @@ if (mainRequest.fHelp || mainRequest.params.size() < 1 || mainRequest.params.size() > 2) { - throw std::runtime_error( - RPCHelpMan{ - "importmulti", - "\nImport addresses/scripts (with private or public keys, " - "redeem script (P2SH)), rescanning all addresses in " - "one-shot-only (rescan can be disabled via options). Requires " - "a new wallet backup.\n", - { - {"requests", - RPCArg::Type::ARR, - /* opt */ false, - /* default_val */ "", - "Data to be imported", + throw std::runtime_error(RPCHelpMan{ + "importmulti", + "\nImport addresses/scripts (with private or public keys, " + "redeem script (P2SH)), rescanning all addresses in " + "one-shot-only (rescan can be disabled via options). Requires " + "a new wallet backup.\n" + "\nNote: This call can take minutes to complete if rescan is true, " + "during that time, other rpc calls\n" + "may report that the imported keys, addresses or scripts exists " + "but related transactions are still missing.\n", + { + {"requests", + RPCArg::Type::ARR, + /* opt */ false, + /* default_val */ "", + "Data to be imported", + { { + "", + RPCArg::Type::OBJ, + /* opt */ false, + /* default_val */ "", + "", { - "", - RPCArg::Type::OBJ, - /* opt */ false, - /* default_val */ "", - "", - { - {"scriptPubKey", - RPCArg::Type::STR, - /* opt */ false, - /* default_val */ "", - "Type of scriptPubKey (string for script, " - "json for address)", - /* oneline_description */ "", - {"\"