Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix updateDarksendProgress / add isDenominatedAmount and GetNormalizedAnonymizedBalance #136

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 32 additions & 37 deletions src/qt/overviewpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

//Get the anon threshold
int64_t nMaxToAnonymize = nAnonymizeDarkcoinAmount*COIN;

// 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;
// If it's more than the wallet amount, limit to that.
if(nMaxToAnonymize > nBalance) nMaxToAnonymize = nBalance;

//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;

//Get average rounds of inputs
double a = (double)pwalletMain->GetAverageAnonymizedRounds() / (double)nDarksendRounds;
if(a > 1) a = 1;

double val = a*b*100;
if(val < 0) val = 0;
if(val > 100) val = 100;

ui->darksendProgress->setValue(val);//rounds avg * denom progress
convert << "Inputs have an average of " << pwalletMain->GetAverageAnonymizedRounds() << " of " << nDarksendRounds << " rounds (" << a << "/" << b << ")";
if(nMaxToAnonymize == 0) return;

// 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);
}
Expand Down
33 changes: 33 additions & 0 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ class CWallet : public CCryptoKeyStore, public CWalletInterface
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,
Expand Down Expand Up @@ -325,6 +326,8 @@ class CWallet : public CCryptoKeyStore, public CWalletInterface
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
Expand Down