MCPcopy Create free account
hub / github.com/ElementsProject/lightning / htlc_tx

Function htlc_tx

common/htlc_tx.c:7–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5#include <common/keyset.h>
6
7static 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,

Callers 2

htlc_success_txFunction · 0.85
htlc_timeout_txFunction · 0.85

Calls 11

bitcoin_tx_add_inputFunction · 0.85
abortFunction · 0.85
bitcoin_wscript_htlc_txFunction · 0.85
bitcoin_tx_add_outputFunction · 0.85
bitcoin_tx_finalizeFunction · 0.85
bitcoin_tx_checkFunction · 0.85
tal_freeFunction · 0.85
bitcoin_txClass · 0.70
amount_sat_subFunction · 0.70
scriptpubkey_p2wshFunction · 0.50

Tested by

no test coverage detected