5 #if defined(HAVE_CONFIG_H) 26 #include <QApplication> 29 #include <QDialogButtonBox> 33 #include <QTreeWidget> 41 int column = treeWidget()->sortColumn();
43 return data(column, Qt::UserRole).toLongLong() < other.data(column, Qt::UserRole).toLongLong();
50 m_coin_control(coin_control),
52 platformStyle(_platformStyle)
68 QAction *clipboardQuantityAction =
new QAction(tr(
"Copy quantity"),
this);
69 QAction *clipboardAmountAction =
new QAction(tr(
"Copy amount"),
this);
70 QAction *clipboardFeeAction =
new QAction(tr(
"Copy fee"),
this);
71 QAction *clipboardAfterFeeAction =
new QAction(tr(
"Copy after fee"),
this);
72 QAction *clipboardBytesAction =
new QAction(tr(
"Copy bytes"),
this);
73 QAction *clipboardLowOutputAction =
new QAction(tr(
"Copy dust"),
this);
74 QAction *clipboardChangeAction =
new QAction(tr(
"Copy change"),
this);
121 if (settings.contains(
"nCoinControlMode") && !settings.value(
"nCoinControlMode").toBool())
123 if (settings.contains(
"nCoinControlSortColumn") && settings.contains(
"nCoinControlSortOrder"))
124 sortView(settings.value(
"nCoinControlSortColumn").toInt(), (
static_cast<Qt::SortOrder
>(settings.value(
"nCoinControlSortOrder").toInt())));
140 settings.setValue(
"nCoinControlSortColumn",
sortColumn);
141 settings.setValue(
"nCoinControlSortOrder", (
int)
sortOrder);
149 if (
ui->
buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole)
150 done(QDialog::Accepted);
156 Qt::CheckState state = Qt::Checked;
157 for (
int i = 0; i <
ui->
treeWidget->topLevelItemCount(); i++)
161 state = Qt::Unchecked;
166 for (
int i = 0; i <
ui->
treeWidget->topLevelItemCount(); i++)
170 if (state == Qt::Unchecked)
239 const QString outpoint = QString(
"%1:%2").arg(address).arg(vout);
328 sortOrder = ((
sortOrder == Qt::AscendingOrder) ? Qt::DescendingOrder : Qt::AscendingOrder);
342 if (checked &&
model)
349 if (checked &&
model)
362 else if (item->isDisabled())
376 std::vector<COutPoint> vOutpts;
378 if (vOutpts.size() > 0)
380 ui->
labelLocked->setText(tr(
"(%1 locked)").arg(vOutpts.size()));
396 nPayAmount += amount;
401 CTxOut txout(amount,
CScript() << std::vector<unsigned char>(24, 0));
410 unsigned int nBytes = 0;
411 unsigned int nBytesInputs = 0;
412 unsigned int nQuantity = 0;
413 bool fWitness =
false;
415 std::vector<COutPoint> vCoinControl;
420 if (out.depth_in_main_chain < 0)
continue;
424 const COutPoint& outpt = vCoinControl[i++];
435 nAmount += out.txout.nValue;
439 int witnessversion = 0;
440 std::vector<unsigned char> witnessprogram;
441 if (out.txout.scriptPubKey.IsWitnessProgram(witnessversion, witnessprogram))
449 PKHash* pkhash = std::get_if<PKHash>(&address);
457 else nBytesInputs += 148;
476 if (nAmount - nPayAmount == 0)
484 nChange = nAmount - nPayAmount;
490 CTxOut txout(nChange,
CScript() << std::vector<unsigned char>(24, 0));
506 nAfterFee = std::max<CAmount>(nAmount - nPayFee, 0);
514 QLabel *l1 = dialog->findChild<QLabel *>(
"labelCoinControlQuantity");
515 QLabel *l2 = dialog->findChild<QLabel *>(
"labelCoinControlAmount");
516 QLabel *l3 = dialog->findChild<QLabel *>(
"labelCoinControlFee");
517 QLabel *l4 = dialog->findChild<QLabel *>(
"labelCoinControlAfterFee");
518 QLabel *l5 = dialog->findChild<QLabel *>(
"labelCoinControlBytes");
519 QLabel *l7 = dialog->findChild<QLabel *>(
"labelCoinControlLowOutput");
520 QLabel *l8 = dialog->findChild<QLabel *>(
"labelCoinControlChange");
523 dialog->findChild<QLabel *>(
"labelCoinControlLowOutputText")->setEnabled(nPayAmount > 0);
524 dialog->findChild<QLabel *>(
"labelCoinControlLowOutput") ->setEnabled(nPayAmount > 0);
525 dialog->findChild<QLabel *>(
"labelCoinControlChangeText") ->setEnabled(nPayAmount > 0);
526 dialog->findChild<QLabel *>(
"labelCoinControlChange") ->setEnabled(nPayAmount > 0);
529 l1->setText(QString::number(nQuantity));
533 l5->setText(((nBytes > 0) ?
ASYMP_UTF8 :
"") + QString::number(nBytes));
534 l7->setText(fDust ? tr(
"yes") : tr(
"no"));
545 l7->setStyleSheet((fDust) ?
"color:red;" :
"");
548 QString toolTipDust = tr(
"This label turns red if any recipient receives an amount smaller than the current dust threshold.");
551 double dFeeVary = (nBytes != 0) ? (
double)nPayFee / nBytes : 0;
553 QString toolTip4 = tr(
"Can vary +/- %1 satoshi(s) per input.").arg(dFeeVary);
555 l3->setToolTip(toolTip4);
556 l4->setToolTip(toolTip4);
557 l7->setToolTip(toolTipDust);
558 l8->setToolTip(toolTip4);
559 dialog->findChild<QLabel *>(
"labelCoinControlFeeText") ->setToolTip(l3->toolTip());
560 dialog->findChild<QLabel *>(
"labelCoinControlAfterFeeText") ->setToolTip(l4->toolTip());
561 dialog->findChild<QLabel *>(
"labelCoinControlBytesText") ->setToolTip(l5->toolTip());
562 dialog->findChild<QLabel *>(
"labelCoinControlLowOutputText")->setToolTip(l7->toolTip());
563 dialog->findChild<QLabel *>(
"labelCoinControlChangeText") ->setToolTip(l8->toolTip());
566 QLabel *label = dialog->findChild<QLabel *>(
"labelCoinControlInsuffFunds");
568 label->setVisible(nChange < 0);
573 if (e->type() == QEvent::PaletteChange) {
577 QDialog::changeEvent(e);
590 QFlags<Qt::ItemFlag> flgCheckbox = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
591 QFlags<Qt::ItemFlag> flgTristate = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsAutoTristate;
599 if (sWalletLabel.isEmpty())
600 sWalletLabel = tr(
"(no label)");
607 itemWalletAddress->setFlags(flgTristate);
619 for (
const auto& outpair : coins.second) {
620 const COutPoint& output = std::get<0>(outpair);
628 itemOutput->setFlags(flgCheckbox);
633 QString sAddress =
"";
639 if (!treeMode || (!(sAddress == sWalletAddress)))
644 if (!(sAddress == sWalletAddress))
647 itemOutput->setToolTip(
COLUMN_LABEL, tr(
"change from %1 (%2)").arg(sWalletLabel).arg(sWalletAddress));
653 if (sLabel.isEmpty())
654 sLabel = tr(
"(no label)");
660 itemOutput->setData(
COLUMN_AMOUNT, Qt::UserRole, QVariant((qlonglong)out.txout.nValue));
664 itemOutput->setData(
COLUMN_DATE, Qt::UserRole, QVariant((qlonglong)out.time));
668 itemOutput->setData(
COLUMN_CONFIRMATIONS, Qt::UserRole, QVariant((qlonglong)out.depth_in_main_chain));
680 itemOutput->setDisabled(
true);
692 itemWalletAddress->setText(
COLUMN_CHECKBOX,
"(" + QString::number(nChildren) +
")");
694 itemWalletAddress->setData(
COLUMN_AMOUNT, Qt::UserRole, QVariant((qlonglong)nSum));
701 for (
int i = 0; i <
ui->
treeWidget->topLevelItemCount(); i++)
const PlatformStyle * platformStyle
void viewItemChanged(QTreeWidgetItem *, int)
virtual CoinsList listCoins()=0
OptionsModel * getOptionsModel() const
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)
CoinControlDialog(wallet::CCoinControl &coin_control, WalletModel *model, const PlatformStyle *platformStyle, QWidget *parent=nullptr)
QRadioButton * radioTreeMode
virtual bool getPubKey(const CScript &script, const CKeyID &address, CPubKey &pub_key)=0
Get public key.
void setupUi(QDialog *CoinControlDialog)
QString dateTimeStr(const QDateTime &date)
BitcoinUnit getDisplayUnit() const
virtual bool lockCoin(const COutPoint &output, const bool write_to_db)=0
Lock coin.
const unsigned char * data() const
bool IsSelected(const COutPoint &output) const
virtual CFeeRate getDustRelayFee()=0
Get dust relay fee.
static QString formatWithUnit(Unit unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as string (with unit)
constexpr auto dialog_flags
QLabel * labelCoinControlChange
void UnSelect(const COutPoint &output)
void Select(const COutPoint &output)
int64_t CAmount
Amount in satoshis (Can be negative)
QAction * m_copy_transaction_outpoint_action
static QList< CAmount > payAmounts
QPushButton * pushButtonSelectAll
Ui::CoinControlDialog * ui
void copyTransactionOutpoint()
virtual bool unlockCoin(const COutPoint &output)=0
Unlock coin.
static QString format(Unit unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD, bool justify=false)
Format as string.
void setClipboard(const QString &str)
void handleCloseWindowShortcut(QWidget *w)
wallet::CCoinControl & m_coin_control
CoinControlTreeWidget * treeWidget
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.
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
QLabel * labelCoinControlQuantity
An outpoint - a combination of a transaction hash and an index n into its vout.
interfaces::Node & node() const
QLabel * labelCoinControlLowOutput
virtual std::vector< WalletTxOut > getCoins(const std::vector< COutPoint > &outputs)=0
Return wallet transaction output information.
bool operator<(const CNetAddr &a, const CNetAddr &b)
QLabel * labelCoinControlAmount
static bool fSubtractFeeFromAmount
QTreeWidgetItem * contextMenuItem
static void updateLabels(wallet::CCoinControl &m_coin_control, WalletModel *, QDialog *)
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.
void ListSelected(std::vector< COutPoint > &vOutpoints) 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)
AddressTableModel * getAddressTableModel() const
void buttonBoxClicked(QAbstractButton *)
QRadioButton * radioListMode
void showMenu(const QPoint &)
QDialogButtonBox * buttonBox
QLabel * labelCoinControlFee
QLabel * labelCoinControlAfterFee
Wallet transaction output.
QLabel * labelCoinControlBytes
virtual CAmount getMinimumFee(unsigned int tx_bytes, const wallet::CCoinControl &coin_control, int *returned_target, FeeReason *reason)=0
Get minimum fee.
CKeyID ToKeyID(const PKHash &key_hash)
bool IsCompressed() const
Check whether this is a compressed public key.