[#wallet-AttemptSelection]
= xref:wallet.adoc[wallet]::AttemptSelection
:relfileprefix: ../
:mrdocs:

Attempt to find a valid input set that preserves privacy by not mixing OutputTypes&period; `ChooseSelectionResult()` will be called on each OutputType individually and the best the solution (according to the waste metric) will be chosen&period; If a valid input cannot be found from any single OutputType, fallback to running `ChooseSelectionResult()` over all available coins&period;

== Synopsis

Declared in `&lt;wallet&sol;spend&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:util/Result.adoc[util::Result&lt;SelectionResult&gt;]
AttemptSelection(
    xref:interfaces/Chain.adoc[interfaces::Chain]& chain,
    xref:CAmount.adoc[CAmount] const& nTargetValue,
    xref:wallet/OutputGroupTypeMap.adoc[OutputGroupTypeMap]& groups,
    xref:wallet/CoinSelectionParams.adoc[CoinSelectionParams] const& coin&lowbar;selection&lowbar;params,
    bool allow&lowbar;mixed&lowbar;output&lowbar;types);
----

== Return Value

If successful, a SelectionResult containing the input set If failed, returns (1) an empty error message if the target was not reached (general &quot;Insufficient funds&quot;) or (2) a specific error message if there was something particularly wrong (e&period;g&period; a selection result that surpassed the tx max weight size)&period;

== Parameters

[cols="1,4"]
|===
| Name| Description
| *chain* [in]
| The chain interface to get information on bump fees for unconfirmed UTXOs
| *nTargetValue* [in]
| The target value
| *groups* [in]
| The grouped outputs mapped by coin eligibility filters
| *coin&lowbar;selection&lowbar;params* [in]
| Parameters for the coin selection
| *allow&lowbar;mixed&lowbar;output&lowbar;types* [in]
| Relax restriction that SelectionResults must be of the same OutputType
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
