plugin: Add a list of notification topics registered by plugin

We will eventually start emitting and dispatching custom notifications
from plugins just like we dispatch internal notifications. In order to
get reasonable error messages we need to make sure that the topics
plugins are asking for were correctly registered. When doing this we
don't really care about whether the plugin that registered the
notification is still alive or not (it might have died, but
subscribers should stay up and running), so we keep a list of all
topics attached to the `struct plugins` which gathers global plugin
information.
This commit is contained in:
Christian Decker
2021-04-27 15:15:09 +02:00
committed by Rusty Russell
parent 29155c2fe8
commit 083b41f090
7 changed files with 80 additions and 9 deletions

View File

@@ -0,0 +1,21 @@
#!/usr/bin/env python3
from pyln.client import Plugin
plugin = Plugin()
@plugin.subscribe("custom")
def on_custom_notification(val, plugin, **kwargs):
plugin.log("Got a custom notification {}".format(val))
@plugin.method("emit")
def emit(plugin):
"""Emit a simple string notification to topic "custom"
"""
plugin.notify("custom", "Hello world")
plugin.add_notification_topic("custom")
plugin.run()