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

Function create_close_tx

common/close_tx.c:8–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6#include <common/psbt_keypath.h>
7
8struct bitcoin_tx *create_close_tx(const tal_t *ctx,
9 const struct chainparams *chainparams,
10 u32 *local_wallet_index,
11 const struct ext_key *local_wallet_ext_key,
12 const u8 *our_script,
13 const u8 *their_script,
14 const u8 *funding_wscript,
15 const struct bitcoin_outpoint *funding,
16 struct amount_sat funding_sats,
17 struct amount_sat to_us,
18 struct amount_sat to_them,
19 struct amount_sat dust_limit)
20{
21 struct bitcoin_tx *tx;
22 size_t num_outputs = 0;
23 struct amount_sat total_out;
24 u8 *script;
25
26 /* BOLT #3:
27 * ## Legacy Closing Transaction
28 *...
29 * ### Requirements
30 *
31 * Each node offering a signature:
32 * - MUST round each output down to whole satoshis.
33 * - MUST subtract the fee given by `fee_satoshis` from the output to the funder.
34 * - MUST remove any output below its own `dust_limit_satoshis`.
35 * - MAY eliminate its own output.
36 */
37 assert(amount_sat_add(&total_out, to_us, to_them));
38 assert(amount_sat_less_eq(total_out, funding_sats));
39
40 /* BOLT #3:
41 *
42 * ## Legacy Closing Transaction
43 *
44 * This variant is used for `closing_signed` messages (i.e. where
45 * `option_simple_close` is not negotiated).
46 *
47 * Note that there are two possible variants for each node.
48 *
49 * * version: 2
50 * * locktime: 0
51 * * txin count: 1
52 */
53 /* Now create close tx: one input, two outputs. */
54 tx = bitcoin_tx(ctx, chainparams, 1, 2, 0);
55
56 /* Our input spends the anchor tx output. */
57 bitcoin_tx_add_input(tx, funding,
58 BITCOIN_TX_DEFAULT_SEQUENCE, NULL,
59 funding_sats, NULL, funding_wscript);
60
61 if (amount_sat_greater_eq(to_us, dust_limit)) {
62 script = tal_dup_talarr(tx, u8, our_script);
63 /* One output is to us. */
64 bitcoin_tx_add_output(tx, script, NULL, to_us);
65 assert((local_wallet_index == NULL) == (local_wallet_ext_key == NULL));

Callers 3

close_txFunction · 0.85
runFunction · 0.85

Calls 13

amount_sat_less_eqFunction · 0.85
bitcoin_tx_add_inputFunction · 0.85
bitcoin_tx_add_outputFunction · 0.85
tal_bytelenFunction · 0.85
tal_freeFunction · 0.85
permute_outputsFunction · 0.85
bitcoin_tx_finalizeFunction · 0.85
bitcoin_tx_checkFunction · 0.85
amount_sat_addFunction · 0.70
bitcoin_txClass · 0.70
amount_sat_greater_eqFunction · 0.70

Tested by

no test coverage detected