5#if defined(HAVE_CONFIG_H)
25#include <QApplication>
28#include <QDialogButtonBox>
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);
118 if (settings.contains(
"nCoinControlMode") && !settings.value(
"nCoinControlMode").toBool())
120 if (settings.contains(
"nCoinControlSortColumn") && settings.contains(
"nCoinControlSortOrder"))
121 sortView(settings.value(
"nCoinControlSortColumn").toInt(), (
static_cast<Qt::SortOrder
>(settings.value(
"nCoinControlSortOrder").toInt())));
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++)
158 state = Qt::Unchecked;
163 for (
int i = 0; i <
ui->
treeWidget->topLevelItemCount(); i++)
167 if (state == Qt::Unchecked)
236 const QString outpoint = QString(
"%1:%2").arg(address).arg(vout);
325 sortOrder = ((
sortOrder == Qt::AscendingOrder) ? Qt::DescendingOrder : Qt::AscendingOrder);
339 if (checked &&
model)
346 if (checked &&
model)
359 else if (item->isDisabled())
373 std::vector<COutPoint> vOutpts;
375 if (vOutpts.size() > 0)
377 ui->
labelLocked->setText(tr(
"(%1 locked)").arg(vOutpts.size()));
393 nPayAmount += amount;
398 CTxOut txout(amount,
CScript() << std::vector<unsigned char>(24, 0));
407 unsigned int nBytes = 0;
408 unsigned int nBytesInputs = 0;
409 unsigned int nQuantity = 0;
410 bool fWitness =
false;
412 std::vector<COutPoint> vCoinControl;
417 if (out.depth_in_main_chain < 0)
continue;
421 const COutPoint& outpt = vCoinControl[i++];
432 nAmount += out.txout.nValue;
436 int witnessversion = 0;
437 std::vector<unsigned char> witnessprogram;
438 if (out.txout.scriptPubKey.IsWitnessProgram(witnessversion, witnessprogram))
446 PKHash* pkhash = std::get_if<PKHash>(&address);
454 else nBytesInputs += 148;
473 if (nAmount - nPayAmount == 0)
481 nChange = nAmount - nPayAmount;
489 CTxOut txout(nChange,
CScript() << std::vector<unsigned char>(24, 0));
504 nAfterFee = std::max<CAmount>(nAmount - nPayFee, 0);
512 QLabel *l1 = dialog->findChild<QLabel *>(
"labelCoinControlQuantity");
513 QLabel *l2 = dialog->findChild<QLabel *>(
"labelCoinControlAmount");
514 QLabel *l3 = dialog->findChild<QLabel *>(
"labelCoinControlFee");
515 QLabel *l4 = dialog->findChild<QLabel *>(
"labelCoinControlAfterFee");
516 QLabel *l5 = dialog->findChild<QLabel *>(
"labelCoinControlBytes");
517 QLabel *l7 = dialog->findChild<QLabel *>(
"labelCoinControlLowOutput");
518 QLabel *l8 = dialog->findChild<QLabel *>(
"labelCoinControlChange");
521 dialog->findChild<QLabel *>(
"labelCoinControlLowOutputText")->setEnabled(nPayAmount > 0);
522 dialog->findChild<QLabel *>(
"labelCoinControlLowOutput") ->setEnabled(nPayAmount > 0);
523 dialog->findChild<QLabel *>(
"labelCoinControlChangeText") ->setEnabled(nPayAmount > 0);
524 dialog->findChild<QLabel *>(
"labelCoinControlChange") ->setEnabled(nPayAmount > 0);
527 l1->setText(QString::number(nQuantity));
531 l5->setText(((nBytes > 0) ?
ASYMP_UTF8 :
"") + QString::number(nBytes));
532 l7->setText(fDust ? tr(
"yes") : tr(
"no"));
543 l7->setStyleSheet((fDust) ?
"color:red;" :
"");
546 QString toolTipDust = tr(
"This label turns red if any recipient receives an amount smaller than the current dust threshold.");
549 double dFeeVary = (nBytes != 0) ? (
double)nPayFee / nBytes : 0;
551 QString toolTip4 = tr(
"Can vary +/- %1 satoshi(s) per input.").arg(dFeeVary);
553 l3->setToolTip(toolTip4);
554 l4->setToolTip(toolTip4);
555 l7->setToolTip(toolTipDust);
556 l8->setToolTip(toolTip4);
557 dialog->findChild<QLabel *>(
"labelCoinControlFeeText") ->setToolTip(l3->toolTip());
558 dialog->findChild<QLabel *>(
"labelCoinControlAfterFeeText") ->setToolTip(l4->toolTip());
559 dialog->findChild<QLabel *>(
"labelCoinControlBytesText") ->setToolTip(l5->toolTip());
560 dialog->findChild<QLabel *>(
"labelCoinControlLowOutputText")->setToolTip(l7->toolTip());
561 dialog->findChild<QLabel *>(
"labelCoinControlChangeText") ->setToolTip(l8->toolTip());
564 QLabel *label = dialog->findChild<QLabel *>(
"labelCoinControlInsuffFunds");
566 label->setVisible(nChange < 0);
571 if (e->type() == QEvent::PaletteChange) {
575 QDialog::changeEvent(e);
588 QFlags<Qt::ItemFlag> flgCheckbox = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
589 QFlags<Qt::ItemFlag> flgTristate = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsTristate;
597 if (sWalletLabel.isEmpty())
598 sWalletLabel = tr(
"(no label)");
605 itemWalletAddress->setFlags(flgTristate);
617 for (
const auto& outpair : coins.second) {
618 const COutPoint& output = std::get<0>(outpair);
626 itemOutput->setFlags(flgCheckbox);
631 QString sAddress =
"";
637 if (!treeMode || (!(sAddress == sWalletAddress)))
642 if (!(sAddress == sWalletAddress))
645 itemOutput->setToolTip(
COLUMN_LABEL, tr(
"change from %1 (%2)").arg(sWalletLabel).arg(sWalletAddress));
651 if (sLabel.isEmpty())
652 sLabel = tr(
"(no label)");
662 itemOutput->setData(
COLUMN_DATE, Qt::UserRole, QVariant((qlonglong)out.
time));
678 itemOutput->setDisabled(
true);
690 itemWalletAddress->setText(
COLUMN_CHECKBOX,
"(" + QString::number(nChildren) +
")");
692 itemWalletAddress->setData(
COLUMN_AMOUNT, Qt::UserRole, QVariant((qlonglong)nSum));
699 for (
int i = 0; i <
ui->
treeWidget->topLevelItemCount(); i++)
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 removeSpaces(QString text)
static QString formatWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as string (with unit)
static QString format(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD, bool justify=false)
Format as string.
bool IsSelected(const COutPoint &output) const
void Select(const COutPoint &output)
void UnSelect(const COutPoint &output)
void ListSelected(std::vector< COutPoint > &vOutpoints) const
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
static void updateLabels(CCoinControl &m_coin_control, WalletModel *, QDialog *)
void copyTransactionOutpoint()
const PlatformStyle * platformStyle
CCoinControl & m_coin_control
void changeEvent(QEvent *e) override
Ui::CoinControlDialog * ui
void sortView(int, Qt::SortOrder)
CoinControlDialog(CCoinControl &coin_control, WalletModel *model, const PlatformStyle *platformStyle, QWidget *parent=nullptr)
void showMenu(const QPoint &)
void viewItemChanged(QTreeWidgetItem *, int)
void clipboardLowOutput()
void buttonSelectAllClicked()
QAction * m_copy_transaction_outpoint_action
static QList< CAmount > payAmounts
static bool fSubtractFeeFromAmount
void buttonBoxClicked(QAbstractButton *)
int getDisplayUnit() const
void setupUi(QDialog *CoinControlDialog)
QLabel * labelCoinControlChange
QPushButton * pushButtonSelectAll
QLabel * labelCoinControlFee
QRadioButton * radioListMode
QDialogButtonBox * buttonBox
QLabel * labelCoinControlQuantity
QLabel * labelCoinControlAmount
QLabel * labelCoinControlBytes
CoinControlTreeWidget * treeWidget
QLabel * labelCoinControlLowOutput
QLabel * labelCoinControlAfterFee
QRadioButton * radioTreeMode
Interface to Bitcoin wallet from Qt view code.
interfaces::Node & node() const
AddressTableModel * getAddressTableModel()
OptionsModel * getOptionsModel()
interfaces::Wallet & wallet() const
const unsigned char * data() const
std::string GetHex() 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 CAmount getMinimumFee(unsigned int tx_bytes, const CCoinControl &coin_control, int *returned_target, FeeReason *reason)=0
Get minimum fee.
virtual bool lockCoin(const COutPoint &output, const bool write_to_db)=0
Lock coin.
static constexpr CAmount MIN_CHANGE
target minimum change amount
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)
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
CKeyID ToKeyID(const PKHash &key_hash)
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
Wallet transaction output.
uint256 uint256S(const char *str)