@@ -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, std::pair< const CWalletTx*, unsigned int > > & t1,
69
- const std::pair<CAmount, std::pair< const CWalletTx*, unsigned int > > & 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
@@ -2061,7 +2061,7 @@ void CWallet::AvailableCoins(std::vector<COutput>& vCoins, bool fOnlySafe, const
2061
2061
}
2062
2062
}
2063
2063
2064
- static void ApproximateBestSubset (const std::vector<std::pair<CAmount, std::pair< const CWalletTx*, unsigned int > > >& vValue, const CAmount& nTotalLower, const CAmount& nTargetValue,
2064
+ static void ApproximateBestSubset (const std::vector<CInputCoin >& vValue, const CAmount& nTotalLower, const CAmount& nTargetValue,
2065
2065
std::vector<char >& vfBest, CAmount& nBest, int iterations = 1000 )
2066
2066
{
2067
2067
std::vector<char > vfIncluded;
@@ -2088,7 +2088,7 @@ static void ApproximateBestSubset(const std::vector<std::pair<CAmount, std::pair
2088
2088
// the selection random.
2089
2089
if (nPass == 0 ? insecure_rand.rand32 ()&1 : !vfIncluded[i])
2090
2090
{
2091
- nTotal += vValue[i].first ;
2091
+ nTotal += vValue[i].txout . nValue ;
2092
2092
vfIncluded[i] = true ;
2093
2093
if (nTotal >= nTargetValue)
2094
2094
{
@@ -2098,7 +2098,7 @@ static void ApproximateBestSubset(const std::vector<std::pair<CAmount, std::pair
2098
2098
nBest = nTotal;
2099
2099
vfBest = vfIncluded;
2100
2100
}
2101
- nTotal -= vValue[i].first ;
2101
+ nTotal -= vValue[i].txout . nValue ;
2102
2102
vfIncluded[i] = false ;
2103
2103
}
2104
2104
}
@@ -2108,16 +2108,14 @@ static void ApproximateBestSubset(const std::vector<std::pair<CAmount, std::pair
2108
2108
}
2109
2109
2110
2110
bool CWallet::SelectCoinsMinConf (const CAmount& nTargetValue, const int nConfMine, const int nConfTheirs, const uint64_t nMaxAncestors, std::vector<COutput> vCoins,
2111
- std::set<std::pair< const CWalletTx*, unsigned int > >& setCoinsRet, CAmount& nValueRet) const
2111
+ std::set<CInputCoin >& setCoinsRet, CAmount& nValueRet) const
2112
2112
{
2113
2113
setCoinsRet.clear ();
2114
2114
nValueRet = 0 ;
2115
2115
2116
2116
// List of values less than target
2117
- std::pair<CAmount, std::pair<const CWalletTx*,unsigned int > > coinLowestLarger;
2118
- coinLowestLarger.first = std::numeric_limits<CAmount>::max ();
2119
- coinLowestLarger.second .first = NULL ;
2120
- std::vector<std::pair<CAmount, std::pair<const CWalletTx*,unsigned int > > > vValue;
2117
+ boost::optional<CInputCoin> coinLowestLarger;
2118
+ std::vector<CInputCoin> vValue;
2121
2119
CAmount nTotalLower = 0 ;
2122
2120
2123
2121
random_shuffle (vCoins.begin (), vCoins.end (), GetRandInt);
@@ -2136,22 +2134,21 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const int nConfMin
2136
2134
continue ;
2137
2135
2138
2136
int i = output.i ;
2139
- CAmount n = pcoin->tx ->vout [i].nValue ;
2140
2137
2141
- std::pair<CAmount,std::pair< const CWalletTx*, unsigned int > > coin = std::make_pair (n, std::make_pair ( pcoin, i) );
2138
+ CInputCoin coin = CInputCoin ( pcoin, i);
2142
2139
2143
- if (n == nTargetValue)
2140
+ if (coin. txout . nValue == nTargetValue)
2144
2141
{
2145
- setCoinsRet.insert (coin. second );
2146
- nValueRet += coin.first ;
2142
+ setCoinsRet.insert (coin);
2143
+ nValueRet += coin.txout . nValue ;
2147
2144
return true ;
2148
2145
}
2149
- else if (n < nTargetValue + MIN_CHANGE)
2146
+ else if (coin. txout . nValue < nTargetValue + MIN_CHANGE)
2150
2147
{
2151
2148
vValue.push_back (coin);
2152
- nTotalLower += n ;
2149
+ nTotalLower += coin. txout . nValue ;
2153
2150
}
2154
- else if (n < coinLowestLarger. first )
2151
+ else if (!coinLowestLarger || coin. txout . nValue < coinLowestLarger-> txout . nValue )
2155
2152
{
2156
2153
coinLowestLarger = coin;
2157
2154
}
@@ -2161,18 +2158,18 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const int nConfMin
2161
2158
{
2162
2159
for (unsigned int i = 0 ; i < vValue.size (); ++i)
2163
2160
{
2164
- setCoinsRet.insert (vValue[i]. second );
2165
- nValueRet += vValue[i].first ;
2161
+ setCoinsRet.insert (vValue[i]);
2162
+ nValueRet += vValue[i].txout . nValue ;
2166
2163
}
2167
2164
return true ;
2168
2165
}
2169
2166
2170
2167
if (nTotalLower < nTargetValue)
2171
2168
{
2172
- if (coinLowestLarger. second . first == NULL )
2169
+ if (! coinLowestLarger)
2173
2170
return false ;
2174
- setCoinsRet.insert (coinLowestLarger.second );
2175
- nValueRet += coinLowestLarger. first ;
2171
+ setCoinsRet.insert (coinLowestLarger.get () );
2172
+ nValueRet += coinLowestLarger-> txout . nValue ;
2176
2173
return true ;
2177
2174
}
2178
2175
@@ -2188,25 +2185,25 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const int nConfMin
2188
2185
2189
2186
// If we have a bigger coin and (either the stochastic approximation didn't find a good solution,
2190
2187
// or the next bigger coin is closer), return the bigger coin
2191
- if (coinLowestLarger. second . first &&
2192
- ((nBest != nTargetValue && nBest < nTargetValue + MIN_CHANGE) || coinLowestLarger. first <= nBest))
2188
+ if (coinLowestLarger &&
2189
+ ((nBest != nTargetValue && nBest < nTargetValue + MIN_CHANGE) || coinLowestLarger-> txout . nValue <= nBest))
2193
2190
{
2194
- setCoinsRet.insert (coinLowestLarger.second );
2195
- nValueRet += coinLowestLarger. first ;
2191
+ setCoinsRet.insert (coinLowestLarger.get () );
2192
+ nValueRet += coinLowestLarger-> txout . nValue ;
2196
2193
}
2197
2194
else {
2198
2195
for (unsigned int i = 0 ; i < vValue.size (); i++)
2199
2196
if (vfBest[i])
2200
2197
{
2201
- setCoinsRet.insert (vValue[i]. second );
2202
- nValueRet += vValue[i].first ;
2198
+ setCoinsRet.insert (vValue[i]);
2199
+ nValueRet += vValue[i].txout . nValue ;
2203
2200
}
2204
2201
2205
2202
if (LogAcceptCategory (BCLog::SELECTCOINS)) {
2206
2203
LogPrint (BCLog::SELECTCOINS, " SelectCoins() best subset: " );
2207
2204
for (unsigned int i = 0 ; i < vValue.size (); i++) {
2208
2205
if (vfBest[i]) {
2209
- LogPrint (BCLog::SELECTCOINS, " %s " , FormatMoney (vValue[i].first ));
2206
+ LogPrint (BCLog::SELECTCOINS, " %s " , FormatMoney (vValue[i].txout . nValue ));
2210
2207
}
2211
2208
}
2212
2209
LogPrint (BCLog::SELECTCOINS, " total %s\n " , FormatMoney (nBest));
@@ -2216,7 +2213,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const int nConfMin
2216
2213
return true ;
2217
2214
}
2218
2215
2219
- bool CWallet::SelectCoins (const std::vector<COutput>& vAvailableCoins, const CAmount& nTargetValue, std::set<std::pair< const CWalletTx*, unsigned int > >& setCoinsRet, CAmount& nValueRet, const CCoinControl* coinControl) const
2216
+ bool CWallet::SelectCoins (const std::vector<COutput>& vAvailableCoins, const CAmount& nTargetValue, std::set<CInputCoin >& setCoinsRet, CAmount& nValueRet, const CCoinControl* coinControl) const
2220
2217
{
2221
2218
std::vector<COutput> vCoins (vAvailableCoins);
2222
2219
@@ -2228,13 +2225,13 @@ bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAm
2228
2225
if (!out.fSpendable )
2229
2226
continue ;
2230
2227
nValueRet += out.tx ->tx ->vout [out.i ].nValue ;
2231
- setCoinsRet.insert (std::make_pair (out.tx , out.i ));
2228
+ setCoinsRet.insert (CInputCoin (out.tx , out.i ));
2232
2229
}
2233
2230
return (nValueRet >= nTargetValue);
2234
2231
}
2235
2232
2236
2233
// calculate value from preset inputs and store them
2237
- std::set<std::pair< const CWalletTx*, uint32_t > > setPresetCoins;
2234
+ std::set<CInputCoin > setPresetCoins;
2238
2235
CAmount nValueFromPresetInputs = 0 ;
2239
2236
2240
2237
std::vector<COutPoint> vPresetInputs;
@@ -2250,15 +2247,15 @@ bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAm
2250
2247
if (pcoin->tx ->vout .size () <= outpoint.n )
2251
2248
return false ;
2252
2249
nValueFromPresetInputs += pcoin->tx ->vout [outpoint.n ].nValue ;
2253
- setPresetCoins.insert (std::make_pair (pcoin, outpoint.n ));
2250
+ setPresetCoins.insert (CInputCoin (pcoin, outpoint.n ));
2254
2251
} else
2255
2252
return false ; // TODO: Allow non-wallet inputs
2256
2253
}
2257
2254
2258
2255
// remove preset inputs from vCoins
2259
2256
for (std::vector<COutput>::iterator it = vCoins.begin (); it != vCoins.end () && coinControl && coinControl->HasSelected ();)
2260
2257
{
2261
- if (setPresetCoins.count (std::make_pair (it->tx , it->i )))
2258
+ if (setPresetCoins.count (CInputCoin (it->tx , it->i )))
2262
2259
it = vCoins.erase (it);
2263
2260
else
2264
2261
++it;
@@ -2424,7 +2421,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
2424
2421
assert (txNew.nLockTime < LOCKTIME_THRESHOLD);
2425
2422
2426
2423
{
2427
- std::set<std::pair< const CWalletTx*, unsigned int > > setCoins;
2424
+ std::set<CInputCoin > setCoins;
2428
2425
LOCK2 (cs_main, cs_wallet);
2429
2426
{
2430
2427
std::vector<COutput> vAvailableCoins;
@@ -2583,7 +2580,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
2583
2580
// behavior."
2584
2581
bool rbf = coinControl ? coinControl->signalRbf : fWalletRbf ;
2585
2582
for (const auto & coin : setCoins)
2586
- txNew.vin .push_back (CTxIn (coin.first -> GetHash (),coin. second ,CScript (),
2583
+ txNew.vin .push_back (CTxIn (coin.outpoint ,CScript (),
2587
2584
std::numeric_limits<unsigned int >::max () - (rbf ? 2 : 1 )));
2588
2585
2589
2586
// Fill in dummy signatures for fee calculation.
@@ -2666,10 +2663,10 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
2666
2663
int nIn = 0 ;
2667
2664
for (const auto & coin : setCoins)
2668
2665
{
2669
- const CScript& scriptPubKey = coin.first -> tx -> vout [coin. second ] .scriptPubKey ;
2666
+ const CScript& scriptPubKey = coin.txout .scriptPubKey ;
2670
2667
SignatureData sigdata;
2671
2668
2672
- if (!ProduceSignature (TransactionSignatureCreator (this , &txNewConst, nIn, coin.first -> tx -> vout [coin. second ] .nValue , SIGHASH_ALL), scriptPubKey, sigdata))
2669
+ if (!ProduceSignature (TransactionSignatureCreator (this , &txNewConst, nIn, coin.txout .nValue , SIGHASH_ALL), scriptPubKey, sigdata))
2673
2670
{
2674
2671
strFailReason = _ (" Signing transaction failed" );
2675
2672
return false ;
0 commit comments