| 1007 | } |
| 1008 | |
| 1009 | struct 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 | |
| 1036 | bool wally_psbt_input_spends(const struct wally_psbt_input *input, |
| 1037 | const struct bitcoin_outpoint *outpoint) |
no test coverage detected