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)
65 QAction *clipboardQuantityAction =
new QAction(tr(
"Copy quantity"),
this);
66 QAction *clipboardAmountAction =
new QAction(tr(
"Copy amount"),
this);
67 QAction *clipboardFeeAction =
new QAction(tr(
"Copy fee"),
this);
68 QAction *clipboardAfterFeeAction =
new QAction(tr(
"Copy after fee"),
this);
69 QAction *clipboardBytesAction =
new QAction(tr(
"Copy bytes"),
this);
70 QAction *clipboardLowOutputAction =
new QAction(tr(
"Copy dust"),
this);
71 QAction *clipboardChangeAction =
new QAction(tr(
"Copy change"),
this);
81 ui->labelCoinControlQuantity->addAction(clipboardQuantityAction);
82 ui->labelCoinControlAmount->addAction(clipboardAmountAction);
83 ui->labelCoinControlFee->addAction(clipboardFeeAction);
84 ui->labelCoinControlAfterFee->addAction(clipboardAfterFeeAction);
85 ui->labelCoinControlBytes->addAction(clipboardBytesAction);
86 ui->labelCoinControlLowOutput->addAction(clipboardLowOutputAction);
87 ui->labelCoinControlChange->addAction(clipboardChangeAction);
97 ui->treeWidget->header()->setSectionsClickable(
true);
118 if (settings.contains(
"nCoinControlMode") && !settings.value(
"nCoinControlMode").toBool())
119 ui->radioTreeMode->click();
120 if (settings.contains(
"nCoinControlSortColumn") && settings.contains(
"nCoinControlSortOrder"))
121 sortView(settings.value(
"nCoinControlSortColumn").toInt(), (
static_cast<Qt::SortOrder
>(settings.value(
"nCoinControlSortOrder").toInt())));
136 settings.setValue(
"nCoinControlMode",
ui->radioListMode->isChecked());
137 settings.setValue(
"nCoinControlSortColumn",
sortColumn);
138 settings.setValue(
"nCoinControlSortOrder", (
int)
sortOrder);
146 if (
ui->buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole)
147 done(QDialog::Accepted);
153 Qt::CheckState state = Qt::Checked;
154 for (
int i = 0; i <
ui->treeWidget->topLevelItemCount(); i++)
156 if (
ui->treeWidget->topLevelItem(i)->checkState(
COLUMN_CHECKBOX) != Qt::Unchecked)
158 state = Qt::Unchecked;
162 ui->treeWidget->setEnabled(
false);
163 for (
int i = 0; i <
ui->treeWidget->topLevelItemCount(); i++)
166 ui->treeWidget->setEnabled(
true);
167 if (state == Qt::Unchecked)
175 QTreeWidgetItem *item =
ui->treeWidget->itemAt(point);
307 ui->treeWidget->sortItems(column, order);
321 sortOrder = ((
sortOrder == Qt::AscendingOrder) ? Qt::DescendingOrder : Qt::AscendingOrder);
335 if (checked &&
model)
342 if (checked &&
model)
355 else if (item->isDisabled())
361 if (
ui->treeWidget->isEnabled())
369 std::vector<COutPoint> vOutpts;
371 if (vOutpts.size() > 0)
373 ui->labelLocked->setText(tr(
"(%1 locked)").arg(vOutpts.size()));
374 ui->labelLocked->setVisible(
true);
376 else ui->labelLocked->setVisible(
false);
389 nPayAmount += amount;
394 CTxOut txout(amount,
CScript() << std::vector<unsigned char>(24, 0));
403 unsigned int nBytes = 0;
404 unsigned int nBytesInputs = 0;
405 unsigned int nQuantity = 0;
406 bool fWitness =
false;
408 std::vector<COutPoint> vCoinControl;
413 if (out.depth_in_main_chain < 0)
continue;
417 const COutPoint& outpt = vCoinControl[i++];
428 nAmount += out.txout.nValue;
432 int witnessversion = 0;
433 std::vector<unsigned char> witnessprogram;
434 if (out.txout.scriptPubKey.IsWitnessProgram(witnessversion, witnessprogram))
442 PKHash* pkhash = std::get_if<PKHash>(&address);
450 else nBytesInputs += 148;
469 if (nAmount - nPayAmount == 0)
477 nChange = nAmount - nPayAmount;
485 CTxOut txout(nChange,
CScript() << std::vector<unsigned char>(24, 0));
500 nAfterFee = std::max<CAmount>(nAmount - nPayFee, 0);
508 QLabel *l1 = dialog->findChild<QLabel *>(
"labelCoinControlQuantity");
509 QLabel *l2 = dialog->findChild<QLabel *>(
"labelCoinControlAmount");
510 QLabel *l3 = dialog->findChild<QLabel *>(
"labelCoinControlFee");
511 QLabel *l4 = dialog->findChild<QLabel *>(
"labelCoinControlAfterFee");
512 QLabel *l5 = dialog->findChild<QLabel *>(
"labelCoinControlBytes");
513 QLabel *l7 = dialog->findChild<QLabel *>(
"labelCoinControlLowOutput");
514 QLabel *l8 = dialog->findChild<QLabel *>(
"labelCoinControlChange");
517 dialog->findChild<QLabel *>(
"labelCoinControlLowOutputText")->setEnabled(nPayAmount > 0);
518 dialog->findChild<QLabel *>(
"labelCoinControlLowOutput") ->setEnabled(nPayAmount > 0);
519 dialog->findChild<QLabel *>(
"labelCoinControlChangeText") ->setEnabled(nPayAmount > 0);
520 dialog->findChild<QLabel *>(
"labelCoinControlChange") ->setEnabled(nPayAmount > 0);
523 l1->setText(QString::number(nQuantity));
527 l5->setText(((nBytes > 0) ?
ASYMP_UTF8 :
"") + QString::number(nBytes));
528 l7->setText(fDust ? tr(
"yes") : tr(
"no"));
539 l7->setStyleSheet((fDust) ?
"color:red;" :
"");
542 QString toolTipDust = tr(
"This label turns red if any recipient receives an amount smaller than the current dust threshold.");
545 double dFeeVary = (nBytes != 0) ? (
double)nPayFee / nBytes : 0;
547 QString toolTip4 = tr(
"Can vary +/- %1 satoshi(s) per input.").arg(dFeeVary);
549 l3->setToolTip(toolTip4);
550 l4->setToolTip(toolTip4);
551 l7->setToolTip(toolTipDust);
552 l8->setToolTip(toolTip4);
553 dialog->findChild<QLabel *>(
"labelCoinControlFeeText") ->setToolTip(l3->toolTip());
554 dialog->findChild<QLabel *>(
"labelCoinControlAfterFeeText") ->setToolTip(l4->toolTip());
555 dialog->findChild<QLabel *>(
"labelCoinControlBytesText") ->setToolTip(l5->toolTip());
556 dialog->findChild<QLabel *>(
"labelCoinControlLowOutputText")->setToolTip(l7->toolTip());
557 dialog->findChild<QLabel *>(
"labelCoinControlChangeText") ->setToolTip(l8->toolTip());
560 QLabel *label = dialog->findChild<QLabel *>(
"labelCoinControlInsuffFunds");
562 label->setVisible(nChange < 0);
567 if (e->type() == QEvent::PaletteChange) {
571 QDialog::changeEvent(e);
579 bool treeMode =
ui->radioTreeMode->isChecked();
581 ui->treeWidget->clear();
582 ui->treeWidget->setEnabled(
false);
583 ui->treeWidget->setAlternatingRowColors(!treeMode);
584 QFlags<Qt::ItemFlag> flgCheckbox = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
585 QFlags<Qt::ItemFlag> flgTristate = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsTristate;
593 if (sWalletLabel.isEmpty())
594 sWalletLabel = tr(
"(no label)");
601 itemWalletAddress->setFlags(flgTristate);
613 for (
const auto& outpair : coins.second) {
614 const COutPoint& output = std::get<0>(outpair);
622 itemOutput->setFlags(flgCheckbox);
627 QString sAddress =
"";
633 if (!treeMode || (!(sAddress == sWalletAddress)))
638 if (!(sAddress == sWalletAddress))
641 itemOutput->setToolTip(
COLUMN_LABEL, tr(
"change from %1 (%2)").arg(sWalletLabel).arg(sWalletAddress));
647 if (sLabel.isEmpty())
648 sLabel = tr(
"(no label)");
654 itemOutput->setData(
COLUMN_AMOUNT, Qt::UserRole, QVariant((qlonglong)out.txout.nValue));
658 itemOutput->setData(
COLUMN_DATE, Qt::UserRole, QVariant((qlonglong)out.time));
662 itemOutput->setData(
COLUMN_CONFIRMATIONS, Qt::UserRole, QVariant((qlonglong)out.depth_in_main_chain));
674 itemOutput->setDisabled(
true);
686 itemWalletAddress->setText(
COLUMN_CHECKBOX,
"(" + QString::number(nChildren) +
")");
688 itemWalletAddress->setData(
COLUMN_AMOUNT, Qt::UserRole, QVariant((qlonglong)nSum));
695 for (
int i = 0; i <
ui->treeWidget->topLevelItemCount(); i++)
696 if (
ui->treeWidget->topLevelItem(i)->checkState(
COLUMN_CHECKBOX) == Qt::PartiallyChecked)
697 ui->treeWidget->topLevelItem(i)->setExpanded(
true);
702 ui->treeWidget->setEnabled(
true);
const PlatformStyle * platformStyle
void viewItemChanged(QTreeWidgetItem *, int)
virtual CoinsList listCoins()=0
interfaces::Wallet & wallet() const
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
Utility functions used by the Bitcoin Qt UI.
void buttonSelectAllClicked()
static const int WITNESS_SCALE_FACTOR
void clipboardLowOutput()
void headerSectionClicked(int)
void copyTransactionHash()
CCoinControl & m_coin_control
virtual bool getPubKey(const CScript &script, const CKeyID &address, CPubKey &pub_key)=0
Get public key.
void ListSelected(std::vector< COutPoint > &vOutpoints) const
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)
static constexpr CAmount MIN_CHANGE
target minimum change amount
virtual void lockCoin(const COutPoint &output)=0
Lock coin.
const unsigned char * data() 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.
int getDisplayUnit() const
constexpr auto dialog_flags
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.
QString labelForAddress(const QString &address) const
Look up label for address in address book, if not found return empty string.
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)
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
friend class CCoinControlWidgetItem
An output of a transaction.
void changeEvent(QEvent *e) override
An outpoint - a combination of a transaction hash and an index n into its vout.
interfaces::Node & node() 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
virtual void listLockedCoins(std::vector< COutPoint > &outputs)=0
List locked coins.
Serialized script, used inside transaction inputs and outputs.
Interface to Bitcoin wallet from Qt view code.
bool IsSelected(const COutPoint &output) const
static QString removeSpaces(QString text)
std::string GetHex() const
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 &)
Wallet transaction output.
OptionsModel * getOptionsModel()
CKeyID ToKeyID(const PKHash &key_hash)
bool IsCompressed() const
Check whether this is a compressed public key.