MCPcopy Create free account
hub / github.com/ElementsProject/lightning / change_amount

Function change_amount

bitcoin/tx.c:897–920  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

895}
896
897struct amount_sat change_amount(struct amount_sat excess, u32 feerate_perkw,
898 size_t total_weight)
899{
900 size_t outweight;
901 struct amount_sat change_fee;
902
903 /* Must be able to pay for its own additional weight */
904 outweight = bitcoin_tx_output_weight(BITCOIN_SCRIPTPUBKEY_P2WPKH_LEN);
905
906 /* Rounding can cause off by one errors, so we do this */
907 if (!amount_sat_sub(&change_fee,
908 amount_tx_fee(feerate_perkw, outweight + total_weight),
909 amount_tx_fee(feerate_perkw, total_weight)))
910 return AMOUNT_SAT(0);
911
912 if (!amount_sat_sub(&excess, excess, change_fee))
913 return AMOUNT_SAT(0);
914
915 /* Must be non-dust */
916 if (!amount_sat_greater_eq(excess, chainparams->dust_limit))
917 return AMOUNT_SAT(0);
918
919 return excess;
920}

Callers 3

finish_psbtFunction · 0.85
psbt_createdFunction · 0.85
mw_after_fundpsbtFunction · 0.85

Calls 4

bitcoin_tx_output_weightFunction · 0.85
amount_sat_subFunction · 0.50
amount_tx_feeFunction · 0.50
amount_sat_greater_eqFunction · 0.50

Tested by

no test coverage detected