plugin: Add function to collect featurebits that plugins registered

This commit is contained in:
Christian Decker 2020-01-30 15:41:40 +01:00 committed by Rusty Russell
parent 9b976da3bc
commit 532bf1730f
2 changed files with 17 additions and 0 deletions

View File

@ -3,6 +3,7 @@
#include <ccan/opt/opt.h>
#include <ccan/tal/str/str.h>
#include <ccan/utf8/utf8.h>
#include <common/features.h>
#include <common/utils.h>
#include <common/version.h>
#include <lightningd/json.h>
@ -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);

View File

@ -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 */