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

Function psbt_changeset_get_next

openingd/dualopend.c:246–313  ·  view source on GitHub ↗

psbt_changeset_get_next - Get next message to send * * This generates the next message to send from a changeset for the * interactive transaction protocol. * * @ctx - allocation context of returned msg * @cid - channel_id for the message * @set - changeset to get next update from * * Returns a wire message or NULL if no changes. */

Source from the content-addressed store, hash-verified

244 * Returns a wire message or NULL if no changes.
245 */
246static u8 *psbt_changeset_get_next(const tal_t *ctx,
247 struct channel_id *cid,
248 struct psbt_changeset *set)
249{
250 u64 serial_id;
251 u8 *msg;
252
253 if (tal_count(set->added_ins) != 0) {
254 const struct input_set *in = &set->added_ins[0];
255
256 if (!psbt_get_serial_id(&in->input.unknowns, &serial_id))
257 abort();
258
259 const u8 *prevtx = linearize_wtx(ctx,
260 in->input.utxo);
261
262 msg = towire_tx_add_input(ctx, cid, serial_id,
263 prevtx, in->input.index,
264 in->input.sequence,
265 NULL);
266
267 tal_arr_remove(&set->added_ins, 0);
268 return msg;
269 }
270 if (tal_count(set->rm_ins) != 0) {
271 if (!psbt_get_serial_id(&set->rm_ins[0].input.unknowns,
272 &serial_id))
273 abort();
274
275 msg = towire_tx_remove_input(ctx, cid, serial_id);
276
277 tal_arr_remove(&set->rm_ins, 0);
278 return msg;
279 }
280 if (tal_count(set->added_outs) != 0) {
281 struct amount_sat sats;
282 struct amount_asset asset_amt;
283
284 const struct output_set *out = &set->added_outs[0];
285 if (!psbt_get_serial_id(&out->output.unknowns, &serial_id))
286 abort();
287
288 asset_amt = wally_psbt_output_get_amount(&out->output);
289 sats = amount_asset_to_sat(&asset_amt);
290 const u8 *script = wally_psbt_output_get_script(ctx,
291 &out->output);
292
293
294 msg = towire_tx_add_output(ctx, cid, serial_id,
295 sats.satoshis, /* Raw: wire interface */
296 script);
297
298 tal_arr_remove(&set->added_outs, 0);
299 return msg;
300 }
301 if (tal_count(set->rm_outs) != 0) {
302 if (!psbt_get_serial_id(&set->rm_outs[0].output.unknowns,
303 &serial_id))

Callers 1

send_nextFunction · 0.85

Calls 6

psbt_get_serial_idFunction · 0.85
abortFunction · 0.85
linearize_wtxFunction · 0.85
amount_asset_to_satFunction · 0.50

Tested by

no test coverage detected