Changeset View
Changeset View
Standalone View
Standalone View
src/qt/coincontroldialog.cpp
Show All 25 Lines | |||||
#include <QDialogButtonBox> | #include <QDialogButtonBox> | ||||
#include <QFlags> | #include <QFlags> | ||||
#include <QIcon> | #include <QIcon> | ||||
#include <QSettings> | #include <QSettings> | ||||
#include <QString> | #include <QString> | ||||
#include <QTreeWidget> | #include <QTreeWidget> | ||||
#include <QTreeWidgetItem> | #include <QTreeWidgetItem> | ||||
QList<CAmount> CoinControlDialog::payAmounts; | QList<Amount> CoinControlDialog::payAmounts; | ||||
CCoinControl *CoinControlDialog::coinControl = new CCoinControl(); | CCoinControl *CoinControlDialog::coinControl = new CCoinControl(); | ||||
bool CoinControlDialog::fSubtractFeeFromAmount = false; | bool CoinControlDialog::fSubtractFeeFromAmount = false; | ||||
bool CCoinControlWidgetItem::operator<(const QTreeWidgetItem &other) const { | bool CCoinControlWidgetItem::operator<(const QTreeWidgetItem &other) const { | ||||
int column = treeWidget()->sortColumn(); | int column = treeWidget()->sortColumn(); | ||||
if (column == CoinControlDialog::COLUMN_AMOUNT || | if (column == CoinControlDialog::COLUMN_AMOUNT || | ||||
column == CoinControlDialog::COLUMN_DATE || | column == CoinControlDialog::COLUMN_DATE || | ||||
column == CoinControlDialog::COLUMN_CONFIRMATIONS) | column == CoinControlDialog::COLUMN_CONFIRMATIONS) | ||||
▲ Show 20 Lines • Show All 402 Lines • ▼ Show 20 Lines | void CoinControlDialog::updateLabelLocked() { | ||||
} else | } else | ||||
ui->labelLocked->setVisible(false); | ui->labelLocked->setVisible(false); | ||||
} | } | ||||
void CoinControlDialog::updateLabels(WalletModel *model, QDialog *dialog) { | void CoinControlDialog::updateLabels(WalletModel *model, QDialog *dialog) { | ||||
if (!model) return; | if (!model) return; | ||||
// nPayAmount | // nPayAmount | ||||
CAmount nPayAmount = 0; | Amount nPayAmount = 0; | ||||
bool fDust = false; | bool fDust = false; | ||||
CMutableTransaction txDummy; | CMutableTransaction txDummy; | ||||
for (const CAmount &amount : CoinControlDialog::payAmounts) { | for (const Amount amount : CoinControlDialog::payAmounts) { | ||||
nPayAmount += amount; | nPayAmount += amount; | ||||
if (amount > 0) { | if (amount > 0) { | ||||
CTxOut txout(Amount(amount), (CScript)std::vector<uint8_t>(24, 0)); | CTxOut txout(Amount(amount), (CScript)std::vector<uint8_t>(24, 0)); | ||||
txDummy.vout.push_back(txout); | txDummy.vout.push_back(txout); | ||||
if (txout.IsDust(dustRelayFee)) fDust = true; | if (txout.IsDust(dustRelayFee)) fDust = true; | ||||
} | } | ||||
} | } | ||||
Show All 24 Lines | for (const COutput &out : vOutputs) { | ||||
coinControl->UnSelect(outpt); | coinControl->UnSelect(outpt); | ||||
continue; | continue; | ||||
} | } | ||||
// Quantity | // Quantity | ||||
nQuantity++; | nQuantity++; | ||||
// Amount | // Amount | ||||
nAmount += out.tx->tx->vout[out.i].nValue.GetSatoshis(); | nAmount += out.tx->tx->vout[out.i].nValue; | ||||
// Priority | // Priority | ||||
dPriorityInputs += | dPriorityInputs += | ||||
(double)out.tx->tx->vout[out.i].nValue.GetSatoshis() * | (double)out.tx->tx->vout[out.i].nValue.GetSatoshis() * | ||||
(out.nDepth + 1); | (out.nDepth + 1); | ||||
// Bytes | // Bytes | ||||
CTxDestination address; | CTxDestination address; | ||||
Show All 25 Lines | if (nQuantity > 0) { | ||||
// already and subtract the bytes, so that fee calculation afterwards is | // already and subtract the bytes, so that fee calculation afterwards is | ||||
// accurate | // accurate | ||||
if (CoinControlDialog::fSubtractFeeFromAmount) | if (CoinControlDialog::fSubtractFeeFromAmount) | ||||
if (nAmount - nPayAmount == 0) nBytes -= 34; | if (nAmount - nPayAmount == 0) nBytes -= 34; | ||||
// Fee | // Fee | ||||
nPayFee = CWallet::GetMinimumFee(nBytes, nTxConfirmTarget, mempool); | nPayFee = CWallet::GetMinimumFee(nBytes, nTxConfirmTarget, mempool); | ||||
if (nPayFee > 0 && coinControl->nMinimumTotalFee > nPayFee) | if (nPayFee > 0 && coinControl->nMinimumTotalFee > nPayFee) | ||||
nPayFee = coinControl->nMinimumTotalFee.GetSatoshis(); | nPayFee = coinControl->nMinimumTotalFee; | ||||
// Allow free? (require at least hard-coded threshold and default to | // Allow free? (require at least hard-coded threshold and default to | ||||
// that if no estimate) | // that if no estimate) | ||||
double mempoolEstimatePriority = | double mempoolEstimatePriority = | ||||
mempool.estimateSmartPriority(nTxConfirmTarget); | mempool.estimateSmartPriority(nTxConfirmTarget); | ||||
// 29 = 180 - 151 (uncompressed public keys are over the limit. max 151 | // 29 = 180 - 151 (uncompressed public keys are over the limit. max 151 | ||||
// bytes of the input are ignored for priority) | // bytes of the input are ignored for priority) | ||||
dPriority = dPriorityInputs / | dPriority = dPriorityInputs / | ||||
(nBytes - nBytesInputs + (nQuantityUncompressed * 29)); | (nBytes - nBytesInputs + (nQuantityUncompressed * 29)); | ||||
double dPriorityNeeded = | double dPriorityNeeded = | ||||
std::max(mempoolEstimatePriority, AllowFreeThreshold()); | std::max(mempoolEstimatePriority, AllowFreeThreshold()); | ||||
fAllowFree = (dPriority >= dPriorityNeeded); | fAllowFree = (dPriority >= dPriorityNeeded); | ||||
if (fSendFreeTransactions) | if (fSendFreeTransactions) | ||||
if (fAllowFree && nBytes <= MAX_FREE_TRANSACTION_CREATE_SIZE) | if (fAllowFree && nBytes <= MAX_FREE_TRANSACTION_CREATE_SIZE) | ||||
nPayFee = 0; | nPayFee = 0; | ||||
if (nPayAmount > 0) { | if (nPayAmount > 0) { | ||||
nChange = nAmount - nPayAmount; | nChange = nAmount - nPayAmount; | ||||
if (!CoinControlDialog::fSubtractFeeFromAmount) nChange -= nPayFee; | if (!CoinControlDialog::fSubtractFeeFromAmount) nChange -= nPayFee; | ||||
// Never create dust outputs; if we would, just add the dust to the | // Never create dust outputs; if we would, just add the dust to the | ||||
// fee. | // fee. | ||||
if (nChange > 0 && nChange < MIN_CHANGE.GetSatoshis()) { | if (nChange > Amount(0) && nChange < MIN_CHANGE) { | ||||
CTxOut txout(nChange, (CScript)std::vector<uint8_t>(24, 0)); | CTxOut txout(nChange, (CScript)std::vector<uint8_t>(24, 0)); | ||||
if (txout.IsDust(dustRelayFee)) { | if (txout.IsDust(dustRelayFee)) { | ||||
// dust-change will be raised until no dust | // dust-change will be raised until no dust | ||||
if (CoinControlDialog::fSubtractFeeFromAmount) { | if (CoinControlDialog::fSubtractFeeFromAmount) { | ||||
nChange = | nChange = txout.GetDustThreshold(dustRelayFee); | ||||
txout.GetDustThreshold(dustRelayFee).GetSatoshis(); | |||||
} else { | } else { | ||||
nPayFee += nChange; | nPayFee += nChange; | ||||
nChange = 0; | nChange = 0; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (nChange == 0 && !CoinControlDialog::fSubtractFeeFromAmount) { | if (nChange == 0 && !CoinControlDialog::fSubtractFeeFromAmount) { | ||||
Show All 28 Lines | dialog->findChild<QLabel *>("labelCoinControlChangeText") | ||||
->setEnabled(nPayAmount > 0); | ->setEnabled(nPayAmount > 0); | ||||
dialog->findChild<QLabel *>("labelCoinControlChange") | dialog->findChild<QLabel *>("labelCoinControlChange") | ||||
->setEnabled(nPayAmount > 0); | ->setEnabled(nPayAmount > 0); | ||||
// stats | // stats | ||||
// Quantity | // Quantity | ||||
l1->setText(QString::number(nQuantity)); | l1->setText(QString::number(nQuantity)); | ||||
// Amount | // Amount | ||||
l2->setText( | l2->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, nAmount)); | ||||
BitcoinUnits::formatWithUnit(nDisplayUnit, nAmount.GetSatoshis())); | |||||
// Fee | // Fee | ||||
l3->setText( | l3->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, nPayFee)); | ||||
BitcoinUnits::formatWithUnit(nDisplayUnit, nPayFee.GetSatoshis())); | |||||
// After Fee | // After Fee | ||||
l4->setText( | l4->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, nAfterFee)); | ||||
BitcoinUnits::formatWithUnit(nDisplayUnit, nAfterFee.GetSatoshis())); | |||||
// Bytes | // Bytes | ||||
l5->setText(((nBytes > 0) ? ASYMP_UTF8 : "") + QString::number(nBytes)); | l5->setText(((nBytes > 0) ? ASYMP_UTF8 : "") + QString::number(nBytes)); | ||||
// Dust | // Dust | ||||
l7->setText(fDust ? tr("yes") : tr("no")); | l7->setText(fDust ? tr("yes") : tr("no")); | ||||
// Change | // Change | ||||
l8->setText( | l8->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, nChange)); | ||||
BitcoinUnits::formatWithUnit(nDisplayUnit, nChange.GetSatoshis())); | |||||
if (nPayFee > Amount(0) && (coinControl->nMinimumTotalFee < nPayFee)) { | if (nPayFee > Amount(0) && (coinControl->nMinimumTotalFee < nPayFee)) { | ||||
l3->setText(ASYMP_UTF8 + l3->text()); | l3->setText(ASYMP_UTF8 + l3->text()); | ||||
l4->setText(ASYMP_UTF8 + l4->text()); | l4->setText(ASYMP_UTF8 + l4->text()); | ||||
if (nChange > 0 && !CoinControlDialog::fSubtractFeeFromAmount) { | if (nChange > 0 && !CoinControlDialog::fSubtractFeeFromAmount) { | ||||
l8->setText(ASYMP_UTF8 + l8->text()); | l8->setText(ASYMP_UTF8 + l8->text()); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | for (const std::pair<QString, std::vector<COutput>> &coins : mapCoins) { | ||||
sLabel = tr("(no label)"); | sLabel = tr("(no label)"); | ||||
} | } | ||||
itemOutput->setText(COLUMN_LABEL, sLabel); | itemOutput->setText(COLUMN_LABEL, sLabel); | ||||
} | } | ||||
// amount | // amount | ||||
itemOutput->setText( | itemOutput->setText( | ||||
COLUMN_AMOUNT, | COLUMN_AMOUNT, | ||||
BitcoinUnits::format( | BitcoinUnits::format(nDisplayUnit, | ||||
nDisplayUnit, | out.tx->tx->vout[out.i].nValue)); | ||||
out.tx->tx->vout[out.i].nValue.GetSatoshis())); | |||||
// padding so that sorting works correctly | // padding so that sorting works correctly | ||||
itemOutput->setData( | itemOutput->setData( | ||||
COLUMN_AMOUNT, Qt::UserRole, | COLUMN_AMOUNT, Qt::UserRole, | ||||
QVariant( | QVariant( | ||||
(qlonglong)out.tx->tx->vout[out.i].nValue.GetSatoshis())); | (qlonglong)out.tx->tx->vout[out.i].nValue.GetSatoshis())); | ||||
// date | // date | ||||
itemOutput->setText(COLUMN_DATE, | itemOutput->setText(COLUMN_DATE, | ||||
Show All 32 Lines | for (const std::pair<QString, std::vector<COutput>> &coins : mapCoins) { | ||||
} | } | ||||
} | } | ||||
// amount | // amount | ||||
if (treeMode) { | if (treeMode) { | ||||
itemWalletAddress->setText(COLUMN_CHECKBOX, | itemWalletAddress->setText(COLUMN_CHECKBOX, | ||||
"(" + QString::number(nChildren) + ")"); | "(" + QString::number(nChildren) + ")"); | ||||
itemWalletAddress->setText( | itemWalletAddress->setText( | ||||
COLUMN_AMOUNT, | COLUMN_AMOUNT, BitcoinUnits::format(nDisplayUnit, nSum)); | ||||
BitcoinUnits::format(nDisplayUnit, nSum.GetSatoshis())); | |||||
itemWalletAddress->setData(COLUMN_AMOUNT, Qt::UserRole, | itemWalletAddress->setData(COLUMN_AMOUNT, Qt::UserRole, | ||||
QVariant((qlonglong)nSum.GetSatoshis())); | QVariant((qlonglong)nSum.GetSatoshis())); | ||||
} | } | ||||
} | } | ||||
// expand all partially selected | // expand all partially selected | ||||
if (treeMode) { | if (treeMode) { | ||||
for (int i = 0; i < ui->treeWidget->topLevelItemCount(); i++) | for (int i = 0; i < ui->treeWidget->topLevelItemCount(); i++) | ||||
Show All 9 Lines |