From 626675c83c9948fab6aa9654859630d38d9ae5a0 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Wed, 27 Nov 2019 16:07:59 +0100 Subject: [PATCH] tlv: Migrate tlv serialization to typesafe function --- common/sphinx.c | 2 +- common/test/run-sphinx.c | 6 ------ tools/gen/impl_template | 2 +- wire/test/run-tlvstream.c | 4 ++-- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/common/sphinx.c b/common/sphinx.c index 96673aee0..f4f3249f2 100644 --- a/common/sphinx.c +++ b/common/sphinx.c @@ -144,7 +144,7 @@ static void sphinx_add_tlv_hop(struct sphinx_path *path, const struct tlv_tlv_payload *tlv) { u8 *tlvs = tal_arr(path, u8, 0); - towire_tlvs(&tlvs, tlvs_tlv_payload, TLVS_TLV_PAYLOAD_ARRAY_SIZE, tlv); + towire_tlv_payload(&tlvs, tlv); sphinx_add_raw_hop(path, pubkey, SPHINX_TLV_PAYLOAD, tlvs); } diff --git a/common/test/run-sphinx.c b/common/test/run-sphinx.c index 923ffe1fe..a1161620a 100644 --- a/common/test/run-sphinx.c +++ b/common/test/run-sphinx.c @@ -43,12 +43,6 @@ size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNN /* Generated stub for bigsize_put */ size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED) { fprintf(stderr, "bigsize_put called!\n"); abort(); } -/* Generated stub for towire_tlvs */ -void towire_tlvs(u8 **pptr UNNEEDED, - const struct tlv_record_type types[] UNNEEDED, - size_t num_types UNNEEDED, - const void *record UNNEEDED) -{ fprintf(stderr, "towire_tlvs called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ secp256k1_context *secp256k1_ctx; diff --git a/tools/gen/impl_template b/tools/gen/impl_template index 4345ad098..c540466c4 100644 --- a/tools/gen/impl_template +++ b/tools/gen/impl_template @@ -409,7 +409,7 @@ u8 *towire_${msg.name}(const tal_t *ctx${''.join([f.arg_desc_to() for f in msg.f % endif % endif % elif f.type_obj.is_tlv(): - towire_tlvs(&p, tlvs_${f.type_obj.tlv.name}, ARRAY_SIZE(tlvs_${f.type_obj.tlv.name}), ${f.name}); + towire_${f.type_obj.tlv.name}(&p, ${f.name}); % elif f.is_optional: ## is optional? if (!${f.name}) towire_bool(&p, false); diff --git a/wire/test/run-tlvstream.c b/wire/test/run-tlvstream.c index bd07ce603..90a4bf43a 100644 --- a/wire/test/run-tlvstream.c +++ b/wire/test/run-tlvstream.c @@ -524,7 +524,7 @@ int main(void) continue; p2 = tal_arr(tmpctx, u8, 0); - towire_tlvs(&p2, tlvs_n1, TLVS_N1_ARRAY_SIZE, tlv_n1); + towire_n1(&p2, tlv_n1); assert(memeq(p2, tal_count(p2), orig_p, tal_count(orig_p))); } @@ -620,7 +620,7 @@ int main(void) continue; u8 *p2 = tal_arr(tmpctx, u8, 0); - towire_tlvs(&p2, tlvs_n1, TLVS_N1_ARRAY_SIZE, tlv_n1); + towire_n1(&p2, tlv_n1); assert(memeq(orig_p, tal_count(orig_p), p2, tal_count(p2))); }