Browse Source

plugin: Add function to collect featurebits that plugins registered

travis-debug
Christian Decker 5 years ago
committed by Rusty Russell
parent
commit
532bf1730f
  1. 13
      lightningd/plugin.c
  2. 4
      lightningd/plugin.h

13
lightningd/plugin.c

@ -3,6 +3,7 @@
#include <ccan/opt/opt.h> #include <ccan/opt/opt.h>
#include <ccan/tal/str/str.h> #include <ccan/tal/str/str.h>
#include <ccan/utf8/utf8.h> #include <ccan/utf8/utf8.h>
#include <common/features.h>
#include <common/utils.h> #include <common/utils.h>
#include <common/version.h> #include <common/version.h>
#include <lightningd/json.h> #include <lightningd/json.h>
@ -46,6 +47,18 @@ struct plugins *plugins_new(const tal_t *ctx, struct log_book *log_book,
return p; 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) static void destroy_plugin(struct plugin *p)
{ {
plugin_hook_unregister_all(p); plugin_hook_unregister_all(p);

4
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); struct plugin_destroyed *plugin_detect_destruction(const struct plugin *plugin);
bool was_plugin_destroyed(struct plugin_destroyed *destroyed); 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 */ #endif /* LIGHTNING_LIGHTNINGD_PLUGIN_H */

Loading…
Cancel
Save