| 1590 | } |
| 1591 | |
| 1592 | static void resolve_htlc_tx(struct tracked_output ***outs, |
| 1593 | size_t out_index, |
| 1594 | const struct tx_parts *htlc_tx, |
| 1595 | size_t input_num, |
| 1596 | u32 tx_blockheight) |
| 1597 | { |
| 1598 | struct tracked_output *out; |
| 1599 | struct bitcoin_tx *tx; |
| 1600 | struct amount_sat amt; |
| 1601 | struct amount_asset asset; |
| 1602 | struct bitcoin_outpoint outpoint; |
| 1603 | enum tx_type tx_type = OUR_DELAYED_RETURN_TO_WALLET; |
| 1604 | u8 *wscript = bitcoin_wscript_htlc_tx(htlc_tx, to_self_delay[LOCAL], |
| 1605 | &keyset->self_revocation_key, |
| 1606 | &keyset->self_delayed_payment_key); |
| 1607 | |
| 1608 | |
| 1609 | /* BOLT #5: |
| 1610 | * |
| 1611 | * - SHOULD resolve the HTLC-timeout transaction by spending it to |
| 1612 | * a convenient address... |
| 1613 | * - MUST wait until the `OP_CHECKSEQUENCEVERIFY` delay has passed |
| 1614 | * (as specified by the remote node's `open_channel` |
| 1615 | * `to_self_delay` field) before spending that HTLC-timeout |
| 1616 | * output. |
| 1617 | */ |
| 1618 | outpoint.txid = htlc_tx->txid; |
| 1619 | outpoint.n = input_num; |
| 1620 | |
| 1621 | asset = wally_tx_output_get_amount(htlc_tx->outputs[outpoint.n]); |
| 1622 | assert(amount_asset_is_main(&asset)); |
| 1623 | amt = amount_asset_to_sat(&asset); |
| 1624 | out = new_tracked_output(outs, &outpoint, |
| 1625 | tx_blockheight, |
| 1626 | (*outs)[out_index]->resolved->tx_type, |
| 1627 | amt, |
| 1628 | DELAYED_OUTPUT_TO_US, |
| 1629 | NULL, NULL, NULL); |
| 1630 | |
| 1631 | /* BOLT #3: |
| 1632 | * |
| 1633 | * ## HTLC-Timeout and HTLC-Success Transactions |
| 1634 | * |
| 1635 | * These HTLC transactions are almost identical, except the |
| 1636 | * HTLC-timeout transaction is timelocked. |
| 1637 | * |
| 1638 | * ... to collect the output, the local node uses an input with |
| 1639 | * nSequence `to_self_delay` and a witness stack `<local_delayedsig> |
| 1640 | * 0` |
| 1641 | */ |
| 1642 | tx = tx_to_us(*outs, delayed_payment_to_us, out, to_self_delay[LOCAL], |
| 1643 | 0, NULL, 0, wscript, &tx_type, htlc_feerate); |
| 1644 | |
| 1645 | propose_resolution(out, tx, to_self_delay[LOCAL], tx_type); |
| 1646 | } |
| 1647 | |
| 1648 | /* BOLT #5: |
| 1649 | * |
no test coverage detected