Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2010 Satoshi Nakamoto2// Copyright (c) 2009-present The Bitcoin Core developers3// Distributed under the MIT software license, see the accompanying4// file COPYING or http://www.opensource.org/licenses/mit-license.php.6#include <rpc/client.h>8#include <tinyformat.h>10#include <algorithm>11#include <cstddef>12#include <ranges>13#include <stdexcept>14#include <string>15#include <string_view>16#include <utility>18//! Specify whether parameter should be parsed by bitcoin-cli as a JSON value,19//! or passed unchanged as a string, or a combination of both.20enum ParamFormat { JSON, STRING, JSON_OR_STRING };22class CRPCConvertParam23{24public:25std::string methodName; //!< method whose params want conversion26int paramIdx; //!< 0-based idx of param to convert27std::string paramName; //!< parameter name28ParamFormat format{ParamFormat::JSON}; //!< parameter format29};31// clang-format off32/**33* Specify a (method, idx, name, format) here if the argument is a non-string RPC34* argument and needs to be converted from JSON, or if it is a string argument35* passed to a method that accepts '=' characters in any string arguments.36*37* JSON parameters need to be listed here to make bitcoin-cli parse command line38* arguments as JSON, instead of passing them as raw strings. `JSON` and39* `JSON_OR_STRING` formats both make `bitcoin-cli` attempt to parse the40* argument as JSON. But if parsing fails, the former triggers an error while41* the latter falls back to passing the argument as a raw string. This is42* useful for arguments like hash_or_height, allowing invocations such as43* `bitcoin-cli getblockstats <hash>` without needing to quote the hash string44* as JSON (`'"<hash>"'`).45*46* String parameters that may contain an '=' character (e.g. base64 strings,47* filenames, or labels) need to be listed here with format `ParamFormat::STRING`48* to make bitcoin-cli treat them as positional parameters when `-named` is used.49* This prevents `bitcoin-cli` from splitting strings like "my=wallet" into a named50* argument "my" and value "wallet" when the whole string is intended to be a51* single positional argument. And if one string parameter is listed for a method,52* other string parameters for that method need to be listed as well so bitcoin-cli53* does not make the opposite mistake and pass other arguments by position instead of54* name because it does not recognize their names. See \ref RPCConvertNamedValues55* for more information on how named and positional arguments are distinguished with56* -named.57*58* @note Parameter indexes start from 0.59*/60static const CRPCConvertParam vRPCConvertParams[] =61{62{ "setmocktime", 0, "timestamp" },63{ "mockscheduler", 0, "delta_time" },64{ "utxoupdatepsbt", 0, "psbt", ParamFormat::STRING },65{ "utxoupdatepsbt", 1, "descriptors" },66{ "generatetoaddress", 0, "nblocks" },67{ "generatetoaddress", 2, "maxtries" },68{ "generatetodescriptor", 0, "num_blocks" },69{ "generatetodescriptor", 2, "maxtries" },70{ "generateblock", 1, "transactions" },71{ "generateblock", 2, "submit" },72{ "getnetworkhashps", 0, "nblocks" },73{ "getnetworkhashps", 1, "height" },74{ "sendtoaddress", 0, "address", ParamFormat::STRING },75{ "sendtoaddress", 1, "amount" },76{ "sendtoaddress", 2, "comment", ParamFormat::STRING },77{ "sendtoaddress", 3, "comment_to", ParamFormat::STRING },78{ "sendtoaddress", 4, "subtractfeefromamount" },79{ "sendtoaddress", 5 , "replaceable" },80{ "sendtoaddress", 6 , "conf_target" },81{ "sendtoaddress", 7, "estimate_mode", ParamFormat::STRING },82{ "sendtoaddress", 8, "avoid_reuse" },83{ "sendtoaddress", 9, "fee_rate"},84{ "sendtoaddress", 10, "verbose"},85{ "getreceivedbyaddress", 1, "minconf" },86{ "getreceivedbyaddress", 2, "include_immature_coinbase" },87{ "getreceivedbylabel", 0, "label", ParamFormat::STRING },88{ "getreceivedbylabel", 1, "minconf" },89{ "getreceivedbylabel", 2, "include_immature_coinbase" },90{ "listreceivedbyaddress", 0, "minconf" },91{ "listreceivedbyaddress", 1, "include_empty" },92{ "listreceivedbyaddress", 2, "include_watchonly" },93{ "listreceivedbyaddress", 4, "include_immature_coinbase" },94{ "listreceivedbylabel", 0, "minconf" },95{ "listreceivedbylabel", 1, "include_empty" },96{ "listreceivedbylabel", 2, "include_watchonly" },97{ "listreceivedbylabel", 3, "include_immature_coinbase" },98{ "getbalance", 1, "minconf" },99{ "getbalance", 2, "include_watchonly" },100{ "getbalance", 3, "avoid_reuse" },101{ "getblockfrompeer", 1, "peer_id" },102{ "getblockhash", 0, "height" },103{ "waitforblockheight", 0, "height" },104{ "waitforblockheight", 1, "timeout" },105{ "waitforblock", 1, "timeout" },106{ "waitfornewblock", 0, "timeout" },107{ "listtransactions", 0, "label", ParamFormat::STRING },108{ "listtransactions", 1, "count" },109{ "listtransactions", 2, "skip" },110{ "listtransactions", 3, "include_watchonly" },111{ "walletpassphrase", 0, "passphrase", ParamFormat::STRING },112{ "walletpassphrase", 1, "timeout" },113{ "getblocktemplate", 0, "template_request" },114{ "listsinceblock", 0, "blockhash", ParamFormat::STRING },115{ "listsinceblock", 1, "target_confirmations" },116{ "listsinceblock", 2, "include_watchonly" },117{ "listsinceblock", 3, "include_removed" },118{ "listsinceblock", 4, "include_change" },119{ "listsinceblock", 5, "label", ParamFormat::STRING },120{ "sendmany", 0, "dummy", ParamFormat::STRING },121{ "sendmany", 1, "amounts" },122{ "sendmany", 2, "minconf" },123{ "sendmany", 3, "comment", ParamFormat::STRING },124{ "sendmany", 4, "subtractfeefrom" },125{ "sendmany", 5 , "replaceable" },126{ "sendmany", 6 , "conf_target" },127{ "sendmany", 7, "estimate_mode", ParamFormat::STRING },128{ "sendmany", 8, "fee_rate"},129{ "sendmany", 9, "verbose" },130{ "deriveaddresses", 1, "range" },131{ "scanblocks", 1, "scanobjects" },132{ "scanblocks", 2, "start_height" },133{ "scanblocks", 3, "stop_height" },134{ "scanblocks", 5, "options" },135{ "scanblocks", 5, "filter_false_positives" },136{ "getdescriptoractivity", 0, "blockhashes" },137{ "getdescriptoractivity", 1, "scanobjects" },138{ "getdescriptoractivity", 2, "include_mempool" },139{ "scantxoutset", 1, "scanobjects" },140{ "createmultisig", 0, "nrequired" },141{ "createmultisig", 1, "keys" },142{ "listunspent", 0, "minconf" },143{ "listunspent", 1, "maxconf" },144{ "listunspent", 2, "addresses" },145{ "listunspent", 3, "include_unsafe" },146{ "listunspent", 4, "query_options" },147{ "listunspent", 4, "minimumAmount" },148{ "listunspent", 4, "maximumAmount" },149{ "listunspent", 4, "maximumCount" },150{ "listunspent", 4, "minimumSumAmount" },151{ "listunspent", 4, "include_immature_coinbase" },152{ "getblock", 1, "verbosity" },153{ "getblock", 1, "verbose" },154{ "getblockheader", 1, "verbose" },155{ "getchaintxstats", 0, "nblocks" },156{ "gettransaction", 1, "include_watchonly" },157{ "gettransaction", 2, "verbose" },158{ "getrawtransaction", 1, "verbosity" },159{ "getrawtransaction", 1, "verbose" },160{ "createrawtransaction", 0, "inputs" },161{ "createrawtransaction", 1, "outputs" },162{ "createrawtransaction", 2, "locktime" },163{ "createrawtransaction", 3, "replaceable" },164{ "createrawtransaction", 4, "version" },165{ "decoderawtransaction", 1, "iswitness" },166{ "signrawtransactionwithkey", 1, "privkeys" },167{ "signrawtransactionwithkey", 2, "prevtxs" },168{ "signrawtransactionwithwallet", 1, "prevtxs" },169{ "sendrawtransaction", 1, "maxfeerate" },170{ "sendrawtransaction", 2, "maxburnamount" },171{ "testmempoolaccept", 0, "rawtxs" },172{ "testmempoolaccept", 1, "maxfeerate" },173{ "submitpackage", 0, "package" },174{ "submitpackage", 1, "maxfeerate" },175{ "submitpackage", 2, "maxburnamount" },176{ "combinerawtransaction", 0, "txs" },177{ "fundrawtransaction", 1, "options" },178{ "fundrawtransaction", 1, "add_inputs"},179{ "fundrawtransaction", 1, "include_unsafe"},180{ "fundrawtransaction", 1, "minconf"},181{ "fundrawtransaction", 1, "maxconf"},182{ "fundrawtransaction", 1, "changePosition"},183{ "fundrawtransaction", 1, "includeWatching"},184{ "fundrawtransaction", 1, "lockUnspents"},185{ "fundrawtransaction", 1, "fee_rate"},186{ "fundrawtransaction", 1, "feeRate"},187{ "fundrawtransaction", 1, "subtractFeeFromOutputs"},188{ "fundrawtransaction", 1, "input_weights"},189{ "fundrawtransaction", 1, "conf_target"},190{ "fundrawtransaction", 1, "replaceable"},191{ "fundrawtransaction", 1, "solving_data"},192{ "fundrawtransaction", 1, "max_tx_weight"},193{ "fundrawtransaction", 2, "iswitness" },194{ "walletcreatefundedpsbt", 0, "inputs" },195{ "walletcreatefundedpsbt", 1, "outputs" },196{ "walletcreatefundedpsbt", 2, "locktime" },197{ "walletcreatefundedpsbt", 3, "options" },198{ "walletcreatefundedpsbt", 3, "add_inputs"},199{ "walletcreatefundedpsbt", 3, "include_unsafe"},200{ "walletcreatefundedpsbt", 3, "minconf"},201{ "walletcreatefundedpsbt", 3, "maxconf"},202{ "walletcreatefundedpsbt", 3, "changePosition"},203{ "walletcreatefundedpsbt", 3, "includeWatching"},204{ "walletcreatefundedpsbt", 3, "lockUnspents"},205{ "walletcreatefundedpsbt", 3, "fee_rate"},206{ "walletcreatefundedpsbt", 3, "feeRate"},207{ "walletcreatefundedpsbt", 3, "subtractFeeFromOutputs"},208{ "walletcreatefundedpsbt", 3, "conf_target"},209{ "walletcreatefundedpsbt", 3, "replaceable"},210{ "walletcreatefundedpsbt", 3, "solving_data"},211{ "walletcreatefundedpsbt", 3, "max_tx_weight"},212{ "walletcreatefundedpsbt", 4, "bip32derivs" },213{ "walletcreatefundedpsbt", 5, "version" },214{ "walletcreatefundedpsbt", 6, "psbt_version" },215{ "walletprocesspsbt", 0, "psbt", ParamFormat::STRING },216{ "walletprocesspsbt", 1, "sign" },217{ "walletprocesspsbt", 2, "sighashtype", ParamFormat::STRING },218{ "walletprocesspsbt", 3, "bip32derivs" },219{ "walletprocesspsbt", 4, "finalize" },220{ "descriptorprocesspsbt", 0, "psbt", ParamFormat::STRING },221{ "descriptorprocesspsbt", 1, "descriptors"},222{ "descriptorprocesspsbt", 2, "sighashtype", ParamFormat::STRING },223{ "descriptorprocesspsbt", 3, "bip32derivs" },224{ "descriptorprocesspsbt", 4, "finalize" },225{ "createpsbt", 0, "inputs" },226{ "createpsbt", 1, "outputs" },227{ "createpsbt", 2, "locktime" },228{ "createpsbt", 3, "replaceable" },229{ "createpsbt", 4, "version" },230{ "createpsbt", 5, "psbt_version" },231{ "combinepsbt", 0, "txs"},232{ "joinpsbts", 0, "txs"},233{ "finalizepsbt", 0, "psbt", ParamFormat::STRING },234{ "finalizepsbt", 1, "extract"},235{ "converttopsbt", 1, "permitsigdata"},236{ "converttopsbt", 2, "iswitness"},237{ "converttopsbt", 3, "psbt_version"},238{ "gettxout", 1, "n" },239{ "gettxout", 2, "include_mempool" },240{ "gettxoutproof", 0, "txids" },241{ "gettxoutsetinfo", 1, "hash_or_height", ParamFormat::JSON_OR_STRING },242{ "gettxoutsetinfo", 2, "use_index"},243{ "dumptxoutset", 0, "path", ParamFormat::STRING },244{ "dumptxoutset", 1, "type", ParamFormat::STRING },245{ "dumptxoutset", 2, "options" },246{ "dumptxoutset", 2, "rollback", ParamFormat::JSON_OR_STRING },247{ "dumptxoutset", 2, "in_memory" },248{ "lockunspent", 0, "unlock" },249{ "lockunspent", 1, "transactions" },250{ "lockunspent", 2, "persistent" },