|
|
@ -2087,7 +2087,6 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const int nConfMin |
|
|
|
// List of values less than target
|
|
|
|
// List of values less than target
|
|
|
|
std::pair<CAmount, CInputCoin> coinLowestLarger; |
|
|
|
std::pair<CAmount, CInputCoin> coinLowestLarger; |
|
|
|
coinLowestLarger.first = std::numeric_limits<CAmount>::max(); |
|
|
|
coinLowestLarger.first = std::numeric_limits<CAmount>::max(); |
|
|
|
coinLowestLarger.second.first = NULL; |
|
|
|
|
|
|
|
std::vector<std::pair<CAmount, CInputCoin> > vValue; |
|
|
|
std::vector<std::pair<CAmount, CInputCoin> > vValue; |
|
|
|
CAmount nTotalLower = 0; |
|
|
|
CAmount nTotalLower = 0; |
|
|
|
|
|
|
|
|
|
|
@ -2109,7 +2108,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const int nConfMin |
|
|
|
int i = output.i; |
|
|
|
int i = output.i; |
|
|
|
CAmount n = pcoin->tx->vout[i].nValue; |
|
|
|
CAmount n = pcoin->tx->vout[i].nValue; |
|
|
|
|
|
|
|
|
|
|
|
std::pair<CAmount,CInputCoin> coin = std::make_pair(n,std::make_pair(pcoin, i)); |
|
|
|
std::pair<CAmount,CInputCoin> coin = std::make_pair(n, CInputCoin(pcoin, i)); |
|
|
|
|
|
|
|
|
|
|
|
if (n == nTargetValue) |
|
|
|
if (n == nTargetValue) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -2140,7 +2139,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const int nConfMin |
|
|
|
|
|
|
|
|
|
|
|
if (nTotalLower < nTargetValue) |
|
|
|
if (nTotalLower < nTargetValue) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (coinLowestLarger.second.first == NULL) |
|
|
|
if (coinLowestLarger.second.IsNull()) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
setCoinsRet.insert(coinLowestLarger.second); |
|
|
|
setCoinsRet.insert(coinLowestLarger.second); |
|
|
|
nValueRet += coinLowestLarger.first; |
|
|
|
nValueRet += coinLowestLarger.first; |
|
|
@ -2159,7 +2158,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const int nConfMin |
|
|
|
|
|
|
|
|
|
|
|
// If we have a bigger coin and (either the stochastic approximation didn't find a good solution,
|
|
|
|
// If we have a bigger coin and (either the stochastic approximation didn't find a good solution,
|
|
|
|
// or the next bigger coin is closer), return the bigger coin
|
|
|
|
// or the next bigger coin is closer), return the bigger coin
|
|
|
|
if (coinLowestLarger.second.first && |
|
|
|
if (coinLowestLarger.second.IsNull() && |
|
|
|
((nBest != nTargetValue && nBest < nTargetValue + MIN_CHANGE) || coinLowestLarger.first <= nBest)) |
|
|
|
((nBest != nTargetValue && nBest < nTargetValue + MIN_CHANGE) || coinLowestLarger.first <= nBest)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
setCoinsRet.insert(coinLowestLarger.second); |
|
|
|
setCoinsRet.insert(coinLowestLarger.second); |
|
|
@ -2199,7 +2198,7 @@ bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAm |
|
|
|
if (!out.fSpendable) |
|
|
|
if (!out.fSpendable) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
nValueRet += out.tx->tx->vout[out.i].nValue; |
|
|
|
nValueRet += out.tx->tx->vout[out.i].nValue; |
|
|
|
setCoinsRet.insert(std::make_pair(out.tx, out.i)); |
|
|
|
setCoinsRet.insert(CInputCoin(out.tx, out.i)); |
|
|
|
} |
|
|
|
} |
|
|
|
return (nValueRet >= nTargetValue); |
|
|
|
return (nValueRet >= nTargetValue); |
|
|
|
} |
|
|
|
} |
|
|
@ -2221,7 +2220,7 @@ bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAm |
|
|
|
if (pcoin->tx->vout.size() <= outpoint.n) |
|
|
|
if (pcoin->tx->vout.size() <= outpoint.n) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
nValueFromPresetInputs += pcoin->tx->vout[outpoint.n].nValue; |
|
|
|
nValueFromPresetInputs += pcoin->tx->vout[outpoint.n].nValue; |
|
|
|
setPresetCoins.insert(std::make_pair(pcoin, outpoint.n)); |
|
|
|
setPresetCoins.insert(CInputCoin(pcoin, outpoint.n)); |
|
|
|
} else |
|
|
|
} else |
|
|
|
return false; // TODO: Allow non-wallet inputs
|
|
|
|
return false; // TODO: Allow non-wallet inputs
|
|
|
|
} |
|
|
|
} |
|
|
@ -2229,7 +2228,7 @@ bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAm |
|
|
|
// remove preset inputs from vCoins
|
|
|
|
// remove preset inputs from vCoins
|
|
|
|
for (std::vector<COutput>::iterator it = vCoins.begin(); it != vCoins.end() && coinControl && coinControl->HasSelected();) |
|
|
|
for (std::vector<COutput>::iterator it = vCoins.begin(); it != vCoins.end() && coinControl && coinControl->HasSelected();) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (setPresetCoins.count(std::make_pair(it->tx, it->i))) |
|
|
|
if (setPresetCoins.count(CInputCoin(it->tx, it->i))) |
|
|
|
it = vCoins.erase(it); |
|
|
|
it = vCoins.erase(it); |
|
|
|
else |
|
|
|
else |
|
|
|
++it; |
|
|
|
++it; |
|
|
@ -2554,7 +2553,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT |
|
|
|
// behavior."
|
|
|
|
// behavior."
|
|
|
|
bool rbf = coinControl ? coinControl->signalRbf : fWalletRbf; |
|
|
|
bool rbf = coinControl ? coinControl->signalRbf : fWalletRbf; |
|
|
|
for (const auto& coin : setCoins) |
|
|
|
for (const auto& coin : setCoins) |
|
|
|
txNew.vin.push_back(CTxIn(coin.first->GetHash(),coin.second,CScript(), |
|
|
|
txNew.vin.push_back(CTxIn(coin.outpoint,CScript(), |
|
|
|
std::numeric_limits<unsigned int>::max() - (rbf ? 2 : 1))); |
|
|
|
std::numeric_limits<unsigned int>::max() - (rbf ? 2 : 1))); |
|
|
|
|
|
|
|
|
|
|
|
// Fill in dummy signatures for fee calculation.
|
|
|
|
// Fill in dummy signatures for fee calculation.
|
|
|
@ -2637,10 +2636,10 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT |
|
|
|
int nIn = 0; |
|
|
|
int nIn = 0; |
|
|
|
for (const auto& coin : setCoins) |
|
|
|
for (const auto& coin : setCoins) |
|
|
|
{ |
|
|
|
{ |
|
|
|
const CScript& scriptPubKey = coin.first->tx->vout[coin.second].scriptPubKey; |
|
|
|
const CScript& scriptPubKey = coin.txout.scriptPubKey; |
|
|
|
SignatureData sigdata; |
|
|
|
SignatureData sigdata; |
|
|
|
|
|
|
|
|
|
|
|
if (!ProduceSignature(TransactionSignatureCreator(this, &txNewConst, nIn, coin.first->tx->vout[coin.second].nValue, SIGHASH_ALL), scriptPubKey, sigdata)) |
|
|
|
if (!ProduceSignature(TransactionSignatureCreator(this, &txNewConst, nIn, coin.txout.nValue, SIGHASH_ALL), scriptPubKey, sigdata)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
strFailReason = _("Signing transaction failed"); |
|
|
|
strFailReason = _("Signing transaction failed"); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|