@@ -2470,22 +2470,29 @@ UniValue listunspent(const JSONRPCRequest& request)
2470
2470
return NullUniValue;
2471
2471
}
2472
2472
2473
- if (request.fHelp || request.params .size () > 4 )
2473
+ if (request.fHelp || request.params .size () > 5 )
2474
2474
throw std::runtime_error (
2475
- " listunspent ( minconf maxconf [\" addresses\" ,...] [include_unsafe] )\n "
2475
+ " listunspent ( minconf maxconf [\" addresses\" ,...] [include_unsafe] [query_options] )\n "
2476
2476
" \n Returns array of unspent transaction outputs\n "
2477
2477
" with between minconf and maxconf (inclusive) confirmations.\n "
2478
2478
" Optionally filter to only include txouts paid to specified addresses.\n "
2479
2479
" \n Arguments:\n "
2480
2480
" 1. minconf (numeric, optional, default=1) The minimum confirmations to filter\n "
2481
2481
" 2. maxconf (numeric, optional, default=9999999) The maximum confirmations to filter\n "
2482
- " 3. \" addresses\" (string) A json array of bitcoin addresses to filter\n "
2482
+ " 3. \" addresses\" (string) A json array of bitcoin addresses to filter\n "
2483
2483
" [\n "
2484
- " \" address\" (string) bitcoin address\n "
2484
+ " \" address\" (string) bitcoin address\n "
2485
2485
" ,...\n "
2486
2486
" ]\n "
2487
2487
" 4. include_unsafe (bool, optional, default=true) Include outputs that are not safe to spend\n "
2488
2488
" See description of \" safe\" attribute below.\n "
2489
+ " 5. query_options (json, optional) JSON with query options\n "
2490
+ " {\n "
2491
+ " \" minimumAmount\" (numeric or string, default=0) Minimum value of each UTXO in " + CURRENCY_UNIT + " \n "
2492
+ " \" maximumAmount\" (numeric or string, default=unlimited) Maximum value of each UTXO in " + CURRENCY_UNIT + " \n "
2493
+ " \" maximumCount\" (numeric or string, default=unlimited) Maximum number of UTXOs\n "
2494
+ " \" minimumSumAmount\" (numeric or string, default=unlimited) Minimum sum value of all UTXOs in " + CURRENCY_UNIT + " \n "
2495
+ " }\n "
2489
2496
" \n Result\n "
2490
2497
" [ (array of json object)\n "
2491
2498
" {\n "
@@ -2510,6 +2517,8 @@ UniValue listunspent(const JSONRPCRequest& request)
2510
2517
+ HelpExampleCli (" listunspent" , " " )
2511
2518
+ HelpExampleCli (" listunspent" , " 6 9999999 \" [\\\" 1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg\\\" ,\\\" 1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP\\\" ]\" " )
2512
2519
+ HelpExampleRpc (" listunspent" , " 6, 9999999 \" [\\\" 1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg\\\" ,\\\" 1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP\\\" ]\" " )
2520
+ + HelpExampleCli (" listunspent" , " 6 9999999 '[]' true '{ \" minimumAmount\" : 0.005 }'" )
2521
+ + HelpExampleRpc (" listunspent" , " 6, 9999999, [] , true, { \" minimumAmount\" : 0.005 } " )
2513
2522
);
2514
2523
2515
2524
int nMinDepth = 1 ;
@@ -2545,15 +2554,34 @@ UniValue listunspent(const JSONRPCRequest& request)
2545
2554
include_unsafe = request.params [3 ].get_bool ();
2546
2555
}
2547
2556
2557
+ CAmount nMinimumAmount = 0 ;
2558
+ CAmount nMaximumAmount = MAX_MONEY;
2559
+ CAmount nMinimumSumAmount = MAX_MONEY;
2560
+ uint64_t nMaximumCount = 0 ;
2561
+
2562
+ if (request.params .size () > 4 ) {
2563
+ const UniValue& options = request.params [4 ].get_obj ();
2564
+
2565
+ if (options.exists (" minimumAmount" ))
2566
+ nMinimumAmount = AmountFromValue (options[" minimumAmount" ]);
2567
+
2568
+ if (options.exists (" maximumAmount" ))
2569
+ nMaximumAmount = AmountFromValue (options[" maximumAmount" ]);
2570
+
2571
+ if (options.exists (" minimumSumAmount" ))
2572
+ nMinimumSumAmount = AmountFromValue (options[" minimumSumAmount" ]);
2573
+
2574
+ if (options.exists (" maximumCount" ))
2575
+ nMaximumCount = options[" maximumCount" ].get_int64 ();
2576
+ }
2577
+
2548
2578
UniValue results (UniValue::VARR);
2549
2579
std::vector<COutput> vecOutputs;
2550
2580
assert (pwallet != NULL );
2551
2581
LOCK2 (cs_main, pwallet->cs_wallet );
2552
- pwallet->AvailableCoins (vecOutputs, !include_unsafe, NULL , true );
2553
- BOOST_FOREACH (const COutput& out, vecOutputs) {
2554
- if (out.nDepth < nMinDepth || out.nDepth > nMaxDepth)
2555
- continue ;
2556
2582
2583
+ pwallet->AvailableCoins (vecOutputs, !include_unsafe, NULL , nMinimumAmount, nMaximumAmount, nMinimumSumAmount, nMaximumCount, nMinDepth, nMaxDepth);
2584
+ BOOST_FOREACH (const COutput& out, vecOutputs) {
2557
2585
CTxDestination address;
2558
2586
const CScript& scriptPubKey = out.tx ->tx ->vout [out.i ].scriptPubKey ;
2559
2587
bool fValidAddress = ExtractDestination (scriptPubKey, address);
@@ -2936,7 +2964,7 @@ static const CRPCCommand commands[] =
2936
2964
{ " wallet" , " listreceivedbyaddress" , &listreceivedbyaddress, false , {" minconf" ," include_empty" ," include_watchonly" } },
2937
2965
{ " wallet" , " listsinceblock" , &listsinceblock, false , {" blockhash" ," target_confirmations" ," include_watchonly" } },
2938
2966
{ " wallet" , " listtransactions" , &listtransactions, false , {" account" ," count" ," skip" ," include_watchonly" } },
2939
- { " wallet" , " listunspent" , &listunspent, false , {" minconf" ," maxconf" ," addresses" ," include_unsafe" } },
2967
+ { " wallet" , " listunspent" , &listunspent, false , {" minconf" ," maxconf" ," addresses" ," include_unsafe" , " query_options " } },
2940
2968
{ " wallet" , " lockunspent" , &lockunspent, true , {" unlock" ," transactions" } },
2941
2969
{ " wallet" , " move" , &movecmd, false , {" fromaccount" ," toaccount" ," amount" ," minconf" ," comment" } },
2942
2970
{ " wallet" , " sendfrom" , &sendfrom, false , {" fromaccount" ," toaddress" ," amount" ," minconf" ," comment" ," comment_to" } },
0 commit comments