From 84b0e6f587720525488650ea78e59ec5b75a7a8d Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Thu, 29 Jan 2015 13:36:18 +0300 Subject: [PATCH] use IsDenominatedAmount instead of loops and GetInputDarksendRounds where applicable --- src/darksend.cpp | 37 +++++++++++++----------------------- src/qt/transactionrecord.cpp | 6 ++---- src/wallet.cpp | 34 +++++++-------------------------- src/wallet.h | 4 ++-- 4 files changed, 24 insertions(+), 57 deletions(-) diff --git a/src/darksend.cpp b/src/darksend.cpp index 089f7f3104..fe509e5714 100644 --- a/src/darksend.cpp +++ b/src/darksend.cpp @@ -394,45 +394,34 @@ int GetInputDarksendRounds(CTxIn in, int rounds) padding.insert(0, ((rounds+1)*5)+3, ' '); CWalletTx tx; - if(pwalletMain->GetTransaction(in.prevout.hash,tx)){ + if(pwalletMain->GetTransaction(in.prevout.hash,tx)) + { // bounds check if(in.prevout.n >= tx.vout.size()) return -4; if(tx.vout[in.prevout.n].nValue == DARKSEND_FEE) return -3; - if(rounds == 0){ //make sure the final output is non-denominate - bool found = false; - BOOST_FOREACH(int64_t d, darkSendDenominations) - if(tx.vout[in.prevout.n].nValue == d) found = true; + //make sure the final output is non-denominate + if(rounds == 0 && !pwalletMain->IsDenominatedAmount(tx.vout[in.prevout.n].nValue)) return -2; //NOT DENOM - if(!found) { - //LogPrintf(" - NOT DENOM\n"); - return -2; - } - } bool found = false; - - BOOST_FOREACH(CTxOut out, tx.vout){ - BOOST_FOREACH(int64_t d, darkSendDenominations) - if(out.nValue == d) - found = true; - } - - if(!found) { - //LogPrintf(" - NOT FOUND\n"); - return rounds - 1; // -1 because of the pre-mixing creation of denominated amounts + BOOST_FOREACH(CTxOut out, tx.vout) + { + found = pwalletMain->IsDenominatedAmount(out.nValue); + if(found) break; // no need to loop more } + if(!found) return rounds - 1; //NOT FOUND, "-1" because of the pre-mixing creation of denominated amounts // find my vin and look that up - BOOST_FOREACH(CTxIn in2, tx.vin) { - if(pwalletMain->IsMine(in2)){ + BOOST_FOREACH(CTxIn in2, tx.vin) + { + if(pwalletMain->IsMine(in2)) + { //LogPrintf("rounds :: %s %s %d NEXT\n", padding.c_str(), in.ToString().c_str(), rounds); int n = GetInputDarksendRounds(in2, rounds+1); if(n != -3) return n; } } - } else { - //LogPrintf("rounds :: %s %s %d NOTFOUND\n", padding.c_str(), in.ToString().c_str(), rounds); } return rounds-1; diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index 883f2df6d7..08f877c6a5 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -175,10 +175,8 @@ QList TransactionRecord::decomposeTransaction(const CWallet * for (unsigned int nOut = 0; nOut < wtx.vout.size(); nOut++) { const CTxOut& txout = wtx.vout[nOut]; - - BOOST_FOREACH(int64_t d, darkSendDenominations) - if(txout.nValue == d) - isDarksent = true; + isDarksent = wallet->IsDenominatedAmount(txout.nValue); + if(isDarksent) break; // no need to loop more } parts.append(TransactionRecord(hash, nTime, isDarksent ? TransactionRecord::DarksendDenominate : TransactionRecord::Other, "", nNet, 0)); diff --git a/src/wallet.cpp b/src/wallet.cpp index eccae4f601..edc5b1daa4 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -747,7 +747,7 @@ int64_t CWallet::GetDebit(const CTxIn &txin) const return 0; } -int64_t CWallet::IsDenominated(const CTxIn &txin) const +bool CWallet::IsDenominated(const CTxIn &txin) const { { LOCK(cs_wallet); @@ -755,16 +755,10 @@ int64_t CWallet::IsDenominated(const CTxIn &txin) const if (mi != mapWallet.end()) { const CWalletTx& prev = (*mi).second; - if (txin.prevout.n < prev.vout.size()){ - BOOST_FOREACH(int64_t d, darkSendDenominations){ - if(prev.vout[txin.prevout.n].nValue == d) { - return true; - } - } - } + if (txin.prevout.n < prev.vout.size()) return IsDenominatedAmount(prev.vout[txin.prevout.n].nValue); } } - return 0; + return false; } bool CWallet::IsDenominatedAmount(int64_t nInputAmount) const @@ -1193,9 +1187,7 @@ int64_t CWallet::GetDenominatedBalance(bool onlyDenom, bool onlyUnconfirmed) con if(IsSpent(out.tx->GetHash(), i)) continue; if(!IsMine(pcoin->vout[i])) continue; if(onlyUnconfirmed != unconfirmed) continue; - - int rounds = GetInputDarksendRounds(vin); - if(onlyDenom != (rounds>=0)) continue; + if(onlyDenom != IsDenominatedAmount(pcoin->vout[i].nValue)) continue; nTotal += pcoin->vout[i].nValue; } @@ -1266,16 +1258,11 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const if(coin_type == ONLY_DENOMINATED) { //should make this a vector - COutput out = COutput(pcoin, i, pcoin->GetDepthInMainChain()); - CTxIn vin = CTxIn(out.tx->GetHash(), out.i); - int rounds = GetInputDarksendRounds(vin); - if(rounds >= 0) found = true; + found = IsDenominatedAmount(pcoin->vout[i].nValue); } else if(coin_type == ONLY_NONDENOMINATED || coin_type == ONLY_NONDENOMINATED_NOTMN) { found = true; if (IsCollateralAmount(pcoin->vout[i].nValue)) continue; // do not use collateral amounts - BOOST_FOREACH(int64_t d, darkSendDenominations) - if(pcoin->vout[i].nValue == d) - found = false; + found = !IsDenominatedAmount(pcoin->vout[i].nValue); if(found && coin_type == ONLY_NONDENOMINATED_NOTMN) found = (pcoin->vout[i].nValue != 1000*COIN); // do not use MN funds } else { found = true; @@ -1392,14 +1379,7 @@ bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, int nConfMine, int nConfT int i = output.i; int64_t n = pcoin->vout[i].nValue; - if (tryDenom == 0) // first run? - { - bool found = false; - BOOST_FOREACH(int64_t d, darkSendDenominations) // loop through predefined denoms - if(n == d) - found = true; - if (found) continue; // we don't want denom values on first run - } + if (tryDenom == 0 && IsDenominatedAmount(n)) continue; // we don't want denom values on first run pair > coin = make_pair(n,make_pair(pcoin, i)); diff --git a/src/wallet.h b/src/wallet.h index d22842f40d..0e488c1101 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -309,9 +309,9 @@ public: std::set GetAccountAddresses(std::string strAccount) const; - int64_t IsDenominated(const CTxIn &txin) const; + bool IsDenominated(const CTxIn &txin) const; - int64_t IsDenominated(const CTransaction& tx) const + bool IsDenominated(const CTransaction& tx) const { /* Return false if ANY inputs are non-denom