From 532bf1730f3f852f7452840205136a42eeb574d2 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 30 Jan 2020 15:41:40 +0100 Subject: [PATCH] plugin: Add function to collect featurebits that plugins registered --- lightningd/plugin.c | 13 +++++++++++++ lightningd/plugin.h | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/lightningd/plugin.c b/lightningd/plugin.c index b9a3845f2..8675290d3 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -46,6 +47,18 @@ struct plugins *plugins_new(const tal_t *ctx, struct log_book *log_book, return p; } +u8 *plugins_collect_featurebits(const tal_t *ctx, const struct plugins *plugins, + enum plugin_features_type type) +{ + struct plugin *p; + u8 *res = tal_arr(ctx, u8, 0); + list_for_each(&plugins->plugins, p, list) { + if (p->featurebits[type]) + res = featurebits_or(ctx, take(res), p->featurebits[type]); + } + return res; +} + static void destroy_plugin(struct plugin *p) { plugin_hook_unregister_all(p); diff --git a/lightningd/plugin.h b/lightningd/plugin.h index da26c7d3e..aa89f902b 100644 --- a/lightningd/plugin.h +++ b/lightningd/plugin.h @@ -266,4 +266,8 @@ struct log *plugin_get_log(struct plugin *plugin); struct plugin_destroyed *plugin_detect_destruction(const struct plugin *plugin); bool was_plugin_destroyed(struct plugin_destroyed *destroyed); +/* Gather all the features of the given type that plugins registered. */ +u8 *plugins_collect_featurebits(const tal_t *ctx, const struct plugins *plugins, + enum plugin_features_type type); + #endif /* LIGHTNING_LIGHTNINGD_PLUGIN_H */