21 #include <validation.h> 24 #include <QApplication> 27 #include <QDialogButtonBox> 32 #include <QTreeWidget> 33 #include <QTreeWidgetItem> 40 int column = treeWidget()->sortColumn();
42 return data(column, Qt::UserRole).toLongLong() < other.data(column, Qt::UserRole).toLongLong();
50 platformStyle(_platformStyle)
59 QAction *copyAddressAction =
new QAction(tr(
"Copy address"),
this);
60 QAction *copyLabelAction =
new QAction(tr(
"Copy label"),
this);
61 QAction *copyAmountAction =
new QAction(tr(
"Copy amount"),
this);
63 lockAction =
new QAction(tr(
"Lock unspent"),
this);
77 connect(
ui->
treeWidget, SIGNAL(customContextMenuRequested(QPoint)),
this, SLOT(
showMenu(QPoint)));
78 connect(copyAddressAction, SIGNAL(triggered()),
this, SLOT(
copyAddress()));
79 connect(copyLabelAction, SIGNAL(triggered()),
this, SLOT(
copyLabel()));
80 connect(copyAmountAction, SIGNAL(triggered()),
this, SLOT(
copyAmount()));
86 QAction *clipboardQuantityAction =
new QAction(tr(
"Copy quantity"),
this);
87 QAction *clipboardAmountAction =
new QAction(tr(
"Copy amount"),
this);
88 QAction *clipboardFeeAction =
new QAction(tr(
"Copy fee"),
this);
89 QAction *clipboardAfterFeeAction =
new QAction(tr(
"Copy after fee"),
this);
90 QAction *clipboardBytesAction =
new QAction(tr(
"Copy bytes"),
this);
91 QAction *clipboardLowOutputAction =
new QAction(tr(
"Copy dust"),
this);
92 QAction *clipboardChangeAction =
new QAction(tr(
"Copy change"),
this);
94 connect(clipboardQuantityAction, SIGNAL(triggered()),
this, SLOT(
clipboardQuantity()));
95 connect(clipboardAmountAction, SIGNAL(triggered()),
this, SLOT(
clipboardAmount()));
96 connect(clipboardFeeAction, SIGNAL(triggered()),
this, SLOT(
clipboardFee()));
97 connect(clipboardAfterFeeAction, SIGNAL(triggered()),
this, SLOT(
clipboardAfterFee()));
98 connect(clipboardBytesAction, SIGNAL(triggered()),
this, SLOT(
clipboardBytes()));
99 connect(clipboardLowOutputAction, SIGNAL(triggered()),
this, SLOT(
clipboardLowOutput()));
100 connect(clipboardChangeAction, SIGNAL(triggered()),
this, SLOT(
clipboardChange()));
118 #if QT_VERSION < 0x050000 149 if (settings.contains(
"nCoinControlMode") && !settings.value(
"nCoinControlMode").toBool())
151 if (settings.contains(
"nCoinControlSortColumn") && settings.contains(
"nCoinControlSortOrder"))
152 sortView(settings.value(
"nCoinControlSortColumn").toInt(), ((Qt::SortOrder)settings.value(
"nCoinControlSortOrder").toInt()));
159 settings.setValue(
"nCoinControlSortColumn",
sortColumn);
160 settings.setValue(
"nCoinControlSortOrder", (
int)
sortOrder);
167 this->
model = _model;
180 if (
ui->
buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole)
181 done(QDialog::Accepted);
187 Qt::CheckState state = Qt::Checked;
188 for (
int i = 0; i <
ui->
treeWidget->topLevelItemCount(); i++)
192 state = Qt::Unchecked;
197 for (
int i = 0; i <
ui->
treeWidget->topLevelItemCount(); i++)
201 if (state == Qt::Unchecked)
355 sortOrder = ((
sortOrder == Qt::AscendingOrder) ? Qt::DescendingOrder : Qt::AscendingOrder);
369 if (checked &&
model)
376 if (checked &&
model)
389 else if (item->isDisabled())
401 #if QT_VERSION >= 0x050000 413 std::vector<COutPoint> vOutpts;
415 if (vOutpts.size() > 0)
417 ui->
labelLocked->setText(tr(
"(%1 locked)").arg(vOutpts.size()));
434 nPayAmount += amount;
438 CTxOut txout(amount, (
CScript)std::vector<unsigned char>(24, 0));
439 txDummy.
vout.push_back(txout);
448 unsigned int nBytes = 0;
449 unsigned int nBytesInputs = 0;
450 unsigned int nQuantity = 0;
451 bool fWitness =
false;
453 std::vector<COutPoint> vCoinControl;
454 std::vector<COutput> vOutputs;
458 for (
const COutput& out : vOutputs) {
461 uint256 txhash = out.tx->GetHash();
473 nAmount += out.tx->tx->vout[out.i].nValue;
477 int witnessversion = 0;
478 std::vector<unsigned char> witnessprogram;
479 if (out.tx->tx->vout[out.i].scriptPubKey.IsWitnessProgram(witnessversion, witnessprogram))
481 nBytesInputs += (32 + 4 + 1 + (107 / WITNESS_SCALE_FACTOR) + 4);
488 if (keyid && model->
getPubKey(*keyid, pubkey))
495 else nBytesInputs += 148;
502 nBytes = nBytesInputs + ((CoinControlDialog::payAmounts.size() > 0 ? CoinControlDialog::payAmounts.size() + 1 : 2) * 34) + 10;
514 if (nAmount - nPayAmount == 0)
522 nChange = nAmount - nPayAmount;
527 if (nChange > 0 && nChange < MIN_CHANGE)
529 CTxOut txout(nChange, (
CScript)std::vector<unsigned char>(24, 0));
544 nAfterFee = std::max<CAmount>(nAmount - nPayFee, 0);
552 QLabel *l1 = dialog->findChild<QLabel *>(
"labelCoinControlQuantity");
553 QLabel *l2 = dialog->findChild<QLabel *>(
"labelCoinControlAmount");
554 QLabel *l3 = dialog->findChild<QLabel *>(
"labelCoinControlFee");
555 QLabel *l4 = dialog->findChild<QLabel *>(
"labelCoinControlAfterFee");
556 QLabel *l5 = dialog->findChild<QLabel *>(
"labelCoinControlBytes");
557 QLabel *l7 = dialog->findChild<QLabel *>(
"labelCoinControlLowOutput");
558 QLabel *l8 = dialog->findChild<QLabel *>(
"labelCoinControlChange");
561 dialog->findChild<QLabel *>(
"labelCoinControlLowOutputText")->setEnabled(nPayAmount > 0);
562 dialog->findChild<QLabel *>(
"labelCoinControlLowOutput") ->setEnabled(nPayAmount > 0);
563 dialog->findChild<QLabel *>(
"labelCoinControlChangeText") ->setEnabled(nPayAmount > 0);
564 dialog->findChild<QLabel *>(
"labelCoinControlChange") ->setEnabled(nPayAmount > 0);
567 l1->setText(QString::number(nQuantity));
571 l5->setText(((nBytes > 0) ?
ASYMP_UTF8 :
"") + QString::number(nBytes));
572 l7->setText(fDust ? tr(
"yes") : tr(
"no"));
583 l7->setStyleSheet((fDust) ?
"color:red;" :
"");
586 QString toolTipDust = tr(
"This label turns red if any recipient receives an amount smaller than the current dust threshold.");
589 double dFeeVary = (double)nPayFee / nBytes;
591 QString toolTip4 = tr(
"Can vary +/- %1 liu(s) per input.").arg(dFeeVary);
593 l3->setToolTip(toolTip4);
594 l4->setToolTip(toolTip4);
595 l7->setToolTip(toolTipDust);
596 l8->setToolTip(toolTip4);
597 dialog->findChild<QLabel *>(
"labelCoinControlFeeText") ->setToolTip(l3->toolTip());
598 dialog->findChild<QLabel *>(
"labelCoinControlAfterFeeText") ->setToolTip(l4->toolTip());
599 dialog->findChild<QLabel *>(
"labelCoinControlBytesText") ->setToolTip(l5->toolTip());
600 dialog->findChild<QLabel *>(
"labelCoinControlLowOutputText")->setToolTip(l7->toolTip());
601 dialog->findChild<QLabel *>(
"labelCoinControlChangeText") ->setToolTip(l8->toolTip());
604 QLabel *label = dialog->findChild<QLabel *>(
"labelCoinControlInsuffFunds");
606 label->setVisible(nChange < 0);
619 QFlags<Qt::ItemFlag> flgCheckbox = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
620 QFlags<Qt::ItemFlag> flgTristate = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsTristate;
624 std::map<QString, std::vector<COutput> > mapCoins;
627 for (
const std::pair<QString, std::vector<COutput>>& coins : mapCoins) {
630 QString sWalletAddress = coins.first;
632 if (sWalletLabel.isEmpty())
633 sWalletLabel = tr(
"(no label)");
640 itemWalletAddress->setFlags(flgTristate);
652 for (
const COutput& out : coins.second) {
653 nSum += out.
tx->
tx->vout[out.
i].nValue;
659 itemOutput->setFlags(flgCheckbox);
664 QString sAddress =
"";
667 sAddress = QString::fromStdString(
CFabcoinAddress(outputAddress).ToString());
670 if (!treeMode || (!(sAddress == sWalletAddress)))
675 if (!(sAddress == sWalletAddress))
678 itemOutput->setToolTip(
COLUMN_LABEL, tr(
"change from %1 (%2)").arg(sWalletLabel).arg(sWalletAddress));
684 if (sLabel.isEmpty())
685 sLabel = tr(
"(no label)");
691 itemOutput->setData(
COLUMN_AMOUNT, Qt::UserRole, QVariant((qlonglong)out.
tx->
tx->vout[out.
i].nValue));
713 itemOutput->setDisabled(
true);
725 itemWalletAddress->setText(
COLUMN_CHECKBOX,
"(" + QString::number(nChildren) +
")");
727 itemWalletAddress->setData(
COLUMN_AMOUNT, Qt::UserRole, QVariant((qlonglong)nSum));
734 for (
int i = 0; i <
ui->
treeWidget->topLevelItemCount(); i++)
const PlatformStyle * platformStyle
void viewItemChanged(QTreeWidgetItem *, int)
#define SetObjectStyleSheet(object, name)
void getOutputs(const std::vector< COutPoint > &vOutpoints, std::vector< COutput > &vOutputs)
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
void lockCoin(COutPoint &output)
void buttonSelectAllClicked()
void clipboardLowOutput()
void headerSectionClicked(int)
static CCoinControl * coinControl
void copyTransactionHash()
const uint256 & GetHash() const
QRadioButton * radioTreeMode
std::string GetHex() const
void setupUi(QDialog *CoinControlDialog)
bool isLockedCoin(uint256 hash, unsigned int n) const
base58-encoded Fabcoin addresses.
QString dateTimeStr(const QDateTime &date)
CoinControlDialog(const PlatformStyle *platformStyle, QWidget *parent=0)
int64_t GetTxTime() const
void ListSelected(std::vector< COutPoint > &vOutpoints) const
AddressTableModel * getAddressTableModel()
void UnSelect(const COutPoint &output)
static QString formatWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string (with unit)
QLabel * labelCoinControlChange
int64_t CAmount
Amount in lius (Can be negative)
CBlockPolicyEstimator feeEstimator
static QList< CAmount > payAmounts
QPushButton * pushButtonSelectAll
QAction * copyTransactionHashAction
bool isSpent(const COutPoint &outpoint) const
Ui::CoinControlDialog * ui
void setClipboard(const QString &str)
static QString format(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string.
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet, txnouttype *typeRet)
CoinControlTreeWidget * treeWidget
void Select(const COutPoint &output)
uint256 uint256S(const char *str)
An encapsulated public key.
bool getPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
static void updateLabels(WalletModel *, QDialog *)
friend class CCoinControlWidgetItem
An output of a transaction.
QLabel * labelCoinControlQuantity
An outpoint - a combination of a transaction hash and an index n into its vout.
std::vector< CTxOut > vout
QLabel * labelCoinControlLowOutput
bool IsCompressed() const
Check whether this is a compressed public key.
QLabel * labelCoinControlAmount
void setModel(WalletModel *model)
static CAmount GetMinimumFee(unsigned int nTxBytes, const CCoinControl &coin_control, const CTxMemPool &pool, const CBlockPolicyEstimator &estimator, FeeCalculation *feeCalc)
Estimate the minimum fee considering user set parameters and the required fee.
static bool fSubtractFeeFromAmount
QTreeWidgetItem * contextMenuItem
QString labelForAddress(const QString &address) const
void listLockedCoins(std::vector< COutPoint > &vOutpts)
Serialized script, used inside transaction inputs and outputs.
Interface to Fabcoin wallet from Qt view code.
void unlockCoin(COutPoint &output)
A reference to a CKey: the Hash160 of its serialized public key.
static QString removeSpaces(QString text)
void sortView(int, Qt::SortOrder)
bool IsDust(const CTxOut &txout, const CFeeRate &dustRelayFeeIn)
A mutable version of CTransaction.
void buttonBoxClicked(QAbstractButton *)
struct evm_uint160be address(struct evm_env *env)
QRadioButton * radioListMode
void showMenu(const QPoint &)
QDialogButtonBox * buttonBox
void listCoins(std::map< QString, std::vector< COutput > > &mapCoins) const
bool IsSelected(const COutPoint &output) const
QLabel * labelCoinControlFee
QLabel * labelCoinControlAfterFee
QLabel * labelCoinControlBytes
bool operator<(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
OptionsModel * getOptionsModel()