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