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

Function psbt_compute_fee

bitcoin/psbt.c:812–837  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

810}
811
812struct amount_sat psbt_compute_fee(const struct wally_psbt *psbt)
813{
814 struct amount_sat fee, input_amt;
815 struct amount_asset asset;
816 bool ok;
817
818 fee = AMOUNT_SAT(0);
819 for (size_t i = 0; i < psbt->num_inputs; i++) {
820 input_amt = psbt_input_get_amount(psbt, i);
821 ok = amount_sat_add(&fee, fee, input_amt);
822 assert(ok);
823 }
824
825 for (size_t i = 0; i < psbt->num_outputs; i++) {
826 asset = wally_tx_output_get_amount(&psbt->tx->outputs[i]);
827 if (!amount_asset_is_main(&asset)
828 || elements_wtx_output_is_fee(psbt->tx, i))
829 continue;
830
831 ok = amount_sat_sub(&fee, fee, amount_asset_to_sat(&asset));
832 if (!ok)
833 return AMOUNT_SAT(0);
834 }
835
836 return fee;
837}

Callers 2

feerate_satisfiedFunction · 0.85
handle_validate_rbfFunction · 0.85

Calls 7

psbt_input_get_amountFunction · 0.70
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