| 60 | } |
| 61 | |
| 62 | int bitcoin_tx_add_output(struct bitcoin_tx *tx, const u8 *script, |
| 63 | const u8 *wscript, struct amount_sat amount) |
| 64 | { |
| 65 | size_t i = tx->wtx->num_outputs; |
| 66 | struct wally_tx_output *output; |
| 67 | struct wally_psbt_output *psbt_out; |
| 68 | int ret; |
| 69 | const struct chainparams *chainparams = tx->chainparams; |
| 70 | assert(i < tx->wtx->outputs_allocation_len); |
| 71 | |
| 72 | assert(tx->wtx != NULL); |
| 73 | assert(chainparams); |
| 74 | |
| 75 | output = wally_tx_output(NULL, script, amount); |
| 76 | assert(output); |
| 77 | tal_wally_start(); |
| 78 | ret = wally_tx_add_output(tx->wtx, output); |
| 79 | assert(ret == WALLY_OK); |
| 80 | tal_wally_end(tx->wtx); |
| 81 | |
| 82 | psbt_out = psbt_add_output(tx->psbt, output, i); |
| 83 | if (wscript) { |
| 84 | tal_wally_start(); |
| 85 | ret = wally_psbt_output_set_witness_script(psbt_out, |
| 86 | wscript, |
| 87 | tal_bytelen(wscript)); |
| 88 | assert(ret == WALLY_OK); |
| 89 | tal_wally_end(tx->psbt); |
| 90 | } |
| 91 | |
| 92 | wally_tx_output_free(output); |
| 93 | bitcoin_tx_output_set_amount(tx, i, amount); |
| 94 | |
| 95 | return i; |
| 96 | } |
| 97 | |
| 98 | void bitcoin_tx_remove_output(struct bitcoin_tx *tx, size_t outnum) |
| 99 | { |
no test coverage detected