From a4520af05652f12ad3f06036dfe7d8e4c6824a88 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Tue, 7 Jul 2015 10:21:13 +0300 Subject: [PATCH] (Yet) another attempt to get progress displayed right --- src/qt/overviewpage.cpp | 34 +++++++++++++++---------------- src/wallet.cpp | 44 ++++++++++++++++++++--------------------- src/wallet.h | 2 +- 3 files changed, 38 insertions(+), 42 deletions(-) diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index 50f466593..e1cbe9b5d 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -355,32 +355,30 @@ void OverviewPage::updateDarksendProgress() } ui->labelAmountRounds->setText(strAmountAndRounds); - // calculate parts of the progress, each of them shouldn't be higher than 1: - // mixing progress of denominated balance - int64_t denominatedBalance = pwalletMain->GetDenominatedBalance(); + // calculate parts of the progress, each of them shouldn't be higher than 1 + // progress of denominating float denomPart = 0; - if(denominatedBalance > 0) - { - denomPart = (float)pwalletMain->GetNormalizedAnonymizedBalance() / denominatedBalance; - denomPart = denomPart > 1 ? 1 : denomPart; - } - - // % of fully anonymized balance + // mixing progress of denominated balance float anonPart = 0; - if(nMaxToAnonymize > 0) - { - anonPart = (float)pwalletMain->GetAnonymizedBalance() / nMaxToAnonymize; - // if anonPart is > 1 then we are done, make denomPart equal 1 too - anonPart = anonPart > 1 ? (denomPart = 1, 1) : anonPart; - } + + int64_t denominatedBalance = pwalletMain->GetDenominatedBalance() + nDenominatedUnconfirmedBalance; + denomPart = (float)denominatedBalance / nMaxToAnonymize; + denomPart = denomPart > 1 ? 1 : denomPart; + + anonPart = (float)pwalletMain->GetNormalizedAnonymizedBalance() / nMaxToAnonymize; + // if anonPart is > 1 then we are done, make denomPart equal 1 too + anonPart = anonPart > 1 ? (denomPart = 1, 1) : anonPart; // apply some weights to them (sum should be <=100) and calculate the whole progress - int progress = 80 * denomPart + 20 * anonPart; + denomPart = ceilf((denomPart * 20) * 100) / 100; + anonPart = ceilf((anonPart * 80) * 100) / 100; + float progress = denomPart + anonPart; if(progress >= 100) progress = 100; ui->darksendProgress->setValue(progress); - QString strToolPip = tr("Progress: %1% (inputs have an average of %2 of %n rounds)", "", nDarksendRounds).arg(progress).arg(pwalletMain->GetAverageAnonymizedRounds()); + QString strToolPip = tr("Progress: %1% (%2% + %3%; denominated inputs have %4 of %n rounds on average)", "", nDarksendRounds) + .arg(progress).arg(denomPart).arg(anonPart).arg(pwalletMain->GetAverageAnonymizedRounds()); ui->darksendProgress->setToolTip(strToolPip); } diff --git a/src/wallet.cpp b/src/wallet.cpp index 61d930207..6ff230817 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1240,6 +1240,8 @@ CAmount CWallet::GetAnonymizedBalance() const return nTotal; } +// Note: calculated including unconfirmed, +// that's ok as long as we use it for informational purposes only double CWallet::GetAverageAnonymizedRounds() const { double fTotal = 0; @@ -1251,20 +1253,17 @@ double CWallet::GetAverageAnonymizedRounds() const { const CWalletTx* pcoin = &(*it).second; - if (pcoin->IsTrusted()) - { - uint256 hash = (*it).first; + uint256 hash = (*it).first; - for (unsigned int i = 0; i < pcoin->vout.size(); i++) { + for (unsigned int i = 0; i < pcoin->vout.size(); i++) { - CTxIn vin = CTxIn(hash, i); + CTxIn vin = CTxIn(hash, i); - if(IsSpent(hash, i) || !IsMine(pcoin->vout[i]) || !IsDenominated(vin)) continue; + if(IsSpent(hash, i) || !IsMine(pcoin->vout[i]) || !IsDenominated(vin)) continue; - int rounds = GetInputDarksendRounds(vin); - fTotal += (float)rounds; - fCount += 1; - } + int rounds = GetInputDarksendRounds(vin); + fTotal += (float)rounds; + fCount += 1; } } } @@ -1274,6 +1273,8 @@ double CWallet::GetAverageAnonymizedRounds() const return fTotal/fCount; } +// Note: calculated including unconfirmed, +// that's ok as long as we use it for informational purposes only CAmount CWallet::GetNormalizedAnonymizedBalance() const { CAmount nTotal = 0; @@ -1284,19 +1285,16 @@ CAmount CWallet::GetNormalizedAnonymizedBalance() const { const CWalletTx* pcoin = &(*it).second; - if (pcoin->IsTrusted()) - { - uint256 hash = (*it).first; + uint256 hash = (*it).first; - for (unsigned int i = 0; i < pcoin->vout.size(); i++) { + for (unsigned int i = 0; i < pcoin->vout.size(); i++) { - CTxIn vin = CTxIn(hash, i); + CTxIn vin = CTxIn(hash, i); - if(IsSpent(hash, i) || !IsMine(pcoin->vout[i]) || !IsDenominated(vin)) continue; + if(IsSpent(hash, i) || !IsMine(pcoin->vout[i]) || !IsDenominated(vin)) continue; - int rounds = GetInputDarksendRounds(vin); - nTotal += pcoin->vout[i].nValue * rounds / nDarksendRounds; - } + int rounds = GetInputDarksendRounds(vin); + nTotal += pcoin->vout[i].nValue * rounds / nDarksendRounds; } } } @@ -1304,7 +1302,7 @@ CAmount CWallet::GetNormalizedAnonymizedBalance() const return nTotal; } -CAmount CWallet::GetDenominatedBalance(bool onlyDenom, bool onlyUnconfirmed, bool includeAlreadyAnonymized) const +CAmount CWallet::GetDenominatedBalance(bool denom, bool unconfirmed, bool includeAlreadyAnonymized) const { CAmount nTotal = 0; { @@ -1318,15 +1316,15 @@ CAmount CWallet::GetDenominatedBalance(bool onlyDenom, bool onlyUnconfirmed, boo // skip conflicted if(nDepth < 0) continue; - bool unconfirmed = (!IsFinalTx(*pcoin) || (!pcoin->IsTrusted() && nDepth == 0)); - if(onlyUnconfirmed != unconfirmed) continue; + bool isUnconfirmed = (!IsFinalTx(*pcoin) || (!pcoin->IsTrusted() && nDepth == 0)); + if(unconfirmed != isUnconfirmed) continue; uint256 hash = (*it).first; for (unsigned int i = 0; i < pcoin->vout.size(); i++) { if(IsSpent(hash, i)) continue; if(!IsMine(pcoin->vout[i])) continue; - if(onlyDenom != IsDenominatedAmount(pcoin->vout[i].nValue)) continue; + if(denom != IsDenominatedAmount(pcoin->vout[i].nValue)) continue; CTxIn vin = CTxIn(hash, i); int rounds = GetInputDarksendRounds(vin); diff --git a/src/wallet.h b/src/wallet.h index def7f903d..f0ac8f4db 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -314,7 +314,7 @@ public: CAmount GetAnonymizedBalance() const; double GetAverageAnonymizedRounds() const; CAmount GetNormalizedAnonymizedBalance() const; - CAmount GetDenominatedBalance(bool onlyDenom=true, bool onlyUnconfirmed=false, bool includeAlreadyAnonymized = true) const; + CAmount GetDenominatedBalance(bool denom=true, bool unconfirmed=false, bool includeAlreadyAnonymized = true) const; CAmount GetWatchOnlyBalance() const; CAmount GetUnconfirmedWatchOnlyBalance() const; CAmount GetImmatureWatchOnlyBalance() const;