Raven Core  3.0.0
P2P Digital Currency
coincontroldialog.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2016 The Bitcoin Core developers
2 // Copyright (c) 2017-2019 The Raven Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include "coincontroldialog.h"
7 #include "ui_coincontroldialog.h"
8 
9 #include "addresstablemodel.h"
10 #include "ravenunits.h"
11 #include "guiutil.h"
12 #include "optionsmodel.h"
13 #include "platformstyle.h"
14 #include "txmempool.h"
15 #include "walletmodel.h"
16 
17 #include "wallet/coincontrol.h"
18 #include "init.h"
19 #include "policy/fees.h"
20 #include "policy/policy.h"
21 #include "validation.h" // For mempool
22 #include "wallet/fees.h"
23 #include "wallet/wallet.h"
24 
25 #include <QApplication>
26 #include <QCheckBox>
27 #include <QCursor>
28 #include <QDialogButtonBox>
29 #include <QFlags>
30 #include <QIcon>
31 #include <QSettings>
32 #include <QString>
33 #include <QTreeWidget>
34 #include <QTreeWidgetItem>
35 
36 QList<CAmount> CoinControlDialog::payAmounts;
39 
40 bool CCoinControlWidgetItem::operator<(const QTreeWidgetItem &other) const {
41  int column = treeWidget()->sortColumn();
43  return data(column, Qt::UserRole).toLongLong() < other.data(column, Qt::UserRole).toLongLong();
44  return QTreeWidgetItem::operator<(other);
45 }
46 
47 CoinControlDialog::CoinControlDialog(const PlatformStyle *_platformStyle, QWidget *parent) :
48  QDialog(parent),
49  ui(new Ui::CoinControlDialog),
50  model(0),
51  platformStyle(_platformStyle)
52 {
53  ui->setupUi(this);
54 
55  // context menu actions
56  QAction *copyAddressAction = new QAction(tr("Copy address"), this);
57  QAction *copyLabelAction = new QAction(tr("Copy label"), this);
58  QAction *copyAmountAction = new QAction(tr("Copy amount"), this);
59  copyTransactionHashAction = new QAction(tr("Copy transaction ID"), this); // we need to enable/disable this
60  lockAction = new QAction(tr("Lock unspent"), this); // we need to enable/disable this
61  unlockAction = new QAction(tr("Unlock unspent"), this); // we need to enable/disable this
62 
63  // context menu
64  contextMenu = new QMenu(this);
65  contextMenu->addAction(copyAddressAction);
66  contextMenu->addAction(copyLabelAction);
67  contextMenu->addAction(copyAmountAction);
69  contextMenu->addSeparator();
70  contextMenu->addAction(lockAction);
71  contextMenu->addAction(unlockAction);
72 
73  // context menu signals
74  connect(ui->treeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showMenu(QPoint)));
75  connect(copyAddressAction, SIGNAL(triggered()), this, SLOT(copyAddress()));
76  connect(copyLabelAction, SIGNAL(triggered()), this, SLOT(copyLabel()));
77  connect(copyAmountAction, SIGNAL(triggered()), this, SLOT(copyAmount()));
78  connect(copyTransactionHashAction, SIGNAL(triggered()), this, SLOT(copyTransactionHash()));
79  connect(lockAction, SIGNAL(triggered()), this, SLOT(lockCoin()));
80  connect(unlockAction, SIGNAL(triggered()), this, SLOT(unlockCoin()));
81 
82  // clipboard actions
83  QAction *clipboardQuantityAction = new QAction(tr("Copy quantity"), this);
84  QAction *clipboardAmountAction = new QAction(tr("Copy amount"), this);
85  QAction *clipboardFeeAction = new QAction(tr("Copy fee"), this);
86  QAction *clipboardAfterFeeAction = new QAction(tr("Copy after fee"), this);
87  QAction *clipboardBytesAction = new QAction(tr("Copy bytes"), this);
88  QAction *clipboardLowOutputAction = new QAction(tr("Copy dust"), this);
89  QAction *clipboardChangeAction = new QAction(tr("Copy change"), this);
90 
91  connect(clipboardQuantityAction, SIGNAL(triggered()), this, SLOT(clipboardQuantity()));
92  connect(clipboardAmountAction, SIGNAL(triggered()), this, SLOT(clipboardAmount()));
93  connect(clipboardFeeAction, SIGNAL(triggered()), this, SLOT(clipboardFee()));
94  connect(clipboardAfterFeeAction, SIGNAL(triggered()), this, SLOT(clipboardAfterFee()));
95  connect(clipboardBytesAction, SIGNAL(triggered()), this, SLOT(clipboardBytes()));
96  connect(clipboardLowOutputAction, SIGNAL(triggered()), this, SLOT(clipboardLowOutput()));
97  connect(clipboardChangeAction, SIGNAL(triggered()), this, SLOT(clipboardChange()));
98 
99  ui->labelCoinControlQuantity->addAction(clipboardQuantityAction);
100  ui->labelCoinControlAmount->addAction(clipboardAmountAction);
101  ui->labelCoinControlFee->addAction(clipboardFeeAction);
102  ui->labelCoinControlAfterFee->addAction(clipboardAfterFeeAction);
103  ui->labelCoinControlBytes->addAction(clipboardBytesAction);
104  ui->labelCoinControlLowOutput->addAction(clipboardLowOutputAction);
105  ui->labelCoinControlChange->addAction(clipboardChangeAction);
106 
107  // toggle tree/list mode
108  connect(ui->radioTreeMode, SIGNAL(toggled(bool)), this, SLOT(radioTreeMode(bool)));
109  connect(ui->radioListMode, SIGNAL(toggled(bool)), this, SLOT(radioListMode(bool)));
110 
111  // click on checkbox
112  connect(ui->treeWidget, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(viewItemChanged(QTreeWidgetItem*, int)));
113 
114  // click on header
115 #if QT_VERSION < 0x050000
116  ui->treeWidget->header()->setClickable(true);
117 #else
118  ui->treeWidget->header()->setSectionsClickable(true);
119 #endif
120  connect(ui->treeWidget->header(), SIGNAL(sectionClicked(int)), this, SLOT(headerSectionClicked(int)));
121 
122  // ok button
123  connect(ui->buttonBox, SIGNAL(clicked( QAbstractButton*)), this, SLOT(buttonBoxClicked(QAbstractButton*)));
124 
125  // (un)select all
126  connect(ui->pushButtonSelectAll, SIGNAL(clicked()), this, SLOT(buttonSelectAllClicked()));
127 
128  // change coin control first column label due Qt4 bug.
129  // see https://github.com/RavenProject/Ravencoin/issues/5716
130  ui->treeWidget->headerItem()->setText(COLUMN_CHECKBOX, QString());
131 
132  ui->treeWidget->setColumnWidth(COLUMN_CHECKBOX, 84);
133  ui->treeWidget->setColumnWidth(COLUMN_AMOUNT, 110);
134  ui->treeWidget->setColumnWidth(COLUMN_LABEL, 190);
135  ui->treeWidget->setColumnWidth(COLUMN_ADDRESS, 320);
136  ui->treeWidget->setColumnWidth(COLUMN_DATE, 130);
137  ui->treeWidget->setColumnWidth(COLUMN_CONFIRMATIONS, 110);
138  ui->treeWidget->setColumnHidden(COLUMN_TXHASH, true); // store transaction hash in this column, but don't show it
139  ui->treeWidget->setColumnHidden(COLUMN_VOUT_INDEX, true); // store vout index in this column, but don't show it
140 
141  // default view is sorted by amount desc
142  sortView(COLUMN_AMOUNT, Qt::DescendingOrder);
143 
144  // restore list mode and sortorder as a convenience feature
145  QSettings settings;
146  if (settings.contains("nCoinControlMode") && !settings.value("nCoinControlMode").toBool())
147  ui->radioTreeMode->click();
148  if (settings.contains("nCoinControlSortColumn") && settings.contains("nCoinControlSortOrder"))
149  sortView(settings.value("nCoinControlSortColumn").toInt(), ((Qt::SortOrder)settings.value("nCoinControlSortOrder").toInt()));
150 }
151 
153 {
154  QSettings settings;
155  settings.setValue("nCoinControlMode", ui->radioListMode->isChecked());
156  settings.setValue("nCoinControlSortColumn", sortColumn);
157  settings.setValue("nCoinControlSortOrder", (int)sortOrder);
158 
159  delete ui;
160 }
161 
163 {
164  this->model = _model;
165 
166  if(_model && _model->getOptionsModel() && _model->getAddressTableModel())
167  {
168  updateView();
170  CoinControlDialog::updateLabels(_model, this);
171  }
172 }
173 
174 // ok button
175 void CoinControlDialog::buttonBoxClicked(QAbstractButton* button)
176 {
177  if (ui->buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole)
178  done(QDialog::Accepted); // closes the dialog
179 }
180 
181 // (un)select all
183 {
184  Qt::CheckState state = Qt::Checked;
185  for (int i = 0; i < ui->treeWidget->topLevelItemCount(); i++)
186  {
187  if (ui->treeWidget->topLevelItem(i)->checkState(COLUMN_CHECKBOX) != Qt::Unchecked)
188  {
189  state = Qt::Unchecked;
190  break;
191  }
192  }
193  ui->treeWidget->setEnabled(false);
194  for (int i = 0; i < ui->treeWidget->topLevelItemCount(); i++)
195  if (ui->treeWidget->topLevelItem(i)->checkState(COLUMN_CHECKBOX) != state)
196  ui->treeWidget->topLevelItem(i)->setCheckState(COLUMN_CHECKBOX, state);
197  ui->treeWidget->setEnabled(true);
198  if (state == Qt::Unchecked)
199  coinControl->UnSelectAll(); // just to be sure
201 }
202 
203 // context menu
204 void CoinControlDialog::showMenu(const QPoint &point)
205 {
206  QTreeWidgetItem *item = ui->treeWidget->itemAt(point);
207  if(item)
208  {
209  contextMenuItem = item;
210 
211  // disable some items (like Copy Transaction ID, lock, unlock) for tree roots in context menu
212  if (item->text(COLUMN_TXHASH).length() == 64) // transaction hash is 64 characters (this means its a child node, so its not a parent node in tree mode)
213  {
214  copyTransactionHashAction->setEnabled(true);
215  if (model->isLockedCoin(uint256S(item->text(COLUMN_TXHASH).toStdString()), item->text(COLUMN_VOUT_INDEX).toUInt()))
216  {
217  lockAction->setEnabled(false);
218  unlockAction->setEnabled(true);
219  }
220  else
221  {
222  lockAction->setEnabled(true);
223  unlockAction->setEnabled(false);
224  }
225  }
226  else // this means click on parent node in tree mode -> disable all
227  {
228  copyTransactionHashAction->setEnabled(false);
229  lockAction->setEnabled(false);
230  unlockAction->setEnabled(false);
231  }
232 
233  // show context menu
234  contextMenu->exec(QCursor::pos());
235  }
236 }
237 
238 // context menu action: copy amount
240 {
242 }
243 
244 // context menu action: copy label
246 {
247  if (ui->radioTreeMode->isChecked() && contextMenuItem->text(COLUMN_LABEL).length() == 0 && contextMenuItem->parent())
249  else
251 }
252 
253 // context menu action: copy address
255 {
256  if (ui->radioTreeMode->isChecked() && contextMenuItem->text(COLUMN_ADDRESS).length() == 0 && contextMenuItem->parent())
258  else
260 }
261 
262 // context menu action: copy transaction id
264 {
266 }
267 
268 // context menu action: lock coin
270 {
271  if (contextMenuItem->checkState(COLUMN_CHECKBOX) == Qt::Checked)
272  contextMenuItem->setCheckState(COLUMN_CHECKBOX, Qt::Unchecked);
273 
274  COutPoint outpt(uint256S(contextMenuItem->text(COLUMN_TXHASH).toStdString()), contextMenuItem->text(COLUMN_VOUT_INDEX).toUInt());
275  model->lockCoin(outpt);
276  contextMenuItem->setDisabled(true);
277  contextMenuItem->setIcon(COLUMN_CHECKBOX, platformStyle->SingleColorIcon(":/icons/lock_closed"));
279 }
280 
281 // context menu action: unlock coin
283 {
284  COutPoint outpt(uint256S(contextMenuItem->text(COLUMN_TXHASH).toStdString()), contextMenuItem->text(COLUMN_VOUT_INDEX).toUInt());
285  model->unlockCoin(outpt);
286  contextMenuItem->setDisabled(false);
287  contextMenuItem->setIcon(COLUMN_CHECKBOX, QIcon());
289 }
290 
291 // copy label "Quantity" to clipboard
293 {
294  GUIUtil::setClipboard(ui->labelCoinControlQuantity->text());
295 }
296 
297 // copy label "Amount" to clipboard
299 {
300  GUIUtil::setClipboard(ui->labelCoinControlAmount->text().left(ui->labelCoinControlAmount->text().indexOf(" ")));
301 }
302 
303 // copy label "Fee" to clipboard
305 {
306  GUIUtil::setClipboard(ui->labelCoinControlFee->text().left(ui->labelCoinControlFee->text().indexOf(" ")).replace(ASYMP_UTF8, ""));
307 }
308 
309 // copy label "After fee" to clipboard
311 {
312  GUIUtil::setClipboard(ui->labelCoinControlAfterFee->text().left(ui->labelCoinControlAfterFee->text().indexOf(" ")).replace(ASYMP_UTF8, ""));
313 }
314 
315 // copy label "Bytes" to clipboard
317 {
318  GUIUtil::setClipboard(ui->labelCoinControlBytes->text().replace(ASYMP_UTF8, ""));
319 }
320 
321 // copy label "Dust" to clipboard
323 {
324  GUIUtil::setClipboard(ui->labelCoinControlLowOutput->text());
325 }
326 
327 // copy label "Change" to clipboard
329 {
330  GUIUtil::setClipboard(ui->labelCoinControlChange->text().left(ui->labelCoinControlChange->text().indexOf(" ")).replace(ASYMP_UTF8, ""));
331 }
332 
333 // treeview: sort
334 void CoinControlDialog::sortView(int column, Qt::SortOrder order)
335 {
336  sortColumn = column;
337  sortOrder = order;
338  ui->treeWidget->sortItems(column, order);
339  ui->treeWidget->header()->setSortIndicator(sortColumn, sortOrder);
340 }
341 
342 // treeview: clicked on header
344 {
345  if (logicalIndex == COLUMN_CHECKBOX) // click on most left column -> do nothing
346  {
347  ui->treeWidget->header()->setSortIndicator(sortColumn, sortOrder);
348  }
349  else
350  {
351  if (sortColumn == logicalIndex)
352  sortOrder = ((sortOrder == Qt::AscendingOrder) ? Qt::DescendingOrder : Qt::AscendingOrder);
353  else
354  {
355  sortColumn = logicalIndex;
356  sortOrder = ((sortColumn == COLUMN_LABEL || sortColumn == COLUMN_ADDRESS) ? Qt::AscendingOrder : Qt::DescendingOrder); // if label or address then default => asc, else default => desc
357  }
358 
360  }
361 }
362 
363 // toggle tree mode
365 {
366  if (checked && model)
367  updateView();
368 }
369 
370 // toggle list mode
372 {
373  if (checked && model)
374  updateView();
375 }
376 
377 // checkbox clicked by user
378 void CoinControlDialog::viewItemChanged(QTreeWidgetItem* item, int column)
379 {
380  if (column == COLUMN_CHECKBOX && item->text(COLUMN_TXHASH).length() == 64) // transaction hash is 64 characters (this means its a child node, so its not a parent node in tree mode)
381  {
382  COutPoint outpt(uint256S(item->text(COLUMN_TXHASH).toStdString()), item->text(COLUMN_VOUT_INDEX).toUInt());
383 
384  if (item->checkState(COLUMN_CHECKBOX) == Qt::Unchecked)
385  coinControl->UnSelect(outpt);
386  else if (item->isDisabled()) // locked (this happens if "check all" through parent node)
387  item->setCheckState(COLUMN_CHECKBOX, Qt::Unchecked);
388  else
389  coinControl->Select(outpt);
390 
391  // selection changed -> update labels
392  if (ui->treeWidget->isEnabled()) // do not update on every click for (un)select all
394  }
395 
396  // TODO: Remove this temporary qt5 fix after Qt5.3 and Qt5.4 are no longer used.
397  // Fixed in Qt5.5 and above: https://bugreports.qt.io/browse/QTBUG-43473
398 #if QT_VERSION >= 0x050000
399  else if (column == COLUMN_CHECKBOX && item->childCount() > 0)
400  {
401  if (item->checkState(COLUMN_CHECKBOX) == Qt::PartiallyChecked && item->child(0)->checkState(COLUMN_CHECKBOX) == Qt::PartiallyChecked)
402  item->setCheckState(COLUMN_CHECKBOX, Qt::Checked);
403  }
404 #endif
405 }
406 
407 // shows count of locked unspent outputs
409 {
410  std::vector<COutPoint> vOutpts;
411  model->listLockedCoins(vOutpts);
412  if (vOutpts.size() > 0)
413  {
414  ui->labelLocked->setText(tr("(%1 locked)").arg(vOutpts.size()));
415  ui->labelLocked->setVisible(true);
416  }
417  else ui->labelLocked->setVisible(false);
418 }
419 
421 {
422  if (!model)
423  return;
424 
425  // nPayAmount
426  CAmount nPayAmount = 0;
427  bool fDust = false;
428  CMutableTransaction txDummy;
429  for (const CAmount &amount : CoinControlDialog::payAmounts)
430  {
431  nPayAmount += amount;
432 
433  if (amount > 0)
434  {
435  CTxOut txout(amount, (CScript)std::vector<unsigned char>(24, 0));
436  txDummy.vout.push_back(txout);
437  fDust |= IsDust(txout, ::dustRelayFee);
438  }
439  }
440 
441  CAmount nAmount = 0;
442  CAmount nPayFee = 0;
443  CAmount nAfterFee = 0;
444  CAmount nChange = 0;
445  unsigned int nBytes = 0;
446  unsigned int nBytesInputs = 0;
447  unsigned int nQuantity = 0;
448  bool fWitness = false;
449 
450  std::vector<COutPoint> vCoinControl;
451  std::vector<COutput> vOutputs;
452  coinControl->ListSelected(vCoinControl);
453  model->getOutputs(vCoinControl, vOutputs);
454 
455  for (const COutput& out : vOutputs) {
456  // unselect already spent, very unlikely scenario, this could happen
457  // when selected are spent elsewhere, like rpc or another computer
458  uint256 txhash = out.tx->GetHash();
459  COutPoint outpt(txhash, out.i);
460  if (model->isSpent(outpt))
461  {
462  coinControl->UnSelect(outpt);
463  continue;
464  }
465 
466  // Quantity
467  nQuantity++;
468 
469  // Amount
470  nAmount += out.tx->tx->vout[out.i].nValue;
471 
472  // Bytes
473  CTxDestination address;
474  int witnessversion = 0;
475  std::vector<unsigned char> witnessprogram;
476  if (out.tx->tx->vout[out.i].scriptPubKey.IsWitnessProgram(witnessversion, witnessprogram))
477  {
478  nBytesInputs += (32 + 4 + 1 + (107 / WITNESS_SCALE_FACTOR) + 4);
479  fWitness = true;
480  }
481  else if(ExtractDestination(out.tx->tx->vout[out.i].scriptPubKey, address))
482  {
483  CPubKey pubkey;
484  CKeyID *keyid = boost::get<CKeyID>(&address);
485  if (keyid && model->getPubKey(*keyid, pubkey))
486  {
487  nBytesInputs += (pubkey.IsCompressed() ? 148 : 180);
488  }
489  else
490  nBytesInputs += 148; // in all error cases, simply assume 148 here
491  }
492  else nBytesInputs += 148;
493  }
494  // calculation
495  if (nQuantity > 0)
496  {
497  // Bytes
498  nBytes = nBytesInputs + ((CoinControlDialog::payAmounts.size() > 0 ? CoinControlDialog::payAmounts.size() + 1 : 2) * 34) + 10; // always assume +1 output for change here
499  if (fWitness)
500  {
501  // there is some fudging in these numbers related to the actual virtual transaction size calculation that will keep this estimate from being exact.
502  // usually, the result will be an overestimate within a couple of satoshis so that the confirmation dialog ends up displaying a slightly smaller fee.
503  // also, the witness stack size value is a variable sized integer. usually, the number of stack items will be well under the single byte var int limit.
504  nBytes += 2; // account for the serialized marker and flag bytes
505  nBytes += nQuantity; // account for the witness byte that holds the number of stack items for each input.
506  }
507 
508  // in the subtract fee from amount case, we can tell if zero change already and subtract the bytes, so that fee calculation afterwards is accurate
510  if (nAmount - nPayAmount == 0)
511  nBytes -= 34;
512 
513  // Fee
514  nPayFee = GetMinimumFee(nBytes, *coinControl, ::mempool, ::feeEstimator, nullptr /* FeeCalculation */);
515 
516  if (nPayAmount > 0)
517  {
518  nChange = nAmount - nPayAmount;
520  nChange -= nPayFee;
521 
522  // Never create dust outputs; if we would, just add the dust to the fee.
523  if (nChange > 0 && nChange < MIN_CHANGE)
524  {
525  CTxOut txout(nChange, (CScript)std::vector<unsigned char>(24, 0));
526  if (IsDust(txout, ::dustRelayFee))
527  {
528  nPayFee += nChange;
529  nChange = 0;
531  nBytes -= 34; // we didn't detect lack of change above
532  }
533  }
534 
535  if (nChange == 0 && !CoinControlDialog::fSubtractFeeFromAmount)
536  nBytes -= 34;
537  }
538 
539  // after fee
540  nAfterFee = std::max<CAmount>(nAmount - nPayFee, 0);
541  }
542 
543  // actually update labels
544  int nDisplayUnit = RavenUnits::RVN;
545  if (model && model->getOptionsModel())
546  nDisplayUnit = model->getOptionsModel()->getDisplayUnit();
547 
548  QLabel *l1 = dialog->findChild<QLabel *>("labelCoinControlQuantity");
549  QLabel *l2 = dialog->findChild<QLabel *>("labelCoinControlAmount");
550  QLabel *l3 = dialog->findChild<QLabel *>("labelCoinControlFee");
551  QLabel *l4 = dialog->findChild<QLabel *>("labelCoinControlAfterFee");
552  QLabel *l5 = dialog->findChild<QLabel *>("labelCoinControlBytes");
553  QLabel *l7 = dialog->findChild<QLabel *>("labelCoinControlLowOutput");
554  QLabel *l8 = dialog->findChild<QLabel *>("labelCoinControlChange");
555 
556  // enable/disable "dust" and "change"
557  dialog->findChild<QLabel *>("labelCoinControlLowOutputText")->setEnabled(nPayAmount > 0);
558  dialog->findChild<QLabel *>("labelCoinControlLowOutput") ->setEnabled(nPayAmount > 0);
559  dialog->findChild<QLabel *>("labelCoinControlChangeText") ->setEnabled(nPayAmount > 0);
560  dialog->findChild<QLabel *>("labelCoinControlChange") ->setEnabled(nPayAmount > 0);
561 
562  // stats
563  l1->setText(QString::number(nQuantity)); // Quantity
564  l2->setText(RavenUnits::formatWithUnit(nDisplayUnit, nAmount)); // Amount
565  l3->setText(RavenUnits::formatWithUnit(nDisplayUnit, nPayFee)); // Fee
566  l4->setText(RavenUnits::formatWithUnit(nDisplayUnit, nAfterFee)); // After Fee
567  l5->setText(((nBytes > 0) ? ASYMP_UTF8 : "") + QString::number(nBytes)); // Bytes
568  l7->setText(fDust ? tr("yes") : tr("no")); // Dust
569  l8->setText(RavenUnits::formatWithUnit(nDisplayUnit, nChange)); // Change
570  if (nPayFee > 0)
571  {
572  l3->setText(ASYMP_UTF8 + l3->text());
573  l4->setText(ASYMP_UTF8 + l4->text());
574  if (nChange > 0 && !CoinControlDialog::fSubtractFeeFromAmount)
575  l8->setText(ASYMP_UTF8 + l8->text());
576  }
577 
578  // turn label red when dust
579  l7->setStyleSheet((fDust) ? "color:red;" : "");
580 
581  // tool tips
582  QString toolTipDust = tr("This label turns red if any recipient receives an amount smaller than the current dust threshold.");
583 
584  // how many satoshis the estimated fee can vary per byte we guess wrong
585  double dFeeVary = (nBytes != 0) ? (double)nPayFee / nBytes : 0;
586 
587  QString toolTip4 = tr("Can vary +/- %1 satoshi(s) per input.").arg(dFeeVary);
588 
589  l3->setToolTip(toolTip4);
590  l4->setToolTip(toolTip4);
591  l7->setToolTip(toolTipDust);
592  l8->setToolTip(toolTip4);
593  dialog->findChild<QLabel *>("labelCoinControlFeeText") ->setToolTip(l3->toolTip());
594  dialog->findChild<QLabel *>("labelCoinControlAfterFeeText") ->setToolTip(l4->toolTip());
595  dialog->findChild<QLabel *>("labelCoinControlBytesText") ->setToolTip(l5->toolTip());
596  dialog->findChild<QLabel *>("labelCoinControlLowOutputText")->setToolTip(l7->toolTip());
597  dialog->findChild<QLabel *>("labelCoinControlChangeText") ->setToolTip(l8->toolTip());
598 
599  // Insufficient funds
600  QLabel *label = dialog->findChild<QLabel *>("labelCoinControlInsuffFunds");
601  if (label)
602  label->setVisible(nChange < 0);
603 }
604 
606 {
608  return;
609 
610  bool treeMode = ui->radioTreeMode->isChecked();
611 
612  ui->treeWidget->clear();
613  ui->treeWidget->setEnabled(false); // performance, otherwise updateLabels would be called for every checked checkbox
614  ui->treeWidget->setAlternatingRowColors(!treeMode);
615  QFlags<Qt::ItemFlag> flgCheckbox = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
616  QFlags<Qt::ItemFlag> flgTristate = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsTristate;
617 
618  int nDisplayUnit = model->getOptionsModel()->getDisplayUnit();
619 
620  std::map<QString, std::vector<COutput> > mapCoins;
621  model->listCoins(mapCoins);
622 
623  for (const std::pair<QString, std::vector<COutput>>& coins : mapCoins) {
624  CCoinControlWidgetItem *itemWalletAddress = new CCoinControlWidgetItem();
625  itemWalletAddress->setCheckState(COLUMN_CHECKBOX, Qt::Unchecked);
626  QString sWalletAddress = coins.first;
627  QString sWalletLabel = model->getAddressTableModel()->labelForAddress(sWalletAddress);
628  if (sWalletLabel.isEmpty())
629  sWalletLabel = tr("(no label)");
630 
631  if (treeMode)
632  {
633  // wallet address
634  ui->treeWidget->addTopLevelItem(itemWalletAddress);
635 
636  itemWalletAddress->setFlags(flgTristate);
637  itemWalletAddress->setCheckState(COLUMN_CHECKBOX, Qt::Unchecked);
638 
639  // label
640  itemWalletAddress->setText(COLUMN_LABEL, sWalletLabel);
641 
642  // address
643  itemWalletAddress->setText(COLUMN_ADDRESS, sWalletAddress);
644  }
645 
646  CAmount nSum = 0;
647  int nChildren = 0;
648  for (const COutput& out : coins.second) {
649  nSum += out.tx->tx->vout[out.i].nValue;
650  nChildren++;
651 
652  CCoinControlWidgetItem *itemOutput;
653  if (treeMode) itemOutput = new CCoinControlWidgetItem(itemWalletAddress);
654  else itemOutput = new CCoinControlWidgetItem(ui->treeWidget);
655  itemOutput->setFlags(flgCheckbox);
656  itemOutput->setCheckState(COLUMN_CHECKBOX,Qt::Unchecked);
657 
658  // address
659  CTxDestination outputAddress;
660  QString sAddress = "";
661  if(ExtractDestination(out.tx->tx->vout[out.i].scriptPubKey, outputAddress))
662  {
663  sAddress = QString::fromStdString(EncodeDestination(outputAddress));
664 
665  // if listMode or change => show raven address. In tree mode, address is not shown again for direct wallet address outputs
666  if (!treeMode || (!(sAddress == sWalletAddress)))
667  itemOutput->setText(COLUMN_ADDRESS, sAddress);
668  }
669 
670  // label
671  if (!(sAddress == sWalletAddress)) // change
672  {
673  // tooltip from where the change comes from
674  itemOutput->setToolTip(COLUMN_LABEL, tr("change from %1 (%2)").arg(sWalletLabel).arg(sWalletAddress));
675  itemOutput->setText(COLUMN_LABEL, tr("(change)"));
676  }
677  else if (!treeMode)
678  {
679  QString sLabel = model->getAddressTableModel()->labelForAddress(sAddress);
680  if (sLabel.isEmpty())
681  sLabel = tr("(no label)");
682  itemOutput->setText(COLUMN_LABEL, sLabel);
683  }
684 
685  // amount
686  itemOutput->setText(COLUMN_AMOUNT, RavenUnits::format(nDisplayUnit, out.tx->tx->vout[out.i].nValue));
687  itemOutput->setData(COLUMN_AMOUNT, Qt::UserRole, QVariant((qlonglong)out.tx->tx->vout[out.i].nValue)); // padding so that sorting works correctly
688 
689  // date
690  itemOutput->setText(COLUMN_DATE, GUIUtil::dateTimeStr(out.tx->GetTxTime()));
691  itemOutput->setData(COLUMN_DATE, Qt::UserRole, QVariant((qlonglong)out.tx->GetTxTime()));
692 
693  // confirmations
694  itemOutput->setText(COLUMN_CONFIRMATIONS, QString::number(out.nDepth));
695  itemOutput->setData(COLUMN_CONFIRMATIONS, Qt::UserRole, QVariant((qlonglong)out.nDepth));
696 
697  // transaction hash
698  uint256 txhash = out.tx->GetHash();
699  itemOutput->setText(COLUMN_TXHASH, QString::fromStdString(txhash.GetHex()));
700 
701  // vout index
702  itemOutput->setText(COLUMN_VOUT_INDEX, QString::number(out.i));
703 
704  // disable locked coins
705  if (model->isLockedCoin(txhash, out.i))
706  {
707  COutPoint outpt(txhash, out.i);
708  coinControl->UnSelect(outpt); // just to be sure
709  itemOutput->setDisabled(true);
710  itemOutput->setIcon(COLUMN_CHECKBOX, platformStyle->SingleColorIcon(":/icons/lock_closed"));
711  }
712 
713  // set checkbox
714  if (coinControl->IsSelected(COutPoint(txhash, out.i)))
715  itemOutput->setCheckState(COLUMN_CHECKBOX, Qt::Checked);
716  }
717 
718  // amount
719  if (treeMode)
720  {
721  itemWalletAddress->setText(COLUMN_CHECKBOX, "(" + QString::number(nChildren) + ")");
722  itemWalletAddress->setText(COLUMN_AMOUNT, RavenUnits::format(nDisplayUnit, nSum));
723  itemWalletAddress->setData(COLUMN_AMOUNT, Qt::UserRole, QVariant((qlonglong)nSum));
724  }
725  }
726 
727  // expand all partially selected
728  if (treeMode)
729  {
730  for (int i = 0; i < ui->treeWidget->topLevelItemCount(); i++)
731  if (ui->treeWidget->topLevelItem(i)->checkState(COLUMN_CHECKBOX) == Qt::PartiallyChecked)
732  ui->treeWidget->topLevelItem(i)->setExpanded(true);
733  }
734 
735  // sort view
737  ui->treeWidget->setEnabled(true);
738 }
bool isLockedCoin(uint256 hash, unsigned int n) const
RVN END.
void listCoins(std::map< QString, std::vector< COutput > > &mapCoins) const
const PlatformStyle * platformStyle
void viewItemChanged(QTreeWidgetItem *, int)
CTxMemPool mempool
static QString format(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard, const int nAssetUnit=MIN_ASSET_UNITS - 1)
Format as string.
Definition: ravenunits.cpp:101
void getOutputs(const std::vector< COutPoint > &vOutpoints, std::vector< COutput > &vOutputs)
int i
Definition: wallet.h:532
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:89
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
Definition: standard.cpp:210
void lockCoin(COutPoint &output)
static CCoinControl * coinControl
const uint256 & GetHash() const
Definition: wallet.h:277
void ListSelected(std::vector< COutPoint > &vOutpoints) const
Definition: coincontrol.h:113
QString dateTimeStr(const QDateTime &date)
Definition: guiutil.cpp:158
CoinControlDialog(const PlatformStyle *platformStyle, QWidget *parent=0)
QIcon SingleColorIcon(const QString &filename) const
Colorize an icon (given filename) with the icon color.
AddressTableModel * getAddressTableModel()
void UnSelect(const COutPoint &output)
Definition: coincontrol.h:92
Coin Control Features.
Definition: coincontrol.h:17
int getDisplayUnit() const
Definition: optionsmodel.h:68
int64_t CAmount
Amount in corbies (Can be negative)
Definition: amount.h:13
CBlockPolicyEstimator feeEstimator
Definition: validation.cpp:109
static QList< CAmount > payAmounts
static QString formatWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string (with unit)
Definition: ravenunits.cpp:146
bool operator<(const QTreeWidgetItem &other) const
bool getPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
QAction * copyTransactionHashAction
int nDepth
Definition: wallet.h:533
Ui::CoinControlDialog * ui
CTransactionRef tx
Definition: wallet.h:211
void setClipboard(const QString &str)
Definition: guiutil.cpp:945
void Select(const COutPoint &output)
Definition: coincontrol.h:81
uint256 uint256S(const char *str)
Definition: uint256.h:150
An encapsulated public key.
Definition: pubkey.h:40
static QString removeSpaces(QString text)
Definition: ravenunits.h:121
QString labelForAddress(const QString &address) const
bool isSpent(const COutPoint &outpoint) const
static void updateLabels(WalletModel *, QDialog *)
friend class CCoinControlWidgetItem
An output of a transaction.
Definition: transaction.h:137
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:22
std::vector< CTxOut > vout
Definition: transaction.h:392
void UnSelectAll()
Definition: coincontrol.h:106
bool operator<(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:303
256-bit opaque blob.
Definition: uint256.h:123
void setModel(WalletModel *model)
static bool fSubtractFeeFromAmount
QTreeWidgetItem * contextMenuItem
#define ASYMP_UTF8
std::string EncodeDestination(const CTxDestination &dest)
Definition: base58.cpp:326
void listLockedCoins(std::vector< COutPoint > &vOutpts)
int64_t GetTxTime() const
Definition: wallet.cpp:1458
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:396
Interface to Raven wallet from Qt view code.
Definition: walletmodel.h:165
bool IsSelected(const COutPoint &output) const
Definition: coincontrol.h:71
void unlockCoin(COutPoint &output)
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:30
const CWalletTx * tx
Definition: wallet.h:531
std::string GetHex() const
Definition: uint256.cpp:22
void sortView(int, Qt::SortOrder)
Qt::SortOrder sortOrder
bool IsDust(const CTxOut &txout, const CFeeRate &dustRelayFeeIn)
Definition: policy.cpp:53
A mutable version of CTransaction.
Definition: transaction.h:389
void buttonBoxClicked(QAbstractButton *)
WalletModel * model
void showMenu(const QPoint &)
CAmount GetMinimumFee(unsigned int nTxBytes, const CCoinControl &coin_control, const CTxMemPool &pool, const CBlockPolicyEstimator &estimator, FeeCalculation *feeCalc)
Estimate the minimum fee considering user set parameters and the required fee.
Definition: fees.cpp:23
OptionsModel * getOptionsModel()
bool IsCompressed() const
Check whether this is a compressed public key.
Definition: pubkey.h:168
CFeeRate dustRelayFee
Definition: policy.cpp:263