6#include <qt/forms/ui_coincontroldialog.h>
22#include <QApplication>
25#include <QDialogButtonBox>
37 int column = treeWidget()->sortColumn();
39 return data(column, Qt::UserRole).toLongLong() < other.data(column, Qt::UserRole).toLongLong();
46 m_coin_control(coin_control),
48 platformStyle(_platformStyle)
64 QAction *clipboardQuantityAction =
new QAction(tr(
"Copy quantity"),
this);
65 QAction *clipboardAmountAction =
new QAction(tr(
"Copy amount"),
this);
66 QAction *clipboardFeeAction =
new QAction(tr(
"Copy fee"),
this);
67 QAction *clipboardAfterFeeAction =
new QAction(tr(
"Copy after fee"),
this);
68 QAction *clipboardBytesAction =
new QAction(tr(
"Copy bytes"),
this);
69 QAction *clipboardChangeAction =
new QAction(tr(
"Copy change"),
this);
78 ui->labelCoinControlQuantity->addAction(clipboardQuantityAction);
79 ui->labelCoinControlAmount->addAction(clipboardAmountAction);
80 ui->labelCoinControlFee->addAction(clipboardFeeAction);
81 ui->labelCoinControlAfterFee->addAction(clipboardAfterFeeAction);
82 ui->labelCoinControlBytes->addAction(clipboardBytesAction);
83 ui->labelCoinControlChange->addAction(clipboardChangeAction);
93 ui->treeWidget->header()->setSectionsClickable(
true);
114 if (settings.contains(
"nCoinControlMode") && !settings.value(
"nCoinControlMode").toBool())
115 ui->radioTreeMode->click();
116 if (settings.contains(
"nCoinControlSortColumn") && settings.contains(
"nCoinControlSortOrder"))
117 sortView(settings.value(
"nCoinControlSortColumn").toInt(), (
static_cast<Qt::SortOrder
>(settings.value(
"nCoinControlSortOrder").toInt())));
132 settings.setValue(
"nCoinControlMode",
ui->radioListMode->isChecked());
133 settings.setValue(
"nCoinControlSortColumn",
sortColumn);
134 settings.setValue(
"nCoinControlSortOrder", (
int)
sortOrder);
142 if (
ui->buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole)
143 done(QDialog::Accepted);
149 Qt::CheckState state = Qt::Checked;
150 for (
int i = 0; i <
ui->treeWidget->topLevelItemCount(); i++)
152 if (
ui->treeWidget->topLevelItem(i)->checkState(
COLUMN_CHECKBOX) != Qt::Unchecked)
154 state = Qt::Unchecked;
158 ui->treeWidget->setEnabled(
false);
159 for (
int i = 0; i <
ui->treeWidget->topLevelItemCount(); i++)
162 ui->treeWidget->setEnabled(
true);
163 if (state == Qt::Unchecked)
171 QTreeWidgetItem *item =
ui->treeWidget->itemAt(point);
227 const QString outpoint = QString(
"%1:%2").arg(address).arg(vout);
296 ui->treeWidget->sortItems(column, order);
310 sortOrder = ((
sortOrder == Qt::AscendingOrder) ? Qt::DescendingOrder : Qt::AscendingOrder);
324 if (checked &&
model)
331 if (checked &&
model)
345 else if (item->isDisabled())
351 if (
ui->treeWidget->isEnabled())
359 std::vector<COutPoint> vOutpts;
361 if (vOutpts.size() > 0)
363 ui->labelLocked->setText(tr(
"(%1 locked)").arg(vOutpts.size()));
364 ui->labelLocked->setVisible(
true);
366 else ui->labelLocked->setVisible(
false);
377 nPayAmount += amount;
384 unsigned int nBytes = 0;
385 unsigned int nBytesInputs = 0;
386 unsigned int nQuantity = 0;
387 bool fWitness =
false;
393 if (
out.depth_in_main_chain < 0)
continue;
397 const COutPoint& outpt = vCoinControl[i++];
408 nAmount +=
out.txout.nValue;
412 int witnessversion = 0;
413 std::vector<unsigned char> witnessprogram;
414 if (
out.txout.scriptPubKey.IsWitnessProgram(witnessversion, witnessprogram))
417 nBytesInputs += (32 + 4 + 1 + 4);
419 if (witnessversion == 0) {
422 }
else if (witnessversion == 1) {
427 throw std::runtime_error(
"Trying to spend future segwit version script");
434 PKHash* pkhash = std::get_if<PKHash>(&address);
442 else nBytesInputs += 148;
461 if (nAmount - nPayAmount == 0)
469 nChange = nAmount - nPayAmount;
475 CTxOut txout(nChange,
CScript() << std::vector<unsigned char>(24, 0));
491 nAfterFee = std::max<CAmount>(nAmount - nPayFee, 0);
499 QLabel *l1 = dialog->findChild<QLabel *>(
"labelCoinControlQuantity");
500 QLabel *l2 = dialog->findChild<QLabel *>(
"labelCoinControlAmount");
501 QLabel *l3 = dialog->findChild<QLabel *>(
"labelCoinControlFee");
502 QLabel *l4 = dialog->findChild<QLabel *>(
"labelCoinControlAfterFee");
503 QLabel *l5 = dialog->findChild<QLabel *>(
"labelCoinControlBytes");
504 QLabel *l8 = dialog->findChild<QLabel *>(
"labelCoinControlChange");
507 dialog->findChild<QLabel *>(
"labelCoinControlChangeText") ->setEnabled(nPayAmount > 0);
508 dialog->findChild<QLabel *>(
"labelCoinControlChange") ->setEnabled(nPayAmount > 0);
511 l1->setText(QString::number(nQuantity));
515 l5->setText(((nBytes > 0) ?
ASYMP_UTF8 :
"") + QString::number(nBytes));
526 double dFeeVary = (nBytes != 0) ? (
double)nPayFee / nBytes : 0;
528 QString toolTip4 = tr(
"Can vary +/- %1 satoshi(s) per input.").arg(dFeeVary);
530 l3->setToolTip(toolTip4);
531 l4->setToolTip(toolTip4);
532 l8->setToolTip(toolTip4);
533 dialog->findChild<QLabel *>(
"labelCoinControlFeeText") ->setToolTip(l3->toolTip());
534 dialog->findChild<QLabel *>(
"labelCoinControlAfterFeeText") ->setToolTip(l4->toolTip());
535 dialog->findChild<QLabel *>(
"labelCoinControlBytesText") ->setToolTip(l5->toolTip());
536 dialog->findChild<QLabel *>(
"labelCoinControlChangeText") ->setToolTip(l8->toolTip());
539 QLabel *label = dialog->findChild<QLabel *>(
"labelCoinControlInsuffFunds");
541 label->setVisible(nChange < 0);
546 if (e->type() == QEvent::PaletteChange) {
550 QDialog::changeEvent(e);
558 bool treeMode =
ui->radioTreeMode->isChecked();
560 ui->treeWidget->clear();
561 ui->treeWidget->setEnabled(
false);
562 ui->treeWidget->setAlternatingRowColors(!treeMode);
563 QFlags<Qt::ItemFlag> flgCheckbox = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
564 QFlags<Qt::ItemFlag> flgTristate = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsAutoTristate;
572 if (sWalletLabel.isEmpty())
573 sWalletLabel = tr(
"(no label)");
580 itemWalletAddress->setFlags(flgTristate);
592 for (
const auto& outpair : coins.second) {
593 const COutPoint& output = std::get<0>(outpair);
595 nSum +=
out.txout.nValue;
601 itemOutput->setFlags(flgCheckbox);
606 QString sAddress =
"";
612 if (!treeMode || (!(sAddress == sWalletAddress)))
617 if (!(sAddress == sWalletAddress))
620 itemOutput->setToolTip(
COLUMN_LABEL, tr(
"change from %1 (%2)").arg(sWalletLabel).arg(sWalletAddress));
626 if (sLabel.isEmpty())
627 sLabel = tr(
"(no label)");
633 itemOutput->setData(
COLUMN_AMOUNT, Qt::UserRole, QVariant((qlonglong)
out.txout.nValue));
637 itemOutput->setData(
COLUMN_DATE, Qt::UserRole, QVariant((qlonglong)
out.time));
653 itemOutput->setDisabled(
true);
665 itemWalletAddress->setText(
COLUMN_CHECKBOX,
"(" + QString::number(nChildren) +
")");
667 itemWalletAddress->setData(
COLUMN_AMOUNT, Qt::UserRole, QVariant((qlonglong)nSum));
674 for (
int i = 0; i <
ui->treeWidget->topLevelItemCount(); i++)
675 if (
ui->treeWidget->topLevelItem(i)->checkState(
COLUMN_CHECKBOX) == Qt::PartiallyChecked)
676 ui->treeWidget->topLevelItem(i)->setExpanded(
true);
681 ui->treeWidget->setEnabled(
true);
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a scriptPubKey for the destination.
CKeyID ToKeyID(const PKHash &key_hash)
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
int64_t CAmount
Amount in satoshis (Can be negative)
QString labelForAddress(const QString &address) const
Look up label for address in address book, if not found return empty string.
static QString format(Unit unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD, bool justify=false)
Format as string.
static QString removeSpaces(QString text)
static QString formatWithUnit(Unit unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as string (with unit)
An outpoint - a combination of a transaction hash and an index n into its vout.
An encapsulated public key.
bool IsCompressed() const
Check whether this is a compressed public key.
Serialized script, used inside transaction inputs and outputs.
An output of a transaction.
void headerSectionClicked(int)
QTreeWidgetItem * contextMenuItem
friend class CCoinControlWidgetItem
CoinControlDialog(wallet::CCoinControl &coin_control, WalletModel *model, const PlatformStyle *platformStyle, QWidget *parent=nullptr)
void copyTransactionOutpoint()
const PlatformStyle * platformStyle
void changeEvent(QEvent *e) override
Ui::CoinControlDialog * ui
void sortView(int, Qt::SortOrder)
void showMenu(const QPoint &)
void viewItemChanged(QTreeWidgetItem *, int)
wallet::CCoinControl & m_coin_control
void buttonSelectAllClicked()
QAction * m_copy_transaction_outpoint_action
static QList< CAmount > payAmounts
static void updateLabels(wallet::CCoinControl &m_coin_control, WalletModel *, QDialog *)
static bool fSubtractFeeFromAmount
void buttonBoxClicked(QAbstractButton *)
BitcoinUnit getDisplayUnit() const
Interface to Bitcoin wallet from Qt view code.
interfaces::Node & node() const
AddressTableModel * getAddressTableModel() const
interfaces::Wallet & wallet() const
OptionsModel * getOptionsModel() const
virtual CFeeRate getDustRelayFee()=0
Get dust relay fee.
virtual bool unlockCoin(const COutPoint &output)=0
Unlock coin.
virtual CoinsList listCoins()=0
virtual bool getPubKey(const CScript &script, const CKeyID &address, CPubKey &pub_key)=0
Get public key.
virtual std::vector< WalletTxOut > getCoins(const std::vector< COutPoint > &outputs)=0
Return wallet transaction output information.
virtual bool isLockedCoin(const COutPoint &output)=0
Return whether coin is locked.
virtual void listLockedCoins(std::vector< COutPoint > &outputs)=0
List locked coins.
virtual bool lockCoin(const COutPoint &output, const bool write_to_db)=0
Lock coin.
virtual CAmount getMinimumFee(unsigned int tx_bytes, const wallet::CCoinControl &coin_control, int *returned_target, FeeReason *reason)=0
Get minimum fee.
std::string GetHex() const
static std::optional< transaction_identifier > FromHex(std::string_view hex)
bool IsSelected(const COutPoint &outpoint) const
Returns true if the given output is pre-selected.
void UnSelectAll()
Unselects all outputs.
void UnSelect(const COutPoint &outpoint)
Unselects the given output.
PreselectedInput & Select(const COutPoint &outpoint)
Lock-in the given output for spending.
std::vector< COutPoint > ListSelected() const
List the selected inputs.
static const int WITNESS_SCALE_FACTOR
std::string EncodeDestination(const CTxDestination &dest)
Utility functions used by the Bitcoin Qt UI.
void handleCloseWindowShortcut(QWidget *w)
QString dateTimeStr(const QDateTime &date)
constexpr auto dialog_flags
void setClipboard(const QString &str)
bool operator<(const CNetAddr &a, const CNetAddr &b)
bool IsDust(const CTxOut &txout, const CFeeRate &dustRelayFeeIn)
Wallet transaction output.