@@ -497,18 +497,20 @@ static int GetCompactSize(uint64_t nSize)
497497 return 9 ;
498498}
499499
500- void CoinControlDialog::updateLabels ()
501- {
502- if (!model)
503- return ;
504-
505- ui->labelTitle ->setText (fSelectTransparent ?
506- " Select PIV Outputs to Spend" :
507- " Select Shielded PIV to Spend" );
508-
509- // nPayAmount (!todo fix dust)
510- CAmount nPayAmount = 0 ;
511- bool fDust = false ;
500+ void CoinControlDialog::getTotals (CAmount& nPayAmount, CAmount& nAmount, CAmount& nPayFee, CAmount& nAfterFee,
501+ CAmount& nChange, unsigned int & nQuantity, unsigned int & nBytes, bool & fDust )
502+ {
503+ // clear references
504+ nPayAmount = 0 ;
505+ nAmount = 0 ;
506+ nPayFee = 0 ;
507+ nAfterFee = 0 ;
508+ nChange = 0 ;
509+ nQuantity = 0 ;
510+ nBytes = 0 ;
511+ fDust = false ;
512+
513+ // todo: fix dust - compute nPayAmount later
512514 for (const auto & amount : payAmounts) {
513515 nPayAmount += amount.first ;
514516 if (amount.first > 0 ) {
@@ -518,14 +520,6 @@ void CoinControlDialog::updateLabels()
518520 }
519521 }
520522
521- CAmount nAmount = 0 ;
522- CAmount nPayFee = 0 ;
523- CAmount nAfterFee = 0 ;
524- CAmount nChange = 0 ;
525- unsigned int nBytes = 0 ;
526- unsigned int nBytesInputs = 0 ;
527- unsigned int nQuantity = 0 ;
528-
529523 std::vector<OutPointWrapper> vCoinControl;
530524 coinControl->ListSelected (vCoinControl);
531525
@@ -535,8 +529,8 @@ void CoinControlDialog::updateLabels()
535529 // Amount
536530 nAmount += out.value ;
537531 // Bytes
538- nBytesInputs += (fSelectTransparent ? (CTXIN_SPEND_DUST_SIZE + (out.isP2CS ? 1 : 0 ))
539- : SPENDDESCRIPTION_SIZE);
532+ nBytes += (fSelectTransparent ? (CTXIN_SPEND_DUST_SIZE + (out.isP2CS ? 1 : 0 ))
533+ : SPENDDESCRIPTION_SIZE);
540534 }
541535
542536 // selected inputs
@@ -549,18 +543,13 @@ void CoinControlDialog::updateLabels()
549543 nShieldIns = nQuantity;
550544 }
551545
552- // update SelectAll button state
553- // if inputs selected > inputs unselected, set checked (label "Unselect All")
554- // if inputs selected <= inputs unselected, set unchecked (label "Select All")
555- updatePushButtonSelectAll (coinControl->QuantitySelected () * 2 > nSelectableInputs);
556-
557546 // calculation
558547 const int P2CS_OUT_SIZE = 61 ;
559548 int nTransOuts = 0 , nShieldOuts = 0 ;
560549 if (nQuantity > 0 ) {
561550 // Bytes: nBytesInputs + (sum of nBytesOutputs)
562551 // always assume +1 (p2pkh) output for change here
563- nBytes = nBytesInputs + (fSelectTransparent ? CTXOUT_REGULAR_SIZE : OUTPUTDESCRIPTION_SIZE);
552+ nBytes += (fSelectTransparent ? CTXOUT_REGULAR_SIZE : OUTPUTDESCRIPTION_SIZE);
564553 for (const auto & a : payAmounts) {
565554 bool shieldedOut = a.second ;
566555 if (shieldedOut) nShieldOuts++;
@@ -607,6 +596,31 @@ void CoinControlDialog::updateLabels()
607596 // after fee
608597 nAfterFee = std::max<CAmount>(nAmount - nPayFee, 0 );
609598 }
599+ }
600+
601+ void CoinControlDialog::updateLabels ()
602+ {
603+ if (!model)
604+ return ;
605+
606+ ui->labelTitle ->setText (fSelectTransparent ?
607+ " Select PIV Outputs to Spend" :
608+ " Select Shielded PIV to Spend" );
609+
610+ CAmount nPayAmount = 0 ;
611+ CAmount nAmount = 0 ;
612+ CAmount nPayFee = 0 ;
613+ CAmount nAfterFee = 0 ;
614+ CAmount nChange = 0 ;
615+ unsigned int nQuantity = 0 ;
616+ unsigned int nBytes = 0 ;
617+ bool fDust = false ;
618+ getTotals (nPayAmount, nAmount, nPayFee, nAfterFee, nChange, nQuantity, nBytes, fDust );
619+
620+ // update SelectAll button state
621+ // if inputs selected > inputs unselected, set checked (label "Unselect All")
622+ // if inputs selected <= inputs unselected, set unchecked (label "Select All")
623+ updatePushButtonSelectAll (coinControl->QuantitySelected () * 2 > nSelectableInputs);
610624
611625 // actually update labels
612626 int nDisplayUnit = BitcoinUnits::PIV;
0 commit comments