mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-01 09:40:19 +01:00
tlv: Add sorting of the tlvstream
So far we didn't need this since we were adding them in the correct order. Now we have multiple possible origins so we better sort them.
This commit is contained in:
parent
45607577b9
commit
aba9af9e12
2 changed files with 11 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <ccan/asort/asort.h>
|
||||||
#include <common/bigsize.h>
|
#include <common/bigsize.h>
|
||||||
#include <wire/tlvstream.h>
|
#include <wire/tlvstream.h>
|
||||||
#include <wire/wire.h>
|
#include <wire/wire.h>
|
||||||
|
@ -8,11 +9,19 @@
|
||||||
#define SUPERVERBOSE(...)
|
#define SUPERVERBOSE(...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void towire_tlvstream_raw(u8 **pptr, const struct tlv_field *fields)
|
static int tlv_field_cmp(const struct tlv_field *a, const struct tlv_field *b,
|
||||||
|
void *x)
|
||||||
|
{
|
||||||
|
return a->numtype > b->numtype ? 1 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void towire_tlvstream_raw(u8 **pptr, struct tlv_field *fields)
|
||||||
{
|
{
|
||||||
if (!fields)
|
if (!fields)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
asort(fields, tal_count(fields), tlv_field_cmp, NULL);
|
||||||
|
|
||||||
for (size_t i = 0; i < tal_count(fields); i++) {
|
for (size_t i = 0; i < tal_count(fields); i++) {
|
||||||
const struct tlv_field *field = &fields[i];
|
const struct tlv_field *field = &fields[i];
|
||||||
/* BOLT #1:
|
/* BOLT #1:
|
||||||
|
|
|
@ -28,7 +28,7 @@ struct tlv_field {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Given any tlvstream serialize the raw fields (untyped ones). */
|
/* Given any tlvstream serialize the raw fields (untyped ones). */
|
||||||
void towire_tlvstream_raw(u8 **pptr, const struct tlv_field *fields);
|
void towire_tlvstream_raw(u8 **pptr, struct tlv_field *fields);
|
||||||
|
|
||||||
/* Given a tlv record with manually-set fields, populate ->fields */
|
/* Given a tlv record with manually-set fields, populate ->fields */
|
||||||
#define tlv_make_fields(tlv, type) \
|
#define tlv_make_fields(tlv, type) \
|
||||||
|
|
Loading…
Add table
Reference in a new issue