5 #if defined(HAVE_CONFIG_H)
10 #include <qt/forms/ui_coincontroldialog.h>
25 #include <QApplication>
28 #include <QDialogButtonBox>
32 #include <QTreeWidget>
38 int column = treeWidget()->sortColumn();
40 return data(column, Qt::UserRole).toLongLong() < other.data(column, Qt::UserRole).toLongLong();
47 m_coin_control(coin_control),
49 platformStyle(_platformStyle)
54 QAction *copyAddressAction =
new QAction(tr(
"Copy address"),
this);
55 QAction *copyLabelAction =
new QAction(tr(
"Copy label"),
this);
56 QAction *copyAmountAction =
new QAction(tr(
"Copy amount"),
this);
58 lockAction =
new QAction(tr(
"Lock unspent"),
this);
81 QAction *clipboardQuantityAction =
new QAction(tr(
"Copy quantity"),
this);
82 QAction *clipboardAmountAction =
new QAction(tr(
"Copy amount"),
this);
83 QAction *clipboardFeeAction =
new QAction(tr(
"Copy fee"),
this);
84 QAction *clipboardAfterFeeAction =
new QAction(tr(
"Copy after fee"),
this);
85 QAction *clipboardBytesAction =
new QAction(tr(
"Copy bytes"),
this);
86 QAction *clipboardLowOutputAction =
new QAction(tr(
"Copy dust"),
this);
87 QAction *clipboardChangeAction =
new QAction(tr(
"Copy change"),
this);
97 ui->labelCoinControlQuantity->addAction(clipboardQuantityAction);
98 ui->labelCoinControlAmount->addAction(clipboardAmountAction);
99 ui->labelCoinControlFee->addAction(clipboardFeeAction);
100 ui->labelCoinControlAfterFee->addAction(clipboardAfterFeeAction);
101 ui->labelCoinControlBytes->addAction(clipboardBytesAction);
102 ui->labelCoinControlLowOutput->addAction(clipboardLowOutputAction);
103 ui->labelCoinControlChange->addAction(clipboardChangeAction);
113 ui->treeWidget->header()->setSectionsClickable(
true);
134 if (settings.contains(
"nCoinControlMode") && !settings.value(
"nCoinControlMode").toBool())
135 ui->radioTreeMode->click();
136 if (settings.contains(
"nCoinControlSortColumn") && settings.contains(
"nCoinControlSortOrder"))
137 sortView(settings.value(
"nCoinControlSortColumn").toInt(), (
static_cast<Qt::SortOrder
>(settings.value(
"nCoinControlSortOrder").toInt())));
152 settings.setValue(
"nCoinControlMode",
ui->radioListMode->isChecked());
153 settings.setValue(
"nCoinControlSortColumn",
sortColumn);
154 settings.setValue(
"nCoinControlSortOrder", (
int)
sortOrder);
162 if (
ui->buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole)
163 done(QDialog::Accepted);
169 Qt::CheckState state = Qt::Checked;
170 for (
int i = 0; i <
ui->treeWidget->topLevelItemCount(); i++)
172 if (
ui->treeWidget->topLevelItem(i)->checkState(
COLUMN_CHECKBOX) != Qt::Unchecked)
174 state = Qt::Unchecked;
178 ui->treeWidget->setEnabled(
false);
179 for (
int i = 0; i <
ui->treeWidget->topLevelItemCount(); i++)
182 ui->treeWidget->setEnabled(
true);
183 if (state == Qt::Unchecked)
191 QTreeWidgetItem *item =
ui->treeWidget->itemAt(point);
323 ui->treeWidget->sortItems(column, order);
337 sortOrder = ((
sortOrder == Qt::AscendingOrder) ? Qt::DescendingOrder : Qt::AscendingOrder);
351 if (checked &&
model)
358 if (checked &&
model)
371 else if (item->isDisabled())
377 if (
ui->treeWidget->isEnabled())
385 std::vector<COutPoint> vOutpts;
387 if (vOutpts.size() > 0)
389 ui->labelLocked->setText(tr(
"(%1 locked)").arg(vOutpts.size()));
390 ui->labelLocked->setVisible(
true);
392 else ui->labelLocked->setVisible(
false);
405 nPayAmount += amount;
410 CTxOut txout(amount,
CScript() << std::vector<unsigned char>(24, 0));
419 unsigned int nBytes = 0;
420 unsigned int nBytesInputs = 0;
421 unsigned int nQuantity = 0;
422 bool fWitness =
false;
424 std::vector<COutPoint> vCoinControl;
429 if (out.depth_in_main_chain < 0)
continue;
433 const COutPoint& outpt = vCoinControl[i++];
444 nAmount += out.txout.nValue;
448 int witnessversion = 0;
449 std::vector<unsigned char> witnessprogram;
450 if (out.txout.scriptPubKey.IsWitnessProgram(witnessversion, witnessprogram))
458 PKHash *pkhash = boost::get<PKHash>(&address);
461 nBytesInputs += (pubkey.IsCompressed() ? 148 : 180);
466 else nBytesInputs += 148;
473 nBytes = nBytesInputs + ((CoinControlDialog::payAmounts.size() > 0 ? CoinControlDialog::payAmounts.size() + 1 : 2) * 34) + 10;
485 if (nAmount - nPayAmount == 0)
493 nChange = nAmount - nPayAmount;
501 CTxOut txout(nChange,
CScript() << std::vector<unsigned char>(24, 0));
516 nAfterFee = std::max<CAmount>(nAmount - nPayFee, 0);
524 QLabel *l1 = dialog->findChild<QLabel *>(
"labelCoinControlQuantity");
525 QLabel *l2 = dialog->findChild<QLabel *>(
"labelCoinControlAmount");
526 QLabel *l3 = dialog->findChild<QLabel *>(
"labelCoinControlFee");
527 QLabel *l4 = dialog->findChild<QLabel *>(
"labelCoinControlAfterFee");
528 QLabel *l5 = dialog->findChild<QLabel *>(
"labelCoinControlBytes");
529 QLabel *l7 = dialog->findChild<QLabel *>(
"labelCoinControlLowOutput");
530 QLabel *l8 = dialog->findChild<QLabel *>(
"labelCoinControlChange");
533 dialog->findChild<QLabel *>(
"labelCoinControlLowOutputText")->setEnabled(nPayAmount > 0);
534 dialog->findChild<QLabel *>(
"labelCoinControlLowOutput") ->setEnabled(nPayAmount > 0);
535 dialog->findChild<QLabel *>(
"labelCoinControlChangeText") ->setEnabled(nPayAmount > 0);
536 dialog->findChild<QLabel *>(
"labelCoinControlChange") ->setEnabled(nPayAmount > 0);
539 l1->setText(QString::number(nQuantity));
543 l5->setText(((nBytes > 0) ?
ASYMP_UTF8 :
"") + QString::number(nBytes));
544 l7->setText(fDust ? tr(
"yes") : tr(
"no"));
555 l7->setStyleSheet((fDust) ?
"color:red;" :
"");
558 QString toolTipDust = tr(
"This label turns red if any recipient receives an amount smaller than the current dust threshold.");
561 double dFeeVary = (nBytes != 0) ? (
double)nPayFee / nBytes : 0;
563 QString toolTip4 = tr(
"Can vary +/- %1 satoshi(s) per input.").arg(dFeeVary);
565 l3->setToolTip(toolTip4);
566 l4->setToolTip(toolTip4);
567 l7->setToolTip(toolTipDust);
568 l8->setToolTip(toolTip4);
569 dialog->findChild<QLabel *>(
"labelCoinControlFeeText") ->setToolTip(l3->toolTip());
570 dialog->findChild<QLabel *>(
"labelCoinControlAfterFeeText") ->setToolTip(l4->toolTip());
571 dialog->findChild<QLabel *>(
"labelCoinControlBytesText") ->setToolTip(l5->toolTip());
572 dialog->findChild<QLabel *>(
"labelCoinControlLowOutputText")->setToolTip(l7->toolTip());
573 dialog->findChild<QLabel *>(
"labelCoinControlChangeText") ->setToolTip(l8->toolTip());
576 QLabel *label = dialog->findChild<QLabel *>(
"labelCoinControlInsuffFunds");
578 label->setVisible(nChange < 0);
586 bool treeMode =
ui->radioTreeMode->isChecked();
588 ui->treeWidget->clear();
589 ui->treeWidget->setEnabled(
false);
590 ui->treeWidget->setAlternatingRowColors(!treeMode);
591 QFlags<Qt::ItemFlag> flgCheckbox = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
592 QFlags<Qt::ItemFlag> flgTristate = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsTristate;
600 if (sWalletLabel.isEmpty())
601 sWalletLabel = tr(
"(no label)");
608 itemWalletAddress->setFlags(flgTristate);
620 for (
const auto& outpair : coins.second) {
621 const COutPoint& output = std::get<0>(outpair);
629 itemOutput->setFlags(flgCheckbox);
634 QString sAddress =
"";
640 if (!treeMode || (!(sAddress == sWalletAddress)))
645 if (!(sAddress == sWalletAddress))
648 itemOutput->setToolTip(
COLUMN_LABEL, tr(
"change from %1 (%2)").arg(sWalletLabel).arg(sWalletAddress));
654 if (sLabel.isEmpty())
655 sLabel = tr(
"(no label)");
661 itemOutput->setData(
COLUMN_AMOUNT, Qt::UserRole, QVariant((qlonglong)out.txout.nValue));
665 itemOutput->setData(
COLUMN_DATE, Qt::UserRole, QVariant((qlonglong)out.time));
669 itemOutput->setData(
COLUMN_CONFIRMATIONS, Qt::UserRole, QVariant((qlonglong)out.depth_in_main_chain));
681 itemOutput->setDisabled(
true);
693 itemWalletAddress->setText(
COLUMN_CHECKBOX,
"(" + QString::number(nChildren) +
")");
695 itemWalletAddress->setData(
COLUMN_AMOUNT, Qt::UserRole, QVariant((qlonglong)nSum));
702 for (
int i = 0; i <
ui->treeWidget->topLevelItemCount(); i++)
703 if (
ui->treeWidget->topLevelItem(i)->checkState(
COLUMN_CHECKBOX) == Qt::PartiallyChecked)
704 ui->treeWidget->topLevelItem(i)->setExpanded(
true);
709 ui->treeWidget->setEnabled(
true);
const PlatformStyle * platformStyle
void viewItemChanged(QTreeWidgetItem *, int)
virtual CoinsList listCoins()=0
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
void buttonSelectAllClicked()
static const int WITNESS_SCALE_FACTOR
void clipboardLowOutput()
void headerSectionClicked(int)
void copyTransactionHash()
CCoinControl & m_coin_control
std::string GetHex() const
virtual bool getPubKey(const CScript &script, const CKeyID &address, CPubKey &pub_key)=0
Get public key.
static QString format(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD, bool justify=false)
Format as string.
QString dateTimeStr(const QDateTime &date)
interfaces::Wallet & wallet() const
static constexpr CAmount MIN_CHANGE
target minimum change amount
virtual void lockCoin(const COutPoint &output)=0
Lock coin.
void ListSelected(std::vector< COutPoint > &vOutpoints) const
AddressTableModel * getAddressTableModel()
void UnSelect(const COutPoint &output)
static void updateLabels(CCoinControl &m_coin_control, WalletModel *, QDialog *)
virtual CFeeRate getDustRelayFee()=0
Get dust relay fee.
int64_t CAmount
Amount in satoshis (Can be negative)
static QList< CAmount > payAmounts
QAction * copyTransactionHashAction
virtual void unlockCoin(const COutPoint &output)=0
Unlock coin.
Ui::CoinControlDialog * ui
void setClipboard(const QString &str)
void handleCloseWindowShortcut(QWidget *w)
void Select(const COutPoint &output)
uint256 uint256S(const char *str)
An encapsulated public key.
virtual CAmount getMinimumFee(unsigned int tx_bytes, const CCoinControl &coin_control, int *returned_target, FeeReason *reason)=0
Get minimum fee.
static QString formatWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as string (with unit)
CoinControlDialog(CCoinControl &coin_control, WalletModel *model, const PlatformStyle *platformStyle, QWidget *parent=nullptr)
friend class CCoinControlWidgetItem
An output of a transaction.
An outpoint - a combination of a transaction hash and an index n into its vout.
int getDisplayUnit() const
virtual std::vector< WalletTxOut > getCoins(const std::vector< COutPoint > &outputs)=0
Return wallet transaction output information.
bool operator<(const CNetAddr &a, const CNetAddr &b)
static bool fSubtractFeeFromAmount
QTreeWidgetItem * contextMenuItem
QString labelForAddress(const QString &address) const
Look up label for address in address book, if not found return empty string.
virtual void listLockedCoins(std::vector< COutPoint > &outputs)=0
List locked coins.
interfaces::Node & node() const
Serialized script, used inside transaction inputs and outputs.
Interface to Bitcoin wallet from Qt view code.
static QString removeSpaces(QString text)
void sortView(int, Qt::SortOrder)
virtual bool isLockedCoin(const COutPoint &output)=0
Return whether coin is locked.
std::string EncodeDestination(const CTxDestination &dest)
bool IsDust(const CTxOut &txout, const CFeeRate &dustRelayFeeIn)
void buttonBoxClicked(QAbstractButton *)
void showMenu(const QPoint &)
const unsigned char * data() const
boost::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
bool IsSelected(const COutPoint &output) const
Wallet transaction output.
OptionsModel * getOptionsModel()
CKeyID ToKeyID(const PKHash &key_hash)