Skip to content

Commit 43c1e4b

Browse files
committed
GUI: connect labels calculation in coin control for shielded outputs
1 parent d2faa04 commit 43c1e4b

File tree

1 file changed

+46
-35
lines changed

1 file changed

+46
-35
lines changed

src/qt/coincontroldialog.cpp

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -505,11 +505,6 @@ void CoinControlDialog::updateLabels()
505505
}
506506
}
507507

508-
// TODO: Connect labels calculation in the future..
509-
if (!fSelectTransparent) {
510-
return;
511-
}
512-
513508
CAmount nAmount = 0;
514509
CAmount nPayFee = 0;
515510
CAmount nAfterFee = 0;
@@ -523,25 +518,36 @@ void CoinControlDialog::updateLabels()
523518
coinControl->ListSelected(vCoinControl);
524519
model->getOutputs(vCoinControl, vOutputs);
525520

526-
for (const COutput& out : vOutputs) {
527-
// unselect already spent, very unlikely scenario, this could happen
528-
// when selected are spent elsewhere, like rpc or another computer
529-
uint256 txhash = out.tx->GetHash();
530-
COutPoint outpt(txhash, out.i);
531-
if (model->isSpent(outpt)) {
532-
coinControl->UnSelect(outpt);
533-
continue;
534-
}
521+
if (fSelectTransparent) {
522+
for (const COutput& out : vOutputs) {
523+
// unselect already spent, very unlikely scenario, this could happen
524+
// when selected are spent elsewhere, like rpc or another computer
525+
uint256 txhash = out.tx->GetHash();
526+
COutPoint outpt(txhash, out.i);
527+
if (model->isSpent(outpt)) {
528+
coinControl->UnSelect(outpt);
529+
continue;
530+
}
535531

536-
// Quantity
537-
nQuantity++;
538-
// Amount
539-
nAmount += out.tx->vout[out.i].nValue;
540-
// Bytes
541-
nBytesInputs += 148;
542-
// Additional byte for P2CS
543-
if (out.tx->vout[out.i].scriptPubKey.IsPayToColdStaking())
544-
nBytesInputs++;
532+
// Quantity
533+
nQuantity++;
534+
// Amount
535+
nAmount += out.tx->vout[out.i].nValue;
536+
// Bytes
537+
nBytesInputs += CTXIN_SPEND_DUST_SIZE;
538+
// Additional byte for P2CS
539+
if (out.tx->vout[out.i].scriptPubKey.IsPayToColdStaking())
540+
nBytesInputs++;
541+
}
542+
} else {
543+
for (const OutPointWrapper& out : vCoinControl) {
544+
// Quantity
545+
nQuantity++;
546+
// Amount
547+
nAmount += out.value;
548+
// Bytes
549+
nBytesInputs += SPENDDESCRIPTION_SIZE;
550+
}
545551
}
546552

547553
// update SelectAll button state
@@ -550,33 +556,38 @@ void CoinControlDialog::updateLabels()
550556
updatePushButtonSelectAll(coinControl->QuantitySelected() * 2 > nSelectableInputs);
551557

552558
// calculation
553-
const int P2PKH_OUT_SIZE = 34;
554559
const int P2CS_OUT_SIZE = 61;
555560
if (nQuantity > 0) {
556561
// Bytes: nBytesInputs + (num_of_outputs * bytes_per_output)
557-
nBytes = nBytesInputs + std::max(1, payAmounts.size()) * (forDelegation ? P2CS_OUT_SIZE : P2PKH_OUT_SIZE);
558562
// always assume +1 (p2pkh) output for change here
559-
nBytes += P2PKH_OUT_SIZE;
563+
if (fSelectTransparent) {
564+
nBytes = nBytesInputs + std::max(1, payAmounts.size()) * (
565+
forDelegation ? P2CS_OUT_SIZE : CTXOUT_REGULAR_SIZE);
566+
nBytes += CTXOUT_REGULAR_SIZE;
567+
} else {
568+
nBytes = nBytesInputs + std::max(1, payAmounts.size()) * SPENDDESCRIPTION_SIZE;
569+
nBytes += SPENDDESCRIPTION_SIZE;
570+
}
571+
560572
// nVersion, nLockTime and vin/vout len sizes
561573
nBytes += 10;
562574

563-
// Fee
564-
nPayFee = CWallet::GetMinimumFee(nBytes, nTxConfirmTarget, mempool);
575+
// Fee (default K fixed for shielded fee for now)
576+
nPayFee = GetMinRelayFee(nBytes, false) * (fSelectTransparent ? 1 : DEFAULT_SHIELDEDTXFEE_K);
565577

566578
if (nPayAmount > 0) {
567579
nChange = nAmount - nPayFee - nPayAmount;
568580

569581
// Never create dust outputs; if we would, just add the dust to the fee.
570-
if (nChange > 0 && nChange < CENT) {
571-
CTxOut txout(nChange, (CScript)std::vector<unsigned char>(24, 0));
572-
if (IsDust(txout, ::minRelayTxFee)) {
573-
nPayFee += nChange;
574-
nChange = 0;
575-
}
582+
CAmount dustThreshold = fSelectTransparent ? GetDustThreshold(minRelayTxFee) :
583+
GetShieldedDustThreshold(minRelayTxFee);
584+
if (nChange > 0 && nChange < dustThreshold) {
585+
nPayFee += nChange;
586+
nChange = 0;
576587
}
577588

578589
if (nChange == 0)
579-
nBytes -= P2PKH_OUT_SIZE;
590+
nBytes -= (fSelectTransparent ? CTXOUT_REGULAR_SIZE : SPENDDESCRIPTION_SIZE);
580591
}
581592

582593
// after fee

0 commit comments

Comments
 (0)