Repository: bitcoin/bitcoin
File: src/wallet/coincontrol.h (C/C++)

Code before:
    void SelectExternal(const COutPoint& outpoint, const CTxOut& txout);
    /**
     * Unselects the given output.
     */
    void UnSelect(const COutPoint& output);
    /**
     * Unselects all outputs.
     */
    void UnSelectAll();
    /**
     * List the selected inputs.
     */
    std::vector<COutPoint> ListSelected() const;
    /**
     * Set an input's weight.
     */
    void SetInputWeight(const COutPoint& outpoint, int64_t weight);
    /**
     * Returns true if the input weight is set.
     */
    bool HasInputWeight(const COutPoint& outpoint) const;
    /**
     * Returns the input weight.
     */
    int64_t GetInputWeight(const COutPoint& outpoint) const;

private:
    //! Selected inputs (inputs that will be used, regardless of whether they're optimal or not)
    std::set<COutPoint> m_selected_inputs;
    //! Map of external inputs to include in the transaction
    //! These are not in the wallet, so we need to track them separately
    std::map<COutPoint, CTxOut> m_external_txouts;
    //! Map of COutPoints to the maximum weight for that input
    std::map<COutPoint, int64_t> m_input_weights;
};
} // namespace wallet

#endif // BITCOIN_WALLET_COINCONTROL_H


Review comment (refactor):
in 03420020b6b4958ee6765be718724b89cd174d5c

`locktime` doesn't belong to `CoinControl` because it has nothing to do with coins being spent. I'd prefer if we keep `CoinControl` scoped down to only containing data necessary to select and spend coins.

Same is true for some other fields in `CoinControl`. Maybe we should extract parameters not related to coins into a separate struct?

Code after:
    //! while requires all selected inputs be used
    bool m_allow_other_inputs = true;
    //! Includes watch only addresses which are solvable
    bool fAllowWatchOnly = false;
    //! Override automatic min/max checks on fee, m_feerate must be set if true
    bool fOverrideFeeRate = false;
    //! Override the wallet's m_pay_tx_fee if set
    std::optional<CFeeRate> m_feerate;
    //! Override the default confirmation target if set
    std::optional<unsigned int> m_confirm_target;
    //! Override the wallet's m_signal_rbf if set
    std::optional<bool> m_signal_bip125_rbf;
    //! Avoid partial use of funds sent to a given address
    bool m_avoid_partial_spends = DEFAULT_AVOIDPARTIALSPENDS;
    //! Forbids inclusion of dirty (previously used) addresses
    bool m_avoid_address_reuse = false;
    //! Fee estimation mode to control arguments to estimateSmartFee
    FeeEstimateMode m_fee_mode = FeeEstimateMode::UNSET;
    //! Minimum chain depth value for coin availability
    int m_min_depth = DEFAULT_MIN_DEPTH;
    //! Maximum chain depth value for coin availability
    int m_max_depth = DEFAULT_MAX_DEPTH;
    //! SigningProvider that has pubkeys and scripts to do spend size estimation for external inputs
    FlatSigningProvider m_external_provider;
    //! Locktime
    std::optional<uint32_t> m_locktime;
    //! Version
    std::optional<uint32_t> m_version;

    CCoinControl();

    /**
     * Returns true if there are pre-selected inputs.
     */
    bool HasSelected() const;
    /**
     * Returns true if the given output is pre-selected.
     */
    bool IsSelected(const COutPoint& outpoint) const;
    /**
     * Returns true if the given output is selected as an external input.
     */
    bool IsExternalSelected(const COutPoint& outpoint) const;
    /**
     * Returns the external output for the given outpoint if it exists.
     */
    std::optional<CTxOut> GetExternalOutput(const COutPoint& outpoint) const;
    /**
     * Lock-in the given output for spending.
     * The output will be included in the transaction even if it's not the most optimal choice.
     */