diff --git a/src/wallet/coinselection.cpp b/src/wallet/coinselection.cpp index 32b9f51d35..16aa72a0e3 100644 --- a/src/wallet/coinselection.cpp +++ b/src/wallet/coinselection.cpp @@ -232,6 +232,7 @@ bool KnapsackSolver(const CAmountMap& mapTargetValue, std::vector& } // Get output groups that only contain this asset. + // We consider that groups will almost always be of one asset entirely. for (OutputGroup g : groups) { bool add = true; for (CInputCoin c : g.m_outputs) { @@ -253,8 +254,7 @@ bool KnapsackSolver(const CAmountMap& mapTargetValue, std::vector& } CAmount outValue; - bool ret = KnapsackSolver(it->second, asset_groups, asset_coinsret, outValue); - if (!ret) { + if (!KnapsackSolver(it->second, asset_groups, asset_coinsret, outValue)) { return false; } mapValueRet[it->first] = outValue; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index cbfd59e253..d6bcca8e4e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -120,12 +120,9 @@ UniValue AmountMapToUniv(const CAmountMap& balance, std::string strasset) asset = policyAsset; } - // The code below circumvents the const constraint that prevents the line below. - //return ValueFromAmount(balance[asset]); - for(std::map::const_iterator it = balance.begin(); it != balance.end(); ++it) { - if (it->first == asset) { - return ValueFromAmount(it->second); - } + std::map::const_iterator it = balance.find(asset); + if (it != balance.end()) { + return ValueFromAmount(it->second); } return ValueFromAmount(0); } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index b39cf70820..900a800721 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2449,7 +2449,7 @@ bool CWallet::SelectCoins(const std::vector& vAvailableCoins, const CAm if (pcoin->tx->vout.size() <= outpoint.n) return false; // Just to calculate the marginal byte size - mapValueFromPresetInputs[pcoin->GetOutputAsset(outpoint.n)] += pcoin->tx->vout[outpoint.n].nValue.GetAmount(); + mapValueFromPresetInputs[pcoin->GetOutputAsset(outpoint.n)] += pcoin->GetOutputValueOut(outpoint.n); setPresetCoins.insert(CInputCoin(pcoin->tx, outpoint.n)); } else return false; // TODO: Allow non-wallet inputs @@ -2478,8 +2478,7 @@ bool CWallet::SelectCoins(const std::vector& vAvailableCoins, const CAm size_t max_descendants = (size_t)std::max(1, gArgs.GetArg("-limitdescendantcount", DEFAULT_DESCENDANT_LIMIT)); bool fRejectLongChains = gArgs.GetBoolArg("-walletrejectlongchains", DEFAULT_WALLET_REJECT_LONG_CHAINS); - CAmountMap mapTargetMinusPreset = mapTargetValue; - mapTargetMinusPreset -= mapValueFromPresetInputs; + CAmountMap mapTargetMinusPreset = mapTargetValue - mapValueFromPresetInputs; bool res = mapTargetValue <= mapValueFromPresetInputs || SelectCoinsMinConf(mapTargetMinusPreset, CoinEligibilityFilter(1, 6, 0), groups, setCoinsRet, mapValueRet, coin_selection_params, bnb_used) ||