Merge pull request #137 from UdjinM6/fix_ds_progress

fix updateDarksendProgress / add isDenominatedAmount and GetNormalizedAnonymizedBalance - v0.11.1.x
This commit is contained in:
evan82 2015-01-28 11:59:51 -07:00
commit 3edcf4beda
3 changed files with 66 additions and 35 deletions

View File

@ -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<CTxIn> 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);
}

View File

@ -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<uint256, CWalletTx>::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;

View File

@ -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<std::pair<CScript, int64_t> >& 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