@@ -461,19 +461,20 @@ util::Result<SelectionResult> KnapsackSolver(std::vector<OutputGroup>& groups, c
461461 }
462462
463463 if (inner_groups.size () == 0 ) {
464- // No output groups for this asset.
465- return std:: nullopt ;
464+ std::string msg = tfm::format ( " No output groups for this asset: %d " , it-> first . GetHex ());
465+ return util::Error{ _ (msg. c_str ())} ;
466466 }
467467
468- if (auto inner_result = KnapsackSolver (inner_groups, it->second , change_target, rng, it->first )) {
468+ if (auto inner_result = KnapsackSolver (inner_groups, it->second , change_target, rng, max_weight, it->first )) {
469469 auto set = inner_result->GetInputSet ();
470470 for (const std::shared_ptr<wallet::COutput>& ic : set) {
471471 non_policy_effective_value += ic->GetEffectiveValue ();
472472 }
473473 result.AddInput (inner_result.value ());
474474 } else {
475- LogPrint (BCLog::SELECTCOINS, " Not enough funds to create target %d for asset %s\n " , it->second , it->first .GetHex ());
476- return std::nullopt ;
475+ std::string msg = tfm::format (" Not enough funds to create target %d for asset %s\n " , it->second , it->first .GetHex ());
476+ LogPrint (BCLog::SELECTCOINS, msg.c_str ());
477+ return util::Error{_ (msg.c_str ())};
477478 }
478479 }
479480
@@ -510,24 +511,24 @@ util::Result<SelectionResult> KnapsackSolver(std::vector<OutputGroup>& groups, c
510511 }
511512
512513 if (inner_groups.size () == 0 ) {
513- // No output groups for this asset.
514- return std::nullopt ;
514+ return util::Error{_ (" No output groups for the policy asset." )};
515515 }
516516
517- if (auto inner_result = KnapsackSolver (inner_groups, policy_target, change_target, rng, ::policyAsset)) {
517+ if (auto inner_result = KnapsackSolver (inner_groups, policy_target, change_target, rng, max_weight, ::policyAsset)) {
518518 result.AddInput (*inner_result);
519519 } else {
520- LogPrint (BCLog::SELECTCOINS, " Not enough funds to create target %d for policy asset %s\n " , policy_target, ::policyAsset.GetHex ());
521- return std::nullopt ;
520+ std::string msg = tfm::format (" Not enough funds to create target %d for policy asset %s\n " , policy_target, ::policyAsset.GetHex ());
521+ LogPrint (BCLog::SELECTCOINS, msg.c_str ());
522+ return util::Error{_ (msg.c_str ())};
522523 }
523524 }
524525
525- if (result.GetSelectedValue () < mapTargetValue) return std:: nullopt ;
526+ if (result.GetSelectedValue () < mapTargetValue) return util::Error{ _ ( " Selected value is less than target value " )} ;
526527 return result;
527528}
528529
529- std::optional <SelectionResult> KnapsackSolver (std::vector<OutputGroup>& groups, const CAmount& nTargetValue,
530- CAmount change_target, FastRandomContext& rng, const CAsset& asset)
530+ util::Result <SelectionResult> KnapsackSolver (std::vector<OutputGroup>& groups, const CAmount& nTargetValue,
531+ CAmount change_target, FastRandomContext& rng, int max_weight, const CAsset& asset)
531532{
532533 CAmountMap map_target{{ asset, nTargetValue }};
533534 SelectionResult result (map_target, SelectionAlgorithm::KNAPSACK);
0 commit comments