@@ -65,10 +65,10 @@ const uint256 CMerkleTx::ABANDON_HASH(uint256S("00000000000000000000000000000000
65
65
66
66
struct CompareValueOnly
67
67
{
68
- bool operator ()(const std::pair<CAmount, CInputCoin> & t1,
69
- const std::pair<CAmount, CInputCoin> & t2) const
68
+ bool operator ()(const CInputCoin& t1,
69
+ const CInputCoin& t2) const
70
70
{
71
- return t1.first < t2.first ;
71
+ return t1.txout . nValue < t2.txout . nValue ;
72
72
}
73
73
};
74
74
@@ -2032,7 +2032,7 @@ void CWallet::AvailableCoins(std::vector<COutput>& vCoins, bool fOnlySafe, const
2032
2032
}
2033
2033
}
2034
2034
2035
- static void ApproximateBestSubset (const std::vector<std::pair<CAmount, CInputCoin> >& vValue, const CAmount& nTotalLower, const CAmount& nTargetValue,
2035
+ static void ApproximateBestSubset (const std::vector<CInputCoin>& vValue, const CAmount& nTotalLower, const CAmount& nTargetValue,
2036
2036
std::vector<char >& vfBest, CAmount& nBest, int iterations = 1000 )
2037
2037
{
2038
2038
std::vector<char > vfIncluded;
@@ -2059,7 +2059,7 @@ static void ApproximateBestSubset(const std::vector<std::pair<CAmount, CInputCoi
2059
2059
// the selection random.
2060
2060
if (nPass == 0 ? insecure_rand.rand32 ()&1 : !vfIncluded[i])
2061
2061
{
2062
- nTotal += vValue[i].first ;
2062
+ nTotal += vValue[i].txout . nValue ;
2063
2063
vfIncluded[i] = true ;
2064
2064
if (nTotal >= nTargetValue)
2065
2065
{
@@ -2069,7 +2069,7 @@ static void ApproximateBestSubset(const std::vector<std::pair<CAmount, CInputCoi
2069
2069
nBest = nTotal;
2070
2070
vfBest = vfIncluded;
2071
2071
}
2072
- nTotal -= vValue[i].first ;
2072
+ nTotal -= vValue[i].txout . nValue ;
2073
2073
vfIncluded[i] = false ;
2074
2074
}
2075
2075
}
@@ -2085,9 +2085,8 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const int nConfMin
2085
2085
nValueRet = 0 ;
2086
2086
2087
2087
// List of values less than target
2088
- std::pair<CAmount, CInputCoin> coinLowestLarger;
2089
- coinLowestLarger.first = std::numeric_limits<CAmount>::max ();
2090
- std::vector<std::pair<CAmount, CInputCoin> > vValue;
2088
+ CInputCoin coinLowestLarger;
2089
+ std::vector<CInputCoin> vValue;
2091
2090
CAmount nTotalLower = 0 ;
2092
2091
2093
2092
random_shuffle (vCoins.begin (), vCoins.end (), GetRandInt);
@@ -2106,22 +2105,21 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const int nConfMin
2106
2105
continue ;
2107
2106
2108
2107
int i = output.i ;
2109
- CAmount n = pcoin->tx ->vout [i].nValue ;
2110
2108
2111
- std::pair<CAmount, CInputCoin> coin = std::make_pair (n, CInputCoin (pcoin, i) );
2109
+ CInputCoin coin = CInputCoin (pcoin, i);
2112
2110
2113
- if (n == nTargetValue)
2111
+ if (coin. txout . nValue == nTargetValue)
2114
2112
{
2115
- setCoinsRet.insert (coin. second );
2116
- nValueRet += coin.first ;
2113
+ setCoinsRet.insert (coin);
2114
+ nValueRet += coin.txout . nValue ;
2117
2115
return true ;
2118
2116
}
2119
- else if (n < nTargetValue + MIN_CHANGE)
2117
+ else if (coin. txout . nValue < nTargetValue + MIN_CHANGE)
2120
2118
{
2121
2119
vValue.push_back (coin);
2122
- nTotalLower += n ;
2120
+ nTotalLower += coin. txout . nValue ;
2123
2121
}
2124
- else if (n < coinLowestLarger.first )
2122
+ else if (coinLowestLarger. IsNull () || coin. txout . nValue < coinLowestLarger.txout . nValue )
2125
2123
{
2126
2124
coinLowestLarger = coin;
2127
2125
}
@@ -2131,18 +2129,18 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const int nConfMin
2131
2129
{
2132
2130
for (unsigned int i = 0 ; i < vValue.size (); ++i)
2133
2131
{
2134
- setCoinsRet.insert (vValue[i]. second );
2135
- nValueRet += vValue[i].first ;
2132
+ setCoinsRet.insert (vValue[i]);
2133
+ nValueRet += vValue[i].txout . nValue ;
2136
2134
}
2137
2135
return true ;
2138
2136
}
2139
2137
2140
2138
if (nTotalLower < nTargetValue)
2141
2139
{
2142
- if (coinLowestLarger.second . IsNull ())
2140
+ if (coinLowestLarger.IsNull ())
2143
2141
return false ;
2144
- setCoinsRet.insert (coinLowestLarger. second );
2145
- nValueRet += coinLowestLarger.first ;
2142
+ setCoinsRet.insert (coinLowestLarger);
2143
+ nValueRet += coinLowestLarger.txout . nValue ;
2146
2144
return true ;
2147
2145
}
2148
2146
@@ -2158,25 +2156,25 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const int nConfMin
2158
2156
2159
2157
// If we have a bigger coin and (either the stochastic approximation didn't find a good solution,
2160
2158
// or the next bigger coin is closer), return the bigger coin
2161
- if (coinLowestLarger. second .IsNull () &&
2162
- ((nBest != nTargetValue && nBest < nTargetValue + MIN_CHANGE) || coinLowestLarger.first <= nBest))
2159
+ if (! coinLowestLarger.IsNull () &&
2160
+ ((nBest != nTargetValue && nBest < nTargetValue + MIN_CHANGE) || coinLowestLarger.txout . nValue <= nBest))
2163
2161
{
2164
- setCoinsRet.insert (coinLowestLarger. second );
2165
- nValueRet += coinLowestLarger.first ;
2162
+ setCoinsRet.insert (coinLowestLarger);
2163
+ nValueRet += coinLowestLarger.txout . nValue ;
2166
2164
}
2167
2165
else {
2168
2166
for (unsigned int i = 0 ; i < vValue.size (); i++)
2169
2167
if (vfBest[i])
2170
2168
{
2171
- setCoinsRet.insert (vValue[i]. second );
2172
- nValueRet += vValue[i].first ;
2169
+ setCoinsRet.insert (vValue[i]);
2170
+ nValueRet += vValue[i].txout . nValue ;
2173
2171
}
2174
2172
2175
2173
if (LogAcceptCategory (BCLog::SELECTCOINS)) {
2176
2174
LogPrint (BCLog::SELECTCOINS, " SelectCoins() best subset: " );
2177
2175
for (unsigned int i = 0 ; i < vValue.size (); i++) {
2178
2176
if (vfBest[i]) {
2179
- LogPrint (BCLog::SELECTCOINS, " %s " , FormatMoney (vValue[i].first ));
2177
+ LogPrint (BCLog::SELECTCOINS, " %s " , FormatMoney (vValue[i].txout . nValue ));
2180
2178
}
2181
2179
}
2182
2180
LogPrint (BCLog::SELECTCOINS, " total %s\n " , FormatMoney (nBest));
0 commit comments