Skip to content

Commit ce2bb23

Browse files
committed
getrawtransaction should take a bool for verbose
1 parent ed64bce commit ce2bb23

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,17 @@ UniValue getrawtransaction(const JSONRPCRequest& request)
135135
"or there is an unspent output in the utxo for this transaction. To make it always work,\n"
136136
"you need to maintain a transaction index, using the -txindex command line option.\n"
137137
"\nReturn the raw transaction data.\n"
138-
"\nIf verbose=0, returns a string that is serialized, hex-encoded data for 'txid'.\n"
139-
"If verbose is non-zero, returns an Object with information about 'txid'.\n"
138+
"\nIf verbose is 'true', returns an Object with information about 'txid'.\n"
139+
"If verbose is 'false' or omitted, returns a string that is serialized, hex-encoded data for 'txid'.\n"
140140

141141
"\nArguments:\n"
142142
"1. \"txid\" (string, required) The transaction id\n"
143-
"2. verbose (numeric, optional, default=0) If 0, return a string, other return a json object\n"
143+
"2. verbose (bool, optional, default=false) If true, return a string, other return a json object\n"
144144

145-
"\nResult (if verbose is not set or set to 0):\n"
145+
"\nResult (if verbose is not set or set to false):\n"
146146
"\"data\" (string) The serialized, hex-encoded data for 'txid'\n"
147147

148-
"\nResult (if verbose > 0):\n"
148+
"\nResult (if verbose is set to true):\n"
149149
"{\n"
150150
" \"hex\" : \"data\", (string) The serialized, hex-encoded data for 'txid'\n"
151151
" \"txid\" : \"id\", (string) The transaction id (same as provided)\n"
@@ -192,17 +192,31 @@ UniValue getrawtransaction(const JSONRPCRequest& request)
192192

193193
"\nExamples:\n"
194194
+ HelpExampleCli("getrawtransaction", "\"mytxid\"")
195-
+ HelpExampleCli("getrawtransaction", "\"mytxid\" 1")
196-
+ HelpExampleRpc("getrawtransaction", "\"mytxid\", 1")
195+
+ HelpExampleCli("getrawtransaction", "\"mytxid\" true")
196+
+ HelpExampleRpc("getrawtransaction", "\"mytxid\", true")
197197
);
198198

199199
LOCK(cs_main);
200200

201201
uint256 hash = ParseHashV(request.params[0], "parameter 1");
202202

203+
// Accept either a bool (true) or a num (>=1) to indicate verbose output.
203204
bool fVerbose = false;
204-
if (request.params.size() > 1)
205-
fVerbose = (request.params[1].get_int() != 0);
205+
if (request.params.size() > 1) {
206+
if (request.params[1].isNum()) {
207+
if (request.params[1].get_int() != 0) {
208+
fVerbose = true;
209+
}
210+
}
211+
else if(request.params[1].isBool()) {
212+
if(request.params[1].isTrue()) {
213+
fVerbose = true;
214+
}
215+
}
216+
else {
217+
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid type provided. Verbose parameter must be a boolean.");
218+
}
219+
}
206220

207221
CTransaction tx;
208222
uint256 hashBlock;

0 commit comments

Comments
 (0)