@@ -43,9 +43,10 @@ bool CCoinControlWidgetItem::operator<(const QTreeWidgetItem &other) const {
4343}
4444
4545
46- CoinControlDialog::CoinControlDialog (QWidget* parent) : QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint),
46+ CoinControlDialog::CoinControlDialog (QWidget* parent, bool _forDelegation ) : QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint),
4747 ui(new Ui::CoinControlDialog),
48- model(0 )
48+ model(0 ),
49+ forDelegation(_forDelegation)
4950{
5051 ui->setupUi (this );
5152
@@ -568,7 +569,6 @@ void CoinControlDialog::updateLabels()
568569 bool fDust = false ;
569570 Q_FOREACH (const CAmount& amount, payAmounts) {
570571 nPayAmount += amount;
571-
572572 if (amount > 0 ) {
573573 CTxOut txout (amount, (CScript)std::vector<unsigned char >(24 , 0 ));
574574 if (txout.IsDust (::minRelayTxFee))
@@ -626,12 +626,22 @@ void CoinControlDialog::updateLabels()
626626 nBytesInputs += 148 ; // in all error cases, simply assume 148 here
627627 } else
628628 nBytesInputs += 148 ;
629+
630+ // Additional byte for P2CS
631+ if (out.tx ->vout [out.i ].scriptPubKey .IsPayToColdStaking ())
632+ nBytesInputs++;
629633 }
630634
631635 // calculation
636+ const int P2PKH_OUT_SIZE = 34 ;
637+ const int P2CS_OUT_SIZE = 61 ;
632638 if (nQuantity > 0 ) {
633- // Bytes
634- nBytes = nBytesInputs + ((payAmounts.size () > 0 ? CoinControlDialog::payAmounts.size () + 1 : 2 ) * 34 ) + 10 ; // always assume +1 output for change here
639+ // Bytes: nBytesInputs + (num_of_outputs * bytes_per_output)
640+ nBytes = nBytesInputs + std::max (1 , payAmounts.size ()) * (forDelegation ? P2CS_OUT_SIZE : P2PKH_OUT_SIZE);
641+ // always assume +1 (p2pkh) output for change here
642+ nBytes += P2PKH_OUT_SIZE;
643+ // nVersion, nLockTime and vin/vout len sizes
644+ nBytes += 10 ;
635645
636646 // Priority
637647 double mempoolEstimatePriority = mempool.estimatePriority (nTxConfirmTarget);
@@ -666,7 +676,7 @@ void CoinControlDialog::updateLabels()
666676 }
667677
668678 if (nChange == 0 )
669- nBytes -= 34 ;
679+ nBytes -= P2PKH_OUT_SIZE ;
670680 }
671681
672682 // after fee
0 commit comments