* 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. */
| 165 | * transactions. |
| 166 | */ |
| 167 | static int elements_tx_add_fee_output(struct bitcoin_tx *tx) |
| 168 | { |
| 169 | struct amount_sat fee = bitcoin_tx_compute_fee(tx); |
| 170 | int pos; |
| 171 | |
| 172 | /* If we aren't using elements, we don't add explicit fee outputs */ |
| 173 | if (!chainparams->is_elements) |
| 174 | return -1; |
| 175 | |
| 176 | /* Try to find any existing fee output */ |
| 177 | for (pos = 0; pos < tx->wtx->num_outputs; pos++) { |
| 178 | if (elements_tx_output_is_fee(tx, pos)) |
| 179 | break; |
| 180 | } |
| 181 | |
| 182 | if (pos == tx->wtx->num_outputs) |
| 183 | return bitcoin_tx_add_output(tx, NULL, NULL, fee); |
| 184 | else { |
| 185 | bitcoin_tx_output_set_amount(tx, pos, fee); |
| 186 | return pos; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | void bitcoin_tx_set_locktime(struct bitcoin_tx *tx, u32 locktime) |
| 191 | { |
no test coverage detected