Changeset View
Changeset View
Standalone View
Standalone View
src/qt/coincontroldialog.cpp
Show First 20 Lines • Show All 451 Lines • ▼ Show 20 Lines | void CoinControlDialog::updateLabels(WalletModel *model, QDialog *dialog) { | ||||
// nPayAmount | // nPayAmount | ||||
CAmount nPayAmount = 0; | CAmount nPayAmount = 0; | ||||
bool fDust = false; | bool fDust = false; | ||||
CMutableTransaction txDummy; | CMutableTransaction txDummy; | ||||
for (const CAmount &amount : CoinControlDialog::payAmounts) { | for (const CAmount &amount : CoinControlDialog::payAmounts) { | ||||
nPayAmount += amount; | nPayAmount += amount; | ||||
if (amount > 0) { | if (amount > 0) { | ||||
CTxOut txout(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; | ||||
} | } | ||||
} | } | ||||
CAmount nAmount = 0; | Amount nAmount(0); | ||||
CAmount nPayFee = 0; | Amount nPayFee(0); | ||||
CAmount nAfterFee = 0; | Amount nAfterFee(0); | ||||
CAmount nChange = 0; | Amount nChange(0); | ||||
unsigned int nBytes = 0; | unsigned int nBytes = 0; | ||||
unsigned int nBytesInputs = 0; | unsigned int nBytesInputs = 0; | ||||
double dPriority = 0; | double dPriority = 0; | ||||
double dPriorityInputs = 0; | double dPriorityInputs = 0; | ||||
unsigned int nQuantity = 0; | unsigned int nQuantity = 0; | ||||
int nQuantityUncompressed = 0; | int nQuantityUncompressed = 0; | ||||
bool fAllowFree = false; | bool fAllowFree = false; | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | if (nQuantity > 0) { | ||||
// 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 == 0) nBytes -= 34; | ||||
// Fee | // Fee | ||||
nPayFee = CWallet::GetMinimumFee(nBytes, nTxConfirmTarget, mempool) | nPayFee = CWallet::GetMinimumFee(nBytes, nTxConfirmTarget, mempool); | ||||
.GetSatoshis(); | |||||
if (nPayFee > 0 && coinControl->nMinimumTotalFee > nPayFee) | if (nPayFee > 0 && coinControl->nMinimumTotalFee > nPayFee) | ||||
nPayFee = coinControl->nMinimumTotalFee.GetSatoshis(); | nPayFee = coinControl->nMinimumTotalFee.GetSatoshis(); | ||||
// 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 | ||||
Show All 9 Lines | if (nQuantity > 0) { | ||||
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) { | if (nChange > 0 && nChange < MIN_CHANGE.GetSatoshis()) { | ||||
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).GetSatoshis(); | txout.GetDustThreshold(dustRelayFee).GetSatoshis(); | ||||
} else { | } else { | ||||
nPayFee += nChange; | nPayFee += nChange; | ||||
nChange = 0; | nChange = 0; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (nChange == 0 && !CoinControlDialog::fSubtractFeeFromAmount) { | if (nChange == 0 && !CoinControlDialog::fSubtractFeeFromAmount) { | ||||
nBytes -= 34; | nBytes -= 34; | ||||
} | } | ||||
} | } | ||||
// after fee | // after fee | ||||
nAfterFee = std::max<CAmount>(nAmount - nPayFee, 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(); | ||||
} | } | ||||
Show All 14 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(BitcoinUnits::formatWithUnit(nDisplayUnit, nAmount)); | l2->setText( | ||||
BitcoinUnits::formatWithUnit(nDisplayUnit, nAmount.GetSatoshis())); | |||||
// Fee | // Fee | ||||
l3->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, nPayFee)); | l3->setText( | ||||
BitcoinUnits::formatWithUnit(nDisplayUnit, nPayFee.GetSatoshis())); | |||||
// After Fee | // After Fee | ||||
l4->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, nAfterFee)); | l4->setText( | ||||
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(BitcoinUnits::formatWithUnit(nDisplayUnit, nChange)); | l8->setText( | ||||
if (nPayFee > 0 && (coinControl->nMinimumTotalFee < nPayFee)) { | BitcoinUnits::formatWithUnit(nDisplayUnit, nChange.GetSatoshis())); | ||||
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()); | ||||
} | } | ||||
} | } | ||||
// turn label red when dust | // turn label red when dust | ||||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | for (const std::pair<QString, std::vector<COutput>> &coins : mapCoins) { | ||||
// label | // label | ||||
itemWalletAddress->setText(COLUMN_LABEL, sWalletLabel); | itemWalletAddress->setText(COLUMN_LABEL, sWalletLabel); | ||||
// address | // address | ||||
itemWalletAddress->setText(COLUMN_ADDRESS, sWalletAddress); | itemWalletAddress->setText(COLUMN_ADDRESS, sWalletAddress); | ||||
} | } | ||||
CAmount nSum = 0; | Amount nSum(0); | ||||
int nChildren = 0; | int nChildren = 0; | ||||
for (const COutput &out : coins.second) { | for (const COutput &out : coins.second) { | ||||
nSum += out.tx->tx->vout[out.i].nValue.GetSatoshis(); | nSum += out.tx->tx->vout[out.i].nValue; | ||||
nChildren++; | nChildren++; | ||||
CCoinControlWidgetItem *itemOutput; | CCoinControlWidgetItem *itemOutput; | ||||
if (treeMode) { | if (treeMode) { | ||||
itemOutput = new CCoinControlWidgetItem(itemWalletAddress); | itemOutput = new CCoinControlWidgetItem(itemWalletAddress); | ||||
} else { | } else { | ||||
itemOutput = new CCoinControlWidgetItem(ui->treeWidget); | itemOutput = new CCoinControlWidgetItem(ui->treeWidget); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 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, BitcoinUnits::format(nDisplayUnit, nSum)); | COLUMN_AMOUNT, | ||||
BitcoinUnits::format(nDisplayUnit, nSum.GetSatoshis())); | |||||
itemWalletAddress->setData(COLUMN_AMOUNT, Qt::UserRole, | itemWalletAddress->setData(COLUMN_AMOUNT, Qt::UserRole, | ||||
QVariant((qlonglong)nSum)); | 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++) | ||||
if (ui->treeWidget->topLevelItem(i)->checkState(COLUMN_CHECKBOX) == | if (ui->treeWidget->topLevelItem(i)->checkState(COLUMN_CHECKBOX) == | ||||
Qt::PartiallyChecked) | Qt::PartiallyChecked) | ||||
ui->treeWidget->topLevelItem(i)->setExpanded(true); | ui->treeWidget->topLevelItem(i)->setExpanded(true); | ||||
} | } | ||||
// sort view | // sort view | ||||
sortView(sortColumn, sortOrder); | sortView(sortColumn, sortOrder); | ||||
ui->treeWidget->setEnabled(true); | ui->treeWidget->setEnabled(true); | ||||
} | } |