From 6f7f19fdcc8aae3791c50e03b122fc93b3f0f4e8 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Wed, 28 Jan 2015 10:35:17 +0300 Subject: [PATCH] fix updateDarksendProgress / add isDenominatedAmount and GetNormalizedAnonymizedBalance --- src/qt/overviewpage.cpp | 65 +++++++++++++++++++---------------------- src/wallet.cpp | 33 +++++++++++++++++++++ src/wallet.h | 3 ++ 3 files changed, 66 insertions(+), 35 deletions(-) diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index 115d998585..c95bd9ea24 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -250,58 +250,53 @@ void OverviewPage::showOutOfSyncWarning(bool fShow) ui->labelTransactionsStatus->setVisible(fShow); } -void OverviewPage::updateDarksendProgress(){ +void OverviewPage::updateDarksendProgress() +{ if(IsInitialBlockDownload()) return; - int64_t balance = pwalletMain->GetBalance(); - if(balance == 0){ + int64_t nBalance = pwalletMain->GetBalance(); + if(nBalance == 0) + { ui->darksendProgress->setValue(0); QString s("No inputs detected"); ui->darksendProgress->setToolTip(s); return; } - std::ostringstream convert; - - // ** find the coins we'll use - std::vector vCoins; - int64_t nValueMin = 0.01*COIN; - int64_t nValueIn = 0; - - if(pwalletMain->GetDenominatedBalance(true, true) > 0){ //get denominated unconfirmed inputs + //get denominated unconfirmed inputs + if(pwalletMain->GetDenominatedBalance(true, true) > 0) + { QString s("Found unconfirmed denominated outputs, will wait till they confirm to recalculate."); ui->darksendProgress->setToolTip(s); return; } - - // Calculate total mixable funds - if (!pwalletMain->SelectCoinsDark(nValueMin, 999999*COIN, vCoins, nValueIn, -2, 10)) { - ui->darksendProgress->setValue(0); - QString s("No inputs detected (2)"); - ui->darksendProgress->setToolTip(s); - return; - } - double nTotalValue = pwalletMain->GetTotalValue(vCoins)/CENT; - //Get the anon threshold - double max = nAnonymizeDarkcoinAmount*100; - //If it's more than the wallet amount, limit to that. - if(max > (double)nTotalValue) max = (double)nTotalValue; - //denominated balance / anon threshold -- the percentage that we've completed - double b = ((double)(pwalletMain->GetDenominatedBalance()/CENT) / max); - if(b > 1) b = 1; + int64_t nMaxToAnonymize = nAnonymizeDarkcoinAmount*COIN; - //Get average rounds of inputs - double a = (double)pwalletMain->GetAverageAnonymizedRounds() / (double)nDarksendRounds; - if(a > 1) a = 1; + // If it's more than the wallet amount, limit to that. + if(nMaxToAnonymize > nBalance) nMaxToAnonymize = nBalance; - double val = a*b*100; - if(val < 0) val = 0; - if(val > 100) val = 100; + if(nMaxToAnonymize == 0) return; - ui->darksendProgress->setValue(val);//rounds avg * denom progress - convert << "Inputs have an average of " << pwalletMain->GetAverageAnonymizedRounds() << " of " << nDarksendRounds << " rounds (" << a << "/" << b << ")"; + // calculate parts of the progress, each of them shouldn't be higher than 1: + // mixing progress of denominated balance + float denomPart = (float)pwalletMain->GetNormalizedAnonymizedBalance() / pwalletMain->GetDenominatedBalance(); + denomPart = denomPart > 1 ? 1 : denomPart; + + // % of fully anonymized balance + float 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; + + // apply some weights to them (sum should be <=100) and calculate the whole progress + int progress = 80 * denomPart + 20 * anonPart; + if(progress > 100) progress = 100; + + ui->darksendProgress->setValue(progress); + + std::ostringstream convert; + convert << "Progress: " << progress << "%, inputs have an average of " << pwalletMain->GetAverageAnonymizedRounds() << " of " << nDarksendRounds << " rounds"; QString s(convert.str().c_str()); ui->darksendProgress->setToolTip(s); } diff --git a/src/wallet.cpp b/src/wallet.cpp index bfffabb7a0..eccae4f601 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -767,6 +767,14 @@ int64_t CWallet::IsDenominated(const CTxIn &txin) const return 0; } +bool CWallet::IsDenominatedAmount(int64_t nInputAmount) const +{ + BOOST_FOREACH(int64_t d, darkSendDenominations) + if(nInputAmount == d) + return true; + return false; +} + bool CWallet::IsChange(const CTxOut& txout) const { CTxDestination address; @@ -1141,6 +1149,31 @@ double CWallet::GetAverageAnonymizedRounds() const return fTotal/fCount; } +int64_t CWallet::GetNormalizedAnonymizedBalance() const +{ + int64_t nTotal = 0; + + { + LOCK(cs_wallet); + for (map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) + { + const CWalletTx* pcoin = &(*it).second; + for (unsigned int i = 0; i < pcoin->vout.size(); i++) { + + COutput out = COutput(pcoin, i, pcoin->GetDepthInMainChain()); + CTxIn vin = CTxIn(out.tx->GetHash(), out.i); + + if(IsSpent(out.tx->GetHash(), i) || !IsMine(pcoin->vout[i]) || !IsDenominated(vin)) continue; + + int rounds = GetInputDarksendRounds(vin); + nTotal += pcoin->vout[i].nValue * rounds / nDarksendRounds; + } + } + } + + return nTotal; +} + int64_t CWallet::GetDenominatedBalance(bool onlyDenom, bool onlyUnconfirmed) const { int64_t nTotal = 0; diff --git a/src/wallet.h b/src/wallet.h index 906a16a04c..d22842f40d 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -279,6 +279,7 @@ public: int64_t GetImmatureBalance() const; int64_t GetAnonymizedBalance() const; double GetAverageAnonymizedRounds() const; + int64_t GetNormalizedAnonymizedBalance() const; int64_t GetDenominatedBalance(bool onlyDenom=true, bool onlyUnconfirmed=false) const; bool CreateTransaction(const std::vector >& vecSend, @@ -325,6 +326,8 @@ public: return ret; } + bool IsDenominatedAmount(int64_t nInputAmount) const; + bool IsMine(const CTxIn& txin) const; int64_t GetDebit(const CTxIn& txin) const; bool IsMine(const CTxOut& txout) const