| 186 | } |
| 187 | |
| 188 | std::optional<SelectionResult> SelectCoinsSRD(const std::vector<OutputGroup>& utxo_pool, CAmount target_value) |
| 189 | { |
| 190 | CAmountMap map_target{{ ::policyAsset, target_value}}; |
| 191 | SelectionResult result(map_target); |
| 192 | |
| 193 | std::vector<size_t> indexes; |
| 194 | indexes.resize(utxo_pool.size()); |
| 195 | std::iota(indexes.begin(), indexes.end(), 0); |
| 196 | Shuffle(indexes.begin(), indexes.end(), FastRandomContext()); |
| 197 | |
| 198 | CAmount selected_eff_value = 0; |
| 199 | for (const size_t i : indexes) { |
| 200 | const OutputGroup& group = utxo_pool.at(i); |
| 201 | Assume(group.GetSelectionAmount() > 0); |
| 202 | selected_eff_value += group.GetSelectionAmount(); |
| 203 | result.AddInput(group); |
| 204 | if (selected_eff_value >= target_value) { |
| 205 | return result; |
| 206 | } |
| 207 | } |
| 208 | return std::nullopt; |
| 209 | } |
| 210 | |
| 211 | static void ApproximateBestSubset(const std::vector<OutputGroup>& groups, const CAmount& nTotalLower, const CAmount& nTargetValue, |
| 212 | std::vector<char>& vfBest, CAmount& nBest, int iterations = 1000) |
no test coverage detected