@@ -2350,9 +2350,9 @@ UniValue listunspent(const JSONRPCRequest& request)
2350
2350
if (!EnsureWalletIsAvailable (request.fHelp ))
2351
2351
return NullUniValue;
2352
2352
2353
- if (request.fHelp || request.params .size () > 3 )
2353
+ if (request.fHelp || request.params .size () > 4 )
2354
2354
throw runtime_error (
2355
- " listunspent ( minconf maxconf [\" addresses\" ,...] )\n "
2355
+ " listunspent ( minconf maxconf [\" addresses\" ,...] [include_unsafe] )\n "
2356
2356
" \n Returns array of unspent transaction outputs\n "
2357
2357
" with between minconf and maxconf (inclusive) confirmations.\n "
2358
2358
" Optionally filter to only include txouts paid to specified addresses.\n "
@@ -2364,6 +2364,10 @@ UniValue listunspent(const JSONRPCRequest& request)
2364
2364
" \" address\" (string) bitcoin address\n "
2365
2365
" ,...\n "
2366
2366
" ]\n "
2367
+ " 4. include_unsafe (bool, optional, default=true) Include outputs that are not safe to spend\n "
2368
+ " because they come from unconfirmed untrusted transactions or unconfirmed\n "
2369
+ " replacement transactions (cases where we are less sure that a conflicting\n "
2370
+ " transaction won't be mined).\n "
2367
2371
" \n Result\n "
2368
2372
" [ (array of json object)\n "
2369
2373
" {\n "
@@ -2387,18 +2391,21 @@ UniValue listunspent(const JSONRPCRequest& request)
2387
2391
+ HelpExampleRpc (" listunspent" , " 6, 9999999 \" [\\\" 1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg\\\" ,\\\" 1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP\\\" ]\" " )
2388
2392
);
2389
2393
2390
- RPCTypeCheck (request.params , boost::assign::list_of (UniValue::VNUM)(UniValue::VNUM)(UniValue::VARR));
2391
-
2392
2394
int nMinDepth = 1 ;
2393
- if (request.params .size () > 0 )
2395
+ if (request.params .size () > 0 && !request.params [0 ].isNull ()) {
2396
+ RPCTypeCheckArgument (request.params [0 ], UniValue::VNUM);
2394
2397
nMinDepth = request.params [0 ].get_int ();
2398
+ }
2395
2399
2396
2400
int nMaxDepth = 9999999 ;
2397
- if (request.params .size () > 1 )
2401
+ if (request.params .size () > 1 && !request.params [1 ].isNull ()) {
2402
+ RPCTypeCheckArgument (request.params [1 ], UniValue::VNUM);
2398
2403
nMaxDepth = request.params [1 ].get_int ();
2404
+ }
2399
2405
2400
2406
set<CBitcoinAddress> setAddress;
2401
- if (request.params .size () > 2 ) {
2407
+ if (request.params .size () > 2 && !request.params [2 ].isNull ()) {
2408
+ RPCTypeCheckArgument (request.params [2 ], UniValue::VARR);
2402
2409
UniValue inputs = request.params [2 ].get_array ();
2403
2410
for (unsigned int idx = 0 ; idx < inputs.size (); idx++) {
2404
2411
const UniValue& input = inputs[idx];
@@ -2411,11 +2418,17 @@ UniValue listunspent(const JSONRPCRequest& request)
2411
2418
}
2412
2419
}
2413
2420
2421
+ bool include_unsafe = true ;
2422
+ if (request.params .size () > 3 && !request.params [3 ].isNull ()) {
2423
+ RPCTypeCheckArgument (request.params [3 ], UniValue::VBOOL);
2424
+ include_unsafe = request.params [3 ].get_bool ();
2425
+ }
2426
+
2414
2427
UniValue results (UniValue::VARR);
2415
2428
vector<COutput> vecOutputs;
2416
2429
assert (pwalletMain != NULL );
2417
2430
LOCK2 (cs_main, pwalletMain->cs_wallet );
2418
- pwalletMain->AvailableCoins (vecOutputs, false , NULL , true );
2431
+ pwalletMain->AvailableCoins (vecOutputs, !include_unsafe , NULL , true );
2419
2432
BOOST_FOREACH (const COutput& out, vecOutputs) {
2420
2433
if (out.nDepth < nMinDepth || out.nDepth > nMaxDepth)
2421
2434
continue ;
@@ -2629,7 +2642,7 @@ static const CRPCCommand commands[] =
2629
2642
{ " wallet" , " listreceivedbyaddress" , &listreceivedbyaddress, false , {" minconf" ," include_empty" ," include_watchonly" } },
2630
2643
{ " wallet" , " listsinceblock" , &listsinceblock, false , {" blockhash" ," target_confirmations" ," include_watchonly" } },
2631
2644
{ " wallet" , " listtransactions" , &listtransactions, false , {" account" ," count" ," skip" ," include_watchonly" } },
2632
- { " wallet" , " listunspent" , &listunspent, false , {" minconf" ," maxconf" ," addresses" } },
2645
+ { " wallet" , " listunspent" , &listunspent, false , {" minconf" ," maxconf" ," addresses" , " include_unsafe " } },
2633
2646
{ " wallet" , " lockunspent" , &lockunspent, true , {" unlock" ," transactions" } },
2634
2647
{ " wallet" , " move" , &movecmd, false , {" fromaccount" ," toaccount" ," amount" ," minconf" ," comment" } },
2635
2648
{ " wallet" , " sendfrom" , &sendfrom, false , {" fromaccount" ," toaddress" ," amount" ," minconf" ," comment" ," comment_to" } },
0 commit comments