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

Function linearize_output

common/psbt_open.c:96–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

94}
95
96static const u8 *linearize_output(const tal_t *ctx,
97 const struct wally_psbt_output *out,
98 const struct wally_tx_output *tx_out)
99{
100 struct wally_psbt *psbt = create_psbt(NULL, 1, 1, 0);
101 size_t byte_len;
102 struct bitcoin_outpoint outpoint;
103
104 /* Add a 'fake' input so this will linearize the tx */
105 memset(&outpoint, 0, sizeof(outpoint));
106 psbt_append_input(psbt, &outpoint, 0, NULL, NULL, NULL);
107
108 tal_wally_start();
109 if (wally_tx_add_output(psbt->tx, tx_out) != WALLY_OK)
110 abort();
111 tal_wally_end(psbt->tx);
112
113 psbt->outputs[0] = *out;
114 psbt->num_outputs++;
115 /* Sort the outputs, so serializing them is ok */
116 wally_map_sort(&psbt->outputs[0].unknowns, 0);
117
118 /* We don't care if the keypaths change */
119 psbt->outputs[0].keypaths.num_items = 0;
120 /* And you can add scripts, no problem */
121 psbt->outputs[0].witness_script_len = 0;
122 psbt->outputs[0].redeem_script_len = 0;
123
124 const u8 *bytes = psbt_get_bytes(ctx, psbt, &byte_len);
125
126 /* Hide the outputs we added, so it doesn't get freed */
127 psbt->num_outputs--;
128 tal_free(psbt);
129 return bytes;
130}
131
132static bool input_identical(const struct wally_psbt *a,
133 size_t a_index,

Callers 1

output_identicalFunction · 0.85

Calls 7

create_psbtFunction · 0.85
tal_wally_startFunction · 0.85
abortFunction · 0.85
tal_wally_endFunction · 0.85
psbt_get_bytesFunction · 0.85
tal_freeFunction · 0.85
psbt_append_inputFunction · 0.50

Tested by

no test coverage detected