| 5 | #include <common/keyset.h> |
| 6 | |
| 7 | static struct bitcoin_tx *htlc_tx(const tal_t *ctx, |
| 8 | const struct chainparams *chainparams, |
| 9 | const struct bitcoin_outpoint *commit, |
| 10 | const u8 *commit_wscript, |
| 11 | struct amount_msat msat, |
| 12 | u16 to_self_delay, |
| 13 | const struct pubkey *revocation_pubkey, |
| 14 | const struct pubkey *local_delayedkey, |
| 15 | struct amount_sat htlc_fee, |
| 16 | u32 locktime, |
| 17 | bool option_anchor_outputs) |
| 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 | u8 *wscript; |
| 24 | struct amount_sat amount; |
| 25 | |
| 26 | /* BOLT #3: |
| 27 | * |
| 28 | * ## HTLC-Timeout and HTLC-Success Transactions |
| 29 | * |
| 30 | * These HTLC transactions are almost identical, except the |
| 31 | * HTLC-timeout transaction is timelocked. Both |
| 32 | * HTLC-timeout/HTLC-success transactions can be spent by a valid |
| 33 | * penalty transaction. |
| 34 | */ |
| 35 | |
| 36 | /* BOLT #3: |
| 37 | * * version: 2 |
| 38 | */ |
| 39 | assert(tx->wtx->version == 2); |
| 40 | |
| 41 | /* BOLT #3: |
| 42 | * * txin count: 1 |
| 43 | * * `txin[0]` outpoint: `txid` of the commitment transaction and |
| 44 | * `output_index` of the matching HTLC output for the HTLC |
| 45 | * transaction |
| 46 | * * `txin[0]` sequence: `0` (set to `1` for `option_anchors`) |
| 47 | */ |
| 48 | amount = amount_msat_to_sat_round_down(msat); |
| 49 | bitcoin_tx_add_input(tx, commit, |
| 50 | option_anchor_outputs ? 1 : 0, |
| 51 | NULL, amount, NULL, commit_wscript); |
| 52 | |
| 53 | /* BOLT #3: |
| 54 | * * txout count: 1 |
| 55 | * * `txout[0]` amount: the HTLC `amount_msat` divided by 1000 |
| 56 | * (rounding down) minus fees in satoshis (see |
| 57 | * [Fee Calculation](#fee-calculation)) |
| 58 | * * `txout[0]` script: version-0 P2WSH with witness script as shown |
| 59 | * below |
| 60 | */ |
| 61 | if (!amount_sat_sub(&amount, amount, htlc_fee)) |
| 62 | abort(); |
| 63 | |
| 64 | wscript = bitcoin_wscript_htlc_tx(tx, to_self_delay, revocation_pubkey, |
no test coverage detected