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

Function tlv_update_fields_

wire/tlvstream.c:378–422  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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