From 986c61fc835b2800af21154870da5a1ded2512fc Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Fri, 3 Jul 2020 17:22:03 +0200 Subject: [PATCH] tlvstream: Allow overwriting an already set value This is necessary in the next commit to override the total_msat that is being delivered to the destination. --- wire/tlvstream.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/wire/tlvstream.c b/wire/tlvstream.c index df96d307a..788744483 100644 --- a/wire/tlvstream.c +++ b/wire/tlvstream.c @@ -21,13 +21,29 @@ void towire_tlvstream_raw(u8 **pptr, const struct tlv_field *fields) } } +static struct tlv_field *tlvstream_get_raw(struct tlv_field *stream, u64 type) +{ + for (size_t i=0; ivalue); + e->length = valuelen; + e->value = tal_dup_arr(*stream, u8, value, e->length, 0); + } else { + /* If we haven't found it insert it insead. */ + f.length = valuelen; + f.numtype = type; + f.value = tal_dup_arr(*stream, u8, value, f.length, 0); + tal_arr_expand(stream, f); + } } void tlvstream_set_short_channel_id(struct tlv_field **stream, u64 type, @@ -52,15 +68,6 @@ void tlvstream_set_tu32(struct tlv_field **stream, u64 type, u32 value) tlvstream_set_raw(stream, type, ser, tal_bytelen(ser)); } -static struct tlv_field *tlvstream_get_raw(struct tlv_field *stream, u64 type) -{ - for (size_t i=0; i