| 810 | } |
| 811 | |
| 812 | struct 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 | } |
no test coverage detected