Changeset View
Changeset View
Standalone View
Standalone View
src/qt/coincontroldialog.cpp
Show First 20 Lines • Show All 444 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 | ||||
Amount nPayAmount = 0; | Amount nPayAmount(0); | ||||
bool fDust = false; | bool fDust = false; | ||||
CMutableTransaction txDummy; | CMutableTransaction txDummy; | ||||
for (const Amount amount : CoinControlDialog::payAmounts) { | for (const Amount amount : CoinControlDialog::payAmounts) { | ||||
nPayAmount += amount; | nPayAmount += amount; | ||||
if (amount > 0) { | if (amount > 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; | ||||
} | } | ||||
} | } | ||||
Amount nAmount(0); | Amount nAmount(0); | ||||
Amount nPayFee(0); | Amount nPayFee(0); | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | if (nQuantity > 0) { | ||||
? CoinControlDialog::payAmounts.size() + 1 | ? CoinControlDialog::payAmounts.size() + 1 | ||||
: 2) * | : 2) * | ||||
34) + | 34) + | ||||
10; | 10; | ||||
// in the subtract fee from amount case, we can tell if zero change | // in the subtract fee from amount case, we can tell if zero change | ||||
// 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 == Amount(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 > Amount(0) && coinControl->nMinimumTotalFee > nPayFee) { | ||||
nPayFee = coinControl->nMinimumTotalFee; | 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 = Amount(0); | ||||
} | |||||
} | |||||
if (nPayAmount > 0) { | if (nPayAmount > Amount(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 > Amount(0) && nChange < MIN_CHANGE) { | 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 = txout.GetDustThreshold(dustRelayFee); | nChange = txout.GetDustThreshold(dustRelayFee); | ||||
} else { | } else { | ||||
nPayFee += nChange; | nPayFee += nChange; | ||||
nChange = 0; | nChange = Amount(0); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (nChange == 0 && !CoinControlDialog::fSubtractFeeFromAmount) { | if (nChange == Amount(0) && | ||||
!CoinControlDialog::fSubtractFeeFromAmount) { | |||||
nBytes -= 34; | nBytes -= 34; | ||||
} | } | ||||
} | } | ||||
// after fee | // after fee | ||||
nAfterFee = std::max(nAmount - nPayFee, Amount(0)); | nAfterFee = std::max(nAmount - nPayFee, Amount(0)); | ||||
} | } | ||||
// actually update labels | // actually update labels | ||||
int nDisplayUnit = BitcoinUnits::BCH; | int nDisplayUnit = BitcoinUnits::BCH; | ||||
if (model && model->getOptionsModel()) { | if (model && model->getOptionsModel()) { | ||||
nDisplayUnit = model->getOptionsModel()->getDisplayUnit(); | nDisplayUnit = model->getOptionsModel()->getDisplayUnit(); | ||||
} | } | ||||
QLabel *l1 = dialog->findChild<QLabel *>("labelCoinControlQuantity"); | QLabel *l1 = dialog->findChild<QLabel *>("labelCoinControlQuantity"); | ||||
QLabel *l2 = dialog->findChild<QLabel *>("labelCoinControlAmount"); | QLabel *l2 = dialog->findChild<QLabel *>("labelCoinControlAmount"); | ||||
QLabel *l3 = dialog->findChild<QLabel *>("labelCoinControlFee"); | QLabel *l3 = dialog->findChild<QLabel *>("labelCoinControlFee"); | ||||
QLabel *l4 = dialog->findChild<QLabel *>("labelCoinControlAfterFee"); | QLabel *l4 = dialog->findChild<QLabel *>("labelCoinControlAfterFee"); | ||||
QLabel *l5 = dialog->findChild<QLabel *>("labelCoinControlBytes"); | QLabel *l5 = dialog->findChild<QLabel *>("labelCoinControlBytes"); | ||||
QLabel *l7 = dialog->findChild<QLabel *>("labelCoinControlLowOutput"); | QLabel *l7 = dialog->findChild<QLabel *>("labelCoinControlLowOutput"); | ||||
QLabel *l8 = dialog->findChild<QLabel *>("labelCoinControlChange"); | QLabel *l8 = dialog->findChild<QLabel *>("labelCoinControlChange"); | ||||
// enable/disable "dust" and "change" | // enable/disable "dust" and "change" | ||||
dialog->findChild<QLabel *>("labelCoinControlLowOutputText") | dialog->findChild<QLabel *>("labelCoinControlLowOutputText") | ||||
->setEnabled(nPayAmount > 0); | ->setEnabled(nPayAmount > Amount(0)); | ||||
dialog->findChild<QLabel *>("labelCoinControlLowOutput") | dialog->findChild<QLabel *>("labelCoinControlLowOutput") | ||||
->setEnabled(nPayAmount > 0); | ->setEnabled(nPayAmount > Amount(0)); | ||||
dialog->findChild<QLabel *>("labelCoinControlChangeText") | dialog->findChild<QLabel *>("labelCoinControlChangeText") | ||||
->setEnabled(nPayAmount > 0); | ->setEnabled(nPayAmount > Amount(0)); | ||||
dialog->findChild<QLabel *>("labelCoinControlChange") | dialog->findChild<QLabel *>("labelCoinControlChange") | ||||
->setEnabled(nPayAmount > 0); | ->setEnabled(nPayAmount > Amount(0)); | ||||
// stats | // stats | ||||
// Quantity | // Quantity | ||||
l1->setText(QString::number(nQuantity)); | l1->setText(QString::number(nQuantity)); | ||||
// Amount | // Amount | ||||
l2->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, nAmount)); | l2->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, nAmount)); | ||||
// Fee | // Fee | ||||
l3->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, nPayFee)); | l3->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, nPayFee)); | ||||
// After Fee | // After Fee | ||||
l4->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, nAfterFee)); | l4->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, nAfterFee)); | ||||
// 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(BitcoinUnits::formatWithUnit(nDisplayUnit, nChange)); | l8->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, nChange)); | ||||
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 > Amount(0) && !CoinControlDialog::fSubtractFeeFromAmount) { | ||||
l8->setText(ASYMP_UTF8 + l8->text()); | l8->setText(ASYMP_UTF8 + l8->text()); | ||||
} | } | ||||
} | } | ||||
// turn label red when dust | // turn label red when dust | ||||
l7->setStyleSheet((fDust) ? "color:red;" : ""); | l7->setStyleSheet((fDust) ? "color:red;" : ""); | ||||
// tool tips | // tool tips | ||||
Show All 31 Lines | void CoinControlDialog::updateLabels(WalletModel *model, QDialog *dialog) { | ||||
dialog->findChild<QLabel *>("labelCoinControlLowOutputText") | dialog->findChild<QLabel *>("labelCoinControlLowOutputText") | ||||
->setToolTip(l7->toolTip()); | ->setToolTip(l7->toolTip()); | ||||
dialog->findChild<QLabel *>("labelCoinControlChangeText") | dialog->findChild<QLabel *>("labelCoinControlChangeText") | ||||
->setToolTip(l8->toolTip()); | ->setToolTip(l8->toolTip()); | ||||
// Insufficient funds | // Insufficient funds | ||||
QLabel *label = dialog->findChild<QLabel *>("labelCoinControlInsuffFunds"); | QLabel *label = dialog->findChild<QLabel *>("labelCoinControlInsuffFunds"); | ||||
if (label) { | if (label) { | ||||
label->setVisible(nChange < 0); | label->setVisible(nChange < Amount(0)); | ||||
} | } | ||||
} | } | ||||
void CoinControlDialog::updateView() { | void CoinControlDialog::updateView() { | ||||
if (!model || !model->getOptionsModel() || !model->getAddressTableModel()) { | if (!model || !model->getOptionsModel() || !model->getAddressTableModel()) { | ||||
return; | return; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 159 Lines • Show Last 20 Lines |