@@ -493,50 +493,51 @@ UniValue listunspent(const UniValue& params, bool fHelp)
493
493
494
494
UniValue consolidateunspent (const UniValue& params, bool fHelp )
495
495
{
496
+ std::stringstream error_strm;
497
+
498
+ error_strm << " consolidateunspent <address> [UTXO size] [maximum number of inputs] [sweep all addresses] [sweep change]\n "
499
+ " \n "
500
+ " <address>: The Gridcoin address target for consolidation.\n "
501
+ " \n "
502
+ " [UTXO size]: Optional parameter for target consolidation output size.\n "
503
+ " \n "
504
+ " [maximum number of inputs]: Defaults and clamped to "
505
+ << std::to_string (GetMaxInputsForConsolidationTxn ())
506
+ << " maximum to prevent transaction failures.\n "
507
+ " \n "
508
+ " [sweep all addresses]: Boolean to indicate whether all addresses should be used for inputs to the\n "
509
+ " consolidation. If true, the source of the consolidation is all addresses and\n "
510
+ " the output will be to the specified address, otherwise inputs will only be\n "
511
+ " sourced from the same address.\n "
512
+ " \n "
513
+ " [sweep change]: Boolean to indicate whether change associated with the address should be\n "
514
+ " consolidated. If [sweep all addresses] is true then this is also forced true.\n "
515
+ " \n "
516
+ " consolidateunspent performs a single transaction to consolidate UTXOs to/on a given address. The optional\n "
517
+ " parameter of UTXO size will result in consolidating UTXOs to generate the largest output possible less\n "
518
+ " than that size or the total value of the specified maximum number of smallest inputs, whichever is less.\n "
519
+ " \n "
520
+ " The script is designed to be run repeatedly and will become a no-op if the UTXO's are consolidated such\n "
521
+ " that no more meet the specified criteria. This is ideal for automated periodic scripting.\n "
522
+ " \n "
523
+ " To consolidate the entire wallet to one address do something like:\n "
524
+ " \n "
525
+ " consolidateunspent <address> <amount equal or larger than balance> 200 true repeatedly until there are\n "
526
+ " no more UTXOs to consolidate.\n "
527
+ " \n "
528
+ " In all cases the address MUST exist in your wallet beforehand. If doing this for the purpose of creating\n "
529
+ " a new smaller wallet, create a new address beforehand to serve as the target of the consolidation.\n " ;
530
+
496
531
if (fHelp || params.size () < 1 || params.size () > 5 )
497
- throw runtime_error (
498
- " consolidateunspent <address> [UTXO size] [maximum number of inputs] [sweep all addresses] [sweep change]\n "
499
- " \n "
500
- " <address>: The Gridcoin address target for consolidation.\n "
501
- " \n "
502
- " [UTXO size]: Optional parameter for target consolidation output size.\n "
503
- " \n "
504
- " [maximum number of inputs]: Defaults to 50, clamped to 200 maximum to prevent transaction failures.\n "
505
- " \n "
506
- " [sweep all addresses]: Boolean to indicate whether all addresses should be used for inputs to the\n "
507
- " consolidation. If true, the source of the consolidation is all addresses and\n "
508
- " the output will be to the specified address, otherwise inputs will only be\n "
509
- " sourced from the same address.\n "
510
- " \n "
511
- " [sweep change]: Boolean to indicate whether change associated with the address should be\n "
512
- " consolidated. If [sweep all addresses] is true then this is also forced true.\n "
513
- " \n "
514
- " consolidateunspent performs a single transaction to consolidate UTXOs to/on a given address. The optional\n "
515
- " parameter of UTXO size will result in consolidating UTXOs to generate the largest output possible less\n "
516
- " than that size or the total value of the specified maximum number of smallest inputs, whichever is less.\n "
517
- " \n "
518
- " The script is designed to be run repeatedly and will become a no-op if the UTXO's are consolidated such\n "
519
- " that no more meet the specified criteria. This is ideal for automated periodic scripting.\n "
520
- " \n "
521
- " To consolidate the entire wallet to one address do something like:\n "
522
- " \n "
523
- " consolidateunspent <address> <amount equal or larger than balance> 200 true repeatedly until there are\n "
524
- " no more UTXOs to consolidate.\n "
525
- " \n "
526
- " In all cases the address MUST exist in your wallet beforehand. If doing this for the purpose of creating\n "
527
- " a new smaller wallet, create a new address beforehand to serve as the target of the consolidation.\n " );
532
+ throw runtime_error (error_strm.str ());
528
533
529
534
UniValue result (UniValue::VOBJ);
530
535
531
536
std::string sAddress = params[0 ].get_str ();
532
537
CBitcoinAddress OptimizeAddress (sAddress );
533
538
534
539
int64_t nConsolidateLimit = 0 ;
535
- // Set default maximum consolidation to 50 inputs if it is not specified. This is based
536
- // on performance tests on the Pi to ensure the transaction returns within a reasonable time.
537
- // The performance tests on the Pi show about 3 UTXOs/second. Intel machines should do
538
- // about 3x that. The GUI will not be responsive during the transaction due to locking.
539
- unsigned int nInputNumberLimit = 50 ;
540
+ unsigned int nInputNumberLimit = GetMaxInputsForConsolidationTxn ();
540
541
541
542
bool sweep_all_addresses = false ;
542
543
@@ -551,8 +552,9 @@ UniValue consolidateunspent(const UniValue& params, bool fHelp)
551
552
552
553
if (params.size () > 4 && !sweep_all_addresses) sweep_change = params[4 ].get_bool ();
553
554
554
- // Clamp InputNumberLimit to 200. Above 200 risks an invalid transaction due to the size.
555
- nInputNumberLimit = std::min<unsigned int >(nInputNumberLimit, 200 );
555
+ // Clamp InputNumberLimit to GetMaxInputsForConsolidationTxn(). Above that number of inputs risks an invalid transaction
556
+ // due to the size.
557
+ nInputNumberLimit = std::min<unsigned int >(nInputNumberLimit, GetMaxInputsForConsolidationTxn ());
556
558
557
559
if (!OptimizeAddress.IsValid ())
558
560
{
0 commit comments