Bitcoin Core  24.1.0
P2P Digital Currency
Public Member Functions | Private Attributes | List of all members
wallet::SelectionResult Struct Reference

#include <coinselection.h>

Public Member Functions

 SelectionResult (const CAmount target, SelectionAlgorithm algo)
 
 SelectionResult ()=delete
 
CAmount GetSelectedValue () const
 Get the sum of the input values. More...
 
CAmount GetSelectedEffectiveValue () const
 
void Clear ()
 
void AddInput (const OutputGroup &group)
 
void ComputeAndSetWaste (const CAmount min_viable_change, const CAmount change_cost, const CAmount change_fee)
 Calculates and stores the waste for this selection via GetSelectionWaste. More...
 
CAmount GetWaste () const
 
void Merge (const SelectionResult &other)
 
const std::set< COutput > & GetInputSet () const
 Get m_selected_inputs. More...
 
std::vector< COutputGetShuffledInputVector () const
 Get the vector of COutputs that will be used to fill in a CTransaction's vin. More...
 
bool operator< (SelectionResult other) const
 
CAmount GetChange (const CAmount min_viable_change, const CAmount change_fee) const
 Get the amount for the change output after paying needed fees. More...
 
CAmount GetTarget () const
 
SelectionAlgorithm GetAlgo () const
 

Private Attributes

std::set< COutputm_selected_inputs
 Set of inputs selected by the algorithm to use in the transaction. More...
 
CAmount m_target
 The target the algorithm selected for. More...
 
SelectionAlgorithm m_algo
 The algorithm used to produce this result. More...
 
bool m_use_effective {false}
 Whether the input values for calculations should be the effective value (true) or normal value (false) More...
 
std::optional< CAmountm_waste
 The computed waste. More...
 

Detailed Description

Definition at line 283 of file coinselection.h.

Constructor & Destructor Documentation

◆ SelectionResult() [1/2]

wallet::SelectionResult::SelectionResult ( const CAmount  target,
SelectionAlgorithm  algo 
)
inlineexplicit

Definition at line 298 of file coinselection.h.

◆ SelectionResult() [2/2]

wallet::SelectionResult::SelectionResult ( )
delete

Member Function Documentation

◆ AddInput()

void wallet::SelectionResult::AddInput ( const OutputGroup group)

Definition at line 441 of file coinselection.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Clear()

void wallet::SelectionResult::Clear ( )

Definition at line 435 of file coinselection.cpp.

Here is the caller graph for this function:

◆ ComputeAndSetWaste()

void wallet::SelectionResult::ComputeAndSetWaste ( const CAmount  min_viable_change,
const CAmount  change_cost,
const CAmount  change_fee 
)

Calculates and stores the waste for this selection via GetSelectionWaste.

Definition at line 409 of file coinselection.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetAlgo()

SelectionAlgorithm wallet::SelectionResult::GetAlgo ( ) const
inline

Definition at line 346 of file coinselection.h.

◆ GetChange()

CAmount wallet::SelectionResult::GetChange ( const CAmount  min_viable_change,
const CAmount  change_fee 
) const

Get the amount for the change output after paying needed fees.

The change amount is not 100% precise due to discrepancies in fee calculation. The final change amount (if any) should be corrected after calculating the final tx fees. When there is a discrepancy, most of the time the final change would be slightly bigger than estimated.

Following are the possible factors of discrepancy:

  • non-input fees always include segwit flags
  • input fee estimation always include segwit stack size
  • input fees are rounded individually and not collectively, which leads to small rounding errors
  • input counter size is always assumed to be 1vbyte
Parameters
[in]min_viable_changeMinimum amount for change output, if change would be less then we forgo change
[in]change_feeFees to include change output in the tx
Returns
Amount for change output, 0 when there is no change.

Definition at line 495 of file coinselection.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetInputSet()

const std::set< COutput > & wallet::SelectionResult::GetInputSet ( ) const

Get m_selected_inputs.

Definition at line 457 of file coinselection.cpp.

Here is the caller graph for this function:

◆ GetSelectedEffectiveValue()

CAmount wallet::SelectionResult::GetSelectedEffectiveValue ( ) const

Definition at line 430 of file coinselection.cpp.

Here is the caller graph for this function:

◆ GetSelectedValue()

CAmount wallet::SelectionResult::GetSelectedValue ( ) const

Get the sum of the input values.

Definition at line 425 of file coinselection.cpp.

Here is the caller graph for this function:

◆ GetShuffledInputVector()

std::vector< COutput > wallet::SelectionResult::GetShuffledInputVector ( ) const

Get the vector of COutputs that will be used to fill in a CTransaction's vin.

Definition at line 462 of file coinselection.cpp.

Here is the call graph for this function:

◆ GetTarget()

CAmount wallet::SelectionResult::GetTarget ( ) const
inline

Definition at line 344 of file coinselection.h.

◆ GetWaste()

CAmount wallet::SelectionResult::GetWaste ( ) const

Definition at line 420 of file coinselection.cpp.

Here is the caller graph for this function:

◆ Merge()

void wallet::SelectionResult::Merge ( const SelectionResult other)

Definition at line 447 of file coinselection.cpp.

Here is the call graph for this function:

◆ operator<()

bool wallet::SelectionResult::operator< ( SelectionResult  other) const

Definition at line 469 of file coinselection.cpp.

Member Data Documentation

◆ m_algo

SelectionAlgorithm wallet::SelectionResult::m_algo
private

The algorithm used to produce this result.

Definition at line 291 of file coinselection.h.

◆ m_selected_inputs

std::set<COutput> wallet::SelectionResult::m_selected_inputs
private

Set of inputs selected by the algorithm to use in the transaction.

Definition at line 287 of file coinselection.h.

◆ m_target

CAmount wallet::SelectionResult::m_target
private

The target the algorithm selected for.

Equal to the recipient amount plus non-input fees

Definition at line 289 of file coinselection.h.

◆ m_use_effective

bool wallet::SelectionResult::m_use_effective {false}
private

Whether the input values for calculations should be the effective value (true) or normal value (false)

Definition at line 293 of file coinselection.h.

◆ m_waste

std::optional<CAmount> wallet::SelectionResult::m_waste
private

The computed waste.

Definition at line 295 of file coinselection.h.


The documentation for this struct was generated from the following files: