Skip to content

Commit

Permalink
bitcoin_functional working
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenroose committed Feb 22, 2019
1 parent d1ccd89 commit 6b41197
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/wallet/coinselection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ bool KnapsackSolver(const CAmountMap& mapTargetValue, std::vector<OutputGroup>&
}

// 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) {
Expand All @@ -253,8 +254,7 @@ bool KnapsackSolver(const CAmountMap& mapTargetValue, std::vector<OutputGroup>&
}

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;
Expand Down
9 changes: 3 additions & 6 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CAsset, CAmount>::const_iterator it = balance.begin(); it != balance.end(); ++it) {
if (it->first == asset) {
return ValueFromAmount(it->second);
}
std::map<CAsset, CAmount>::const_iterator it = balance.find(asset);
if (it != balance.end()) {
return ValueFromAmount(it->second);
}
return ValueFromAmount(0);
}
Expand Down
5 changes: 2 additions & 3 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2449,7 +2449,7 @@ bool CWallet::SelectCoins(const std::vector<COutput>& 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
Expand Down Expand Up @@ -2478,8 +2478,7 @@ bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAm
size_t max_descendants = (size_t)std::max<int64_t>(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) ||
Expand Down

0 comments on commit 6b41197

Please sign in to comment.