Browse Source

wire: Add a function to serialize a raw set of TLV fields

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.
register-keysend-plugin
Christian Decker 5 years ago
committed by Rusty Russell
parent
commit
1b32cc1c73
  1. 2
      plugins/Makefile
  2. 21
      wire/tlvstream.c
  3. 3
      wire/tlvstream.h

2
plugins/Makefile

@ -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)

21
wire/tlvstream.c

@ -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
wire/tlvstream.h

@ -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 */

Loading…
Cancel
Save