From 165d039f6c5cd76e39644ef1bdc4b3ccb1915847 Mon Sep 17 00:00:00 2001 From: niftynei Date: Wed, 9 Sep 2020 20:52:08 -0500 Subject: [PATCH] elements: consolidate fee outputs into a single fee output In the case that you've got more than one fee output already on a psbt, we consolidate them into a single fee output (the first) --- bitcoin/psbt.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bitcoin/psbt.c b/bitcoin/psbt.c index 970e67a53..71f267e1d 100644 --- a/bitcoin/psbt.c +++ b/bitcoin/psbt.c @@ -327,7 +327,13 @@ void psbt_elements_normalize_fees(struct wally_psbt *psbt) for (size_t i = 0; i < psbt->num_outputs; i++) { asset = wally_tx_output_get_amount(&psbt->tx->outputs[i]); if (elements_wtx_output_is_fee(psbt->tx, i)) { - fee_output_idx = i; + if (fee_output_idx == psbt->num_outputs) { + fee_output_idx = i; + continue; + } + /* We already have at least one fee output, + * remove this one */ + psbt_rm_output(psbt, i--); continue; } if (!amount_asset_is_main(&asset))