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

Function towire_tlv

wire/tlvstream.c:326–374  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

324}
325
326void towire_tlv(u8 **pptr,
327 const struct tlv_record_type *types, size_t num_types,
328 const void *record)
329{
330 const struct tlv_field *field, *end;
331 if (!record)
332 return;
333
334 /* First field is always "struct tlv_field *fields;" */
335 field = first_unknown_field(*(struct tlv_field **)record, &end);
336
337 for (size_t i = 0; i < num_types; i++) {
338 u8 *val;
339 if (i != 0)
340 assert(types[i].type > types[i-1].type);
341
342 /* Do any unknown fields first */
343 while (field && field->numtype < types[i].type) {
344 towire_bigsize(pptr, field->numtype);
345 towire_bigsize(pptr, field->length);
346 towire(pptr, field->value, field->length);
347 field = next_unknown_field(field, end);
348 }
349
350 val = types[i].towire(NULL, record);
351 if (!val)
352 continue;
353
354 /* BOLT #1:
355 *
356 * The sending node:
357 ...
358 * - MUST minimally encode `type` and `length`.
359 */
360 towire_bigsize(pptr, types[i].type);
361 towire_bigsize(pptr, tal_bytelen(val));
362 towire(pptr, val, tal_bytelen(val));
363 tal_free(val);
364 }
365
366 /* Add any trailing unknown fields */
367 while (field) {
368 towire_bigsize(pptr, field->numtype);
369 towire_bigsize(pptr, field->length);
370 towire(pptr, field->value, field->length);
371 field = next_unknown_field(field, end);
372 }
373
374}
375
376void tlv_update_fields_(const struct tlv_record_type *types,
377 size_t num_types,

Callers

nothing calls this directly

Calls 6

first_unknown_fieldFunction · 0.85
next_unknown_fieldFunction · 0.85
tal_bytelenFunction · 0.85
tal_freeFunction · 0.85
towireFunction · 0.70
towire_bigsizeFunction · 0.50

Tested by

no test coverage detected