 |
Bitcoin Core
22.99.0
P2P Digital Currency
|
Go to the documentation of this file.
5 #ifndef BITCOIN_WALLET_COINSELECTION_H
6 #define BITCOIN_WALLET_COINSELECTION_H
27 throw std::invalid_argument(
"tx should not be null");
28 if (i >= tx->vout.size())
29 throw std::out_of_range(
"The output index is out of range");
179 void Insert(
const CInputCoin& output,
int depth,
bool from_me,
size_t ancestors,
size_t descendants,
bool positive_only);
240 std::optional<SelectionResult>
SelectCoinsBnB(std::vector<OutputGroup>& utxo_pool,
const CAmount& selection_target,
const CAmount& cost_of_change);
249 std::optional<SelectionResult>
SelectCoinsSRD(
const std::vector<OutputGroup>& utxo_pool,
CAmount target_value);
252 std::optional<SelectionResult>
KnapsackSolver(std::vector<OutputGroup>& groups,
const CAmount& nTargetValue);
255 #endif // BITCOIN_WALLET_COINSELECTION_H
size_t tx_noinputs_size
Size of the transaction before coin selection, consisting of the header and recipient output(s),...
std::optional< SelectionResult > SelectCoinsSRD(const std::vector< OutputGroup > &utxo_pool, CAmount target_value)
Select coins by Single Random Draw.
bool m_subtract_fee_outputs
Indicate that we are subtracting the fee from outputs.
std::vector< CInputCoin > m_outputs
The list of UTXOs contained in this output group.
CoinEligibilityFilter(int conf_mine, int conf_theirs, uint64_t max_ancestors)
CAmount GetSelectedValue() const
Get the sum of the input values.
CFeeRate m_discard_feerate
If the cost to spend a change output at the discard feerate exceeds its value, drop it to fees.
CAmount long_term_fee
The fee to spend these UTXOs at the long term feerate.
void Insert(const CInputCoin &output, int depth, bool from_me, size_t ancestors, size_t descendants, bool positive_only)
const bool m_include_partial_groups
When avoid_reuse=true and there are full groups (OUTPUT_GROUP_MAX_ENTRIES), whether or not to use any...
CAmount GetSelectionWaste(const std::set< CInputCoin > &inputs, CAmount change_cost, CAmount target, bool use_effective_value)
Compute the waste for this result given the cost of change and the opportunity cost of spending these...
SelectionResult(const CAmount target)
CFeeRate m_long_term_feerate
The feerate for spending a created change output eventually (i.e.
size_t m_descendants
The maximum count of descendants of a single UTXO in this output group.
CAmount effective_value
The value of the UTXOs after deducting the cost of spending them at the effective feerate.
const std::set< CInputCoin > & GetInputSet() const
Get m_selected_inputs.
std::shared_ptr< const CTransaction > CTransactionRef
CAmount GetSelectionAmount() const
std::optional< SelectionResult > KnapsackSolver(std::vector< OutputGroup > &groups, const CAmount &nTargetValue)
CAmount m_cost_of_change
Cost of creating the change output + cost of spending the change output in the future.
Fee rate in satoshis per kilobyte: CAmount / kB.
bool m_avoid_partial_spends
When true, always spend all (up to OUTPUT_GROUP_MAX_ENTRIES) or none of the outputs associated with t...
const uint64_t max_ancestors
Maximum number of unconfirmed ancestors aggregated across all UTXOs in an OutputGroup.
CFeeRate m_effective_feerate
The target feerate of the transaction we're trying to build.
bool m_use_effective
Whether the input values for calculations should be the effective value (true) or normal value (false...
CFeeRate m_effective_feerate
The targeted feerate of the transaction being built.
void ComputeAndSetWaste(CAmount change_cost)
Calculates and stores the waste for this selection via GetSelectionWaste.
CoinEligibilityFilter(int conf_mine, int conf_theirs, uint64_t max_ancestors, uint64_t max_descendants, bool include_partial)
An output of a transaction.
const CAmount m_target
The target the algorithm selected for.
CoinSelectionParams(size_t change_output_size, size_t change_spend_size, CFeeRate effective_feerate, CFeeRate long_term_feerate, CFeeRate discard_feerate, size_t tx_noinputs_size, bool avoid_partial)
CAmount m_value
The total value of the UTXOs in sum.
bool m_from_me
Whether the UTXOs were sent by the wallet to itself.
int64_t CAmount
Amount in satoshis (Can be negative)
int m_depth
The minimum number of confirmations the UTXOs in the group have.
const uint64_t max_descendants
Maximum number of descendants that a single UTXO in the OutputGroup may have.
A group of UTXOs paid to the same output script.
size_t change_spend_size
Size of the input to spend a change output in virtual bytes.
std::optional< SelectionResult > SelectCoinsBnB(std::vector< OutputGroup > &utxo_pool, const CAmount &selection_target, const CAmount &cost_of_change)
bool EligibleForSpending(const CoinEligibilityFilter &eligibility_filter) const
CAmount m_change_fee
Cost of creating the change output.
static constexpr CAmount MIN_CHANGE
target minimum change amount
CFeeRate m_long_term_feerate
The feerate estimate used to estimate an upper bound on what should be sufficient to spend the change...
std::vector< CInputCoin > GetShuffledInputVector() const
Get the vector of CInputCoins that will be used to fill in a CTransaction's vin.
static const CAmount MIN_FINAL_CHANGE
final minimum change amount after paying for fees
Parameters for one iteration of Coin Selection.
CoinEligibilityFilter(int conf_mine, int conf_theirs, uint64_t max_ancestors, uint64_t max_descendants)
size_t m_ancestors
The aggregated count of unconfirmed ancestors of all UTXOs in this group.
bool m_subtract_fee_outputs
Indicate that we are subtracting the fee from outputs.
void AddInput(const OutputGroup &group)
const int conf_mine
Minimum number of confirmations for outputs that we sent to ourselves.
std::optional< CAmount > m_waste
The computed waste.
An outpoint - a combination of a transaction hash and an index n into its vout.
CAmount fee
The fee to spend these UTXOs at the effective feerate.
static constexpr CAmount COIN
The amount of satoshis in one BTC.
const int conf_theirs
Minimum number of confirmations for outputs received from a different wallet.
Parameters for filtering which OutputGroups we may use in coin selection.
OutputGroup(const CoinSelectionParams ¶ms)
std::set< CInputCoin > m_selected_inputs
Set of inputs selected by the algorithm to use in the transaction.
size_t change_output_size
Size of a change output in bytes, determined by the output type.
bool operator<(SelectionResult other) const