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

Function tlv_update_fields_

wire/tlvstream.c:376–420  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

374}
375
376void tlv_update_fields_(const struct tlv_record_type *types,
377 size_t num_types,
378 const void *record,
379 struct tlv_field **tlv_fields)
380{
381 /* We merge unknown fields from record */
382 const struct tlv_field *field, *end;
383 struct tlv_field *fields = tal_arr(record, struct tlv_field, 0);
384
385 field = first_unknown_field(*tlv_fields, &end);
386
387 for (size_t i = 0; i < num_types; i++) {
388 struct tlv_field f;
389 u8 *val;
390 if (i != 0)
391 assert(types[i].type > types[i-1].type);
392
393 /* Add any unknowns which precede this. */
394 while (field && field->numtype < types[i].type) {
395 tal_steal(fields, field->value);
396 tal_arr_expand(&fields, *field);
397 field = next_unknown_field(field, end);
398 }
399
400 val = types[i].towire(NULL, record);
401 if (!val)
402 continue;
403
404 f.meta = &types[i];
405 f.numtype = types[i].type;
406 f.length = tal_bytelen(val);
407 f.value = tal_steal(fields, val);
408 tal_arr_expand(&fields, f);
409 }
410
411 /* Add any unknowns at the end. */
412 while (field) {
413 tal_steal(fields, field->value);
414 tal_arr_expand(&fields, *field);
415 field = next_unknown_field(field, end);
416 }
417
418 tal_free(*tlv_fields);
419 *tlv_fields = fields;
420}

Callers

nothing calls this directly

Calls 4

first_unknown_fieldFunction · 0.85
next_unknown_fieldFunction · 0.85
tal_bytelenFunction · 0.85
tal_freeFunction · 0.85

Tested by

no test coverage detected