wallet::SelectionResult::GetChange

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

Synopsis

Declared in <wallet/coinselection.h>

CAmount
GetChange(
    CAmount min_viable_change,
    CAmount change_fee) const;

Description

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

Return Value

Amount for change output, 0 when there is no change.

Parameters

NameDescription
min_viable_change [in]Minimum amount for change output, if change would be less then we forgo change
change_fee [in]Fees to include change output in the tx