@@ -2999,14 +2999,14 @@ struct CompareByAmount {
2999
2999
}
3000
3000
};
3001
3001
3002
- bool CWallet::SelectCoinsGroupedByAddresses (std::vector<CompactTallyItem>& vecTallyRet, bool fSkipDenominated , bool fAnonymizable , bool fSkipUnconfirmed ) const
3002
+ bool CWallet::SelectCoinsGroupedByAddresses (std::vector<CompactTallyItem>& vecTallyRet, bool fSkipDenominated , bool fAnonymizable , bool fSkipUnconfirmed , int nMaxOupointsPerAddress ) const
3003
3003
{
3004
3004
LOCK2 (cs_main, cs_wallet);
3005
3005
3006
3006
isminefilter filter = ISMINE_SPENDABLE;
3007
3007
3008
- // try to use cache
3009
- if ( fAnonymizable && fSkipUnconfirmed ) {
3008
+ // try to use cache for already confirmed anonymizable inputs, no cache should be used when the limit is specified
3009
+ if (nMaxOupointsPerAddress != - 1 && fAnonymizable && fSkipUnconfirmed ) {
3010
3010
if (fSkipDenominated && fAnonymizableTallyCachedNonDenom ) {
3011
3011
vecTallyRet = vecAnonymizableTallyCachedNonDenom;
3012
3012
LogPrint (" selectcoins" , " SelectCoinsGroupedByAddresses - using cache for non-denom inputs\n " );
@@ -3049,6 +3049,10 @@ bool CWallet::SelectCoinsGroupedByAddresses(std::vector<CompactTallyItem>& vecTa
3049
3049
if (!(mine & filter))
3050
3050
continue ;
3051
3051
3052
+ auto itTallyItem = mapTally.find (txdest);
3053
+ if (nMaxOupointsPerAddress != -1 && itTallyItem != mapTally.end () && itTallyItem->second .vecOutPoints .size () >= nMaxOupointsPerAddress)
3054
+ continue ;
3055
+
3052
3056
if (IsSpent (outpoint.hash , i) || IsLockedCoin (outpoint.hash , i))
3053
3057
continue ;
3054
3058
@@ -3070,10 +3074,12 @@ bool CWallet::SelectCoinsGroupedByAddresses(std::vector<CompactTallyItem>& vecTa
3070
3074
continue ;
3071
3075
}
3072
3076
3073
- CompactTallyItem& item = mapTally[txdest];
3074
- item.txdest = txdest;
3075
- item.nAmount += wtx.tx ->vout [i].nValue ;
3076
- item.vecOutPoints .emplace_back (outpoint.hash , i);
3077
+ if (itTallyItem == mapTally.end ()) {
3078
+ itTallyItem = mapTally.emplace (txdest, CompactTallyItem ()).first ;
3079
+ itTallyItem->second .txdest = txdest;
3080
+ }
3081
+ itTallyItem->second .nAmount += wtx.tx ->vout [i].nValue ;
3082
+ itTallyItem->second .vecOutPoints .emplace_back (outpoint.hash , i);
3077
3083
}
3078
3084
}
3079
3085
@@ -3088,8 +3094,8 @@ bool CWallet::SelectCoinsGroupedByAddresses(std::vector<CompactTallyItem>& vecTa
3088
3094
// order by amounts per address, from smallest to largest
3089
3095
sort (vecTallyRet.rbegin (), vecTallyRet.rend (), CompareByAmount ());
3090
3096
3091
- // cache anonymizable for later use
3092
- if ( fAnonymizable && fSkipUnconfirmed ) {
3097
+ // cache already confirmed anonymizable entries for later use, no cache should be saved when the limit is specified
3098
+ if (nMaxOupointsPerAddress != - 1 && fAnonymizable && fSkipUnconfirmed ) {
3093
3099
if (fSkipDenominated ) {
3094
3100
vecAnonymizableTallyCachedNonDenom = vecTallyRet;
3095
3101
fAnonymizableTallyCachedNonDenom = true ;
0 commit comments