Skip to content

Commit

Permalink
wire: Add a function to serialize a raw set of TLV fields
Browse files Browse the repository at this point in the history
The generated wrappers will ignore the raw fields and will only consider the
shortcut fields. This function takes the raw fields and serializes them
instead.
  • Loading branch information
cdecker authored and rustyrussell committed Apr 16, 2020
1 parent ef0f28c commit 1b32cc1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugins/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ plugins/fundchannel: common/addr.o $(PLUGIN_FUNDCHANNEL_OBJS) $(PLUGIN_LIB_OBJS)

plugins/bcli: bitcoin/chainparams.o $(PLUGIN_BCLI_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS)

plugins/keysend: bitcoin/chainparams.o wire/gen_onion_wire.o $(PLUGIN_KEYSEND_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS)
plugins/keysend: bitcoin/chainparams.o wire/tlvstream.o wire/gen_onion_wire.o $(PLUGIN_KEYSEND_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS)

$(PLUGIN_PAY_OBJS) $(PLUGIN_AUTOCLEAN_OBJS) $(PLUGIN_FUNDCHANNEL_OBJS) $(PLUGIN_BCLI_OBJS) $(PLUGIN_LIB_OBJS): $(PLUGIN_LIB_HEADER)

Expand Down
21 changes: 21 additions & 0 deletions wire/tlvstream.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <wire/tlvstream.h>
#include <wire/wire.h>

void towire_tlvstream_raw(u8 **pptr, const struct tlv_field *fields)
{
if (!fields)
return;

for (size_t i = 0; i < tal_count(fields); i++) {
const struct tlv_field *field = &fields[i];
/* BOLT #1:
*
* The sending node:
...
* - MUST minimally encode `type` and `length`.
*/
towire_bigsize(pptr, field->numtype);
towire_bigsize(pptr, field->length);
towire(pptr, field->value, field->length);
}
}
3 changes: 3 additions & 0 deletions wire/tlvstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ void towire_tlvs(u8 **pptr,
size_t num_types,
const void *record);

/* Given any tlvstream serialize the raw fields (untyped ones). */
void towire_tlvstream_raw(u8 **pptr, const struct tlv_field *fields);

#endif /* LIGHTNING_WIRE_TLVSTREAM_H */

0 comments on commit 1b32cc1

Please sign in to comment.