* Add an explicit fee output if necessary. * * An explicit fee output is only necessary if we are using an elements * transaction, and we have a non-zero fee. This method may be called multiple * times. * * Returns the position of the fee output, or -1 in the case of non-elements * transactions. */
| 155 | * transactions. |
| 156 | */ |
| 157 | static int elements_tx_add_fee_output(struct bitcoin_tx *tx) |
| 158 | { |
| 159 | struct amount_sat fee = bitcoin_tx_compute_fee(tx); |
| 160 | int pos; |
| 161 | |
| 162 | /* If we aren't using elements, we don't add explicit fee outputs */ |
| 163 | if (!chainparams->is_elements) |
| 164 | return -1; |
| 165 | |
| 166 | /* Try to find any existing fee output */ |
| 167 | for (pos = 0; pos < tx->wtx->num_outputs; pos++) { |
| 168 | if (elements_tx_output_is_fee(tx, pos)) |
| 169 | break; |
| 170 | } |
| 171 | |
| 172 | if (pos == tx->wtx->num_outputs) |
| 173 | return bitcoin_tx_add_output(tx, NULL, NULL, fee); |
| 174 | else { |
| 175 | bitcoin_tx_output_set_amount(tx, pos, fee); |
| 176 | return pos; |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | void bitcoin_tx_set_locktime(struct bitcoin_tx *tx, u32 locktime) |
| 181 | { |
no test coverage detected