From 3eecbaee4da4c3a798b0700ab81d1435176205e4 Mon Sep 17 00:00:00 2001 From: niftynei Date: Tue, 10 Jan 2023 14:57:17 -0600 Subject: [PATCH] tx_roles: allow to be serialized btw processes We're going to use this in a bit to pass role type btw dualopend/lightningd --- common/Makefile | 4 ++-- common/tx_roles.c | 18 ++++++++++++++++++ common/tx_roles.h | 5 +++++ lightningd/Makefile | 1 + openingd/Makefile | 1 + openingd/dualopend_wire.csv | 1 + 6 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 common/tx_roles.c diff --git a/common/Makefile b/common/Makefile index 273bd153c..8b63eb3ca 100644 --- a/common/Makefile +++ b/common/Makefile @@ -87,6 +87,7 @@ COMMON_SRC_NOGEN := \ common/status_wire.c \ common/subdaemon.c \ common/timeout.c \ + common/tx_roles.c \ common/type_to_string.c \ common/utils.c \ common/utxo.c \ @@ -108,8 +109,7 @@ COMMON_HEADERS_NOGEN := $(COMMON_SRC_NOGEN:.c=.h) \ common/htlc.h \ common/json_command.h \ common/jsonrpc_errors.h \ - common/overflows.h \ - common/tx_roles.h + common/overflows.h COMMON_HEADERS_GEN := common/htlc_state_names_gen.h common/status_wiregen.h common/peer_status_wiregen.h common/scb_wiregen.h diff --git a/common/tx_roles.c b/common/tx_roles.c new file mode 100644 index 000000000..541deb7b0 --- /dev/null +++ b/common/tx_roles.c @@ -0,0 +1,18 @@ +#include "config.h" +#include +#include + +void towire_tx_role(u8 **pptr, const enum tx_role tx_role) +{ + towire_u8(pptr, tx_role); +} + +enum tx_role fromwire_tx_role(const u8 **cursor, size_t *max) +{ + u8 tx_role = fromwire_u8(cursor, max); + if (tx_role >= NUM_TX_ROLES) { + tx_role = TX_INITIATOR; + fromwire_fail(cursor, max); + } + return tx_role; +} diff --git a/common/tx_roles.h b/common/tx_roles.h index 5a65dbc10..9b7b5bbb9 100644 --- a/common/tx_roles.h +++ b/common/tx_roles.h @@ -2,6 +2,8 @@ #define LIGHTNING_COMMON_TX_ROLES_H #include "config.h" +#include +#include #define NUM_TX_ROLES (TX_ACCEPTER + 1) enum tx_role { @@ -9,4 +11,7 @@ enum tx_role { TX_ACCEPTER, }; + +void towire_tx_role(u8 **pptr, const enum tx_role tx_role); +enum tx_role fromwire_tx_role(const u8 **cursor, size_t *max); #endif /* LIGHTNING_COMMON_TX_ROLES_H */ diff --git a/lightningd/Makefile b/lightningd/Makefile index 0e2418be1..11dbaaf7a 100644 --- a/lightningd/Makefile +++ b/lightningd/Makefile @@ -126,6 +126,7 @@ LIGHTNINGD_COMMON_OBJS := \ common/sphinx.o \ common/status_wire.o \ common/timeout.o \ + common/tx_roles.o \ common/type_to_string.o \ common/utils.o \ common/utxo.o \ diff --git a/openingd/Makefile b/openingd/Makefile index 1da236ac3..100525c2e 100644 --- a/openingd/Makefile +++ b/openingd/Makefile @@ -77,6 +77,7 @@ OPENINGD_COMMON_OBJS := \ common/status_wire.o \ common/status_wiregen.o \ common/subdaemon.o \ + common/tx_roles.o \ common/type_to_string.o \ common/utils.o \ common/utxo.o \ diff --git a/openingd/dualopend_wire.csv b/openingd/dualopend_wire.csv index c5050b3c8..c9bffc2fd 100644 --- a/openingd/dualopend_wire.csv +++ b/openingd/dualopend_wire.csv @@ -9,6 +9,7 @@ #include #include #include +#include #include #include