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

GetOutPointPrivateSendRounds readability #2149

Merged
4 changes: 2 additions & 2 deletions src/qt/coincontroldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ void CoinControlDialog::viewItemChanged(QTreeWidgetItem* item, int column)
item->setCheckState(COLUMN_CHECKBOX, Qt::Unchecked);
else {
coinControl->Select(outpt);
int nRounds = pwalletMain->GetOutpointPrivateSendRounds(outpt);
int nRounds = pwalletMain->GetCappedOutpointPrivateSendRounds(outpt);
if (coinControl->fUsePrivateSend && nRounds < privateSendClient.nPrivateSendRounds) {
QMessageBox::warning(this, windowTitle(),
tr("Non-anonymized input selected. <b>PrivateSend will be disabled.</b><br><br>If you still want to use PrivateSend, please deselect all non-nonymized inputs first and then check PrivateSend checkbox again."),
Expand Down Expand Up @@ -781,7 +781,7 @@ void CoinControlDialog::updateView()

// PrivateSend rounds
COutPoint outpoint = COutPoint(out.tx->tx->GetHash(), out.i);
int nRounds = pwalletMain->GetOutpointPrivateSendRounds(outpoint);
int nRounds = pwalletMain->GetCappedOutpointPrivateSendRounds(outpoint);

if (nRounds >= 0 || fDebug) itemOutput->setText(COLUMN_PRIVATESEND_ROUNDS, QString::number(nRounds));
else itemOutput->setText(COLUMN_PRIVATESEND_ROUNDS, tr("n/a"));
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2647,7 +2647,7 @@ UniValue listunspent(const JSONRPCRequest& request)
entry.push_back(Pair("confirmations", out.nDepth));
entry.push_back(Pair("spendable", out.fSpendable));
entry.push_back(Pair("solvable", out.fSolvable));
entry.push_back(Pair("ps_rounds", pwalletMain->GetOutpointPrivateSendRounds(COutPoint(out.tx->GetHash(), out.i))));
entry.push_back(Pair("ps_rounds", pwalletMain->GetCappedOutpointPrivateSendRounds(COutPoint(out.tx->GetHash(), out.i))));
results.push_back(entry);
}

Expand Down
20 changes: 10 additions & 10 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1506,10 +1506,10 @@ int CWallet::GetRealOutpointPrivateSendRounds(const COutPoint& outpoint, int nRo
}

// respect current settings
int CWallet::GetOutpointPrivateSendRounds(const COutPoint& outpoint) const
int CWallet::GetCappedOutpointPrivateSendRounds(const COutPoint& outpoint) const
{
LOCK(cs_wallet);
int realPrivateSendRounds = GetRealOutpointPrivateSendRounds(outpoint, 0);
int realPrivateSendRounds = GetRealOutpointPrivateSendRounds(outpoint);
return realPrivateSendRounds > privateSendClient.nPrivateSendRounds ? privateSendClient.nPrivateSendRounds : realPrivateSendRounds;
}

Expand Down Expand Up @@ -2172,7 +2172,7 @@ CAmount CWalletTx::GetAnonymizedCredit(bool fUseCache) const

if(pwallet->IsSpent(hashTx, i) || !pwallet->IsDenominated(outpoint)) continue;

const int nRounds = pwallet->GetOutpointPrivateSendRounds(outpoint);
const int nRounds = pwallet->GetCappedOutpointPrivateSendRounds(outpoint);
if(nRounds >= privateSendClient.nPrivateSendRounds){
nCredit += pwallet->GetCredit(txout, ISMINE_SPENDABLE);
if (!MoneyRange(nCredit))
Expand Down Expand Up @@ -2420,7 +2420,7 @@ float CWallet::GetAverageAnonymizedRounds() const
for (const auto& outpoint : setWalletUTXO) {
if(!IsDenominated(outpoint)) continue;

nTotal += GetOutpointPrivateSendRounds(outpoint);
nTotal += GetCappedOutpointPrivateSendRounds(outpoint);
nCount++;
}

Expand All @@ -2444,7 +2444,7 @@ CAmount CWallet::GetNormalizedAnonymizedBalance() const
if (!IsDenominated(outpoint)) continue;
if (it->second.GetDepthInMainChain() < 0) continue;

int nRounds = GetOutpointPrivateSendRounds(outpoint);
int nRounds = GetCappedOutpointPrivateSendRounds(outpoint);
nTotal += it->second.tx->vout[outpoint.n].nValue * nRounds / privateSendClient.nPrivateSendRounds;
}

Expand Down Expand Up @@ -2844,7 +2844,7 @@ bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAm

if(nCoinType == ONLY_DENOMINATED) {
COutPoint outpoint = COutPoint(out.tx->GetHash(),out.i);
int nRounds = GetOutpointPrivateSendRounds(outpoint);
int nRounds = GetCappedOutpointPrivateSendRounds(outpoint);
// make sure it's actually anonymized
if(nRounds < privateSendClient.nPrivateSendRounds) continue;
}
Expand All @@ -2867,7 +2867,7 @@ bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAm
//make sure it's the denom we're looking for, round the amount up to smallest denom
if(out.tx->tx->vout[out.i].nValue == nDenom && nValueRet + nDenom < nTargetValue + nSmallestDenom) {
COutPoint outpoint = COutPoint(out.tx->GetHash(),out.i);
int nRounds = GetOutpointPrivateSendRounds(outpoint);
int nRounds = GetCappedOutpointPrivateSendRounds(outpoint);
// make sure it's actually anonymized
if(nRounds < privateSendClient.nPrivateSendRounds) continue;
nValueRet += nDenom;
Expand Down Expand Up @@ -3028,7 +3028,7 @@ bool CWallet::SelectCoinsByDenominations(int nDenom, CAmount nValueMin, CAmount

CTxIn txin = CTxIn(out.tx->GetHash(), out.i);

int nRounds = GetOutpointPrivateSendRounds(txin.prevout);
int nRounds = GetCappedOutpointPrivateSendRounds(txin.prevout);
if(nRounds >= nPrivateSendRoundsMax) continue;
if(nRounds < nPrivateSendRoundsMin) continue;

Expand Down Expand Up @@ -3112,7 +3112,7 @@ bool CWallet::SelectCoinsGrouppedByAddresses(std::vector<CompactTallyItem>& vecT
// otherwise they will just lead to higher fee / lower priority
if(wtx.tx->vout[i].nValue <= nSmallestDenom/10) continue;
// ignore anonymized
if(GetOutpointPrivateSendRounds(COutPoint(outpoint.hash, i)) >= privateSendClient.nPrivateSendRounds) continue;
if(GetCappedOutpointPrivateSendRounds(COutPoint(outpoint.hash, i)) >= privateSendClient.nPrivateSendRounds) continue;
}

CompactTallyItem& item = mapTally[txdest];
Expand Down Expand Up @@ -3178,7 +3178,7 @@ bool CWallet::SelectCoinsDark(CAmount nValueMin, CAmount nValueMax, std::vector<
if(nValueRet + out.tx->tx->vout[out.i].nValue <= nValueMax){
CTxIn txin = CTxIn(out.tx->GetHash(),out.i);

int nRounds = GetOutpointPrivateSendRounds(txin.prevout);
int nRounds = GetCappedOutpointPrivateSendRounds(txin.prevout);
if(nRounds >= nPrivateSendRoundsMax) continue;
if(nRounds < nPrivateSendRoundsMin) continue;

Expand Down
4 changes: 2 additions & 2 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -820,9 +820,9 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
int CountInputsWithAmount(CAmount nInputAmount);

// get the PrivateSend chain depth for a given input
int GetRealOutpointPrivateSendRounds(const COutPoint& outpoint, int nRounds) const;
int GetRealOutpointPrivateSendRounds(const COutPoint& outpoint, int nRounds = 0) const;
// respect current settings
int GetOutpointPrivateSendRounds(const COutPoint& outpoint) const;
int GetCappedOutpointPrivateSendRounds(const COutPoint& outpoint) const;

bool IsDenominated(const COutPoint& outpoint) const;

Expand Down