Skip to content

Commit 41363fe

Browse files
committed
Merge #12327: [gui] Defer coin control instancing
6558f8a [gui] Defer coin control instancing (João Barbosa) Pull request description: Defer the GUI coin control instancing so that argument processing is taken into account for the default coin control values. Fixes #12312 Tree-SHA512: ecda28b94f4709319e9484b01afe763c7c3569097d2afb89db79da8a195c46d20ea77166df7edce0c8ab77627b295def01c072148714503436d27675d5e75d99
2 parents 84291d1 + 6558f8a commit 41363fe

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

src/qt/coincontroldialog.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include <QTreeWidget>
3232

3333
QList<CAmount> CoinControlDialog::payAmounts;
34-
CCoinControl* CoinControlDialog::coinControl = new CCoinControl();
3534
bool CoinControlDialog::fSubtractFeeFromAmount = false;
3635

3736
bool CCoinControlWidgetItem::operator<(const QTreeWidgetItem &other) const {
@@ -193,7 +192,7 @@ void CoinControlDialog::buttonSelectAllClicked()
193192
ui->treeWidget->topLevelItem(i)->setCheckState(COLUMN_CHECKBOX, state);
194193
ui->treeWidget->setEnabled(true);
195194
if (state == Qt::Unchecked)
196-
coinControl->UnSelectAll(); // just to be sure
195+
coinControl()->UnSelectAll(); // just to be sure
197196
CoinControlDialog::updateLabels(model, this);
198197
}
199198

@@ -379,11 +378,11 @@ void CoinControlDialog::viewItemChanged(QTreeWidgetItem* item, int column)
379378
COutPoint outpt(uint256S(item->text(COLUMN_TXHASH).toStdString()), item->text(COLUMN_VOUT_INDEX).toUInt());
380379

381380
if (item->checkState(COLUMN_CHECKBOX) == Qt::Unchecked)
382-
coinControl->UnSelect(outpt);
381+
coinControl()->UnSelect(outpt);
383382
else if (item->isDisabled()) // locked (this happens if "check all" through parent node)
384383
item->setCheckState(COLUMN_CHECKBOX, Qt::Unchecked);
385384
else
386-
coinControl->Select(outpt);
385+
coinControl()->Select(outpt);
387386

388387
// selection changed -> update labels
389388
if (ui->treeWidget->isEnabled()) // do not update on every click for (un)select all
@@ -446,7 +445,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
446445

447446
std::vector<COutPoint> vCoinControl;
448447
std::vector<COutput> vOutputs;
449-
coinControl->ListSelected(vCoinControl);
448+
coinControl()->ListSelected(vCoinControl);
450449
model->getOutputs(vCoinControl, vOutputs);
451450

452451
for (const COutput& out : vOutputs) {
@@ -456,7 +455,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
456455
COutPoint outpt(txhash, out.i);
457456
if (model->isSpent(outpt))
458457
{
459-
coinControl->UnSelect(outpt);
458+
coinControl()->UnSelect(outpt);
460459
continue;
461460
}
462461

@@ -509,7 +508,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
509508
nBytes -= 34;
510509

511510
// Fee
512-
nPayFee = GetMinimumFee(nBytes, *coinControl, ::mempool, ::feeEstimator, nullptr /* FeeCalculation */);
511+
nPayFee = GetMinimumFee(nBytes, *coinControl(), ::mempool, ::feeEstimator, nullptr /* FeeCalculation */);
513512

514513
if (nPayAmount > 0)
515514
{
@@ -600,6 +599,12 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
600599
label->setVisible(nChange < 0);
601600
}
602601

602+
CCoinControl* CoinControlDialog::coinControl()
603+
{
604+
static CCoinControl coin_control;
605+
return &coin_control;
606+
}
607+
603608
void CoinControlDialog::updateView()
604609
{
605610
if (!model || !model->getOptionsModel() || !model->getAddressTableModel())
@@ -703,13 +708,13 @@ void CoinControlDialog::updateView()
703708
if (model->isLockedCoin(txhash, out.i))
704709
{
705710
COutPoint outpt(txhash, out.i);
706-
coinControl->UnSelect(outpt); // just to be sure
711+
coinControl()->UnSelect(outpt); // just to be sure
707712
itemOutput->setDisabled(true);
708713
itemOutput->setIcon(COLUMN_CHECKBOX, platformStyle->SingleColorIcon(":/icons/lock_closed"));
709714
}
710715

711716
// set checkbox
712-
if (coinControl->IsSelected(COutPoint(txhash, out.i)))
717+
if (coinControl()->IsSelected(COutPoint(txhash, out.i)))
713718
itemOutput->setCheckState(COLUMN_CHECKBOX, Qt::Checked);
714719
}
715720

src/qt/coincontroldialog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class CoinControlDialog : public QDialog
5252
static void updateLabels(WalletModel*, QDialog*);
5353

5454
static QList<CAmount> payAmounts;
55-
static CCoinControl *coinControl;
55+
static CCoinControl *coinControl();
5656
static bool fSubtractFeeFromAmount;
5757

5858
private:

src/qt/sendcoinsdialog.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ void SendCoinsDialog::on_sendButton_clicked()
256256
// Always use a CCoinControl instance, use the CoinControlDialog instance if CoinControl has been enabled
257257
CCoinControl ctrl;
258258
if (model->getOptionsModel()->getCoinControlFeatures())
259-
ctrl = *CoinControlDialog::coinControl;
259+
ctrl = *CoinControlDialog::coinControl();
260260

261261
updateCoinControlState(ctrl);
262262

@@ -367,7 +367,7 @@ void SendCoinsDialog::on_sendButton_clicked()
367367
if (sendStatus.status == WalletModel::OK)
368368
{
369369
accept();
370-
CoinControlDialog::coinControl->UnSelectAll();
370+
CoinControlDialog::coinControl()->UnSelectAll();
371371
coinControlUpdateLabels();
372372
}
373373
fNewRecipientAllowed = true;
@@ -604,7 +604,7 @@ void SendCoinsDialog::useAvailableBalance(SendCoinsEntry* entry)
604604
// Get CCoinControl instance if CoinControl is enabled or create a new one.
605605
CCoinControl coin_control;
606606
if (model->getOptionsModel()->getCoinControlFeatures()) {
607-
coin_control = *CoinControlDialog::coinControl;
607+
coin_control = *CoinControlDialog::coinControl();
608608
}
609609

610610
// Calculate available amount to send.
@@ -754,7 +754,7 @@ void SendCoinsDialog::coinControlFeatureChanged(bool checked)
754754
ui->frameCoinControl->setVisible(checked);
755755

756756
if (!checked && model) // coin control features disabled
757-
CoinControlDialog::coinControl->SetNull();
757+
CoinControlDialog::coinControl()->SetNull();
758758

759759
coinControlUpdateLabels();
760760
}
@@ -773,7 +773,7 @@ void SendCoinsDialog::coinControlChangeChecked(int state)
773773
{
774774
if (state == Qt::Unchecked)
775775
{
776-
CoinControlDialog::coinControl->destChange = CNoDestination();
776+
CoinControlDialog::coinControl()->destChange = CNoDestination();
777777
ui->labelCoinControlChangeLabel->clear();
778778
}
779779
else
@@ -789,7 +789,7 @@ void SendCoinsDialog::coinControlChangeEdited(const QString& text)
789789
if (model && model->getAddressTableModel())
790790
{
791791
// Default to no change address until verified
792-
CoinControlDialog::coinControl->destChange = CNoDestination();
792+
CoinControlDialog::coinControl()->destChange = CNoDestination();
793793
ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:red;}");
794794

795795
const CTxDestination dest = DecodeDestination(text.toStdString());
@@ -812,7 +812,7 @@ void SendCoinsDialog::coinControlChangeEdited(const QString& text)
812812
QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel);
813813

814814
if(btnRetVal == QMessageBox::Yes)
815-
CoinControlDialog::coinControl->destChange = dest;
815+
CoinControlDialog::coinControl()->destChange = dest;
816816
else
817817
{
818818
ui->lineEditCoinControlChange->setText("");
@@ -831,7 +831,7 @@ void SendCoinsDialog::coinControlChangeEdited(const QString& text)
831831
else
832832
ui->labelCoinControlChangeLabel->setText(tr("(no label)"));
833833

834-
CoinControlDialog::coinControl->destChange = dest;
834+
CoinControlDialog::coinControl()->destChange = dest;
835835
}
836836
}
837837
}
@@ -843,7 +843,7 @@ void SendCoinsDialog::coinControlUpdateLabels()
843843
if (!model || !model->getOptionsModel())
844844
return;
845845

846-
updateCoinControlState(*CoinControlDialog::coinControl);
846+
updateCoinControlState(*CoinControlDialog::coinControl());
847847

848848
// set pay amounts
849849
CoinControlDialog::payAmounts.clear();
@@ -861,7 +861,7 @@ void SendCoinsDialog::coinControlUpdateLabels()
861861
}
862862
}
863863

864-
if (CoinControlDialog::coinControl->HasSelected())
864+
if (CoinControlDialog::coinControl()->HasSelected())
865865
{
866866
// actual coin control calculation
867867
CoinControlDialog::updateLabels(model, this);

0 commit comments

Comments
 (0)