Low-level tx creator: used when onchaind has done most of the work! */
| 6 | |
| 7 | /* Low-level tx creator: used when onchaind has done most of the work! */ |
| 8 | struct bitcoin_tx *htlc_tx(const tal_t *ctx, |
| 9 | const struct chainparams *chainparams, |
| 10 | const struct bitcoin_outpoint *commit, |
| 11 | const u8 *commit_wscript, |
| 12 | struct amount_sat amount, |
| 13 | const u8 *htlc_tx_wscript, |
| 14 | struct amount_sat htlc_fee, |
| 15 | u32 locktime, |
| 16 | bool option_anchor_outputs, |
| 17 | bool option_anchors_zero_fee_htlc_tx) |
| 18 | { |
| 19 | /* BOLT #3: |
| 20 | * * locktime: `0` for HTLC-success, `cltv_expiry` for HTLC-timeout |
| 21 | */ |
| 22 | struct bitcoin_tx *tx = bitcoin_tx(ctx, chainparams, 1, 1, locktime); |
| 23 | |
| 24 | /* BOLT #3: |
| 25 | * |
| 26 | * ## HTLC-Timeout and HTLC-Success Transactions |
| 27 | * |
| 28 | * These HTLC transactions are almost identical, except the |
| 29 | * HTLC-timeout transaction is timelocked. Both |
| 30 | * HTLC-timeout/HTLC-success transactions can be spent by a valid |
| 31 | * penalty transaction. |
| 32 | */ |
| 33 | |
| 34 | /* BOLT #3: |
| 35 | * * version: 2 |
| 36 | */ |
| 37 | assert(tx->wtx->version == 2); |
| 38 | |
| 39 | /* BOLT #3: |
| 40 | * * txin count: 1 |
| 41 | * * `txin[0]` outpoint: `txid` of the commitment transaction and |
| 42 | * `output_index` of the matching HTLC output for the HTLC |
| 43 | * transaction |
| 44 | * * `txin[0]` sequence: `0` (set to `1` for `option_anchors`) |
| 45 | */ |
| 46 | bitcoin_tx_add_input(tx, commit, |
| 47 | (option_anchor_outputs || option_anchors_zero_fee_htlc_tx) ? 1 : 0, |
| 48 | NULL, amount, NULL, commit_wscript); |
| 49 | |
| 50 | /* BOLT #3: |
| 51 | * * txout count: 1 |
| 52 | * * `txout[0]` amount: the HTLC `amount_msat` divided by 1000 |
| 53 | * (rounding down) minus fees in satoshis (see |
| 54 | * [Fee Calculation](#fee-calculation)) |
| 55 | * * `txout[0]` script: version-0 P2WSH with witness script as shown |
| 56 | * below |
| 57 | */ |
| 58 | /* Note: for option_anchors_zero_fee_htlc_tx, htlc_fee is 0 */ |
| 59 | if (!amount_sat_sub(&amount, amount, htlc_fee)) |
| 60 | return tal_free(tx); |
| 61 | |
| 62 | bitcoin_tx_add_output(tx, scriptpubkey_p2wsh(tmpctx, htlc_tx_wscript), |
| 63 | htlc_tx_wscript, amount); |
| 64 | |
| 65 | bitcoin_tx_finalize(tx); |
no test coverage detected