diff options
author | Andrew Chow <achow101-github@achow101.com> | 2022-05-31 17:39:19 -0400 |
---|---|---|
committer | Andrew Chow <github@achow101.com> | 2023-12-08 14:54:48 -0500 |
commit | e1abfb5b2037ca4fe5a05aa578030c8016491c8b (patch) | |
tree | 7a16d2f76ed6a6eb88629dc63757a82e01b5667c /src/wallet/coincontrol.h | |
parent | dce1dfbc47050404bcf3ce2461e8baff0b088ffb (diff) | |
download | bitcoin-e1abfb5b2037ca4fe5a05aa578030c8016491c8b.tar.xz |
wallet: Introduce and use PreselectedInput class in CCoinControl
Instead of having different maps for selected inputs, external inputs,
and input weight in CCoinControl, have a class PreselectedInput which
tracks stores that information for each input.
Diffstat (limited to 'src/wallet/coincontrol.h')
-rw-r--r-- | src/wallet/coincontrol.h | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/src/wallet/coincontrol.h b/src/wallet/coincontrol.h index 71593e236f..4f87d13d99 100644 --- a/src/wallet/coincontrol.h +++ b/src/wallet/coincontrol.h @@ -24,6 +24,33 @@ const int DEFAULT_MAX_DEPTH = 9999999; //! Default for -avoidpartialspends static constexpr bool DEFAULT_AVOIDPARTIALSPENDS = false; +class PreselectedInput +{ +private: + //! The previous output being spent by this input + std::optional<CTxOut> m_txout; + //! The input weight for spending this input + std::optional<int64_t> m_weight; + +public: + /** + * Set the previous output for this input. + * Only necessary if the input is expected to be an external input. + */ + void SetTxOut(const CTxOut& txout); + /** Retrieve the previous output for this input. */ + CTxOut GetTxOut() const; + /** Return whether the previous output is set for this input. */ + bool HasTxOut() const; + + /** Set the weight for this input. */ + void SetInputWeight(int64_t weight); + /** Retrieve the input weight for this input. */ + int64_t GetInputWeight() const; + /** Return whether the input weight is set. */ + bool HasInputWeight() const; +}; + /** Coin Control Features. */ class CCoinControl { @@ -69,11 +96,11 @@ public: /** * Returns true if the given output is pre-selected. */ - bool IsSelected(const COutPoint& output) const; + bool IsSelected(const COutPoint& outpoint) const; /** * Returns true if the given output is selected as an external input. */ - bool IsExternalSelected(const COutPoint& output) const; + bool IsExternalSelected(const COutPoint& outpoint) const; /** * Returns the external output for the given outpoint if it exists. */ @@ -82,7 +109,7 @@ public: * Lock-in the given output for spending. * The output will be included in the transaction even if it's not the most optimal choice. */ - void Select(const COutPoint& output); + PreselectedInput& Select(const COutPoint& outpoint); /** * Lock-in the given output as an external input for spending because it is not in the wallet. * The output will be included in the transaction even if it's not the most optimal choice. @@ -91,7 +118,7 @@ public: /** * Unselects the given output. */ - void UnSelect(const COutPoint& output); + void UnSelect(const COutPoint& outpoint); /** * Unselects all outputs. */ @@ -115,12 +142,7 @@ public: 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; + std::map<COutPoint, PreselectedInput> m_selected; }; } // namespace wallet |