Skip to content

Commit 5813567

Browse files
committed
plugin: Dispatch notifications to subscribed plugins
Signed-off-by: Christian Decker <decker.christian@gmail.com>
1 parent 37b2f90 commit 5813567

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lightningd/plugin.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,3 +1054,28 @@ void json_add_opt_plugins(struct json_stream *response,
10541054
json_add_string(response, "plugin", p->cmd);
10551055
}
10561056
}
1057+
1058+
/**
1059+
* Determine whether a plugin is subscribed to a given topic/method.
1060+
*/
1061+
static bool plugin_subscriptions_contains(struct plugin *plugin,
1062+
const char *method)
1063+
{
1064+
for (size_t i = 0; i < tal_count(plugin->subscriptions); i++)
1065+
if (streq(method, plugin->subscriptions[i]))
1066+
return true;
1067+
1068+
return false;
1069+
}
1070+
1071+
void plugins_notify(struct plugins *plugins,
1072+
const struct jsonrpc_notification *n TAKES)
1073+
{
1074+
struct plugin *p;
1075+
list_for_each(&plugins->plugins, p, list) {
1076+
if (plugin_subscriptions_contains(p, n->method))
1077+
plugin_send(p, json_stream_dup(p, n->stream));
1078+
}
1079+
if (taken(n))
1080+
tal_free(n);
1081+
}

lightningd/plugin.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,7 @@ char *add_plugin_dir(struct plugins *plugins, const char *dir,
7979
*/
8080
void clear_plugins(struct plugins *plugins);
8181

82+
void plugins_notify(struct plugins *plugins,
83+
const struct jsonrpc_notification *n TAKES);
84+
8285
#endif /* LIGHTNING_LIGHTNINGD_PLUGIN_H */

0 commit comments

Comments
 (0)