As suggested by @gmaxwell in #9024 .
getrawtransaction now takes a bool for verbose. It will still take an int for verbose for back-compatibility, but issue a warning to the user.
utACK, but please remove the deprecation warning. We may want to repurpose the ints as 'verbosity level' in the future, if an even more verbose mode is added. See #8704 (comment) . There's zero overhead in simply accepting both without warnings or complaints.
Maybe add a GetVerbosityLevel function that accepts UniValue and returns int. It would map bool false to 0, bool true to 1, as well as accepts integers (which are returned as-is). This could be shared between various RPC calls that have a verbosity level (yay consistency).
Seems if we're going to do a verbosity level for getblock, we should just make that the "preferred" form here too?
Seems if we're going to do a verbosity level for getblock, we should just make that the "preferred" form here too?
NACK. There are several other RPCs which take a bool for a more verbose output: getrawmempool, getmempoolancestors, getmempooldescendants, getblockheader, getblock, gettxout (where the option is includemempool). As far as I can tell, getrawtransaction is the only call which currently takes a num. It's less disruptive to change one RPC to use a bool than change all the others to use nums.
143 | "\nArguments:\n" 144 | "1. \"txid\" (string, required) The transaction id\n" 145 | - "2. verbose (numeric, optional, default=0) If 0, return a string, other return a json object\n" 146 | + "2. verbose (bool, optional, default=false) If true, return a string, other return a json object\n" 147 | 148 | "\nResult (if verbose is not set or set to 0):\n"
maybe s/or set to 0/or set to false/?
206 | bool fVerbose = false; 207 | - if (request.params.size() > 1) 208 | - fVerbose = (request.params[1].get_int() != 0); 209 | + if ((request.params.size() > 1) && 210 | + ((request.params[1].isNum() && request.params[1].get_int() != 0) || 211 | + (request.params[1].isBool() && request.params[1].get_bool())))
maybe simplify with s/(request.params[1].isBool() && request.params[1].get_bool())/request.params[1].isTrue()/
utACK 837c06fe22a08d49f480ae629767c1ed8b7b9246, maybe consider nits/simplifications.
Thanks @jonasschnelli . Nits fixed and squashed.
206 | bool fVerbose = false; 207 | - if (request.params.size() > 1) 208 | - fVerbose = (request.params[1].get_int() != 0); 209 | + if ((request.params.size() > 1) && 210 | + ((request.params[1].isNum() && request.params[1].get_int() != 0) || 211 | + (request.params[1].isTrue())))
Note that isTrue doesn't fail if the value is not a bool, so this also accepts non-bool and non-int values. E.g.:
src/bitcoin-cli -regtest getrawtransaction 0000000000000000000000000000000000000000000000000000000000000000 '"b"'
error code: -5
error message:
No information available about transaction
Same for {} [] etc. Should probably raise an error in that case.