getrawtransaction should take a bool for verbose

This commit is contained in:
jnewbery 2016-10-26 13:09:54 +01:00 committed by John Newbery
parent ed64bcec2d
commit ce2bb23aa5

View File

@ -135,17 +135,17 @@ UniValue getrawtransaction(const JSONRPCRequest& request)
"or there is an unspent output in the utxo for this transaction. To make it always work,\n" "or there is an 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.\n" "you need to maintain a transaction index, using the -txindex command line option.\n"
"\nReturn the raw transaction data.\n" "\nReturn the raw transaction data.\n"
"\nIf verbose=0, returns a string that is serialized, hex-encoded data for 'txid'.\n" "\nIf verbose is 'true', returns an Object with information about 'txid'.\n"
"If verbose is non-zero, 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"
"\nArguments:\n" "\nArguments:\n"
"1. \"txid\" (string, required) The transaction id\n" "1. \"txid\" (string, required) The transaction id\n"
"2. verbose (numeric, optional, default=0) If 0, return a string, other return a json object\n" "2. verbose (bool, optional, default=false) If true, return a string, other return a json object\n"
"\nResult (if verbose is not set or set to 0):\n" "\nResult (if verbose is not set or set to false):\n"
"\"data\" (string) The serialized, hex-encoded data for 'txid'\n" "\"data\" (string) The serialized, hex-encoded data for 'txid'\n"
"\nResult (if verbose > 0):\n" "\nResult (if verbose is set to true):\n"
"{\n" "{\n"
" \"hex\" : \"data\", (string) The serialized, hex-encoded data for 'txid'\n" " \"hex\" : \"data\", (string) The serialized, hex-encoded data for 'txid'\n"
" \"txid\" : \"id\", (string) The transaction id (same as provided)\n" " \"txid\" : \"id\", (string) The transaction id (same as provided)\n"
@ -192,17 +192,31 @@ UniValue getrawtransaction(const JSONRPCRequest& request)
"\nExamples:\n" "\nExamples:\n"
+ HelpExampleCli("getrawtransaction", "\"mytxid\"") + HelpExampleCli("getrawtransaction", "\"mytxid\"")
+ HelpExampleCli("getrawtransaction", "\"mytxid\" 1") + HelpExampleCli("getrawtransaction", "\"mytxid\" true")
+ HelpExampleRpc("getrawtransaction", "\"mytxid\", 1") + HelpExampleRpc("getrawtransaction", "\"mytxid\", true")
); );
LOCK(cs_main); LOCK(cs_main);
uint256 hash = ParseHashV(request.params[0], "parameter 1"); uint256 hash = ParseHashV(request.params[0], "parameter 1");
// Accept either a bool (true) or a num (>=1) to indicate verbose output.
bool fVerbose = false; bool fVerbose = false;
if (request.params.size() > 1) if (request.params.size() > 1) {
fVerbose = (request.params[1].get_int() != 0); if (request.params[1].isNum()) {
if (request.params[1].get_int() != 0) {
fVerbose = true;
}
}
else if(request.params[1].isBool()) {
if(request.params[1].isTrue()) {
fVerbose = true;
}
}
else {
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid type provided. Verbose parameter must be a boolean.");
}
}
CTransaction tx; CTransaction tx;
uint256 hashBlock; uint256 hashBlock;