From 75c6dd19814199a801f49a57f469be43a1e7401b Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 7 Feb 2017 12:14:21 +1030 Subject: [PATCH] channel_config: convenient structure for handling open/accept config info. Signed-off-by: Rusty Russell --- lightningd/Makefile | 1 + lightningd/channel_config.c | 31 +++++++++++++++++++++++++ lightningd/channel_config.h | 46 +++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 lightningd/channel_config.c create mode 100644 lightningd/channel_config.h diff --git a/lightningd/Makefile b/lightningd/Makefile index 00a02a07a..6d4951d2a 100644 --- a/lightningd/Makefile +++ b/lightningd/Makefile @@ -27,6 +27,7 @@ LIGHTNINGD_OLD_OBJS := $(LIGHTNINGD_OLD_SRC:.c=.o) LIGHTNINGD_OLD_HEADERS := $(LIGHTNINGD_OLD_SRC:.c=.h) LIGHTNINGD_LIB_SRC := \ + lightningd/channel_config.c \ lightningd/cryptomsg.c \ lightningd/key_derive.c diff --git a/lightningd/channel_config.c b/lightningd/channel_config.c new file mode 100644 index 000000000..e6b4f26a6 --- /dev/null +++ b/lightningd/channel_config.c @@ -0,0 +1,31 @@ +#include +#include + +void towire_channel_config(u8 **pptr, const struct channel_config *config) +{ + towire_u64(pptr, config->dust_limit_satoshis); + towire_u64(pptr, config->max_htlc_value_in_flight_msat); + towire_u64(pptr, config->channel_reserve_satoshis); + towire_u32(pptr, config->minimum_depth); + towire_u32(pptr, config->htlc_minimum_msat); + towire_u16(pptr, config->to_self_delay); + towire_u16(pptr, config->max_accepted_htlcs); +} + +struct channel_config *fromwire_channel_config(const tal_t *ctx, + const u8 **ptr, size_t *max) +{ + struct channel_config *config = tal(ctx, struct channel_config); + + config->dust_limit_satoshis = fromwire_u64(ptr, max); + config->max_htlc_value_in_flight_msat = fromwire_u64(ptr, max); + config->channel_reserve_satoshis = fromwire_u64(ptr, max); + config->minimum_depth = fromwire_u32(ptr, max); + config->htlc_minimum_msat = fromwire_u32(ptr, max); + config->to_self_delay = fromwire_u16(ptr, max); + config->max_accepted_htlcs = fromwire_u16(ptr, max); + + if (!*ptr) + return tal_free(config); + return config; +} diff --git a/lightningd/channel_config.h b/lightningd/channel_config.h new file mode 100644 index 000000000..7d1e7c4a9 --- /dev/null +++ b/lightningd/channel_config.h @@ -0,0 +1,46 @@ +#ifndef LIGHTNING_LIGHTNINGD_CHANNEL_CONFIG_H +#define LIGHTNING_LIGHTNINGD_CHANNEL_CONFIG_H +#include "config.h" +#include +#include + +/* BOLT #2: + * + * 1. type: 32 (`open_channel`) + * 2. data: + * * [8:temporary-channel-id] + * * [8:funding-satoshis] + * * [8:push-msat] + * * [8:dust-limit-satoshis] + * * [8:max-htlc-value-in-flight-msat] + * * [8:channel-reserve-satoshis] + * * [4:htlc-minimum-msat] + * * [4:feerate-per-kw] + * * [2:to-self-delay] + * * [2:max-accepted-htlcs] + *... + * 1. type: 33 (`accept_channel`) + * 2. data: + * * [8:temporary-channel-id] + * * [8:dust-limit-satoshis] + * * [8:max-htlc-value-in-flight-msat] + * * [8:channel-reserve-satoshis] + * * [4:minimum-depth] + * * [4:htlc-minimum-msat] + * * [2:to-self-delay] + * * [2:max-accepted-htlcs] + */ +struct channel_config { + u64 dust_limit_satoshis; + u64 max_htlc_value_in_flight_msat; + u64 channel_reserve_satoshis; + u32 minimum_depth; + u32 htlc_minimum_msat; + u16 to_self_delay; + u16 max_accepted_htlcs; +}; + +void towire_channel_config(u8 **pptr, const struct channel_config *config); +struct channel_config *fromwire_channel_config(const tal_t *ctx, + const u8 **ptr, size_t *max); +#endif /* LIGHTNING_LIGHTNINGD_CHANNEL_CONFIG_H */