The method CWallet::CreateTransaction currently returns several values in the form of out-parameters: the actual newly created transaction (CTransactionRef& tx) its required fee (CAmount& nFeeRate) the position of the change output (int& nChangePosInOut) -- as the name suggests, this is both an in- and out-param By returning these values in an optional structure (which returns no value a.k.a. std::nullopt if an error occured), the interfaces is shorter, cleaner (requested change position is now in-param and can be passed by value) and callers don't have to create dummy variables for results that they are not interested in. Note that the names of the replaced out-variables were kept in CreateTransactionInternal to keep the diff minimal. Also, the fee calculation data (FeeCalculation& fee_calc_out) would be another candidate to put into the structure, but FeeCalculation is currently an opaque data type in the wallet interface and I think it should stay that way.
Backport of core#20640.
Depends on D17953.