Skip to content

Commit 0f23f40

Browse files
committed
[GUI] CoinControl: fix fee calculation for P2CS scripts
1 parent cb1b3f8 commit 0f23f40

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

src/qt/coincontroldialog.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/qt/coincontroldialog.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class CoinControlDialog : public QDialog
4444
Q_OBJECT
4545

4646
public:
47-
explicit CoinControlDialog(QWidget* parent = nullptr);
47+
explicit CoinControlDialog(QWidget* parent = nullptr, bool _forDelegation = false);
4848
~CoinControlDialog();
4949

5050
void setModel(WalletModel* model);
@@ -65,6 +65,7 @@ class CoinControlDialog : public QDialog
6565
WalletModel* model;
6666
int sortColumn;
6767
Qt::SortOrder sortOrder;
68+
bool forDelegation;
6869
bool fSelectAllToggled{true}; // false when pushButtonSelectAll text is "Unselect All"
6970
QList<CAmount> payAmounts{};
7071

src/qt/pivx/coldstakingwidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ void ColdStakingWidget::onCoinControlClicked()
531531
if (isInDelegation) {
532532
if (walletModel->getBalance() > 0) {
533533
if (!coinControlDialog) {
534-
coinControlDialog = new CoinControlDialog();
534+
coinControlDialog = new CoinControlDialog(nullptr, true);
535535
coinControlDialog->setModel(walletModel);
536536
} else {
537537
coinControlDialog->refreshDialog();

0 commit comments

Comments
 (0)