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 *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);
319 sortOrder = ((
sortOrder == Qt::AscendingOrder) ? Qt::DescendingOrder : Qt::AscendingOrder);
333 if (checked &&
model)
340 if (checked &&
model)
353 else if (item->isDisabled())
367 std::vector<COutPoint> vOutpts;
369 if (vOutpts.size() > 0)
371 ui->
labelLocked->setText(tr(
"(%1 locked)").arg(vOutpts.size()));
385 nPayAmount += amount;
392 unsigned int nBytes = 0;
393 unsigned int nBytesInputs = 0;
394 unsigned int nQuantity = 0;
395 bool fWitness =
false;
401 if (
out.depth_in_main_chain < 0)
continue;
405 const COutPoint& outpt = vCoinControl[i++];
416 nAmount +=
out.txout.nValue;
420 int witnessversion = 0;
421 std::vector<unsigned char> witnessprogram;
422 if (
out.txout.scriptPubKey.IsWitnessProgram(witnessversion, witnessprogram))
425 nBytesInputs += (32 + 4 + 1 + 4);
427 if (witnessversion == 0) {
430 }
else if (witnessversion == 1) {
435 throw std::runtime_error(
"Trying to spend future segwit version script");
442 PKHash* pkhash = std::get_if<PKHash>(&address);
450 else nBytesInputs += 148;
469 if (nAmount - nPayAmount == 0)
477 nChange = nAmount - nPayAmount;
483 CTxOut txout(nChange,
CScript() << std::vector<unsigned char>(24, 0));
499 nAfterFee = std::max<CAmount>(nAmount - nPayFee, 0);
507 QLabel *l1 = dialog->findChild<QLabel *>(
"labelCoinControlQuantity");
508 QLabel *l2 = dialog->findChild<QLabel *>(
"labelCoinControlAmount");
509 QLabel *l3 = dialog->findChild<QLabel *>(
"labelCoinControlFee");
510 QLabel *l4 = dialog->findChild<QLabel *>(
"labelCoinControlAfterFee");
511 QLabel *l5 = dialog->findChild<QLabel *>(
"labelCoinControlBytes");
512 QLabel *l8 = dialog->findChild<QLabel *>(
"labelCoinControlChange");
515 dialog->findChild<QLabel *>(
"labelCoinControlChangeText") ->setEnabled(nPayAmount > 0);
516 dialog->findChild<QLabel *>(
"labelCoinControlChange") ->setEnabled(nPayAmount > 0);
519 l1->setText(QString::number(nQuantity));
523 l5->setText(((nBytes > 0) ?
ASYMP_UTF8 :
"") + QString::number(nBytes));
534 double dFeeVary = (nBytes != 0) ? (
double)nPayFee / nBytes : 0;
536 QString toolTip4 = tr(
"Can vary +/- %1 satoshi(s) per input.").arg(dFeeVary);
538 l3->setToolTip(toolTip4);
539 l4->setToolTip(toolTip4);
540 l8->setToolTip(toolTip4);
541 dialog->findChild<QLabel *>(
"labelCoinControlFeeText") ->setToolTip(l3->toolTip());
542 dialog->findChild<QLabel *>(
"labelCoinControlAfterFeeText") ->setToolTip(l4->toolTip());
543 dialog->findChild<QLabel *>(
"labelCoinControlBytesText") ->setToolTip(l5->toolTip());
544 dialog->findChild<QLabel *>(
"labelCoinControlChangeText") ->setToolTip(l8->toolTip());
547 QLabel *label = dialog->findChild<QLabel *>(
"labelCoinControlInsuffFunds");
549 label->setVisible(nChange < 0);
554 if (e->type() == QEvent::PaletteChange) {
558 QDialog::changeEvent(e);
571 QFlags<Qt::ItemFlag> flgCheckbox = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
572 QFlags<Qt::ItemFlag> flgTristate = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsAutoTristate;
580 if (sWalletLabel.isEmpty())
581 sWalletLabel = tr(
"(no label)");
588 itemWalletAddress->setFlags(flgTristate);
600 for (
const auto& outpair : coins.second) {
601 const COutPoint& output = std::get<0>(outpair);
603 nSum +=
out.txout.nValue;
609 itemOutput->setFlags(flgCheckbox);
614 QString sAddress =
"";
620 if (!treeMode || (!(sAddress == sWalletAddress)))
625 if (!(sAddress == sWalletAddress))
628 itemOutput->setToolTip(
COLUMN_LABEL, tr(
"change from %1 (%2)").arg(sWalletLabel).arg(sWalletAddress));
634 if (sLabel.isEmpty())
635 sLabel = tr(
"(no label)");
641 itemOutput->setData(
COLUMN_AMOUNT, Qt::UserRole, QVariant((qlonglong)
out.txout.nValue));
645 itemOutput->setData(
COLUMN_DATE, Qt::UserRole, QVariant((qlonglong)
out.time));
661 itemOutput->setDisabled(
true);
673 itemWalletAddress->setText(
COLUMN_CHECKBOX,
"(" + QString::number(nChildren) +
")");
675 itemWalletAddress->setData(
COLUMN_AMOUNT, Qt::UserRole, QVariant((qlonglong)nSum));
682 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
Utility functions used by the Bitcoin Qt UI.
void buttonSelectAllClicked()
static const int WITNESS_SCALE_FACTOR
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.
bool IsSelected(const COutPoint &output) const
Returns true if the given output is pre-selected.
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)
Unselects the given output.
void Select(const COutPoint &output)
Lock-in the given output for spending.
int64_t CAmount
Amount in satoshis (Can be negative)
QAction * m_copy_transaction_outpoint_action
static QList< CAmount > payAmounts
QPushButton * pushButtonSelectAll
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a scriptPubKey for the destination.
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.
void UnSelectAll()
Unselects all outputs.
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
virtual std::vector< WalletTxOut > getCoins(const std::vector< COutPoint > &outputs)=0
Return wallet transaction output information.
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
bool operator<(const CNetAddr &a, const CNetAddr &b)
QLabel * labelCoinControlAmount
static bool fSubtractFeeFromAmount
QTreeWidgetItem * contextMenuItem
constexpr const unsigned char * data() const
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.
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
std::vector< COutPoint > ListSelected() const
List the selected inputs.
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.