From f963a6a5514760b85ed97e33215822f065c5154d Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Wed, 28 Apr 2021 17:28:27 +0200 Subject: [PATCH] libplugin: Add notification topics to plugin_main --- plugins/autoclean.c | 2 +- plugins/bcli.c | 2 +- plugins/fetchinvoice.c | 1 + plugins/keysend.c | 2 +- plugins/libplugin.c | 13 ++++++++++--- plugins/libplugin.h | 2 ++ plugins/offers.c | 2 +- plugins/pay.c | 1 + plugins/spender/main.c | 1 + plugins/txprepare.c | 2 +- tests/plugins/test_libplugin.c | 1 + 11 files changed, 21 insertions(+), 8 deletions(-) diff --git a/plugins/autoclean.c b/plugins/autoclean.c index 93b71923e..21f0c8d30 100644 --- a/plugins/autoclean.c +++ b/plugins/autoclean.c @@ -91,7 +91,7 @@ int main(int argc, char *argv[]) { setup_locale(); plugin_main(argv, init, PLUGIN_STATIC, true, NULL, commands, ARRAY_SIZE(commands), - NULL, 0, NULL, 0, + NULL, 0, NULL, 0, NULL, 0, plugin_option("autocleaninvoice-cycle", "string", "Perform cleanup of expired invoices every" diff --git a/plugins/bcli.c b/plugins/bcli.c index ea1ab0013..e19aee2e5 100644 --- a/plugins/bcli.c +++ b/plugins/bcli.c @@ -972,7 +972,7 @@ int main(int argc, char *argv[]) plugin_main(argv, init, PLUGIN_STATIC, false /* Do not init RPC on startup*/, NULL, commands, ARRAY_SIZE(commands), - NULL, 0, NULL, 0, + NULL, 0, NULL, 0, NULL, 0, plugin_option("bitcoin-datadir", "string", "-datadir arg for bitcoin-cli", diff --git a/plugins/fetchinvoice.c b/plugins/fetchinvoice.c index 311ba99b0..598aab0a3 100644 --- a/plugins/fetchinvoice.c +++ b/plugins/fetchinvoice.c @@ -1389,6 +1389,7 @@ int main(int argc, char *argv[]) /* No notifications */ NULL, 0, hooks, ARRAY_SIZE(hooks), + NULL, 0, /* No options */ NULL); } diff --git a/plugins/keysend.c b/plugins/keysend.c index ef6533440..69cf7e38b 100644 --- a/plugins/keysend.c +++ b/plugins/keysend.c @@ -388,5 +388,5 @@ int main(int argc, char *argv[]) plugin_main(argv, init, PLUGIN_STATIC, true, &features, commands, ARRAY_SIZE(commands), NULL, 0, hooks, ARRAY_SIZE(hooks), - NULL); + NULL, 0, NULL); } diff --git a/plugins/libplugin.c b/plugins/libplugin.c index 487208cef..8e1a69635 100644 --- a/plugins/libplugin.c +++ b/plugins/libplugin.c @@ -92,7 +92,8 @@ struct plugin { * initialization or need to recover from a disconnect. */ const char *rpc_location; - char **notification_topics; + const char **notif_topics; + size_t num_notif_topics; }; /* command_result is mainly used as a compile-time check to encourage you @@ -1318,6 +1319,8 @@ static struct plugin *new_plugin(const tal_t *ctx, size_t num_notif_subs, const struct plugin_hook *hook_subs, size_t num_hook_subs, + const char **notif_topics, + size_t num_notif_topics, va_list ap) { const char *optname; @@ -1355,6 +1358,8 @@ static struct plugin *new_plugin(const tal_t *ctx, p->commands = commands; p->num_commands = num_commands; + p->notif_topics = notif_topics; + p->num_notif_topics = num_notif_topics; p->notif_subs = notif_subs; p->num_notif_subs = num_notif_subs; p->hook_subs = hook_subs; @@ -1387,6 +1392,8 @@ void plugin_main(char *argv[], size_t num_notif_subs, const struct plugin_hook *hook_subs, size_t num_hook_subs, + const char **notif_topics, + size_t num_notif_topics, ...) { struct plugin *plugin; @@ -1399,10 +1406,10 @@ void plugin_main(char *argv[], /* Note this already prints to stderr, which is enough for now */ daemon_setup(argv[0], NULL, NULL); - va_start(ap, num_hook_subs); + va_start(ap, num_notif_topics); plugin = new_plugin(NULL, init, restartability, init_rpc, features, commands, num_commands, notif_subs, num_notif_subs, hook_subs, - num_hook_subs, ap); + num_hook_subs, notif_topics, num_notif_topics, ap); va_end(ap); setup_command_usage(plugin); diff --git a/plugins/libplugin.h b/plugins/libplugin.h index ee6197399..99840da39 100644 --- a/plugins/libplugin.h +++ b/plugins/libplugin.h @@ -293,6 +293,8 @@ void NORETURN LAST_ARG_NULL plugin_main(char *argv[], size_t num_notif_subs, const struct plugin_hook *hook_subs, size_t num_hook_subs, + const char **notif_topics, + size_t num_notif_topics, ...); struct listpeers_channel { diff --git a/plugins/offers.c b/plugins/offers.c index 17117eef9..5bf5a5da1 100644 --- a/plugins/offers.c +++ b/plugins/offers.c @@ -722,5 +722,5 @@ int main(int argc, char *argv[]) setenv("TZ", "", 1); plugin_main(argv, init, PLUGIN_RESTARTABLE, true, NULL, commands, ARRAY_SIZE(commands), NULL, 0, hooks, ARRAY_SIZE(hooks), - NULL); + NULL, 0, NULL); } diff --git a/plugins/pay.c b/plugins/pay.c index 189ebbbf7..f5ce5f4ee 100644 --- a/plugins/pay.c +++ b/plugins/pay.c @@ -2198,6 +2198,7 @@ int main(int argc, char *argv[]) setup_locale(); plugin_main(argv, init, PLUGIN_RESTARTABLE, true, NULL, commands, ARRAY_SIZE(commands), NULL, 0, NULL, 0, + NULL, 0, plugin_option("disable-mpp", "flag", "Disable multi-part payments.", flag_option, &disablempp), diff --git a/plugins/spender/main.c b/plugins/spender/main.c index 86beee723..90264ca53 100644 --- a/plugins/spender/main.c +++ b/plugins/spender/main.c @@ -39,6 +39,7 @@ int main(int argc, char **argv) commands, tal_count(commands), notifs, tal_count(notifs), NULL, 0, + NULL, 0, /* Notification topics */ NULL); tal_free(owner); diff --git a/plugins/txprepare.c b/plugins/txprepare.c index 4300bfe23..64e9b4832 100644 --- a/plugins/txprepare.c +++ b/plugins/txprepare.c @@ -553,5 +553,5 @@ int main(int argc, char *argv[]) { setup_locale(); plugin_main(argv, NULL, PLUGIN_RESTARTABLE, true, NULL, commands, - ARRAY_SIZE(commands), NULL, 0, NULL, 0, NULL); + ARRAY_SIZE(commands), NULL, 0, NULL, 0, NULL, 0, NULL); } diff --git a/tests/plugins/test_libplugin.c b/tests/plugins/test_libplugin.c index cbccaa222..6197116d8 100644 --- a/tests/plugins/test_libplugin.c +++ b/tests/plugins/test_libplugin.c @@ -146,6 +146,7 @@ int main(int argc, char *argv[]) plugin_main(argv, init, PLUGIN_RESTARTABLE, true, NULL, commands, ARRAY_SIZE(commands), notifs, ARRAY_SIZE(notifs), hooks, ARRAY_SIZE(hooks), + NULL, 0, /* Notification topics we publish */ plugin_option("name", "string", "Who to say hello to.",