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

Function htlc_tx

common/htlc_tx.c:8–69  ·  view source on GitHub ↗

Low-level tx creator: used when onchaind has done most of the work! */

Source from the content-addressed store, hash-verified

6
7/* Low-level tx creator: used when onchaind has done most of the work! */
8struct 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);

Callers 4

htlc_success_txFunction · 0.85
htlc_timeout_txFunction · 0.85

Calls 8

bitcoin_tx_add_inputFunction · 0.85
tal_freeFunction · 0.85
bitcoin_tx_add_outputFunction · 0.85
scriptpubkey_p2wshFunction · 0.85
bitcoin_tx_finalizeFunction · 0.85
bitcoin_tx_checkFunction · 0.85
bitcoin_txClass · 0.70
amount_sat_subFunction · 0.70

Tested by

no test coverage detected