55
66#include < wallet/coinjoin.h>
77
8- #include < key_io.h>
98#include < coinjoin/common.h>
109#include < coinjoin/options.h>
1110#include < evo/dmn_types.h>
11+ #include < key_io.h>
1212#include < wallet/receive.h>
1313#include < wallet/spend.h>
14- #include < wallet/wallet.h>
1514#include < wallet/transaction.h>
15+ #include < wallet/wallet.h>
1616
1717namespace wallet {
1818void CWallet::InitCJSaltFromDb ()
@@ -78,21 +78,20 @@ bool CWallet::SelectTxDSInsByDenomination(int nDenom, CAmount nValueMax, std::ve
7878 nValueTotal += nValue;
7979 vecTxDSInRet.emplace_back (CTxDSIn (txin, scriptPubKey, nRounds));
8080 setRecentTxIds.emplace (txHash);
81- WalletCJLogPrint (this , " CWallet::%s -- hash: %s, nValue: %d.%08d\n " ,
82- __func__, txHash. ToString (), nValue / COIN, nValue % COIN);
81+ WalletCJLogPrint (this , " CWallet::%s -- hash: %s, nValue: %d.%08d\n " , __func__, txHash. ToString (), nValue / COIN,
82+ nValue % COIN);
8383 }
8484
8585 WalletCJLogPrint (this , " CWallet::%s -- setRecentTxIds.size(): %d\n " , __func__, setRecentTxIds.size ());
8686
8787 return nValueTotal > 0 ;
8888}
8989
90- struct CompareByPriority
91- {
92- bool operator ()(const COutput& t1,
93- const COutput& t2) const
90+ struct CompareByPriority {
91+ bool operator ()(const COutput& t1, const COutput& t2) const
9492 {
95- return CoinJoin::CalculateAmountPriority (t1.GetEffectiveValue ()) > CoinJoin::CalculateAmountPriority (t2.GetEffectiveValue ());
93+ return CoinJoin::CalculateAmountPriority (t1.GetEffectiveValue ()) >
94+ CoinJoin::CalculateAmountPriority (t2.GetEffectiveValue ());
9695 }
9796};
9897
@@ -121,21 +120,24 @@ bool CWallet::SelectDenominatedAmounts(CAmount nValueMax, std::set<CAmount>& set
121120 return nValueTotal >= CoinJoin::GetSmallestDenomination ();
122121}
123122
124- std::vector<CompactTallyItem> CWallet::SelectCoinsGroupedByAddresses (bool fSkipDenominated , bool fAnonymizable , bool fSkipUnconfirmed , int nMaxOupointsPerAddress) const
123+ std::vector<CompactTallyItem> CWallet::SelectCoinsGroupedByAddresses (bool fSkipDenominated , bool fAnonymizable ,
124+ bool fSkipUnconfirmed , int nMaxOupointsPerAddress) const
125125{
126126 LOCK (cs_wallet);
127127
128128 isminefilter filter = ISMINE_SPENDABLE;
129129
130130 // Try using the cache for already confirmed mixable inputs.
131131 // This should only be used if nMaxOupointsPerAddress was NOT specified.
132- if (nMaxOupointsPerAddress == -1 && fAnonymizable && fSkipUnconfirmed ) {
133- if (fSkipDenominated && fAnonymizableTallyCachedNonDenom ) {
134- LogPrint (BCLog::SELECTCOINS, " SelectCoinsGroupedByAddresses - using cache for non-denom inputs %d\n " , vecAnonymizableTallyCachedNonDenom.size ());
132+ if (nMaxOupointsPerAddress == -1 && fAnonymizable && fSkipUnconfirmed ) {
133+ if (fSkipDenominated && fAnonymizableTallyCachedNonDenom ) {
134+ LogPrint (BCLog::SELECTCOINS, " SelectCoinsGroupedByAddresses - using cache for non-denom inputs %d\n " ,
135+ vecAnonymizableTallyCachedNonDenom.size ());
135136 return vecAnonymizableTallyCachedNonDenom;
136137 }
137- if (!fSkipDenominated && fAnonymizableTallyCached ) {
138- LogPrint (BCLog::SELECTCOINS, " SelectCoinsGroupedByAddresses - using cache for all inputs %d\n " , vecAnonymizableTallyCached.size ());
138+ if (!fSkipDenominated && fAnonymizableTallyCached ) {
139+ LogPrint (BCLog::SELECTCOINS, " SelectCoinsGroupedByAddresses - using cache for all inputs %d\n " ,
140+ vecAnonymizableTallyCached.size ());
139141 return vecAnonymizableTallyCached;
140142 }
141143 }
@@ -146,7 +148,6 @@ std::vector<CompactTallyItem> CWallet::SelectCoinsGroupedByAddresses(bool fSkipD
146148 std::map<CTxDestination, CompactTallyItem> mapTally;
147149 std::set<uint256> setWalletTxesCounted;
148150 for (const auto & outpoint : setWalletUTXO) {
149-
150151 if (!setWalletTxesCounted.emplace (outpoint.hash ).second ) continue ;
151152
152153 const auto it = mapWallet.find (outpoint.hash );
@@ -163,23 +164,25 @@ std::vector<CompactTallyItem> CWallet::SelectCoinsGroupedByAddresses(bool fSkipD
163164 if (!ExtractDestination (wtx.tx ->vout [i].scriptPubKey , txdest)) continue ;
164165
165166 isminefilter mine = IsMine (txdest);
166- if (!(mine & filter)) continue ;
167+ if (!(mine & filter)) continue ;
167168
168169 auto itTallyItem = mapTally.find (txdest);
169- if (nMaxOupointsPerAddress != -1 && itTallyItem != mapTally.end () && int64_t (itTallyItem->second .outpoints .size ()) >= nMaxOupointsPerAddress) continue ;
170+ if (nMaxOupointsPerAddress != -1 && itTallyItem != mapTally.end () &&
171+ int64_t (itTallyItem->second .outpoints .size ()) >= nMaxOupointsPerAddress)
172+ continue ;
170173
171174 COutPoint target_outpoint (outpoint.hash , i);
172- if (IsSpent (target_outpoint) || IsLockedCoin (target_outpoint)) continue ;
175+ if (IsSpent (target_outpoint) || IsLockedCoin (target_outpoint)) continue ;
173176
174- if (fSkipDenominated && CoinJoin::IsDenominatedAmount (wtx.tx ->vout [i].nValue )) continue ;
177+ if (fSkipDenominated && CoinJoin::IsDenominatedAmount (wtx.tx ->vout [i].nValue )) continue ;
175178
176- if (fAnonymizable ) {
179+ if (fAnonymizable ) {
177180 // ignore collaterals
178- if (CoinJoin::IsCollateralAmount (wtx.tx ->vout [i].nValue )) continue ;
181+ if (CoinJoin::IsCollateralAmount (wtx.tx ->vout [i].nValue )) continue ;
179182 if (fMasternodeMode && dmn_types::IsCollateralAmount (wtx.tx ->vout [i].nValue )) continue ;
180183 // ignore outputs that are 10 times smaller then the smallest denomination
181184 // otherwise they will just lead to higher fee / lower priority
182- if (wtx.tx ->vout [i].nValue <= nSmallestDenom/ 10 ) continue ;
185+ if (wtx.tx ->vout [i].nValue <= nSmallestDenom / 10 ) continue ;
183186 // ignore mixed
184187 if (IsFullyMixed (target_outpoint)) continue ;
185188 }
@@ -197,14 +200,14 @@ std::vector<CompactTallyItem> CWallet::SelectCoinsGroupedByAddresses(bool fSkipD
197200 // NOTE: vecTallyRet is "sorted" by txdest (i.e. address), just like mapTally
198201 std::vector<CompactTallyItem> vecTallyRet;
199202 for (const auto & item : mapTally) {
200- if (fAnonymizable && item.second .nAmount < nSmallestDenom) continue ;
203+ if (fAnonymizable && item.second .nAmount < nSmallestDenom) continue ;
201204 vecTallyRet.push_back (item.second );
202205 }
203206
204207 // Cache already confirmed mixable entries for later use.
205208 // This should only be used if nMaxOupointsPerAddress was NOT specified.
206- if (nMaxOupointsPerAddress == -1 && fAnonymizable && fSkipUnconfirmed ) {
207- if (fSkipDenominated ) {
209+ if (nMaxOupointsPerAddress == -1 && fAnonymizable && fSkipUnconfirmed ) {
210+ if (fSkipDenominated ) {
208211 vecAnonymizableTallyCachedNonDenom = vecTallyRet;
209212 fAnonymizableTallyCachedNonDenom = true ;
210213 } else {
@@ -217,7 +220,7 @@ std::vector<CompactTallyItem> CWallet::SelectCoinsGroupedByAddresses(bool fSkipD
217220 if (LogAcceptDebug (BCLog::SELECTCOINS)) {
218221 std::string strMessage = " SelectCoinsGroupedByAddresses - vecTallyRet:\n " ;
219222 for (const auto & item : vecTallyRet)
220- strMessage += strprintf (" %s %f\n " , EncodeDestination (item.txdest ), float (item.nAmount )/ COIN);
223+ strMessage += strprintf (" %s %f\n " , EncodeDestination (item.txdest ), float (item.nAmount ) / COIN);
221224 LogPrint (BCLog::SELECTCOINS, " %s" , strMessage); /* Continued */
222225 }
223226
@@ -298,7 +301,7 @@ int CWallet::GetRealOutpointCoinJoinRounds(const COutPoint& outpoint, int nRound
298301 }
299302
300303 // make sure the final output is non-denominate
301- if (!CoinJoin::IsDenominatedAmount (txOutRef->nValue )) { // NOT DENOM
304+ if (!CoinJoin::IsDenominatedAmount (txOutRef->nValue )) { // NOT DENOM
302305 *nRoundsRef = -2 ;
303306 WalletCJLogPrint (this , " %s UPDATED %-70s %3d\n " , __func__, outpoint.ToStringShort (), *nRoundsRef);
304307 return *nRoundsRef;
@@ -327,15 +330,17 @@ int CWallet::GetRealOutpointCoinJoinRounds(const COutPoint& outpoint, int nRound
327330 if (InputIsMine (*this , txinNext)) {
328331 int n = GetRealOutpointCoinJoinRounds (txinNext.prevout , nRounds + 1 );
329332 // denom found, find the shortest chain or initially assign nShortest with the first found value
330- if (n >= 0 && (n < nShortest || nShortest == -10 )) {
333+ if (n >= 0 && (n < nShortest || nShortest == -10 )) {
331334 nShortest = n;
332335 fDenomFound = true ;
333336 }
334337 }
335338 }
336339 *nRoundsRef = fDenomFound
337- ? (nShortest >= nRoundsMax - 1 ? nRoundsMax : nShortest + 1 ) // good, we a +1 to the shortest one but only nRoundsMax rounds max allowed
338- : 0 ; // too bad, we are the fist one in that chain
340+ ? (nShortest >= nRoundsMax - 1
341+ ? nRoundsMax
342+ : nShortest + 1 ) // good, we a +1 to the shortest one but only nRoundsMax rounds max allowed
343+ : 0 ; // too bad, we are the fist one in that chain
339344 WalletCJLogPrint (this , " %s UPDATED %-70s %3d\n " , __func__, outpoint.ToStringShort (), *nRoundsRef);
340345 return *nRoundsRef;
341346}
@@ -345,7 +350,8 @@ int CWallet::GetCappedOutpointCoinJoinRounds(const COutPoint& outpoint) const
345350{
346351 LOCK (cs_wallet);
347352 int realCoinJoinRounds = GetRealOutpointCoinJoinRounds (outpoint);
348- return realCoinJoinRounds > CCoinJoinClientOptions::GetRounds () ? CCoinJoinClientOptions::GetRounds () : realCoinJoinRounds;
353+ return realCoinJoinRounds > CCoinJoinClientOptions::GetRounds () ? CCoinJoinClientOptions::GetRounds ()
354+ : realCoinJoinRounds;
349355}
350356
351357void CWallet::ClearCoinJoinRoundsCache ()
@@ -432,10 +438,9 @@ CAmount CWallet::GetAnonymizableBalance(bool fSkipDenominated, bool fSkipUnconfi
432438 const CAmount nMixingCollateral = CoinJoin::GetCollateralAmount ();
433439 for (const auto & item : vecTally) {
434440 bool fIsDenominated = CoinJoin::IsDenominatedAmount (item.nAmount );
435- if (fSkipDenominated && fIsDenominated ) continue ;
441+ if (fSkipDenominated && fIsDenominated ) continue ;
436442 // assume that the fee to create denoms should be mixing collateral at max
437- if (item.nAmount >= nSmallestDenom + (fIsDenominated ? 0 : nMixingCollateral))
438- nTotal += item.nAmount ;
443+ if (item.nAmount >= nSmallestDenom + (fIsDenominated ? 0 : nMixingCollateral)) nTotal += item.nAmount ;
439444 }
440445
441446 return nTotal;
@@ -452,15 +457,15 @@ float CWallet::GetAverageAnonymizedRounds() const
452457
453458 LOCK (cs_wallet);
454459 for (const auto & outpoint : setWalletUTXO) {
455- if (!IsDenominated (outpoint)) continue ;
460+ if (!IsDenominated (outpoint)) continue ;
456461
457462 nTotal += GetCappedOutpointCoinJoinRounds (outpoint);
458463 nCount++;
459464 }
460465
461- if (nCount == 0 ) return 0 ;
466+ if (nCount == 0 ) return 0 ;
462467
463- return (float )nTotal/ nCount;
468+ return (float )nTotal / nCount;
464469}
465470
466471// Note: calculated including unconfirmed,
@@ -492,14 +497,12 @@ CAmount CachedTxGetAnonymizedCredit(const CWallet& wallet, const CWalletTx& wtx,
492497 AssertLockHeld (wallet.cs_wallet );
493498
494499 // Exclude coinbase and conflicted txes
495- if (wtx.IsCoinBase () || wallet.GetTxDepthInMainChain (wtx) < 0 )
496- return 0 ;
500+ if (wtx.IsCoinBase () || wallet.GetTxDepthInMainChain (wtx) < 0 ) return 0 ;
497501
498502 CAmount nCredit = 0 ;
499503 uint256 hashTx = wtx.GetHash ();
500- for (unsigned int i = 0 ; i < wtx.tx ->vout .size (); i++)
501- {
502- const CTxOut &txout = wtx.tx ->vout [i];
504+ for (unsigned int i = 0 ; i < wtx.tx ->vout .size (); i++) {
505+ const CTxOut& txout = wtx.tx ->vout [i];
503506 const COutPoint outpoint = COutPoint (hashTx, i);
504507
505508 if (coinControl.HasSelected () && !coinControl.IsSelected (outpoint)) {
@@ -510,8 +513,7 @@ CAmount CachedTxGetAnonymizedCredit(const CWallet& wallet, const CWalletTx& wtx,
510513
511514 if (wallet.IsFullyMixed (outpoint)) {
512515 nCredit += OutputGetCredit (wallet, txout, ISMINE_SPENDABLE);
513- if (!MoneyRange (nCredit))
514- throw std::runtime_error (std::string (__func__) + " : value out of range" );
516+ if (!MoneyRange (nCredit)) throw std::runtime_error (std::string (__func__) + " : value out of range" );
515517 }
516518 }
517519
@@ -525,8 +527,7 @@ CoinJoinCredits CachedTxGetAvailableCoinJoinCredits(const CWallet& wallet, const
525527 AssertLockHeld (wallet.cs_wallet );
526528
527529 // Must wait until coinbase is safely deep enough in the chain before valuing it
528- if (wtx.IsCoinBase () && wallet.GetTxBlocksToMaturity (wtx) > 0 )
529- return ret;
530+ if (wtx.IsCoinBase () && wallet.GetTxBlocksToMaturity (wtx) > 0 ) return ret;
530531
531532 int nDepth = wallet.GetTxDepthInMainChain (wtx);
532533 if (nDepth < 0 ) return ret;
@@ -535,29 +536,29 @@ CoinJoinCredits CachedTxGetAvailableCoinJoinCredits(const CWallet& wallet, const
535536
536537 if (wtx.m_amounts [CWalletTx::ANON_CREDIT].m_cached [ISMINE_SPENDABLE]) {
537538 if (ret.is_unconfirmed && wtx.m_amounts [CWalletTx::DENOM_UCREDIT].m_cached [ISMINE_SPENDABLE]) {
538- return {wtx.m_amounts [CWalletTx::ANON_CREDIT].m_value [ISMINE_SPENDABLE], wtx.m_amounts [CWalletTx::DENOM_UCREDIT].m_value [ISMINE_SPENDABLE], ret.is_unconfirmed };
539+ return {wtx.m_amounts [CWalletTx::ANON_CREDIT].m_value [ISMINE_SPENDABLE],
540+ wtx.m_amounts [CWalletTx::DENOM_UCREDIT].m_value [ISMINE_SPENDABLE], ret.is_unconfirmed };
539541 } else if (!ret.is_unconfirmed && wtx.m_amounts [CWalletTx::DENOM_CREDIT].m_cached [ISMINE_SPENDABLE]) {
540- return {wtx.m_amounts [CWalletTx::ANON_CREDIT].m_value [ISMINE_SPENDABLE], wtx.m_amounts [CWalletTx::DENOM_CREDIT].m_value [ISMINE_SPENDABLE], ret.is_unconfirmed };
542+ return {wtx.m_amounts [CWalletTx::ANON_CREDIT].m_value [ISMINE_SPENDABLE],
543+ wtx.m_amounts [CWalletTx::DENOM_CREDIT].m_value [ISMINE_SPENDABLE], ret.is_unconfirmed };
541544 }
542545 }
543546
544547 uint256 hashTx = wtx.GetHash ();
545548 for (unsigned int i = 0 ; i < wtx.tx ->vout .size (); i++) {
546- const CTxOut & txout = wtx.tx ->vout [i];
549+ const CTxOut& txout = wtx.tx ->vout [i];
547550 const COutPoint outpoint = COutPoint (hashTx, i);
548551
549552 if (wallet.IsSpent (outpoint) || !CoinJoin::IsDenominatedAmount (txout.nValue )) continue ;
550553 const CAmount credit = OutputGetCredit (wallet, txout, ISMINE_SPENDABLE);
551554
552555 if (wallet.IsFullyMixed (outpoint)) {
553556 ret.m_anonymized += credit;
554- if (!MoneyRange (ret.m_anonymized ))
555- throw std::runtime_error (std::string (__func__) + " : value out of range" );
557+ if (!MoneyRange (ret.m_anonymized )) throw std::runtime_error (std::string (__func__) + " : value out of range" );
556558 }
557559
558560 ret.m_denominated += credit;
559- if (!MoneyRange (ret.m_denominated ))
560- throw std::runtime_error (std::string (__func__) + " : value out of range" );
561+ if (!MoneyRange (ret.m_denominated )) throw std::runtime_error (std::string (__func__) + " : value out of range" );
561562 }
562563
563564 wtx.m_amounts [CWalletTx::ANON_CREDIT].Set (ISMINE_SPENDABLE, ret.m_anonymized );
0 commit comments