Bitcoin ABC  0.26.3
P2P Digital Currency
sendcoinsdialog.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2016 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #if defined(HAVE_CONFIG_H)
6 #include <config/bitcoin-config.h>
7 #endif
8 
9 #include <qt/forms/ui_sendcoinsdialog.h>
10 #include <qt/sendcoinsdialog.h>
11 
12 #include <chainparams.h>
13 #include <interfaces/node.h>
14 #include <key_io.h>
15 #include <node/ui_interface.h>
16 #include <qt/addresstablemodel.h>
17 #include <qt/bitcoinunits.h>
18 #include <qt/clientmodel.h>
19 #include <qt/coincontroldialog.h>
20 #include <qt/guiutil.h>
21 #include <qt/optionsmodel.h>
22 #include <qt/platformstyle.h>
23 #include <qt/sendcoinsentry.h>
24 #include <txmempool.h>
25 #include <wallet/coincontrol.h>
26 #include <wallet/fees.h>
27 #include <wallet/wallet.h>
28 
29 #include <validation.h>
30 
31 #include <QScrollBar>
32 #include <QSettings>
33 #include <QTextDocument>
34 
36  WalletModel *_model, QWidget *parent)
37  : QDialog(parent), ui(new Ui::SendCoinsDialog), clientModel(nullptr),
38  model(_model), m_coin_control(new CCoinControl),
39  fNewRecipientAllowed(true), fFeeMinimized(true),
40  platformStyle(_platformStyle) {
41  ui->setupUi(this);
42 
43  if (!_platformStyle->getImagesOnButtons()) {
44  ui->addButton->setIcon(QIcon());
45  ui->clearButton->setIcon(QIcon());
46  ui->sendButton->setIcon(QIcon());
47  } else {
48  ui->addButton->setIcon(_platformStyle->SingleColorIcon(":/icons/add"));
49  ui->clearButton->setIcon(
50  _platformStyle->SingleColorIcon(":/icons/remove"));
51  ui->sendButton->setIcon(
52  _platformStyle->SingleColorIcon(":/icons/send"));
53  }
54 
55  GUIUtil::setupAddressWidget(ui->lineEditCoinControlChange, this);
56 
57  addEntry();
58 
59  connect(ui->addButton, &QPushButton::clicked, this,
61  connect(ui->clearButton, &QPushButton::clicked, this,
63 
64  // Coin Control
65  connect(ui->pushButtonCoinControl, &QPushButton::clicked, this,
67  connect(ui->checkBoxCoinControlChange, &QCheckBox::stateChanged, this,
69  connect(ui->lineEditCoinControlChange, &QValidatedLineEdit::textEdited,
71 
72  // Coin Control: clipboard actions
73  QAction *clipboardQuantityAction = new QAction(tr("Copy quantity"), this);
74  QAction *clipboardAmountAction = new QAction(tr("Copy amount"), this);
75  QAction *clipboardFeeAction = new QAction(tr("Copy fee"), this);
76  QAction *clipboardAfterFeeAction = new QAction(tr("Copy after fee"), this);
77  QAction *clipboardBytesAction = new QAction(tr("Copy bytes"), this);
78  QAction *clipboardLowOutputAction = new QAction(tr("Copy dust"), this);
79  QAction *clipboardChangeAction = new QAction(tr("Copy change"), this);
80  connect(clipboardQuantityAction, &QAction::triggered, this,
82  connect(clipboardAmountAction, &QAction::triggered, this,
84  connect(clipboardFeeAction, &QAction::triggered, this,
86  connect(clipboardAfterFeeAction, &QAction::triggered, this,
88  connect(clipboardBytesAction, &QAction::triggered, this,
90  connect(clipboardLowOutputAction, &QAction::triggered, this,
92  connect(clipboardChangeAction, &QAction::triggered, this,
94  ui->labelCoinControlQuantity->addAction(clipboardQuantityAction);
95  ui->labelCoinControlAmount->addAction(clipboardAmountAction);
96  ui->labelCoinControlFee->addAction(clipboardFeeAction);
97  ui->labelCoinControlAfterFee->addAction(clipboardAfterFeeAction);
98  ui->labelCoinControlBytes->addAction(clipboardBytesAction);
99  ui->labelCoinControlLowOutput->addAction(clipboardLowOutputAction);
100  ui->labelCoinControlChange->addAction(clipboardChangeAction);
101 
102  // init transaction fee section
103  QSettings settings;
104  if (!settings.contains("fFeeSectionMinimized")) {
105  settings.setValue("fFeeSectionMinimized", true);
106  }
107  // compatibility
108  if (!settings.contains("nFeeRadio") &&
109  settings.contains("nTransactionFee") &&
110  settings.value("nTransactionFee").toLongLong() > 0) {
111  // custom
112  settings.setValue("nFeeRadio", 1);
113  }
114  if (!settings.contains("nFeeRadio")) {
115  // recommended
116  settings.setValue("nFeeRadio", 0);
117  }
118  if (!settings.contains("nTransactionFee")) {
119  settings.setValue("nTransactionFee",
120  qint64(DEFAULT_PAY_TX_FEE / SATOSHI));
121  }
122  ui->groupFee->setId(ui->radioSmartFee, 0);
123  ui->groupFee->setId(ui->radioCustomFee, 1);
124  ui->groupFee
125  ->button(
126  std::max<int>(0, std::min(1, settings.value("nFeeRadio").toInt())))
127  ->setChecked(true);
128  ui->customFee->SetAllowEmpty(false);
129  ui->customFee->setValue(
130  int64_t(settings.value("nTransactionFee").toLongLong()) * SATOSHI);
131  minimizeFeeSection(settings.value("fFeeSectionMinimized").toBool());
132 
133  // Set the model properly.
134  setModel(model);
135 }
136 
138  this->clientModel = _clientModel;
139 
140  if (_clientModel) {
141  connect(_clientModel, &ClientModel::numBlocksChanged, this,
143  }
144 }
145 
147  this->model = _model;
148 
149  if (_model && _model->getOptionsModel()) {
150  for (int i = 0; i < ui->entries->count(); ++i) {
151  SendCoinsEntry *entry = qobject_cast<SendCoinsEntry *>(
152  ui->entries->itemAt(i)->widget());
153  if (entry) {
154  entry->setModel(_model);
155  }
156  }
157 
158  interfaces::WalletBalances balances = _model->wallet().getBalances();
159  setBalance(balances);
160  connect(_model, &WalletModel::balanceChanged, this,
165 
166  // Coin Control
169  connect(_model->getOptionsModel(),
172  ui->frameCoinControl->setVisible(
175 
176  // fee section
177 #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
178  const auto buttonClickedEvent =
179  QOverload<int>::of(&QButtonGroup::idClicked);
180 #else
181  /* QOverload in introduced from Qt 5.7, but we support down to 5.5.1 */
182  const auto buttonClickedEvent =
183  static_cast<void (QButtonGroup::*)(int)>(
184  &QButtonGroup::buttonClicked);
185 #endif
186  connect(ui->groupFee, buttonClickedEvent, this,
188  connect(ui->groupFee, buttonClickedEvent, this,
190  connect(ui->customFee, &BitcoinAmountField::valueChanged, this,
192  Amount requiredFee = model->wallet().getRequiredFee(1000);
193  ui->customFee->SetMinValue(requiredFee);
194  if (ui->customFee->value() < requiredFee) {
195  ui->customFee->setValue(requiredFee);
196  }
197  ui->customFee->setSingleStep(requiredFee);
200 
201  if (model->wallet().privateKeysDisabled()) {
202  ui->sendButton->setText(tr("Cr&eate Unsigned"));
203  ui->sendButton->setToolTip(
204  tr("Creates a Partially Signed Bitcoin Transaction (PSBT) for "
205  "use with e.g. an offline %1 wallet, or a PSBT-compatible "
206  "hardware wallet.")
207  .arg(PACKAGE_NAME));
208  }
209  }
210 }
211 
213  QSettings settings;
214  settings.setValue("fFeeSectionMinimized", fFeeMinimized);
215  settings.setValue("nFeeRadio", ui->groupFee->checkedId());
216  settings.setValue("nTransactionFee",
217  qint64(ui->customFee->value() / SATOSHI));
218 
219  delete ui;
220 }
221 
222 bool SendCoinsDialog::PrepareSendText(QString &question_string,
223  QString &informative_text,
224  QString &detailed_text) {
225  QList<SendCoinsRecipient> recipients;
226  bool valid = true;
227 
228  for (int i = 0; i < ui->entries->count(); ++i) {
229  SendCoinsEntry *entry =
230  qobject_cast<SendCoinsEntry *>(ui->entries->itemAt(i)->widget());
231  if (entry) {
232  if (entry->validate(model->node())) {
233  recipients.append(entry->getValue());
234  } else if (valid) {
235  ui->scrollArea->ensureWidgetVisible(entry);
236  valid = false;
237  }
238  }
239  }
240 
241  if (!valid || recipients.isEmpty()) {
242  return false;
243  }
244 
245  fNewRecipientAllowed = false;
247  if (!ctx.isValid()) {
248  // Unlock wallet was cancelled
249  fNewRecipientAllowed = true;
250  return false;
251  }
252 
253  // prepare transaction for getting txFee earlier
255  std::make_unique<WalletModelTransaction>(recipients);
256  WalletModel::SendCoinsReturn prepareStatus;
257 
259 
260  prepareStatus =
262 
263  // process prepareStatus and on error generate message shown to user
264  processSendCoinsReturn(prepareStatus,
267  m_current_transaction->getTransactionFee()));
268 
269  if (prepareStatus.status != WalletModel::OK) {
270  fNewRecipientAllowed = true;
271  return false;
272  }
273 
274  Amount txFee = m_current_transaction->getTransactionFee();
275  QStringList formatted;
276  for (const SendCoinsRecipient &rcp :
277  m_current_transaction->getRecipients()) {
278  // generate amount string with wallet name in case of multiwallet
279  QString amount = BitcoinUnits::formatWithUnit(
280  model->getOptionsModel()->getDisplayUnit(), rcp.amount);
281  if (model->isMultiwallet()) {
282  amount.append(
283  tr(" from wallet '%1'")
285  }
286  // generate address string
287  QString address = rcp.address;
288 
289  QString recipientElement;
290 
291 #ifdef ENABLE_BIP70
292  // normal payment
293  if (!rcp.paymentRequest.IsInitialized())
294 #endif
295  {
296  if (rcp.label.length() > 0) {
297  // label with address
298  recipientElement.append(
299  tr("%1 to '%2'")
300  .arg(amount, GUIUtil::HtmlEscape(rcp.label)));
301  recipientElement.append(QString(" (%1)").arg(address));
302  } else {
303  // just address
304  recipientElement.append(tr("%1 to %2").arg(amount, address));
305  }
306  }
307 #ifdef ENABLE_BIP70
308  // authenticated payment request
309  else if (!rcp.authenticatedMerchant.isEmpty()) {
310  recipientElement.append(
311  tr("%1 to '%2'").arg(amount, rcp.authenticatedMerchant));
312  } else {
313  // unauthenticated payment request
314  recipientElement.append(tr("%1 to %2").arg(amount, address));
315  }
316 #endif
317 
318  formatted.append(recipientElement);
319  }
320 
321  if (model->wallet().privateKeysDisabled()) {
322  question_string.append(tr("Do you want to draft this transaction?"));
323  } else {
324  question_string.append(tr("Are you sure you want to send?"));
325  }
326 
327  question_string.append("<br /><span style='font-size:10pt;'>");
328  if (model->wallet().privateKeysDisabled()) {
329  question_string.append(
330  tr("Please, review your transaction proposal. This will produce a "
331  "Partially Signed Bitcoin Transaction (PSBT) which you can save "
332  "or copy and then sign with e.g. an offline %1 wallet, or a "
333  "PSBT-compatible hardware wallet.")
334  .arg(PACKAGE_NAME));
335  } else {
336  question_string.append(tr("Please, review your transaction."));
337  }
338  question_string.append("</span>%1");
339 
340  if (txFee > Amount::zero()) {
341  // append fee string if a fee is required
342  question_string.append("<hr /><b>");
343  question_string.append(tr("Transaction fee"));
344  question_string.append("</b>");
345 
346  // append transaction size
347  question_string.append(
348  " (" +
349  QString::number(
350  (double)m_current_transaction->getTransactionSize() / 1000) +
351  " kB): ");
352 
353  // append transaction fee value
354  question_string.append(
355  "<span style='color:#aa0000; font-weight:bold;'>");
356  question_string.append(BitcoinUnits::formatHtmlWithUnit(
357  model->getOptionsModel()->getDisplayUnit(), txFee));
358  question_string.append("</span><br />");
359  }
360 
361  // add total amount in all subdivision units
362  question_string.append("<hr />");
363  Amount totalAmount =
364  m_current_transaction->getTotalTransactionAmount() + txFee;
365  QStringList alternativeUnits;
367  if (u != model->getOptionsModel()->getDisplayUnit()) {
368  alternativeUnits.append(
369  BitcoinUnits::formatHtmlWithUnit(u, totalAmount));
370  }
371  }
372  question_string.append(
373  QString("<b>%1</b>: <b>%2</b>")
374  .arg(tr("Total Amount"))
376  model->getOptionsModel()->getDisplayUnit(), totalAmount)));
377  question_string.append(
378  QString("<br /><span style='font-size:10pt; "
379  "font-weight:normal;'>(=%1)</span>")
380  .arg(alternativeUnits.join(" " + tr("or") + " ")));
381 
382  if (formatted.size() > 1) {
383  question_string = question_string.arg("");
384  informative_text =
385  tr("To review recipient list click \"Show Details...\"");
386  detailed_text = formatted.join("\n\n");
387  } else {
388  question_string = question_string.arg("<br /><br />" + formatted.at(0));
389  }
390 
391  return true;
392 }
393 
395  if (!model || !model->getOptionsModel()) {
396  return;
397  }
398 
399  QString question_string, informative_text, detailed_text;
400  if (!PrepareSendText(question_string, informative_text, detailed_text)) {
401  return;
402  }
404 
405  const QString confirmation = model->wallet().privateKeysDisabled()
406  ? tr("Confirm transaction proposal")
407  : tr("Confirm send coins");
408  const QString confirmButtonText = model->wallet().privateKeysDisabled()
409  ? tr("Create Unsigned")
410  : tr("Send");
411  SendConfirmationDialog confirmationDialog(
412  confirmation, question_string, informative_text, detailed_text,
413  SEND_CONFIRM_DELAY, confirmButtonText, this);
414  confirmationDialog.exec();
415  QMessageBox::StandardButton retval =
416  static_cast<QMessageBox::StandardButton>(confirmationDialog.result());
417 
418  if (retval != QMessageBox::Yes) {
419  fNewRecipientAllowed = true;
420  return;
421  }
422 
423  bool send_failure = false;
424  if (model->wallet().privateKeysDisabled()) {
425  CMutableTransaction mtx =
427  PartiallySignedTransaction psbtx(mtx);
428  bool complete = false;
429  const TransactionError err = model->wallet().fillPSBT(
430  SigHashType().withForkId(), false /* sign */,
431  true /* bip32derivs */, psbtx, complete);
432  assert(!complete);
434  // Serialize the PSBT
436  ssTx << psbtx;
437  GUIUtil::setClipboard(EncodeBase64(ssTx.str()).c_str());
438  QMessageBox msgBox;
439  msgBox.setText("Unsigned Transaction");
440  msgBox.setInformativeText(
441  "The PSBT has been copied to the clipboard. You can also save it.");
442  msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard);
443  msgBox.setDefaultButton(QMessageBox::Discard);
444  switch (msgBox.exec()) {
445  case QMessageBox::Save: {
446  QString selectedFilter;
447  QString fileNameSuggestion = "";
448  bool first = true;
449  for (const SendCoinsRecipient &rcp :
450  m_current_transaction->getRecipients()) {
451  if (!first) {
452  fileNameSuggestion.append(" - ");
453  }
454  QString labelOrAddress =
455  rcp.label.isEmpty() ? rcp.address : rcp.label;
456  QString amount = BitcoinUnits::formatWithUnit(
457  model->getOptionsModel()->getDisplayUnit(), rcp.amount);
458  fileNameSuggestion.append(labelOrAddress + "-" + amount);
459  first = false;
460  }
461  fileNameSuggestion.append(".psbt");
462  QString filename = GUIUtil::getSaveFileName(
463  this, tr("Save Transaction Data"), fileNameSuggestion,
464  tr("Partially Signed Transaction (Binary) (*.psbt)"),
465  &selectedFilter);
466  if (filename.isEmpty()) {
467  return;
468  }
469  fsbridge::ofstream out{filename.toLocal8Bit().data(),
470  fsbridge::ofstream::out |
471  fsbridge::ofstream::binary};
472  out << ssTx.str();
473  out.close();
474  Q_EMIT message(tr("PSBT saved"), "PSBT saved to disk",
476  break;
477  }
478  case QMessageBox::Discard:
479  break;
480  default:
481  assert(false);
482  }
483  } else {
484  // now send the prepared transaction
485  WalletModel::SendCoinsReturn sendStatus =
487  // process sendStatus and on error generate message shown to user
488  processSendCoinsReturn(sendStatus);
489 
490  if (sendStatus.status == WalletModel::OK) {
491  Q_EMIT coinsSent(m_current_transaction->getWtx()->GetId());
492  } else {
493  send_failure = true;
494  }
495  }
496  if (!send_failure) {
497  accept();
498  m_coin_control->UnSelectAll();
500  }
501  fNewRecipientAllowed = true;
502  m_current_transaction.reset();
503 }
504 
506  m_current_transaction.reset();
507 
508  // Clear coin control settings
509  m_coin_control->UnSelectAll();
510  ui->checkBoxCoinControlChange->setChecked(false);
511  ui->lineEditCoinControlChange->clear();
513 
514  // Remove entries until only one left
515  while (ui->entries->count()) {
516  ui->entries->takeAt(0)->widget()->deleteLater();
517  }
518  addEntry();
519 
521 }
522 
524  clear();
525 }
526 
528  clear();
529 }
530 
532  SendCoinsEntry *entry = new SendCoinsEntry(platformStyle, model, this);
533  ui->entries->addWidget(entry);
534  connect(entry, &SendCoinsEntry::removeEntry, this,
536  connect(entry, &SendCoinsEntry::useAvailableBalance, this,
538  connect(entry, &SendCoinsEntry::payAmountChanged, this,
540  connect(entry, &SendCoinsEntry::subtractFeeFromAmountChanged, this,
542 
543  // Focus the field, so that entry can start immediately
544  entry->clear();
545  entry->setFocus();
546  ui->scrollAreaWidgetContents->resize(
547  ui->scrollAreaWidgetContents->sizeHint());
548  qApp->processEvents();
549  QScrollBar *bar = ui->scrollArea->verticalScrollBar();
550  if (bar) {
551  bar->setSliderPosition(bar->maximum());
552  }
553 
555  return entry;
556 }
557 
559  setupTabChain(nullptr);
561 }
562 
564  entry->hide();
565 
566  // If the last entry is about to be removed add an empty one
567  if (ui->entries->count() == 1) {
568  addEntry();
569  }
570 
571  entry->deleteLater();
572 
574 }
575 
576 QWidget *SendCoinsDialog::setupTabChain(QWidget *prev) {
577  for (int i = 0; i < ui->entries->count(); ++i) {
578  SendCoinsEntry *entry =
579  qobject_cast<SendCoinsEntry *>(ui->entries->itemAt(i)->widget());
580  if (entry) {
581  prev = entry->setupTabChain(prev);
582  }
583  }
584  QWidget::setTabOrder(prev, ui->sendButton);
585  QWidget::setTabOrder(ui->sendButton, ui->clearButton);
586  QWidget::setTabOrder(ui->clearButton, ui->addButton);
587  return ui->addButton;
588 }
589 
590 void SendCoinsDialog::setAddress(const QString &address) {
591  SendCoinsEntry *entry = nullptr;
592  // Replace the first entry if it is still unused
593  if (ui->entries->count() == 1) {
594  SendCoinsEntry *first =
595  qobject_cast<SendCoinsEntry *>(ui->entries->itemAt(0)->widget());
596  if (first->isClear()) {
597  entry = first;
598  }
599  }
600  if (!entry) {
601  entry = addEntry();
602  }
603 
604  entry->setAddress(address);
605 }
606 
608  if (!fNewRecipientAllowed) {
609  return;
610  }
611 
612  SendCoinsEntry *entry = nullptr;
613  // Replace the first entry if it is still unused
614  if (ui->entries->count() == 1) {
615  SendCoinsEntry *first =
616  qobject_cast<SendCoinsEntry *>(ui->entries->itemAt(0)->widget());
617  if (first->isClear()) {
618  entry = first;
619  }
620  }
621  if (!entry) {
622  entry = addEntry();
623  }
624 
625  entry->setValue(rv);
627 }
628 
630  // Just paste the entry, all pre-checks are done in paymentserver.cpp.
631  pasteEntry(rv);
632  return true;
633 }
634 
636  if (model && model->getOptionsModel()) {
637  Amount balance = balances.balance;
638  if (model->wallet().privateKeysDisabled()) {
639  balance = balances.watch_only_balance;
640  ui->labelBalanceName->setText(tr("Watch-only balance:"));
641  }
642  ui->labelBalance->setText(BitcoinUnits::formatWithUnit(
644  }
645 }
646 
649  ui->customFee->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
651 }
652 
654  const WalletModel::SendCoinsReturn &sendCoinsReturn,
655  const QString &msgArg) {
656  QPair<QString, CClientUIInterface::MessageBoxFlags> msgParams;
657  // Default to a warning message, override if error message is needed
658  msgParams.second = CClientUIInterface::MSG_WARNING;
659 
660  // This comment is specific to SendCoinsDialog usage of
661  // WalletModel::SendCoinsReturn.
662  // All status values are used only in WalletModel::prepareTransaction()
663  switch (sendCoinsReturn.status) {
665  msgParams.first =
666  tr("The recipient address is not valid. Please recheck.");
667  break;
669  msgParams.first = tr("The amount to pay must be larger than 0.");
670  break;
672  msgParams.first = tr("The amount exceeds your balance.");
673  break;
675  msgParams.first = tr("The total exceeds your balance when the %1 "
676  "transaction fee is included.")
677  .arg(msgArg);
678  break;
680  msgParams.first = tr("Duplicate address found: addresses should "
681  "only be used once each.");
682  break;
684  msgParams.first = tr("Transaction creation failed!");
685  msgParams.second = CClientUIInterface::MSG_ERROR;
686  break;
688  msgParams.first =
689  tr("A fee higher than %1 is considered an absurdly high fee.")
693  break;
695  msgParams.first = tr("Payment request expired.");
696  msgParams.second = CClientUIInterface::MSG_ERROR;
697  break;
698  // included to prevent a compiler warning.
699  case WalletModel::OK:
700  default:
701  return;
702  }
703 
704  Q_EMIT message(tr("Send Coins"), msgParams.first, msgParams.second);
705 }
706 
708  ui->labelFeeMinimized->setVisible(fMinimize);
709  ui->buttonChooseFee->setVisible(fMinimize);
710  ui->buttonMinimizeFee->setVisible(!fMinimize);
711  ui->frameFeeSelection->setVisible(!fMinimize);
712  ui->horizontalLayoutSmartFee->setContentsMargins(0, (fMinimize ? 0 : 6), 0,
713  0);
714  fFeeMinimized = fMinimize;
715 }
716 
718  minimizeFeeSection(false);
719 }
720 
723  minimizeFeeSection(true);
724 }
725 
727  // Include watch-only for wallets without private key
728  m_coin_control->fAllowWatchOnly = model->wallet().privateKeysDisabled();
729 
730  // Calculate available amount to send.
732  for (int i = 0; i < ui->entries->count(); ++i) {
733  SendCoinsEntry *e =
734  qobject_cast<SendCoinsEntry *>(ui->entries->itemAt(i)->widget());
735  if (e && !e->isHidden() && e != entry) {
736  amount -= e->getValue().amount;
737  }
738  }
739 
740  if (amount > Amount::zero()) {
742  entry->setAmount(amount);
743  } else {
744  entry->setAmount(Amount::zero());
745  }
746 }
747 
749  ui->labelSmartFee->setEnabled(ui->radioSmartFee->isChecked());
750  ui->labelSmartFee2->setEnabled(ui->radioSmartFee->isChecked());
751  ui->labelFeeEstimation->setEnabled(ui->radioSmartFee->isChecked());
752  ui->labelCustomFeeWarning->setEnabled(ui->radioCustomFee->isChecked());
753  ui->labelCustomPerKilobyte->setEnabled(ui->radioCustomFee->isChecked());
754  ui->customFee->setEnabled(ui->radioCustomFee->isChecked());
755 }
756 
758  if (!model || !model->getOptionsModel()) {
759  return;
760  }
761 
762  if (ui->radioSmartFee->isChecked()) {
763  ui->labelFeeMinimized->setText(ui->labelSmartFee->text());
764  } else {
765  ui->labelFeeMinimized->setText(
768  ui->customFee->value()) +
769  "/kB");
770  }
771 }
772 
774  if (ui->radioCustomFee->isChecked()) {
775  ctrl.m_feerate = CFeeRate(ui->customFee->value());
776  } else {
777  ctrl.m_feerate.reset();
778  }
779  // Include watch-only for wallets without private key
781 }
782 
784  const QDateTime &blockDate,
785  double nVerificationProgress,
786  bool headers,
787  SynchronizationState sync_state) {
788  if (sync_state == SynchronizationState::POST_INIT) {
790  }
791 }
792 
794  if (!model || !model->getOptionsModel()) {
795  return;
796  }
797 
799  // Explicitly use only fee estimation rate for smart fee labels
800  m_coin_control->m_feerate.reset();
801  CFeeRate feeRate(model->wallet().getMinimumFee(1000, *m_coin_control));
802 
803  ui->labelSmartFee->setText(
805  feeRate.GetFeePerK()) +
806  "/kB");
807  // not enough data => minfee
808  if (feeRate <= CFeeRate(Amount::zero())) {
809  // (Smart fee not initialized yet. This usually takes a few blocks...)
810  ui->labelSmartFee2->show();
811  ui->labelFeeEstimation->setText("");
812  } else {
813  ui->labelSmartFee2->hide();
814  ui->labelFeeEstimation->setText(
815  tr("Estimated to begin confirmation by next block."));
816  }
817 
819 }
820 
821 // Coin Control: copy label "Quantity" to clipboard
823  GUIUtil::setClipboard(ui->labelCoinControlQuantity->text());
824 }
825 
826 // Coin Control: copy label "Amount" to clipboard
828  GUIUtil::setClipboard(ui->labelCoinControlAmount->text().left(
829  ui->labelCoinControlAmount->text().indexOf(" ")));
830 }
831 
832 // Coin Control: copy label "Fee" to clipboard
835  ui->labelCoinControlFee->text()
836  .left(ui->labelCoinControlFee->text().indexOf(" "))
837  .replace(ASYMP_UTF8, ""));
838 }
839 
840 // Coin Control: copy label "After fee" to clipboard
843  ui->labelCoinControlAfterFee->text()
844  .left(ui->labelCoinControlAfterFee->text().indexOf(" "))
845  .replace(ASYMP_UTF8, ""));
846 }
847 
848 // Coin Control: copy label "Bytes" to clipboard
851  ui->labelCoinControlBytes->text().replace(ASYMP_UTF8, ""));
852 }
853 
854 // Coin Control: copy label "Dust" to clipboard
856  GUIUtil::setClipboard(ui->labelCoinControlLowOutput->text());
857 }
858 
859 // Coin Control: copy label "Change" to clipboard
862  ui->labelCoinControlChange->text()
863  .left(ui->labelCoinControlChange->text().indexOf(" "))
864  .replace(ASYMP_UTF8, ""));
865 }
866 
867 // Coin Control: settings menu - coin control enabled/disabled by user
869  ui->frameCoinControl->setVisible(checked);
870 
871  // coin control features disabled
872  if (!checked && model) {
873  m_coin_control->SetNull();
874  }
875 
877 }
878 
879 // Coin Control: button inputs -> show actual coin control dialog
882  dlg.exec();
884 }
885 
886 // Coin Control: checkbox custom change address
888  if (state == Qt::Unchecked) {
889  m_coin_control->destChange = CNoDestination();
890  ui->labelCoinControlChangeLabel->clear();
891  } else {
892  // use this to re-validate an already entered address
893  coinControlChangeEdited(ui->lineEditCoinControlChange->text());
894  }
895 
896  ui->lineEditCoinControlChange->setEnabled((state == Qt::Checked));
897 }
898 
899 // Coin Control: custom change address changed
900 void SendCoinsDialog::coinControlChangeEdited(const QString &text) {
901  if (model && model->getAddressTableModel()) {
902  // Default to no change address until verified
903  m_coin_control->destChange = CNoDestination();
904  ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:red;}");
905 
906  const CTxDestination dest =
907  DecodeDestination(text.toStdString(), model->getChainParams());
908 
909  if (text.isEmpty()) {
910  // Nothing entered
911  ui->labelCoinControlChangeLabel->setText("");
912  } else if (!IsValidDestination(dest)) {
913  // Invalid address
914  ui->labelCoinControlChangeLabel->setText(
915  tr("Warning: Invalid Bitcoin address"));
916  } else {
917  // Valid address
918  if (!model->wallet().isSpendable(dest)) {
919  ui->labelCoinControlChangeLabel->setText(
920  tr("Warning: Unknown change address"));
921 
922  // confirmation dialog
923  QMessageBox::StandardButton btnRetVal = QMessageBox::question(
924  this, tr("Confirm custom change address"),
925  tr("The address you selected for change is not part of "
926  "this wallet. Any or all funds in your wallet may be "
927  "sent to this address. Are you sure?"),
928  QMessageBox::Yes | QMessageBox::Cancel,
929  QMessageBox::Cancel);
930 
931  if (btnRetVal == QMessageBox::Yes) {
932  m_coin_control->destChange = dest;
933  } else {
934  ui->lineEditCoinControlChange->setText("");
935  ui->labelCoinControlChangeLabel->setStyleSheet(
936  "QLabel{color:black;}");
937  ui->labelCoinControlChangeLabel->setText("");
938  }
939  } else {
940  // Known change address
941  ui->labelCoinControlChangeLabel->setStyleSheet(
942  "QLabel{color:black;}");
943 
944  // Query label
945  QString associatedLabel =
947  if (!associatedLabel.isEmpty()) {
948  ui->labelCoinControlChangeLabel->setText(associatedLabel);
949  } else {
950  ui->labelCoinControlChangeLabel->setText(tr("(no label)"));
951  }
952 
953  m_coin_control->destChange = dest;
954  }
955  }
956  }
957 }
958 
959 // Coin Control: update labels
961  if (!model || !model->getOptionsModel()) {
962  return;
963  }
964 
966 
967  // set pay amounts
970  for (int i = 0; i < ui->entries->count(); ++i) {
971  SendCoinsEntry *entry =
972  qobject_cast<SendCoinsEntry *>(ui->entries->itemAt(i)->widget());
973  if (entry && !entry->isHidden()) {
974  SendCoinsRecipient rcp = entry->getValue();
976  if (rcp.fSubtractFeeFromAmount) {
978  }
979  }
980  }
981 
982  if (m_coin_control->HasSelected()) {
983  // actual coin control calculation
985 
986  // show coin control stats
987  ui->labelCoinControlAutomaticallySelected->hide();
988  ui->widgetCoinControl->show();
989  } else {
990  // hide coin control stats
991  ui->labelCoinControlAutomaticallySelected->show();
992  ui->widgetCoinControl->hide();
993  ui->labelCoinControlInsuffFunds->hide();
994  }
995 }
996 
998  const QString &title, const QString &text, const QString &informative_text,
999  const QString &detailed_text, int _secDelay,
1000  const QString &_confirmButtonText, QWidget *parent)
1001  : QMessageBox(parent), secDelay(_secDelay),
1002  confirmButtonText(_confirmButtonText) {
1003  setIcon(QMessageBox::Question);
1004  // On macOS, the window title is ignored (as required by the macOS
1005  // Guidelines).
1006  setWindowTitle(title);
1007  setText(text);
1008  setInformativeText(informative_text);
1009  setDetailedText(detailed_text);
1010  setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
1011  setDefaultButton(QMessageBox::Cancel);
1012  yesButton = button(QMessageBox::Yes);
1013  updateYesButton();
1014  connect(&countDownTimer, &QTimer::timeout, this,
1016 }
1017 
1019  updateYesButton();
1020  countDownTimer.start(1000);
1021  return QMessageBox::exec();
1022 }
1023 
1025  secDelay--;
1026  updateYesButton();
1027 
1028  if (secDelay <= 0) {
1029  countDownTimer.stop();
1030  }
1031 }
1032 
1034  if (secDelay > 0) {
1035  yesButton->setEnabled(false);
1036  yesButton->setText(confirmButtonText + " (" +
1037  QString::number(secDelay) + ")");
1038  } else {
1039  yesButton->setEnabled(true);
1040  yesButton->setText(confirmButtonText);
1041  }
1042 }
static constexpr Amount SATOSHI
Definition: amount.h:153
secp256k1_context * ctx
QString labelForAddress(const QString &address) const
Look up label for address in address book, if not found return empty string.
static QString formatWithUnit(int unit, const Amount amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as string (with unit)
static QList< Unit > availableUnits()
Get list of units, for drop-down box.
Unit
Currency units Please add only sensible ones.
Definition: bitcoinunits.h:42
static QString formatHtmlWithUnit(int unit, const Amount amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as HTML string (with unit)
@ MSG_INFORMATION
Predefined combinations for certain default usage cases.
Definition: ui_interface.h:71
Coin Control Features.
Definition: coincontrol.h:21
bool fAllowWatchOnly
Includes watch only addresses which are solvable.
Definition: coincontrol.h:32
std::optional< CFeeRate > m_feerate
Override the wallet's m_pay_tx_fee if set.
Definition: coincontrol.h:36
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:197
std::string str() const
Definition: streams.h:271
Fee rate in satoshis per kilobyte: Amount / kB.
Definition: feerate.h:21
Amount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
Definition: feerate.h:54
A mutable version of CTransaction.
Definition: transaction.h:278
Model for Bitcoin network client.
Definition: clientmodel.h:36
void numBlocksChanged(int count, const QDateTime &blockDate, double nVerificationProgress, bool header, SynchronizationState sync_state)
static QList< Amount > payAmounts
static void updateLabels(CCoinControl &m_coin_control, WalletModel *, QDialog *)
static bool fSubtractFeeFromAmount
int getDisplayUnit() const
Definition: optionsmodel.h:97
bool getCoinControlFeatures() const
Definition: optionsmodel.h:100
void coinControlFeaturesChanged(bool)
void displayUnitChanged(int unit)
QIcon SingleColorIcon(const QString &filename) const
Colorize an icon (given filename) with the icon color.
bool getImagesOnButtons() const
Definition: platformstyle.h:20
Dialog for sending bitcoins.
void useAvailableBalance(SendCoinsEntry *entry)
WalletModel * model
ClientModel * clientModel
void coinControlChangeEdited(const QString &)
void coinControlChangeChecked(int)
void coinControlClipboardFee()
void updateNumberOfBlocks(int count, const QDateTime &blockDate, double nVerificationProgress, bool headers, SynchronizationState sync_state)
Ui::SendCoinsDialog * ui
void on_buttonChooseFee_clicked()
void processSendCoinsReturn(const WalletModel::SendCoinsReturn &sendCoinsReturn, const QString &msgArg=QString())
void setClientModel(ClientModel *clientModel)
void updateFeeSectionControls()
std::unique_ptr< CCoinControl > m_coin_control
SendCoinsEntry * addEntry()
void pasteEntry(const SendCoinsRecipient &rv)
void updateFeeMinimizedLabel()
void accept() override
const PlatformStyle * platformStyle
void coinControlClipboardQuantity()
void coinControlButtonClicked()
void coinControlClipboardAfterFee()
QWidget * setupTabChain(QWidget *prev)
Set up the tab chain manually, as Qt messes up the tab chain by default in some cases (issue https://...
bool PrepareSendText(QString &question_string, QString &informative_text, QString &detailed_text)
void setModel(WalletModel *model)
void coinControlClipboardLowOutput()
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
SendCoinsDialog(const PlatformStyle *platformStyle, WalletModel *model, QWidget *parent=nullptr)
void setBalance(const interfaces::WalletBalances &balances)
void coinControlClipboardAmount()
void updateCoinControlState(CCoinControl &ctrl)
void setAddress(const QString &address)
void coinControlClipboardChange()
std::unique_ptr< WalletModelTransaction > m_current_transaction
void removeEntry(SendCoinsEntry *entry)
void reject() override
void coinControlClipboardBytes()
void message(const QString &title, const QString &message, unsigned int style)
void coinsSent(const uint256 &txid)
void on_buttonMinimizeFee_clicked()
void coinControlUpdateLabels()
void coinControlFeatureChanged(bool)
void minimizeFeeSection(bool fMinimize)
A single entry in the dialog for sending bitcoins.
void setFocus()
void setAmount(const Amount amount)
void setAddress(const QString &address)
bool isClear()
Return whether the entry is still empty and unedited.
void subtractFeeFromAmountChanged()
void useAvailableBalance(SendCoinsEntry *entry)
void setValue(const SendCoinsRecipient &value)
void setModel(WalletModel *model)
void removeEntry(SendCoinsEntry *entry)
void payAmountChanged()
QWidget * setupTabChain(QWidget *prev)
Set up the tab chain manually, as Qt messes up the tab chain by default in some cases (issue https://...
void clear()
bool validate(interfaces::Node &node)
void checkSubtractFeeFromAmount()
SendCoinsRecipient getValue()
SendConfirmationDialog(const QString &title, const QString &text, const QString &informative_text="", const QString &detailed_text="", int secDelay=SEND_CONFIRM_DELAY, const QString &confirmText="Send", QWidget *parent=nullptr)
QAbstractButton * yesButton
Signature hash type wrapper class.
Definition: sighashtype.h:37
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:47
SendCoinsReturn sendCoins(WalletModelTransaction &transaction)
const CChainParams & getChainParams() const
AddressTableModel * getAddressTableModel()
OptionsModel * getOptionsModel()
interfaces::Wallet & wallet() const
Definition: walletmodel.h:150
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const CCoinControl &coinControl)
bool isMultiwallet()
interfaces::Node & node() const
Definition: walletmodel.h:149
UnlockContext requestUnlock()
void balanceChanged(const interfaces::WalletBalances &balances)
QString getWalletName() const
@ AmountWithFeeExceedsBalance
Definition: walletmodel.h:63
@ TransactionCreationFailed
Definition: walletmodel.h:66
@ AmountExceedsBalance
Definition: walletmodel.h:62
@ DuplicateAddress
Definition: walletmodel.h:64
@ PaymentRequestExpired
Definition: walletmodel.h:68
virtual Amount getAvailableBalance(const CCoinControl &coin_control)=0
Get available balance.
virtual bool isSpendable(const CTxDestination &dest)=0
Return whether wallet has private key.
virtual WalletBalances getBalances()=0
Get balances.
virtual TransactionError fillPSBT(SigHashType sighash_type, bool sign, bool bip32derivs, PartiallySignedTransaction &psbtx, bool &complete) const =0
Fill PSBT.
virtual bool privateKeysDisabled()=0
virtual Amount getMinimumFee(unsigned int tx_bytes, const CCoinControl &coin_control)=0
Get minimum fee.
virtual Amount getDefaultMaxTxFee()=0
Get max tx fee.
virtual Amount getRequiredFee(unsigned int tx_bytes)=0
Get required fee.
#define ASYMP_UTF8
static Amount balance
TransactionError
Definition: error.h:22
CTxDestination DecodeDestination(const std::string &addr, const CChainParams &params)
Definition: key_io.cpp:177
QString HtmlEscape(const QString &str, bool fMultiLine)
Definition: guiutil.cpp:243
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedSuffixOut)
Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix when ...
Definition: guiutil.cpp:286
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
Definition: guiutil.cpp:122
void setClipboard(const QString &str)
Definition: guiutil.cpp:769
fs::ofstream ofstream
Definition: fs.h:247
#define SEND_CONFIRM_DELAY
@ SER_NETWORK
Definition: serialize.h:166
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
Definition: standard.cpp:263
boost::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:93
std::string EncodeBase64(Span< const uint8_t > input)
Definition: amount.h:19
static constexpr Amount zero()
Definition: amount.h:42
A version of CTransaction with the PSBT format.
Definition: psbt.h:335
Collection of wallet balances.
Definition: wallet.h:351
static int count
Definition: tests.c:31
assert(!tx.IsCoinBase())
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:120
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:11
constexpr Amount DEFAULT_PAY_TX_FEE
-paytxfee default
Definition: wallet.h:82