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

Function psbt_compute_fee

bitcoin/psbt.c:1009–1034  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1007}
1008
1009struct amount_sat psbt_compute_fee(const struct wally_psbt *psbt)
1010{
1011 struct amount_sat fee, input_amt;
1012 struct amount_asset asset;
1013 bool ok;
1014
1015 fee = AMOUNT_SAT(0);
1016 for (size_t i = 0; i < psbt->num_inputs; i++) {
1017 input_amt = psbt_input_get_amount(psbt, i);
1018 ok = amount_sat_add(&fee, fee, input_amt);
1019 assert(ok);
1020 }
1021
1022 for (size_t i = 0; i < psbt->num_outputs; i++) {
1023 asset = wally_psbt_output_get_amount(&psbt->outputs[i]);
1024 if (!amount_asset_is_main(&asset)
1025 || elements_psbt_output_is_fee(psbt, i))
1026 continue;
1027
1028 ok = amount_sat_sub(&fee, fee, amount_asset_to_sat(&asset));
1029 if (!ok)
1030 return AMOUNT_SAT(0);
1031 }
1032
1033 return fee;
1034}
1035
1036bool wally_psbt_input_spends(const struct wally_psbt_input *input,
1037 const struct bitcoin_outpoint *outpoint)

Callers 5

feerate_satisfiedFunction · 0.85
handle_validate_rbfFunction · 0.85
anchor_psbtFunction · 0.85
try_anchor_psbtFunction · 0.85

Calls 7

psbt_input_get_amountFunction · 0.85
amount_sat_addFunction · 0.50
amount_asset_is_mainFunction · 0.50
amount_sat_subFunction · 0.50
amount_asset_to_satFunction · 0.50

Tested by

no test coverage detected